Skip to content

Commit

Permalink
Clean up concepts test
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhbell committed Mar 1, 2024
1 parent b741e39 commit b8efaae
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions src/tests/catch_test_concepts.cxx
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/benchmark/catch_benchmark_all.hpp>
using Catch::Approx;

#include <iostream>
#include <concepts>

template<typename T>
concept UsesTauDelta = requires(T t) {
{ t.has_alphar_taudelta } -> std::same_as<std::true_type&>;
};

template<typename T>
concept DoesntUseTauDelta = requires(T t) {
{ t.has_alphar_taudelta } -> std::same_as<std::false_type&>;
template<typename T, typename target_type>
concept TauDeltaDef = requires(T t) {
{ t.has_alphar_taudelta } -> std::same_as<target_type&>;
};

void get(auto t){
if constexpr (UsesTauDelta<decltype(t)>){
if constexpr (TauDeltaDef<decltype(t), std::true_type>){
std::cout << "Defined and used" << std::endl;
}
else if constexpr (DoesntUseTauDelta<decltype(t)>){
else if constexpr (TauDeltaDef<decltype(t), std::false_type>){
std::cout << "Defined and not used" << std::endl;
}
else{
Expand All @@ -29,16 +21,15 @@ void get(auto t){
}

struct Adeftrue{
std::false_type has_alphar_taudelta;
};

struct Bdeffalse{
std::true_type has_alphar_taudelta;
};
struct Adeffalse{
std::false_type has_alphar_taudelta;
};
struct C{
};

TEST_CASE("Test some C++20 things", "[C++20]"){
static_assert(DoesntUseTauDelta<Adeffalse>);
static_assert(UsesTauDelta<Adeftrue>);
static_assert(TauDeltaDef<Adeffalse, std::false_type>);
static_assert(TauDeltaDef<Adeftrue, std::true_type>);
}

0 comments on commit b8efaae

Please sign in to comment.