Skip to content

Commit 0632284

Browse files
committed
Code cleanup
1 parent 58ff6ba commit 0632284

File tree

7 files changed

+21
-16
lines changed

7 files changed

+21
-16
lines changed

math/math.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,10 @@ template <typename ResultType, typename... Args>
115115
constexpr ResultType arithmeticMean(Args&&... args) noexcept
116116
{
117117
ResultType acc = ResultType(0);
118-
size_t n = 0;
118+
constexpr size_t n = sizeof...(Args);
119119

120120
pack::for_value([&](auto&& value) {
121121
acc += value;
122-
++n;
123122
}, std::forward<Args>(args)...);
124123

125124
return acc / n;

parameter_pack/parameter_pack_helpers.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#pragma once
22

33
#include "../utility/constexpr_algorithms.hpp"
4-
#include "../utility/integer_literals.hpp"
54
#include "../utility/optional_consteval.hpp"
6-
#include "../utility/template_magic.hpp"
75

86
#include <tuple>
97
#include <type_traits>

tests/test-app/constexpr_algos_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "3rdparty/catch2/catch.hpp"
2-
#include "utility/constexpr_algorithms.hpp"
32
#include "tuple/tuple_helpers.hpp"
3+
#include "utility/constexpr_algorithms.hpp"
4+
#include "utility/template_magic.hpp"
45

56
#include <array>
67
#include <numeric>

tests/test-app/math_tests.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
#include "3rdparty/catch2/catch.hpp"
22
#include "math/math.hpp"
33

4-
TEST_CASE("pow2")
4+
TEST_CASE("pow2", "[math]")
55
{
66
uint64_t p = 2;
77
for (uint64_t i = 1; i < 63; ++i, p *= 2)
88
CHECK(Math::pow2(i) == p);
99

1010
static_assert(Math::pow2(16) == 65536);
1111
}
12+
13+
TEST_CASE("arithmeticMean", "[math]")
14+
{
15+
REQUIRE(Math::arithmeticMean<int>(2, 4, 6) == 4);
16+
REQUIRE(Math::arithmeticMean<float>(2, 1) == 1.5f);
17+
18+
static_assert(Math::arithmeticMean<int>(99, 1, 0, 4) == 26);
19+
}

tests/test-app/odd_sized_integer_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "utility/odd_sized_integer.hpp"
44
#include "math/math.hpp"
55

6-
TEST_CASE("Construction from and conversion to regular integer")
6+
TEST_CASE("Construction from and conversion to regular integer", "[odd_sized_integer]")
77
{
88
static constexpr size_t N = 3;
99

@@ -20,7 +20,7 @@ TEST_CASE("Construction from and conversion to regular integer")
2020
}
2121
}
2222

23-
TEST_CASE("Copy construction")
23+
TEST_CASE("Copy construction", "[odd_sized_integer]")
2424
{
2525
odd_sized_integer<5> oi {5};
2626
const auto oi2 = oi;
@@ -29,15 +29,15 @@ TEST_CASE("Copy construction")
2929
REQUIRE(oi2 == 5);
3030
}
3131

32-
TEST_CASE("Move construction")
32+
TEST_CASE("Move construction", "[odd_sized_integer]")
3333
{
3434
odd_sized_integer<5> oi {5};
3535
const auto oi2 = std::move(oi);
3636

3737
REQUIRE(oi2 == 5);
3838
}
3939

40-
TEST_CASE("Assignemnt and move assignment")
40+
TEST_CASE("Assignemnt and move assignment", "[odd_sized_integer]")
4141
{
4242
odd_sized_integer<5> oi {5};
4343

@@ -53,7 +53,7 @@ TEST_CASE("Assignemnt and move assignment")
5353
CHECK(oi == 500'000);
5454
}
5555

56-
TEST_CASE("comparison operators")
56+
TEST_CASE("comparison operators", "[odd_sized_integer]")
5757
{
5858
odd_sized_integer<7> o1 {7};
5959
odd_sized_integer<7> o2 {7'000'000'000ULL};
@@ -90,7 +90,7 @@ TEST_CASE("comparison operators")
9090
CHECK(!(o2 != o3.toUi64()));
9191
}
9292

93-
TEST_CASE("Arithmetics")
93+
TEST_CASE("Arithmetics", "[odd_sized_integer]")
9494
{
9595
odd_sized_integer<7> oi {7};
9696
CHECK(oi + 10 == 17);

utility/constexpr_algorithms.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma once
2-
#include "template_magic.hpp"
32

43
#include <type_traits>
54
#include <utility>
@@ -46,7 +45,7 @@ constexpr void constexpr_for_fold([[maybe_unused]] Functor&& f) noexcept
4645
{
4746
if constexpr (First < Last)
4847
{
49-
static_assert(std::is_same_v<void, decltype(f. template operator() < First > ())>, "This implementation does not take return value into account!");
48+
static_assert(std::is_same_v<void, decltype(f. template operator()<First>())>, "This implementation does not take return value into account!");
5049
detail::constexpr_for_fold_impl<First>(std::forward<Functor>(f), std::make_index_sequence<Last - First>{});
5150
}
5251
}

utility/optional_consteval.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
// std::optional has very limited constexpr support C++20 and earlier standards.
4-
// This is a consteval class that implements std::optional interface.
3+
// std::optional has very limited constexpr support in C++20 and earlier standards.
4+
// This is a consteval class that implements std::optional interface for use in compile-time calculations.
55

66
template <typename T>
77
class optional_consteval {

0 commit comments

Comments
 (0)