Skip to content

Commit

Permalink
Add a .clang-tidy file
Browse files Browse the repository at this point in the history
Fix some of the clang-tidy diagnostics, mute a few specific ones. There
are still diagnostics firing with the current configuration, but they
can be ignored for now. This is but a first stone.
  • Loading branch information
Morwenn committed Dec 31, 2023
1 parent a53a0e2 commit bb621a7
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 16 deletions.
8 changes: 3 additions & 5 deletions include/cpp-sort/utility/apply_permutation.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Morwenn
* Copyright (c) 2022-2023 Morwenn
* SPDX-License-Identifier: MIT
*/
#ifndef CPPSORT_UTILITY_APPLY_PERMUTATION_H_
Expand All @@ -13,9 +13,7 @@
#include <cpp-sort/mstd/ranges.h>
#include "../detail/config.h"

namespace cppsort
{
namespace utility
namespace cppsort::utility
{
template<
mstd::random_access_iterator Iterator1,
Expand Down Expand Up @@ -53,6 +51,6 @@ namespace utility
apply_permutation(mstd::begin(range), mstd::end(range),
mstd::begin(indices), mstd::end(indices));
}
}}
}

#endif // CPPSORT_UTILITY_APPLY_PERMUTATION_H_
9 changes: 8 additions & 1 deletion tests/sorters/ska_sorter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2022 Morwenn
* Copyright (c) 2017-2023 Morwenn
* SPDX-License-Identifier: MIT
*/
#include <algorithm>
Expand All @@ -23,6 +23,7 @@ TEST_CASE( "ska_sorter tests", "[ska_sorter]" )
SECTION( "sort with range of int" )
{
std::vector<int> vec;
vec.reserve(100'000);
distribution(std::back_inserter(vec), 100'000);
cppsort::ska_sort(vec);
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -31,6 +32,7 @@ TEST_CASE( "ska_sorter tests", "[ska_sorter]" )
SECTION( "sort with unsigned int iterators" )
{
std::vector<unsigned> vec;
vec.reserve(100'000);
distribution(std::back_inserter(vec), 100'000);
cppsort::ska_sort(vec.begin(), vec.end());
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -40,6 +42,7 @@ TEST_CASE( "ska_sorter tests", "[ska_sorter]" )
SECTION( "sort with range of int128" )
{
std::vector<__int128_t> vec;
vec.reserve(100'000);
distribution(std::back_inserter(vec), 100'000, -10'000);
cppsort::ska_sort(vec);
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -48,6 +51,7 @@ TEST_CASE( "ska_sorter tests", "[ska_sorter]" )
SECTION( "sort with range of unsigned int128" )
{
std::vector<__uint128_t> vec;
vec.reserve(100'000);
distribution(std::back_inserter(vec), 100'000);
cppsort::ska_sort(vec);
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -57,6 +61,7 @@ TEST_CASE( "ska_sorter tests", "[ska_sorter]" )
SECTION( "sort with range of float" )
{
std::vector<float> vec;
vec.reserve(100'000);
distribution.call<float>(std::back_inserter(vec), 100'000);
cppsort::ska_sort(vec);
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -65,6 +70,7 @@ TEST_CASE( "ska_sorter tests", "[ska_sorter]" )
SECTION( "sort with double iterators" )
{
std::vector<double> vec;
vec.reserve(100'000);
distribution.call<double>(std::back_inserter(vec), 100'000);
cppsort::ska_sort(vec.begin(), vec.end());
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -73,6 +79,7 @@ TEST_CASE( "ska_sorter tests", "[ska_sorter]" )
SECTION( "sort with std::string" )
{
std::vector<std::string> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.push_back(std::to_string(i));
}
Expand Down
7 changes: 6 additions & 1 deletion tests/sorters/ska_sorter_projection.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2022 Morwenn
* Copyright (c) 2017-2023 Morwenn
* SPDX-License-Identifier: MIT
*/
#include <algorithm>
Expand All @@ -19,6 +19,7 @@ TEST_CASE( "ska_sorter tests with projections",
SECTION( "sort with range of int" )
{
std::vector<std::pair<int, float>> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(i, float(i));
}
Expand All @@ -31,6 +32,7 @@ TEST_CASE( "ska_sorter tests with projections",
SECTION( "sort with unsigned int iterators" )
{
std::vector<std::pair<unsigned, float>> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(i, float(i));
}
Expand All @@ -43,6 +45,7 @@ TEST_CASE( "ska_sorter tests with projections",
SECTION( "sort with range of float" )
{
std::vector<std::pair<int, float>> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(i, float(i));
}
Expand All @@ -55,6 +58,7 @@ TEST_CASE( "ska_sorter tests with projections",
SECTION( "sort with double iterators" )
{
std::vector<std::pair<int, double>> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(i, double(i));
}
Expand All @@ -69,6 +73,7 @@ TEST_CASE( "ska_sorter tests with projections",
using wrapper = generic_wrapper<std::string>;

std::vector<wrapper> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(std::to_string(i));
}
Expand Down
8 changes: 7 additions & 1 deletion tests/sorters/spread_sorter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2022 Morwenn
* Copyright (c) 2015-2023 Morwenn
* SPDX-License-Identifier: MIT
*/
#include <algorithm>
Expand All @@ -18,6 +18,7 @@ TEST_CASE( "spread_sorter tests", "[spread_sorter]" )
SECTION( "sort with range of int" )
{
std::vector<int> vec;
vec.reserve(100'000);
distribution(std::back_inserter(vec), 100'000);
cppsort::spread_sort(vec);
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -26,6 +27,7 @@ TEST_CASE( "spread_sorter tests", "[spread_sorter]" )
SECTION( "sort with unsigned int iterators" )
{
std::vector<unsigned> vec;
vec.reserve(100'000);
distribution(std::back_inserter(vec), 100'000);
cppsort::spread_sort(vec.begin(), vec.end());
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -34,6 +36,7 @@ TEST_CASE( "spread_sorter tests", "[spread_sorter]" )
SECTION( "sort with range of float" )
{
std::vector<float> vec;
vec.reserve(100'000);
distribution.call<float>(std::back_inserter(vec), 100'000);
cppsort::spread_sort(vec);
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -42,6 +45,7 @@ TEST_CASE( "spread_sorter tests", "[spread_sorter]" )
SECTION( "sort with double iterators" )
{
std::vector<double> vec;
vec.reserve(100'000);
distribution.call<double>(std::back_inserter(vec), 100'000);
cppsort::spread_sort(vec.begin(), vec.end());
CHECK( std::is_sorted(vec.begin(), vec.end()) );
Expand All @@ -50,6 +54,7 @@ TEST_CASE( "spread_sorter tests", "[spread_sorter]" )
SECTION( "sort with std::string" )
{
std::vector<std::string> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.push_back(std::to_string(i));
}
Expand All @@ -66,6 +71,7 @@ TEST_CASE( "spread_sorter tests", "[spread_sorter]" )
SECTION( "reverse sort with std::string" )
{
std::vector<std::string> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.push_back(std::to_string(i));
}
Expand Down
8 changes: 7 additions & 1 deletion tests/sorters/spread_sorter_projection.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2022 Morwenn
* Copyright (c) 2016-2023 Morwenn
* SPDX-License-Identifier: MIT
*/
#include <algorithm>
Expand All @@ -19,6 +19,7 @@ TEST_CASE( "spread_sorter tests with projections",
SECTION( "sort with range of int" )
{
std::vector<std::pair<int, float>> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(i, float(i));
}
Expand All @@ -31,6 +32,7 @@ TEST_CASE( "spread_sorter tests with projections",
SECTION( "sort with unsigned int iterators" )
{
std::vector<std::pair<unsigned, float>> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(i, float(i));
}
Expand All @@ -43,6 +45,7 @@ TEST_CASE( "spread_sorter tests with projections",
SECTION( "sort with range of float" )
{
std::vector<std::pair<int, float>> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(i, float(i));
}
Expand All @@ -55,6 +58,7 @@ TEST_CASE( "spread_sorter tests with projections",
SECTION( "sort with double iterators" )
{
std::vector<std::pair<int, double>> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(i, double(i));
}
Expand All @@ -69,6 +73,7 @@ TEST_CASE( "spread_sorter tests with projections",
using wrapper = generic_wrapper<std::string>;

std::vector<wrapper> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(std::to_string(i));
}
Expand All @@ -83,6 +88,7 @@ TEST_CASE( "spread_sorter tests with projections",
using wrapper = generic_wrapper<std::string>;

std::vector<wrapper> vec;
vec.reserve(100'000);
for (int i = 0 ; i < 100'000 ; ++i) {
vec.emplace_back(std::to_string(i));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testing-tools/random.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Morwenn
* Copyright (c) 2021-2023 Morwenn
* SPDX-License-Identifier: MIT
*/
#ifndef CPPSORT_TESTSUITE_RANDOM_H_
Expand Down Expand Up @@ -136,7 +136,7 @@ namespace hasard // Blame POSIX for picking the good name
//
// Returns a random integer in the range [low, high].
// See *Optimal Discrete Uniform Generation from Coin Flips,
// and Applications* by Jérémie Lumbroso
// and Applications* by Jérémie Lumbroso

template<typename Integer, typename URBG>
auto randint(Integer low, Integer high, URBG& generator)
Expand Down
4 changes: 2 additions & 2 deletions tests/utility/branchless_traits.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2022 Morwenn
* Copyright (c) 2017-2023 Morwenn
* SPDX-License-Identifier: MIT
*/
#include <functional>
Expand Down Expand Up @@ -74,7 +74,7 @@ TEST_CASE( "test that some specific projections are branchless",
struct foobar
{
int foo;
int bar() { return 0; }
auto bar() -> int { return 0; }
};

STATIC_CHECK( is_probably_branchless_projection_v<std::identity, std::string> );
Expand Down
8 changes: 5 additions & 3 deletions tests/utility/chainable_projections.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022 Morwenn
* Copyright (c) 2020-2023 Morwenn
* SPDX-License-Identifier: MIT
*/
#include <algorithm>
Expand All @@ -20,7 +20,8 @@ namespace
struct proj1:
cppsort::utility::projection_base
{
int operator()(int value) const
auto operator()(int value) const
-> int
{
return -value;
}
Expand All @@ -29,7 +30,8 @@ namespace
struct proj2:
cppsort::utility::projection_base
{
int operator()(int value)
auto operator()(int value)
-> int
{
return -value;
}
Expand Down

0 comments on commit bb621a7

Please sign in to comment.