diff --git a/src/amdis/common/TypeTraits.hpp b/src/amdis/common/TypeTraits.hpp index f1af06aeecd86e8eaf21b062df102b9e5003aad7..72d5ed416a4084bf1a470a21079a4bc5ea12acf9 100644 --- a/src/amdis/common/TypeTraits.hpp +++ b/src/amdis/common/TypeTraits.hpp @@ -97,4 +97,38 @@ namespace AMDiS return std::make_unique<TYPEOF(obj)>(FWD(obj)); } + + + template <template <class...> class> + constexpr bool is_template() { return true; } + +#if AMDIS_HAS_CXX_AUTO_TEMPLATE_PARAMETER + template <template <auto...> class> + constexpr bool is_template() { return true; } + + template <template <class,auto,auto...> class> + constexpr bool is_template() { return true; } +#else + template <template <int...> class> + constexpr bool is_template() { return true; } + + template <template <class,int,int...> class> + constexpr bool is_template() { return true; } + + template <template <std::size_t...> class> + constexpr bool is_template() { return true; } + + template <template <class,std::size_t,std::size_t...> class> + constexpr bool is_template() { return true; } +#endif + + template <class> + constexpr bool is_template() { return false; } + + + template <bool... b> + using enable_if_all_t + = std::enable_if_t<std::is_same<std::integer_sequence<bool,true,b...>, + std::integer_sequence<bool,b...,true>>::value>; + } // end namespace AMDiS diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bf5096109c15048b6e26a19df9bef7033546a9db..a92e8dd03e32a54fe2412da8debb5d5650661571 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -78,3 +78,6 @@ dune_add_test(SOURCES TreeDataTest.cpp dune_add_test(SOURCES TreeContainerTest.cpp LINK_LIBRARIES amdis) + +dune_add_test(SOURCES TypeTraitsTest.cpp + LINK_LIBRARIES amdis) diff --git a/test/TypeTraitsTest.cpp b/test/TypeTraitsTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d267744700225acee5d3377a23345b38b966f628 --- /dev/null +++ b/test/TypeTraitsTest.cpp @@ -0,0 +1,31 @@ +#include <amdis/AMDiS.hpp> +#include <amdis/common/TypeTraits.hpp> + +using namespace AMDiS; + +template <std::size_t i> +struct A {}; + +template <class T> +struct B {}; + +template <class T, std::size_t i> +struct C {}; + + +struct D {}; + + +int main(int argc, char** argv) +{ + Environment env(argc, argv); + + static_assert(is_template<A>(), ""); + static_assert(is_template<B>(), ""); + static_assert(is_template<C>(), ""); + + static_assert(not is_template<std::size_t>(), ""); + static_assert(not is_template<D>(), ""); + + return 0; +}