Skip to content

Commit 14a8b78

Browse files
refactor: Apply clang-tidy fixes
1 parent c9039c4 commit 14a8b78

5 files changed

Lines changed: 117 additions & 116 deletions

File tree

benchmark/benchmark_main.cpp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <cstdlib>
66
#include <filesystem>
7+
#include <numbers>
78

89
namespace cppfig::bench {
910

@@ -24,7 +25,7 @@ namespace settings {
2425
struct DoubleSetting {
2526
static constexpr std::string_view path = "benchmark.double";
2627
using value_type = double;
27-
static auto default_value() -> double { return 3.14159; }
28+
static auto default_value() -> double { return std::numbers::pi; }
2829
};
2930

3031
struct BoolSetting {
@@ -119,7 +120,7 @@ class BenchmarkFixture : public ::benchmark::Fixture {
119120
return temp_path.string();
120121
}
121122

122-
void RemoveFile(const std::string& path)
123+
static void RemoveFile(const std::string& path)
123124
{
124125
if (std::filesystem::exists(path)) {
125126
std::filesystem::remove(path);
@@ -129,7 +130,7 @@ class BenchmarkFixture : public ::benchmark::Fixture {
129130

130131
BENCHMARK_DEFINE_F(BenchmarkFixture, GetString)(benchmark::State& state)
131132
{
132-
std::string path = CreateTempFile();
133+
const std::string path = CreateTempFile();
133134
Configuration<SmallSchema> config(path);
134135
(void)config.Load();
135136

@@ -144,7 +145,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, GetString);
144145

145146
BENCHMARK_DEFINE_F(BenchmarkFixture, GetInt)(benchmark::State& state)
146147
{
147-
std::string path = CreateTempFile();
148+
const std::string path = CreateTempFile();
148149
Configuration<MediumSchema> config(path);
149150
(void)config.Load();
150151

@@ -159,7 +160,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, GetInt);
159160

160161
BENCHMARK_DEFINE_F(BenchmarkFixture, GetDouble)(benchmark::State& state)
161162
{
162-
std::string path = CreateTempFile();
163+
const std::string path = CreateTempFile();
163164
Configuration<MediumSchema> config(path);
164165
(void)config.Load();
165166

@@ -174,7 +175,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, GetDouble);
174175

175176
BENCHMARK_DEFINE_F(BenchmarkFixture, GetBool)(benchmark::State& state)
176177
{
177-
std::string path = CreateTempFile();
178+
const std::string path = CreateTempFile();
178179
Configuration<MediumSchema> config(path);
179180
(void)config.Load();
180181

@@ -189,7 +190,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, GetBool);
189190

190191
BENCHMARK_DEFINE_F(BenchmarkFixture, GetValidated)(benchmark::State& state)
191192
{
192-
std::string path = CreateTempFile();
193+
const std::string path = CreateTempFile();
193194
Configuration<MediumSchema> config(path);
194195
(void)config.Load();
195196

@@ -204,13 +205,13 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, GetValidated);
204205

205206
BENCHMARK_DEFINE_F(BenchmarkFixture, SetString)(benchmark::State& state)
206207
{
207-
std::string path = CreateTempFile();
208+
const std::string path = CreateTempFile();
208209
Configuration<SmallSchema> config(path);
209210
(void)config.Load();
210211

211212
int counter = 0;
212213
for (auto _ : state) {
213-
std::string value = "value_" + std::to_string(counter++);
214+
const std::string value = "value_" + std::to_string(counter++);
214215
auto status = config.Set<settings::StringSetting>(value);
215216
benchmark::DoNotOptimize(status);
216217
}
@@ -221,7 +222,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, SetString);
221222

222223
BENCHMARK_DEFINE_F(BenchmarkFixture, SetInt)(benchmark::State& state)
223224
{
224-
std::string path = CreateTempFile();
225+
const std::string path = CreateTempFile();
225226
Configuration<MediumSchema> config(path);
226227
(void)config.Load();
227228

@@ -237,7 +238,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, SetInt);
237238

238239
BENCHMARK_DEFINE_F(BenchmarkFixture, SetValidated)(benchmark::State& state)
239240
{
240-
std::string path = CreateTempFile();
241+
const std::string path = CreateTempFile();
241242
Configuration<MediumSchema> config(path);
242243
(void)config.Load();
243244

@@ -252,7 +253,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, SetValidated);
252253

253254
BENCHMARK_DEFINE_F(BenchmarkFixture, LoadSmallSchema)(benchmark::State& state)
254255
{
255-
std::string path = CreateTempFile();
256+
const std::string path = CreateTempFile();
256257

257258
// Create initial file
258259
{
@@ -273,7 +274,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, LoadSmallSchema);
273274

274275
BENCHMARK_DEFINE_F(BenchmarkFixture, LoadMediumSchema)(benchmark::State& state)
275276
{
276-
std::string path = CreateTempFile();
277+
const std::string path = CreateTempFile();
277278

278279
// Create initial file
279280
{
@@ -294,7 +295,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, LoadMediumSchema);
294295

295296
BENCHMARK_DEFINE_F(BenchmarkFixture, LoadLargeSchema)(benchmark::State& state)
296297
{
297-
std::string path = CreateTempFile();
298+
const std::string path = CreateTempFile();
298299

299300
// Create initial file
300301
{
@@ -315,7 +316,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, LoadLargeSchema);
315316

316317
BENCHMARK_DEFINE_F(BenchmarkFixture, SaveSmallSchema)(benchmark::State& state)
317318
{
318-
std::string path = CreateTempFile();
319+
const std::string path = CreateTempFile();
319320
Configuration<SmallSchema> config(path);
320321
(void)config.Load();
321322

@@ -330,7 +331,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, SaveSmallSchema);
330331

331332
BENCHMARK_DEFINE_F(BenchmarkFixture, SaveMediumSchema)(benchmark::State& state)
332333
{
333-
std::string path = CreateTempFile();
334+
const std::string path = CreateTempFile();
334335
Configuration<MediumSchema> config(path);
335336
(void)config.Load();
336337

@@ -345,7 +346,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, SaveMediumSchema);
345346

346347
BENCHMARK_DEFINE_F(BenchmarkFixture, SaveLargeSchema)(benchmark::State& state)
347348
{
348-
std::string path = CreateTempFile();
349+
const std::string path = CreateTempFile();
349350
Configuration<LargeSchema> config(path);
350351
(void)config.Load();
351352

@@ -372,7 +373,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, ValidatorRange);
372373
BENCHMARK_DEFINE_F(BenchmarkFixture, ValidatorNotEmpty)(benchmark::State& state)
373374
{
374375
auto not_empty_validator = cppfig::NotEmpty();
375-
std::string test_value = "test";
376+
const std::string test_value = "test";
376377

377378
for (auto _ : state) {
378379
auto result = not_empty_validator(test_value);
@@ -405,7 +406,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, ValidatorCombined);
405406

406407
BENCHMARK_DEFINE_F(BenchmarkFixture, DiffNoChanges)(benchmark::State& state)
407408
{
408-
std::string path = CreateTempFile();
409+
const std::string path = CreateTempFile();
409410
Configuration<MediumSchema> config(path);
410411
(void)config.Load();
411412

@@ -420,7 +421,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, DiffNoChanges);
420421

421422
BENCHMARK_DEFINE_F(BenchmarkFixture, DiffWithChanges)(benchmark::State& state)
422423
{
423-
std::string path = CreateTempFile();
424+
const std::string path = CreateTempFile();
424425
Configuration<MediumSchema> config(path);
425426
(void)config.Load();
426427

@@ -439,7 +440,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, DiffWithChanges);
439440

440441
BENCHMARK_DEFINE_F(BenchmarkFixture, JsonSerializerParse)(benchmark::State& state)
441442
{
442-
std::string json_str = R"({
443+
const std::string json_str = R"({
443444
"benchmark": {
444445
"string": "test",
445446
"int": 42,
@@ -462,7 +463,7 @@ BENCHMARK_DEFINE_F(BenchmarkFixture, JsonSerializerStringify)(benchmark::State&
462463
auto benchmark_obj = Value::Object();
463464
benchmark_obj["string"] = Value("test");
464465
benchmark_obj["int"] = Value(42);
465-
benchmark_obj["double"] = Value(3.14159);
466+
benchmark_obj["double"] = Value(std::numbers::pi);
466467
benchmark_obj["bool"] = Value(true);
467468
benchmark_obj["validated"] = Value(50);
468469
value["benchmark"] = benchmark_obj;
@@ -483,7 +484,7 @@ BENCHMARK_DEFINE_F(BenchmarkFixture, ValueGetAtPath)(benchmark::State& state)
483484
connection["port"] = Value(5432);
484485
database["connection"] = connection;
485486
value["database"] = database;
486-
std::string path = "database.connection.host";
487+
const std::string path = "database.connection.host";
487488

488489
for (auto _ : state) {
489490
auto result = value.GetAtPath(path);
@@ -501,7 +502,7 @@ BENCHMARK_DEFINE_F(BenchmarkFixture, ValueSetAtPath)(benchmark::State& state)
501502
connection["port"] = Value(5432);
502503
database["connection"] = connection;
503504
value["database"] = database;
504-
std::string path = "database.connection.host";
505+
const std::string path = "database.connection.host";
505506

506507
for (auto _ : state) {
507508
Value value_copy = value;
@@ -522,7 +523,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, TraitsSerializeInt);
522523

523524
BENCHMARK_DEFINE_F(BenchmarkFixture, TraitsDeserializeInt)(benchmark::State& state)
524525
{
525-
Value val(42);
526+
const Value val(42);
526527

527528
for (auto _ : state) {
528529
auto result = ConfigTraits<int>::Deserialize(val);
@@ -533,7 +534,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, TraitsDeserializeInt);
533534

534535
BENCHMARK_DEFINE_F(BenchmarkFixture, TraitsSerializeString)(benchmark::State& state)
535536
{
536-
std::string value = "benchmark_test_string";
537+
const std::string value = "benchmark_test_string";
537538

538539
for (auto _ : state) {
539540
auto val = ConfigTraits<std::string>::Serialize(value);
@@ -544,7 +545,7 @@ BENCHMARK_REGISTER_F(BenchmarkFixture, TraitsSerializeString);
544545

545546
BENCHMARK_DEFINE_F(BenchmarkFixture, TraitsDeserializeString)(benchmark::State& state)
546547
{
547-
Value val("benchmark_test_string");
548+
const Value val("benchmark_test_string");
548549

549550
for (auto _ : state) {
550551
auto result = ConfigTraits<std::string>::Deserialize(val);

examples/basic_example.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,20 @@ int main()
7272
// Load configuration (creates file with defaults if it doesn't exist)
7373
auto status = config.Load();
7474
if (!status.ok()) {
75-
std::cerr << "Failed to load configuration: " << status.message() << std::endl;
75+
std::cerr << "Failed to load configuration: " << status.message() << '\n';
7676
return 1;
7777
}
7878

7979
// Access configuration values - fully type-safe with IDE autocompletion!
8080
std::cout << "Application: " << config.Get<settings::AppName>() << " v" << config.Get<settings::AppVersion>()
81-
<< std::endl;
81+
<< '\n';
8282
std::cout << "Server: " << config.Get<settings::ServerHost>() << ":" << config.Get<settings::ServerPort>()
83-
<< std::endl;
84-
std::cout << "Max connections: " << config.Get<settings::ServerMaxConnections>() << std::endl;
85-
std::cout << "Logging enabled: " << (config.Get<settings::LoggingEnabled>() ? "yes" : "no") << std::endl;
86-
std::cout << "Logging level: " << config.Get<settings::LoggingLevel>() << std::endl;
83+
<< '\n';
84+
std::cout << "Max connections: " << config.Get<settings::ServerMaxConnections>() << '\n';
85+
std::cout << "Logging enabled: " << (config.Get<settings::LoggingEnabled>() ? "yes" : "no") << '\n';
86+
std::cout << "Logging level: " << config.Get<settings::LoggingLevel>() << '\n';
8787
std::cout << "Experimental features: " << (config.Get<settings::FeaturesExperimental>() ? "enabled" : "disabled")
88-
<< std::endl;
88+
<< '\n';
8989

9090
// Show the diff between file and defaults
9191
std::cout << "\n"
@@ -94,23 +94,23 @@ int main()
9494
// Modify a setting (with validation)
9595
status = config.Set<settings::ServerPort>(9000);
9696
if (!status.ok()) {
97-
std::cerr << "Failed to set port: " << status.message() << std::endl;
97+
std::cerr << "Failed to set port: " << status.message() << '\n';
9898
}
9999

100100
// Try to set an invalid value
101101
status = config.Set<settings::ServerPort>(99999); // Out of range!
102102
if (!status.ok()) {
103-
std::cout << "\nExpected validation error: " << status.message() << std::endl;
103+
std::cout << "\nExpected validation error: " << status.message() << '\n';
104104
}
105105

106106
// Save updated configuration
107107
status = config.Save();
108108
if (!status.ok()) {
109-
std::cerr << "Failed to save configuration: " << status.message() << std::endl;
109+
std::cerr << "Failed to save configuration: " << status.message() << '\n';
110110
return 1;
111111
}
112112

113-
std::cout << "\nConfiguration saved to: " << config.GetFilePath() << std::endl;
113+
std::cout << "\nConfiguration saved to: " << config.GetFilePath() << '\n';
114114

115115
return 0;
116116
}

0 commit comments

Comments
 (0)