From 0d63a6a71634dbb937aad2fd1caddbac09811b2a Mon Sep 17 00:00:00 2001 From: Simon Praetorius <simon.praetorius@tu-dresden.de> Date: Wed, 8 May 2019 15:37:27 +0200 Subject: [PATCH] added tests for is_template --- src/amdis/common/TypeTraits.hpp | 15 ++++++++++++--- test/CMakeLists.txt | 3 +++ test/TypeTraitsTest.cpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 test/TypeTraitsTest.cpp diff --git a/src/amdis/common/TypeTraits.hpp b/src/amdis/common/TypeTraits.hpp index 743bc762..72d5ed41 100644 --- a/src/amdis/common/TypeTraits.hpp +++ b/src/amdis/common/TypeTraits.hpp @@ -103,13 +103,22 @@ namespace AMDiS constexpr bool is_template() { return true; } #if AMDIS_HAS_CXX_AUTO_TEMPLATE_PARAMETER - template <template <class,auto...> class> + 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 <class,int...> class> + 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...> class> + template <template <class,std::size_t,std::size_t...> class> constexpr bool is_template() { return true; } #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 82bc31b7..c7d0fecd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -72,3 +72,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 00000000..d2677447 --- /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; +} -- GitLab