Skip to content

Commit

Permalink
Try to use concepts
Browse files Browse the repository at this point in the history
Let's see if this breaks things
  • Loading branch information
ianhbell committed Mar 1, 2024
1 parent 89741de commit 387a404
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ option (TEQP_MULTICOMPLEX_ENABLED


#### SETUP
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)

set(ZIPFN "${CMAKE_CURRENT_SOURCE_DIR}/dev/docker/boost_bcp_docker/boost_teqp.tar.xz")
set(OUTFN "${CMAKE_CURRENT_SOURCE_DIR}/boost_teqp/boost/version.hpp")
Expand Down
44 changes: 44 additions & 0 deletions src/tests/catch_test_concepts.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#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&>;
};

void get(auto t){
if constexpr (UsesTauDelta<decltype(t)>){
std::cout << "Defined and used" << std::endl;
}
else if constexpr (DoesntUseTauDelta<decltype(t)>){
std::cout << "Defined and not used" << std::endl;
}
else{
std::cout << "unknown" << std::endl;
}
}

struct Adeftrue{
std::false_type has_alphar_taudelta;
};

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

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

0 comments on commit 387a404

Please sign in to comment.