Update some 2015 sources to .clang-tidy

This commit is contained in:
2021-12-02 19:57:58 +00:00
parent 7ab7ecb00a
commit 9ecc3ff53d
27 changed files with 305 additions and 336 deletions

View File

@@ -2,7 +2,6 @@
#include <cassert>
#include <iostream>
#include <regex>
#include <set>
#include <string>
enum class Action { TurnOn, Toggle, TurnOff };
@@ -12,9 +11,9 @@ using Point = std::pair<unsigned, unsigned>;
/// A command
struct Command
{
Command(std::string const& s)
explicit Command(std::string const& s)
{
const char* re = "(turn on|toggle|turn off)\\s(\\d+),(\\d+)\\sthrough\\s(\\d+),(\\d+)";
const char* re = R"((turn on|toggle|turn off)\s(\d+),(\d+)\sthrough\s(\d+),(\d+))";
std::smatch m;
if (!std::regex_search(s, m, std::regex(re))) {
std::cerr << "Unable to interpret:" << s << "\n";
@@ -51,7 +50,7 @@ struct Array
{
for (unsigned i = 0; i < N; ++i) {
for (unsigned j = 0; j < N; ++j) {
lights_[i][j] = false;
lights_[i][j] = false; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
}
}
}
@@ -68,13 +67,14 @@ struct Array
for (unsigned j = command.bottom_left_.second; j <= command.top_right_.second; ++j) {
switch (command.act_) {
case Action::TurnOn:
lights_[i][j] = true;
lights_[i][j] = true; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
break;
case Action::Toggle:
lights_[i][j] = !lights_[i][j];
lights_[i][j] = // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
!lights_[i][j]; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
break;
case Action::TurnOff:
lights_[i][j] = false;
lights_[i][j] = false; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
break;
}
}
@@ -82,12 +82,12 @@ struct Array
}
/// How many lights are on
unsigned num_on() const noexcept
[[nodiscard]] auto num_on() const noexcept -> unsigned
{
unsigned count = 0;
for (unsigned i = 0; i < N; ++i) {
for (unsigned j = 0; j < N; ++j) {
count += lights_[i][j];
count += lights_[i][j]; // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
}
}
@@ -100,7 +100,9 @@ struct Array
std::cout << "P1\n" << N << " " << N << "\n";
for (unsigned i = 0; i < N; ++i) {
for (unsigned j = 0; j < N; ++j) {
std::cout << (lights_[i][j] ? "1" : "0");
std::cout << (lights_[i][j] // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
? "1"
: "0"); // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
if (j % 70 == 0) {
std::cout << "\n";
}
@@ -109,10 +111,10 @@ struct Array
}
}
bool lights_[N][N];
bool lights_[N][N]{}; // NOLINT(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
};
int main(int argc, char** argv)
auto main() -> int
{
Array<1000> arr;
for (std::string line; std::getline(std::cin, line);) {