diff --git a/cmake/modules/CheckCXXFeatures.cmake b/cmake/modules/CheckCXXFeatures.cmake index 7ef462770b285d07f9c0973f97d7dfeb784973f2..cd3d99d573d5134eca0fa2f63f412033c309d852 100644 --- a/cmake/modules/CheckCXXFeatures.cmake +++ b/cmake/modules/CheckCXXFeatures.cmake @@ -19,6 +19,9 @@ # :code:`HAS_ATTRIBUTE_DEPRECATED_MSG` # True if attribute deprecated("msg") is supported # +# :code:`DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION` +# True if C++17's class template argument deduction is supported +# # .. cmake_variable:: DISABLE_CXX_VERSION_CHECK # # You may set this variable to TRUE to disable checking for @@ -313,6 +316,37 @@ check_cxx_source_compiles(" " HAVE_IS_INDEXABLE_SUPPORT ) +# support for C++17's class template deduction guides +check_cxx_source_compiles(" + #include <type_traits> + + template<typename T1> + struct A { + A(T1) {} + + template<typename T2> + A(T2, T2) {} + }; + + struct B { + using type = bool; + }; + + template<typename T2> + A(T2, T2) + -> A<typename T2::type>; + + int main() + { + A a1(1); + static_assert(std::is_same_v< decltype(a1), A<int> >); + + B b; + A a2(b, b); + static_assert(std::is_same_v< decltype(a2), A<bool> >); + } +" DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION + ) # find the threading library # Use a copy FindThreads from CMake 3.1 due to its support of pthread diff --git a/config.h.cmake b/config.h.cmake index 75a78ecc8bda27d93ce5ddf1e82a226cb4e5ce72..4dad7f50ce0b9f0a82f8eefd90f160df13cec6ab 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -26,6 +26,9 @@ /* does the compiler support __attribute__((unused))? */ #cmakedefine HAS_ATTRIBUTE_UNUSED 1 +/* does the compiler support C++17's class template argument deduction? */ +#cmakedefine DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION 1 + /* Define if you have a BLAS library. */ #cmakedefine HAVE_BLAS 1