basedOpinionated utility library |
git clone git://git.dimitrijedobrota.com/based.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |
commit | 630d79b6b927b251d8d4b2bd975cf8d2533bcc49 |
parent | 731a0b1a3f91f31037a48f5df9c5c9691a58728a |
author | Dimitrije Dobrota < mail@dimitrijedobrota.com > |
date | Thu, 1 May 2025 20:07:39 +0200 |
Reimplement and test some standrard type_traits
M | include/based/template.hpp | | | + - |
M | test/source/max_test.cpp | | | +++++++++++++++++++++++++++++++++ -------------------------------- |
M | test/source/min_test.cpp | | | +++++++++++++++++++++++++++++++++ -------------------------------- |
3 files changed, 67 insertions(+), 65 deletions(-)
diff --git a/ include/based/template.hpp b/ include/based/template.hpp
@@ -129,7 +129,7 @@
public:
template<typename CallableArg, typename Callable = std::decay_t<CallableArg>>
requires(requires {
!std::same_as<function, Callable>;
!SameAs<function, Callable>;
sizeof(Callable) <= size;
alignof(Callable) <= alignment;
std::is_trivially_destructible_v<Callable>;
diff --git a/ test/source/max_test.cpp b/ test/source/max_test.cpp
@@ -1,18 +1,19 @@
#include <catch2/catch_test_macros.hpp>
#include "based/type_traits.hpp"
#include "based/algorithm.hpp"
TEST_CASE("max(literal, literal) = right", "[algorithm/max]")
{
using res_t = decltype(based::max(3, 4));
REQUIRE(std::same_as<int&&, res_t>);
REQUIRE(based::SameAs<int&&, res_t>);
REQUIRE(based::max(3, 4) == 4);
}
TEST_CASE("max(literal, literal) = left", "[algorithm/max]")
{
using res_t = decltype(based::max(4, 3));
REQUIRE(std::same_as<int&&, res_t>);
REQUIRE(based::SameAs<int&&, res_t>);
REQUIRE(based::max(4, 3) == 4);
}
@@ -21,7 +22,7 @@
TEST_CASE("max(value, literal) = right", "[algorithm/max]")
int a = 3; // NOLINT misc-const-correctness
using res_t = decltype(based::max(a, 4));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::max(a, 4) == 4);
}
@@ -30,7 +31,7 @@
TEST_CASE("max(value, literal) = left", "[algorithm/max]")
int a = 4; // NOLINT misc-const-correctness
using res_t = decltype(based::max(a, 3));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::max(a, 3) == 4);
}
@@ -39,7 +40,7 @@
TEST_CASE("max(literal, value) = right", "[algorithm/max]")
int b = 4; // NOLINT misc-const-correctness
using res_t = decltype(based::max(3, b));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::max(3, b) == 4);
}
@@ -48,7 +49,7 @@
TEST_CASE("max(literal, value) = left", "[algorithm/max]")
int b = 3; // NOLINT misc-const-correctness
using res_t = decltype(based::max(4, b));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::max(4, b) == 4);
}
@@ -58,7 +59,7 @@
TEST_CASE("max(value, value) = right", "[algorithm/max]")
int b = 4;
using res_t = decltype(based::max(a, b));
REQUIRE(std::same_as<int&, res_t>);
REQUIRE(based::SameAs<int&, res_t>);
REQUIRE(based::max(a, b) == 4);
}
@@ -68,7 +69,7 @@
TEST_CASE("max(value, value) = left", "[algorithm/max]")
int b = 3;
using res_t = decltype(based::max(a, b));
REQUIRE(std::same_as<int&, res_t>);
REQUIRE(based::SameAs<int&, res_t>);
REQUIRE(based::max(a, b) == 4);
}
@@ -77,7 +78,7 @@
TEST_CASE("max(const value, literal) = right", "[algorithm/max]")
const int a = 3;
using res_t = decltype(based::max(a, 4));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::max(a, 4) == 4);
}
@@ -86,7 +87,7 @@
TEST_CASE("max(const value, literal) = left", "[algorithm/max]")
const int a = 4;
using res_t = decltype(based::max(a, 3));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::max(a, 3) == 4);
}
@@ -95,7 +96,7 @@
TEST_CASE("max(literal, const value) = right", "[algorithm/max]")
const int b = 4;
using res_t = decltype(based::max(3, b));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::max(3, b) == 4);
}
@@ -104,7 +105,7 @@
TEST_CASE("max(literal, const value) = left", "[algorithm/max]")
const int b = 3;
using res_t = decltype(based::max(4, b));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::max(4, b) == 4);
}
@@ -114,7 +115,7 @@
TEST_CASE("max(const value, const value) = right", "[algorithm/max]")
const int b = 4;
using res_t = decltype(based::max(a, b));
REQUIRE(std::same_as<const int&, res_t>);
REQUIRE(based::SameAs<const int&, res_t>);
REQUIRE(based::max(a, b) == 4);
}
@@ -124,7 +125,7 @@
TEST_CASE("max(const value, const value) = left", "[algorithm/max]")
const int b = 3;
using res_t = decltype(based::max(a, b));
REQUIRE(std::same_as<const int&, res_t>);
REQUIRE(based::SameAs<const int&, res_t>);
REQUIRE(based::max(a, b) == 4);
}
@@ -134,7 +135,7 @@
TEST_CASE("max(value, const value) = right", "[algorithm/max]")
const int b = 4;
using res_t = decltype(based::max(a, b));
REQUIRE(std::same_as<const int&, res_t>);
REQUIRE(based::SameAs<const int&, res_t>);
REQUIRE(based::max(a, b) == 4);
}
@@ -144,7 +145,7 @@
TEST_CASE("max(value, const value) = left", "[algorithm/max]")
const int b = 3;
using res_t = decltype(based::max(a, b));
REQUIRE(std::same_as<const int&, res_t>);
REQUIRE(based::SameAs<const int&, res_t>);
REQUIRE(based::max(a, b) == 4);
}
@@ -154,7 +155,7 @@
TEST_CASE("max(const value, value) = right", "[algorithm/max]")
int b = 4; // NOLINT misc-const-correctness
using res_t = decltype(based::max(a, b));
REQUIRE(std::same_as<const int&, res_t>);
REQUIRE(based::SameAs<const int&, res_t>);
REQUIRE(based::max(a, b) == 4);
}
@@ -164,7 +165,7 @@
TEST_CASE("max(const value, value) = left", "[algorithm/max]")
int b = 3; // NOLINT misc-const-correctness
using res_t = decltype(based::max(a, b));
REQUIRE(std::same_as<const int&, res_t>);
REQUIRE(based::SameAs<const int&, res_t>);
REQUIRE(based::max(a, b) == 4);
}
@@ -175,7 +176,7 @@
TEST_CASE("max(move, literal) = right", "[algorithm/max]")
int a = 3;
using res_t = decltype(based::max(std::move(a), 4));
REQUIRE(std::same_as<int&&, res_t>);
REQUIRE(based::SameAs<int&&, res_t>);
REQUIRE(based::max(std::move(a), 4) == 4);
}
@@ -184,7 +185,7 @@
TEST_CASE("max(move, literal) = left", "[algorithm/max]")
int a = 4;
using res_t = decltype(based::max(std::move(a), 3));
REQUIRE(std::same_as<int&&, res_t>);
REQUIRE(based::SameAs<int&&, res_t>);
REQUIRE(based::max(std::move(a), 3) == 4);
}
@@ -194,7 +195,7 @@
TEST_CASE("max(move, value) = right", "[algorithm/max]")
int b = 4; // NOLINT misc-const-correctness
using res_t = decltype(based::max(std::move(a), b));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::max(std::move(a), b) == 4);
}
@@ -204,7 +205,7 @@
TEST_CASE("max(move, value) = left", "[algorithm/max]")
int b = 3; // NOLINT misc-const-correctness
using res_t = decltype(based::max(std::move(a), b));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::max(std::move(a), b) == 4);
}
@@ -214,7 +215,7 @@
TEST_CASE("max(move, const value) = right", "[algorithm/max]")
const int b = 4;
using res_t = decltype(based::max(std::move(a), b));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::max(std::move(a), b) == 4);
}
@@ -224,7 +225,7 @@
TEST_CASE("max(move, const value) = left", "[algorithm/max]")
const int b = 3;
using res_t = decltype(based::max(std::move(a), b));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::max(std::move(a), b) == 4);
}
@@ -233,7 +234,7 @@
TEST_CASE("max(literal, move) = right", "[algorithm/max]")
int b = 4;
using res_t = decltype(based::max(3, std::move(b)));
REQUIRE(std::same_as<int&&, res_t>);
REQUIRE(based::SameAs<int&&, res_t>);
REQUIRE(based::max(3, std::move(b)) == 4);
}
@@ -242,7 +243,7 @@
TEST_CASE("max(literal, move) = left", "[algorithm/max]")
int b = 3;
using res_t = decltype(based::max(4, std::move(b)));
REQUIRE(std::same_as<int&&, res_t>);
REQUIRE(based::SameAs<int&&, res_t>);
REQUIRE(based::max(4, std::move(b)) == 4);
}
@@ -252,7 +253,7 @@
TEST_CASE("max(value, move) = right", "[algorithm/max]")
int b = 4;
using res_t = decltype(based::max(a, std::move(b)));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::max(a, std::move(b)) == 4);
}
@@ -262,7 +263,7 @@
TEST_CASE("max(value, move) = left", "[algorithm/max]")
int b = 3;
using res_t = decltype(based::max(a, std::move(b)));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::max(a, std::move(b)) == 4);
}
@@ -272,7 +273,7 @@
TEST_CASE("max(const value, move) = right", "[algorithm/max]")
int b = 4;
using res_t = decltype(based::max(a, std::move(b)));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::max(a, std::move(b)) == 4);
}
@@ -282,7 +283,7 @@
TEST_CASE("max(const value, move) = left", "[algorithm/max]")
int b = 3;
using res_t = decltype(based::max(a, std::move(b)));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::max(a, std::move(b)) == 4);
}
@@ -292,7 +293,7 @@
TEST_CASE("max(move, move) = right", "[algorithm/max]")
int b = 4;
using res_t = decltype(based::max(std::move(a), std::move(b)));
REQUIRE(std::same_as<int&&, res_t>);
REQUIRE(based::SameAs<int&&, res_t>);
REQUIRE(based::max(std::move(a), std::move(b)) == 4);
}
@@ -302,7 +303,7 @@
TEST_CASE("max(move, move) = left", "[algorithm/max]")
int b = 3;
using res_t = decltype(based::max(std::move(a), std::move(b)));
REQUIRE(std::same_as<int&&, res_t>);
REQUIRE(based::SameAs<int&&, res_t>);
REQUIRE(based::max(std::move(a), std::move(b)) == 4);
}
diff --git a/ test/source/min_test.cpp b/ test/source/min_test.cpp
@@ -1,18 +1,19 @@
#include <catch2/catch_test_macros.hpp>
#include "based/algorithm.hpp"
#include "based/type_traits.hpp"
TEST_CASE("min(literal, literal) = left", "[algorithm/min]")
{
using res_t = decltype(based::min(3, 4));
REQUIRE(std::same_as<int&&, res_t>);
REQUIRE(based::SameAs<int&&, res_t>);
REQUIRE(based::min(3, 4) == 3);
}
TEST_CASE("min(literal, literal) = right", "[algorithm/min]")
{
using res_t = decltype(based::min(4, 3));
REQUIRE(std::same_as<int&&, res_t>);
REQUIRE(based::SameAs<int&&, res_t>);
REQUIRE(based::min(4, 3) == 3);
}
@@ -21,7 +22,7 @@
TEST_CASE("min(value, literal) = left", "[algorithm/min]")
int a = 3; // NOLINT misc-const-correctness
using res_t = decltype(based::min(a, 4));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::min(a, 4) == 3);
}
@@ -30,7 +31,7 @@
TEST_CASE("min(value, literal) = right", "[algorithm/min]")
int a = 4; // NOLINT misc-const-correctness
using res_t = decltype(based::min(a, 3));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::min(a, 3) == 3);
}
@@ -39,7 +40,7 @@
TEST_CASE("min(literal, value) = left", "[algorithm/min]")
int b = 4; // NOLINT misc-const-correctness
using res_t = decltype(based::min(3, b));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::min(3, b) == 3);
}
@@ -48,7 +49,7 @@
TEST_CASE("min(literal, value) = right", "[algorithm/min]")
int b = 3; // NOLINT misc-const-correctness
using res_t = decltype(based::min(4, b));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::min(4, b) == 3);
}
@@ -58,7 +59,7 @@
TEST_CASE("min(value, value) = left", "[algorithm/min]")
int b = 4;
using res_t = decltype(based::min(a, b));
REQUIRE(std::same_as<int&, res_t>);
REQUIRE(based::SameAs<int&, res_t>);
REQUIRE(based::min(a, b) == 3);
}
@@ -68,7 +69,7 @@
TEST_CASE("min(value, value) = right", "[algorithm/min]")
int b = 3;
using res_t = decltype(based::min(a, b));
REQUIRE(std::same_as<int&, res_t>);
REQUIRE(based::SameAs<int&, res_t>);
REQUIRE(based::min(a, b) == 3);
}
@@ -77,7 +78,7 @@
TEST_CASE("min(const value, literal) = left", "[algorithm/min]")
const int a = 3;
using res_t = decltype(based::min(a, 4));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::min(a, 4) == 3);
}
@@ -86,7 +87,7 @@
TEST_CASE("min(const value, literal) = right", "[algorithm/min]")
const int a = 4;
using res_t = decltype(based::min(a, 3));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::min(a, 3) == 3);
}
@@ -95,7 +96,7 @@
TEST_CASE("min(literal, const value) = left", "[algorithm/min]")
const int b = 4;
using res_t = decltype(based::min(3, b));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::min(3, b) == 3);
}
@@ -104,7 +105,7 @@
TEST_CASE("min(literal, const value) = right", "[algorithm/min]")
const int b = 3;
using res_t = decltype(based::min(4, b));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::min(4, b) == 3);
}
@@ -114,7 +115,7 @@
TEST_CASE("min(const value, const value) = left", "[algorithm/min]")
const int b = 4;
using res_t = decltype(based::min(a, b));
REQUIRE(std::same_as<const int&, res_t>);
REQUIRE(based::SameAs<const int&, res_t>);
REQUIRE(based::min(a, b) == 3);
}
@@ -124,7 +125,7 @@
TEST_CASE("min(const value, const value) = right", "[algorithm/min]")
const int b = 3;
using res_t = decltype(based::min(a, b));
REQUIRE(std::same_as<const int&, res_t>);
REQUIRE(based::SameAs<const int&, res_t>);
REQUIRE(based::min(a, b) == 3);
}
@@ -134,7 +135,7 @@
TEST_CASE("min(value, const value) = left", "[algorithm/min]")
const int b = 4;
using res_t = decltype(based::min(a, b));
REQUIRE(std::same_as<const int&, res_t>);
REQUIRE(based::SameAs<const int&, res_t>);
REQUIRE(based::min(a, b) == 3);
}
@@ -144,7 +145,7 @@
TEST_CASE("min(value, const value) = right", "[algorithm/min]")
const int b = 3;
using res_t = decltype(based::min(a, b));
REQUIRE(std::same_as<const int&, res_t>);
REQUIRE(based::SameAs<const int&, res_t>);
REQUIRE(based::min(a, b) == 3);
}
@@ -154,7 +155,7 @@
TEST_CASE("min(const value, value) = left", "[algorithm/min]")
int b = 4; // NOLINT misc-const-correctness
using res_t = decltype(based::min(a, b));
REQUIRE(std::same_as<const int&, res_t>);
REQUIRE(based::SameAs<const int&, res_t>);
REQUIRE(based::min(a, b) == 3);
}
@@ -164,7 +165,7 @@
TEST_CASE("min(const value, value) = right", "[algorithm/min]")
int b = 3; // NOLINT misc-const-correctness
using res_t = decltype(based::min(a, b));
REQUIRE(std::same_as<const int&, res_t>);
REQUIRE(based::SameAs<const int&, res_t>);
REQUIRE(based::min(a, b) == 3);
}
@@ -175,7 +176,7 @@
TEST_CASE("min(move, literal) = left", "[algorithm/min]")
int a = 3;
using res_t = decltype(based::min(std::move(a), 4));
REQUIRE(std::same_as<int&&, res_t>);
REQUIRE(based::SameAs<int&&, res_t>);
REQUIRE(based::min(std::move(a), 4) == 3);
}
@@ -184,7 +185,7 @@
TEST_CASE("min(move, literal) = right", "[algorithm/min]")
int a = 4;
using res_t = decltype(based::min(std::move(a), 3));
REQUIRE(std::same_as<int&&, res_t>);
REQUIRE(based::SameAs<int&&, res_t>);
REQUIRE(based::min(std::move(a), 3) == 3);
}
@@ -194,7 +195,7 @@
TEST_CASE("min(move, value) = left", "[algorithm/min]")
int b = 4; // NOLINT misc-const-correctness
using res_t = decltype(based::min(std::move(a), b));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::min(std::move(a), b) == 3);
}
@@ -204,7 +205,7 @@
TEST_CASE("min(move, value) = right", "[algorithm/min]")
int b = 3; // NOLINT misc-const-correctness
using res_t = decltype(based::min(std::move(a), b));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::min(std::move(a), b) == 3);
}
@@ -214,7 +215,7 @@
TEST_CASE("min(move, const value) = left", "[algorithm/min]")
const int b = 4;
using res_t = decltype(based::min(std::move(a), b));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::min(std::move(a), b) == 3);
}
@@ -224,7 +225,7 @@
TEST_CASE("min(move, const value) = right", "[algorithm/min]")
const int b = 3;
using res_t = decltype(based::min(std::move(a), b));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::min(std::move(a), b) == 3);
}
@@ -233,7 +234,7 @@
TEST_CASE("min(literal, move) = left", "[algorithm/min]")
int b = 4;
using res_t = decltype(based::min(3, std::move(b)));
REQUIRE(std::same_as<int&&, res_t>);
REQUIRE(based::SameAs<int&&, res_t>);
REQUIRE(based::min(3, std::move(b)) == 3);
}
@@ -242,7 +243,7 @@
TEST_CASE("min(literal, move) = right", "[algorithm/min]")
int b = 3;
using res_t = decltype(based::min(4, std::move(b)));
REQUIRE(std::same_as<int&&, res_t>);
REQUIRE(based::SameAs<int&&, res_t>);
REQUIRE(based::min(4, std::move(b)) == 3);
}
@@ -252,7 +253,7 @@
TEST_CASE("min(value, move) = left", "[algorithm/min]")
int b = 4;
using res_t = decltype(based::min(a, std::move(b)));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::min(a, std::move(b)) == 3);
}
@@ -262,7 +263,7 @@
TEST_CASE("min(value, move) = right", "[algorithm/min]")
int b = 3;
using res_t = decltype(based::min(a, std::move(b)));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::min(a, std::move(b)) == 3);
}
@@ -272,7 +273,7 @@
TEST_CASE("min(const value, move) = left", "[algorithm/min]")
int b = 4;
using res_t = decltype(based::min(a, std::move(b)));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::min(a, std::move(b)) == 3);
}
@@ -282,7 +283,7 @@
TEST_CASE("min(const value, move) = right", "[algorithm/min]")
int b = 3;
using res_t = decltype(based::min(a, std::move(b)));
REQUIRE(std::same_as<int, res_t>);
REQUIRE(based::SameAs<int, res_t>);
REQUIRE(based::min(a, std::move(b)) == 3);
}
@@ -292,7 +293,7 @@
TEST_CASE("min(move, move) = left", "[algorithm/min]")
int b = 4;
using res_t = decltype(based::min(std::move(a), std::move(b)));
REQUIRE(std::same_as<int&&, res_t>);
REQUIRE(based::SameAs<int&&, res_t>);
REQUIRE(based::min(std::move(a), std::move(b)) == 3);
}
@@ -302,7 +303,7 @@
TEST_CASE("min(move, move) = right", "[algorithm/min]")
int b = 3;
using res_t = decltype(based::min(std::move(a), std::move(b)));
REQUIRE(std::same_as<int&&, res_t>);
REQUIRE(based::SameAs<int&&, res_t>);
REQUIRE(based::min(std::move(a), std::move(b)) == 3);
}