Skip to content
Snippets Groups Projects
Commit f194064a authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Merge branch 'feature/template_traits' into 'master'

add traits for testing whether something is a template or a type and add enable_if_all

See merge request !54
parents 24e19192 0d63a6a7
No related branches found
No related tags found
1 merge request!54add traits for testing whether something is a template or a type and add enable_if_all
...@@ -97,4 +97,38 @@ namespace AMDiS ...@@ -97,4 +97,38 @@ namespace AMDiS
return std::make_unique<TYPEOF(obj)>(FWD(obj)); 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 } // end namespace AMDiS
...@@ -78,3 +78,6 @@ dune_add_test(SOURCES TreeDataTest.cpp ...@@ -78,3 +78,6 @@ dune_add_test(SOURCES TreeDataTest.cpp
dune_add_test(SOURCES TreeContainerTest.cpp dune_add_test(SOURCES TreeContainerTest.cpp
LINK_LIBRARIES amdis) LINK_LIBRARIES amdis)
dune_add_test(SOURCES TypeTraitsTest.cpp
LINK_LIBRARIES amdis)
#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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment