31#define ein_ensures(concept, x) \
33 []<typename T> static constexpr noexcept { \
34 static_assert(concept<T>, #concept " not satisfied"); \
35 }.template operator()<decltype(x)>(), \
39#if defined(EIN_TESTING) || defined(EIN_TESTING_CONCEPTS)
43static auto add_integers(std::integral
auto x, std::integral
auto y) {
47static auto add_floats(std::floating_point
auto x, std::floating_point
auto y) {
52concept Stringifiable =
requires(T a) {
53 { std::to_string(a) } -> std::convertible_to<std::string>;
56static auto stringifyable_addition(Stringifiable
auto x, Stringifiable
auto y) {
60TEST_CASE(
"concepts",
"[concepts]") {
61 SECTION(
"Test integral addition with ein_ensures") {
62 CHECK(add_integers(2, 3) == 5);
63 CHECK(add_integers(-10, 4) == -6);
66 SECTION(
"Test floating-point addition with ein_ensures") {
67 CHECK(add_floats(1.5, 2.0) == Catch::Approx(3.5));
68 CHECK(add_floats(-10.0, 4.5) == Catch::Approx(-5.5));
71 SECTION(
"Test custom concept Stringifiable with ein_ensures") {
72 CHECK(stringifyable_addition(10, 20) == 30);
75 SECTION(
"Test ein_ensures with non-matching concept should compile-time fail") {
#define ein_ensures(concept, x)
statically checks that a concept is satisfied by the type of an expression