Update clang-format to disallow single line for-loops

This commit is contained in:
Thraix
2026-08-23 12:12:53 +02:00
parent ab6c726ebc
commit 988c5552d0
22 changed files with 79 additions and 40 deletions
+1 -1
View File
@@ -81,7 +81,7 @@ AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: false AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: Never AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true AllowShortLoopsOnASingleLine: false
AllowShortNamespacesOnASingleLine: false AllowShortNamespacesOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: true AlwaysBreakBeforeMultilineStrings: true
+4 -2
View File
@@ -28,7 +28,8 @@ namespace y2021::day08
std::string s; std::string s;
ss >> s; ss >> s;
std::set<char> set; std::set<char> set;
for (char c : s) set.emplace(c); for (char c : s)
set.emplace(c);
signal.numbers.emplace_back(set); signal.numbers.emplace_back(set);
} }
char c; char c;
@@ -38,7 +39,8 @@ namespace y2021::day08
std::string s; std::string s;
ss >> s; ss >> s;
std::set<char> set; std::set<char> set;
for (char c : s) set.emplace(c); for (char c : s)
set.emplace(c);
signal.display.emplace_back(set); signal.display.emplace_back(set);
} }
signals.emplace_back(signal); signals.emplace_back(signal);
+6 -3
View File
@@ -5,7 +5,8 @@ namespace y2021::day11
std::set<Index2D> CalculateFlashing(Array2D<int>& array) std::set<Index2D> CalculateFlashing(Array2D<int>& array)
{ {
for (auto& val : array) val++; for (auto& val : array)
val++;
std::set<Index2D> flashed; std::set<Index2D> flashed;
bool hasChanged = true; bool hasChanged = true;
while (hasChanged) while (hasChanged)
@@ -59,7 +60,8 @@ namespace y2021::day11
{ {
std::set<Index2D> flashed = CalculateFlashing(array); std::set<Index2D> flashed = CalculateFlashing(array);
count += flashed.size(); count += flashed.size();
for (auto& flash : flashed) array[flash] = 0; for (auto& flash : flashed)
array[flash] = 0;
} }
return count; return count;
} }
@@ -74,7 +76,8 @@ namespace y2021::day11
std::set<Index2D> flashed = CalculateFlashing(array); std::set<Index2D> flashed = CalculateFlashing(array);
if (flashed.size() == array.width * array.height) if (flashed.size() == array.width * array.height)
return count; return count;
for (auto& flash : flashed) array[flash] = 0; for (auto& flash : flashed)
array[flash] = 0;
count++; count++;
} }
return count; return count;
+2 -1
View File
@@ -272,7 +272,8 @@ namespace y2021::day18
while (changed) while (changed)
{ {
changed = false; changed = false;
while (node.Explode()) changed = true; while (node.Explode())
changed = true;
if (node.Split()) if (node.Split())
changed = true; changed = true;
} }
+2 -1
View File
@@ -68,7 +68,8 @@ namespace y$1::day11
std::getline(input, str); std::getline(input, str);
std::stringstream ss{str}; std::stringstream ss{str};
ss >> "Starting items: "; ss >> "Starting items: ";
while (std::getline(ss, str, ',')) monkey.items.emplace_back(std::stoi(str)); while (std::getline(ss, str, ','))
monkey.items.emplace_back(std::stoi(str));
} }
{ // operator { // operator
std::getline(input, str); std::getline(input, str);
+2 -1
View File
@@ -77,7 +77,8 @@ namespace y$1::day13
Node node; Node node;
node.nodes = std::stoi(str.substr(index)); node.nodes = std::stoi(str.substr(index));
nodes.emplace_back(node); nodes.emplace_back(node);
while (str[index] >= '0' && str[index] <= '9') index++; while (str[index] >= '0' && str[index] <= '9')
index++;
} }
else else
{ {
+4 -2
View File
@@ -131,7 +131,8 @@ namespace y$1::day22
if (input.directions[i] >= '0' && input.directions[i] <= '9') if (input.directions[i] >= '0' && input.directions[i] <= '9')
{ {
int amount = std::stoi(&input.directions[i]); int amount = std::stoi(&input.directions[i]);
while (input.directions[i] >= '0' && input.directions[i] <= '9') i++; while (input.directions[i] >= '0' && input.directions[i] <= '9')
i++;
for (int j = 0; j < amount; j++) for (int j = 0; j < amount; j++)
{ {
@@ -219,7 +220,8 @@ namespace y$1::day22
if (input.directions[i] >= '0' && input.directions[i] <= '9') if (input.directions[i] >= '0' && input.directions[i] <= '9')
{ {
int amount = std::stoi(&input.directions[i]); int amount = std::stoi(&input.directions[i]);
while (input.directions[i] >= '0' && input.directions[i] <= '9') i++; while (input.directions[i] >= '0' && input.directions[i] <= '9')
i++;
for (int j = 0; j < amount; j++) for (int j = 0; j < amount; j++)
{ {
+2 -1
View File
@@ -39,7 +39,8 @@ namespace y$1::day25
// Convert to base 5 // Convert to base 5
std::string base5 = ""; std::string base5 = "";
int64_t numbers = log(base10) / log(5) + 1; int64_t numbers = log(base10) / log(5) + 1;
for (int i = 0; i < numbers + 1; i++) base5.push_back('0'); for (int i = 0; i < numbers + 1; i++)
base5.push_back('0');
int64_t base5Max = Pow(5, numbers - 2); int64_t base5Max = Pow(5, numbers - 2);
for (int i = 1; i < base5.size(); i++) for (int i = 1; i < base5.size(); i++)
+6 -3
View File
@@ -55,7 +55,8 @@ namespace y2023::day03
if (Helper::IsDigit(array.Get(x, y))) if (Helper::IsDigit(array.Get(x, y)))
{ {
Index2D numberStart = Index2D{x, y}; Index2D numberStart = Index2D{x, y};
while (numberStart.x >= 0 && Helper::IsDigit(array.Get(numberStart))) numberStart.x--; while (numberStart.x >= 0 && Helper::IsDigit(array.Get(numberStart)))
numberStart.x--;
numberStart.x++; numberStart.x++;
int number = GetNumber(array, numberStart); int number = GetNumber(array, numberStart);
@@ -64,7 +65,8 @@ namespace y2023::day03
else else
return firstNum * number; return firstNum * number;
while (x < array.width && Helper::IsDigit(array.Get(x, y))) x++; while (x < array.width && Helper::IsDigit(array.Get(x, y)))
x++;
x--; x--;
} }
} }
@@ -88,7 +90,8 @@ namespace y2023::day03
if (Helper::IsDigit(input.Get(x, y))) if (Helper::IsDigit(input.Get(x, y)))
{ {
int i = 1; int i = 1;
while (x + i < input.width && Helper::IsDigit(input.Get(x + i, y))) i++; while (x + i < input.width && Helper::IsDigit(input.Get(x + i, y)))
i++;
if (HasAdjecent(input, Index2D{x, y}, i)) if (HasAdjecent(input, Index2D{x, y}, i))
{ {
sum += GetNumber(input, Index2D{x, y}); sum += GetNumber(input, Index2D{x, y});
+4 -2
View File
@@ -28,12 +28,14 @@ namespace y2023::day04
std::stringstream ss{str}; std::stringstream ss{str};
ss >> "Card " >> i >> ":"; ss >> "Card " >> i >> ":";
while (ss >> i) game.winning.emplace_back(i); while (ss >> i)
game.winning.emplace_back(i);
ss.clear(); // clear the failbit to be able to read more data ss.clear(); // clear the failbit to be able to read more data
ss >> "|"; ss >> "|";
while (ss >> i) game.numbers.emplace(i); while (ss >> i)
game.numbers.emplace(i);
games.emplace_back(game); games.emplace_back(game);
} }
+2 -1
View File
@@ -82,7 +82,8 @@ namespace y2023::day05
std::stringstream ss{str}; std::stringstream ss{str};
int64_t i; int64_t i;
ss >> "seeds: "; ss >> "seeds: ";
while (ss >> i) plantation.seeds.emplace_back(i); while (ss >> i)
plantation.seeds.emplace_back(i);
std::getline(input, str); std::getline(input, str);
while (std::getline(input, str)) while (std::getline(input, str))
{ {
+2 -1
View File
@@ -18,7 +18,8 @@ namespace y2023::day06
std::stringstream ss{str}; std::stringstream ss{str};
int i; int i;
ss >> "Time: "; ss >> "Time: ";
while (ss >> i) games.emplace_back(i, 0); while (ss >> i)
games.emplace_back(i, 0);
std::getline(input, str); std::getline(input, str);
std::stringstream ss2{str}; std::stringstream ss2{str};
+2 -1
View File
@@ -18,7 +18,8 @@ namespace y2023::day09
std::vector<int> numbers; std::vector<int> numbers;
std::stringstream ss{str}; std::stringstream ss{str};
int i; int i;
while (ss >> i) numbers.emplace_back(i); while (ss >> i)
numbers.emplace_back(i);
ints.emplace_back(numbers); ints.emplace_back(numbers);
} }
+2 -1
View File
@@ -26,7 +26,8 @@ namespace y2024::day03
{ {
int32_t sum = 0; int32_t sum = 0;
std::vector<std::string> matches = Helper::GetAllRegexMatches(input, "mul\\([0-9]*,[0-9]*\\)"); std::vector<std::string> matches = Helper::GetAllRegexMatches(input, "mul\\([0-9]*,[0-9]*\\)");
for (auto& str : matches) sum += Mult(str); for (auto& str : matches)
sum += Mult(str);
return sum; return sum;
} }
+2 -1
View File
@@ -50,7 +50,8 @@ namespace y2024::day07
int64_t Concat(int64_t i1, int64_t i2) int64_t Concat(int64_t i1, int64_t i2)
{ {
int64_t base = 10; int64_t base = 10;
while (i2 >= base) base *= 10; while (i2 >= base)
base *= 10;
return i1 * base + i2; return i1 * base + i2;
} }
+6 -3
View File
@@ -13,7 +13,8 @@ namespace y2024::day11
READ_INPUT(input) READ_INPUT(input)
{ {
Stones stones; Stones stones;
for (auto i : Input::ReadInt64s(input, ' ')) stones[i]++; for (auto i : Input::ReadInt64s(input, ' '))
stones[i]++;
return stones; return stones;
} }
@@ -33,7 +34,8 @@ namespace y2024::day11
{ {
int64_t pow = 1; int64_t pow = 1;
for (int j = 0; j < i; j++) pow *= 10; for (int j = 0; j < i; j++)
pow *= 10;
return pow; return pow;
} }
@@ -74,7 +76,8 @@ namespace y2024::day11
{ {
std::map<int64_t, int64_t> cpy = stones; std::map<int64_t, int64_t> cpy = stones;
for (int i = 0; i < iterations; i++) Step(cpy); for (int i = 0; i < iterations; i++)
Step(cpy);
int64_t sum = 0; int64_t sum = 0;
for (auto& [cur, count] : cpy) for (auto& [cur, count] : cpy)
+2 -1
View File
@@ -21,7 +21,8 @@ namespace y2024::day15
map.map = Input::ReadArray2D(input); map.map = Input::ReadArray2D(input);
std::string str; std::string str;
while (std::getline(input, str)) map.input += str; while (std::getline(input, str))
map.input += str;
return map; return map;
} }
+2 -1
View File
@@ -48,7 +48,8 @@ namespace y2024::day16
Helper::DijkstrasAllVisited(input, std::pair{input.Find('S'), Index2D{1, 0}}, Branch, Goal); Helper::DijkstrasAllVisited(input, std::pair{input.Find('S'), Index2D{1, 0}}, Branch, Goal);
std::set<Index2D> solutions; std::set<Index2D> solutions;
for (const auto& [pos, dir] : allVisited) solutions.emplace(pos); for (const auto& [pos, dir] : allVisited)
solutions.emplace(pos);
return solutions.size(); return solutions.size();
} }
+4 -2
View File
@@ -92,13 +92,15 @@ namespace y2024::day23
FindLargest(input, computers, largest); FindLargest(input, computers, largest);
} }
for (const auto& s : largest) std::cout << s << ","; for (const auto& s : largest)
std::cout << s << ",";
std::cout << std::endl; std::cout << std::endl;
// Some arbitrary solution number to have some form of verification in the code. // Some arbitrary solution number to have some form of verification in the code.
// Sum all letters of the computers (with a=0, b=1, etc) // Sum all letters of the computers (with a=0, b=1, etc)
int64_t sum = 0; int64_t sum = 0;
for (const auto& s : largest) sum += (s[0] - 'a') + (s[1] - 'a'); for (const auto& s : largest)
sum += (s[0] - 'a') + (s[1] - 'a');
return sum; return sum;
} }
+4 -2
View File
@@ -313,7 +313,8 @@ struct Helper
{ {
std::map<State, int> visited; std::map<State, int> visited;
std::multimap<int, std::pair<int, State>> open; std::multimap<int, std::pair<int, State>> open;
for (int i = 0; i < initial.size(); i++) open.emplace(0, std::pair<int, State>{0, initial[i]}); for (int i = 0; i < initial.size(); i++)
open.emplace(0, std::pair<int, State>{0, initial[i]});
while (!open.empty()) while (!open.empty())
{ {
auto it = open.begin(); auto it = open.begin();
@@ -355,7 +356,8 @@ struct Helper
{ {
std::map<State, int> visited; std::map<State, int> visited;
std::multimap<int, std::pair<int, std::vector<State>>> open; std::multimap<int, std::pair<int, std::vector<State>>> open;
for (int i = 0; i < initial.size(); i++) open.emplace(0, std::pair<int, std::vector<State>>{0, {initial[i]}}); for (int i = 0; i < initial.size(); i++)
open.emplace(0, std::pair<int, std::vector<State>>{0, {initial[i]}});
while (!open.empty()) while (!open.empty())
{ {
const auto& [heuristicVal, state] = *open.begin(); const auto& [heuristicVal, state] = *open.begin();
+16 -8
View File
@@ -13,9 +13,11 @@
static std::istream& operator>>(std::istream& stream, char const* pattern) static std::istream& operator>>(std::istream& stream, char const* pattern)
{ {
char c; char c;
while (stream.peek() == ' ') stream.get(c); while (stream.peek() == ' ')
stream.get(c);
while (*pattern != '\0' && stream && *pattern == stream.peek() && stream.get(c)) ++pattern; while (*pattern != '\0' && stream && *pattern == stream.peek() && stream.get(c))
++pattern;
if (*pattern != '\0') if (*pattern != '\0')
stream.setstate(std::ios::failbit); stream.setstate(std::ios::failbit);
@@ -37,7 +39,8 @@ struct Input
break; break;
width = (int)str.length(); width = (int)str.length();
height++; height++;
for (auto c : str) data.emplace_back(c); for (auto c : str)
data.emplace_back(c);
} }
return Array2D<char>(width, height, data); return Array2D<char>(width, height, data);
} }
@@ -52,7 +55,8 @@ struct Input
{ {
width = (int)str.length(); width = (int)str.length();
height++; height++;
for (auto c : str) data.emplace_back(c - '0'); for (auto c : str)
data.emplace_back(c - '0');
} }
return Array2D<int>(width, height, data); return Array2D<int>(width, height, data);
} }
@@ -93,7 +97,8 @@ struct Input
{ {
std::vector<int> ints; std::vector<int> ints;
std::string str; std::string str;
while (getline(input, str, delimiter)) ints.emplace_back(std::atoi(str.c_str())); while (getline(input, str, delimiter))
ints.emplace_back(std::atoi(str.c_str()));
return ints; return ints;
} }
@@ -101,7 +106,8 @@ struct Input
{ {
std::vector<int64_t> ints; std::vector<int64_t> ints;
std::string str; std::string str;
while (getline(input, str, delimiter)) ints.emplace_back(std::atoll(str.c_str())); while (getline(input, str, delimiter))
ints.emplace_back(std::atoll(str.c_str()));
return ints; return ints;
} }
@@ -109,7 +115,8 @@ struct Input
{ {
std::vector<std::string> strings; std::vector<std::string> strings;
std::string str; std::string str;
while (getline(input, str)) strings.emplace_back(str); while (getline(input, str))
strings.emplace_back(str);
return strings; return strings;
} }
@@ -117,7 +124,8 @@ struct Input
{ {
std::string result; std::string result;
std::string str; std::string str;
while (getline(input, str)) result += str + '\n'; while (getline(input, str))
result += str + '\n';
if (!result.empty()) if (!result.empty())
result.pop_back(); result.pop_back();
return result; return result;
+2 -1
View File
@@ -97,7 +97,8 @@ bool JsonUtil::ReadString(const std::string& str, uint64_t& pos, Json& json)
uint64_t stringStart = pos; uint64_t stringStart = pos;
while (true) while (true)
{ {
while (pos < str.size() && str[pos] != '\"') pos++; while (pos < str.size() && str[pos] != '\"')
pos++;
if (pos >= str.size() || str[pos - 1] != '\\') if (pos >= str.size() || str[pos - 1] != '\\')
break; break;
} }