diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt index 00e6852a10d206c33b990005680e130fbdeabda3..cee14ed1ca7d33ed5d227337cbab5bbd11a21408 100644 --- a/cmake/modules/CMakeLists.txt +++ b/cmake/modules/CMakeLists.txt @@ -10,6 +10,7 @@ set(modules DuneBoost.cmake DuneTestMacros.cmake DuneTests.cmake FindBoostFusion.cmake + FindCXX11Conditional.cmake FindCXX11Features.cmake FindGMP.cmake FindInkscape.cmake diff --git a/cmake/modules/DuneMacros.cmake b/cmake/modules/DuneMacros.cmake index 51da973d8c0e2699db1d7a0056dd30cb03a1c9a2..ea12136ccf69b4cfd7dbd006cd094c2b83777eda 100644 --- a/cmake/modules/DuneMacros.cmake +++ b/cmake/modules/DuneMacros.cmake @@ -419,6 +419,7 @@ macro(dune_project) # set required compiler flags for C++11 (former C++0x) find_package(CXX11Features) + find_package(CXX11Conditional) include(DuneCxaDemangle) diff --git a/cmake/modules/FindCXX11Conditional.cmake b/cmake/modules/FindCXX11Conditional.cmake new file mode 100644 index 0000000000000000000000000000000000000000..6c85ca65ed3d01b1b6f558dcd4e077a57f3a9239 --- /dev/null +++ b/cmake/modules/FindCXX11Conditional.cmake @@ -0,0 +1,17 @@ +# Module that checks whether the compiler supports +# C++11 std::conditional. +# +# Sets the following variable: +# HAVE_STD_CONDITIONAL +# +# perform tests +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + + #include <type_traits> + + int main(void){ + return std::conditional<true,std::integral_constant<int,0>,void>::type::value; + }" + HAVE_STD_CONDITIONAL) diff --git a/cmake/modules/Makefile.am b/cmake/modules/Makefile.am index 04631b7ddae96c54891037b9e56207a31e14888a..7870a68fa51c92b0a58212bdc6125d7dbf52ceee 100644 --- a/cmake/modules/Makefile.am +++ b/cmake/modules/Makefile.am @@ -10,6 +10,7 @@ MODULES = DuneBoost.cmake \ DuneTestMacros.cmake \ DuneTests.cmake \ FindBoostFusion.cmake \ + FindCXX11Conditional.cmake \ FindCXX11Features.cmake \ FindGMP.cmake \ FindInkscape.cmake \ diff --git a/config.h.cmake b/config.h.cmake index 1ded4db4d386a0aa37d9cd5db2a8f33e804d70f3..af32e048e87c7fa5f694b68ff0808a918bf0103e 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -108,6 +108,9 @@ /* Define to 1 if you have the <type_traits> header file. */ #cmakedefine HAVE_TYPE_TRAITS 1 +/* Define to 1 if you have the <type_traits> header file. */ +#cmakedefine HAVE_STD_CONDITIONAL 1 + /* Define to 1 if the MPI2 Standard is supported */ #cmakedefine MPI_2 1 diff --git a/dune/common/typetraits.hh b/dune/common/typetraits.hh index 1d08eb286a0c90e7955b2416ea44270ffdb1da2f..4763ed9b5522effe7df36b52976126ea0cb48960 100644 --- a/dune/common/typetraits.hh +++ b/dune/common/typetraits.hh @@ -395,6 +395,8 @@ namespace Dune typedef T2 Type DUNE_DEPRECATED_MSG("Use Dune::conditional::type instead"); }; +#if DOXYGEN || !HAVE_STD_CONDITIONAL + /** * @brief Select a type based on a condition. * @@ -403,7 +405,8 @@ namespace Dune * The selected type is accessible through the typedef * type. * - * \note This is a reimplementation of the C++11 stl feature of the same name. + * \note If available, this uses C++11 std::conditional, otherwise it provides + * a reimplementation. */ template<bool first, class T1, class T2> struct conditional @@ -423,6 +426,13 @@ namespace Dune typedef T2 type; }; +#else // DOXYGEN || !HAVE_STD_CONDITONAL + + // pull in default implementation + using std::conditional; + +#endif // DOXYGEN || !HAVE_STD_CONDITONAL + //////////////////////////////////////////////////////////////////////// // // integral_constant (C++0x 20.7.3 "Helper classes") diff --git a/m4/CMakeLists.txt b/m4/CMakeLists.txt index 5a842931e66674c4c53c92a75f81b363982c02fb..40c791eb1a29f6d3837fee16a753360a7a05ba01 100644 --- a/m4/CMakeLists.txt +++ b/m4/CMakeLists.txt @@ -13,6 +13,7 @@ install(PROGRAMS cxx0x_static_assert.m4 cxx0x_variadic.m4 cxx0x_variadic_constructor_sfinae.m4 + cxx11_conditional.m4 dune.m4 dune_all.m4 dune_autobuild.m4 diff --git a/m4/Makefile.am b/m4/Makefile.am index 68a0b3f51e1ecc4bfaff302f2f02901b15854b47..32fbabbd59d89418cc3fe28357981e2308b74613 100644 --- a/m4/Makefile.am +++ b/m4/Makefile.am @@ -17,6 +17,7 @@ ALLM4S = \ cxx0x_static_assert.m4 \ cxx0x_variadic.m4 \ cxx0x_variadic_constructor_sfinae.m4 \ + cxx11_conditional.m4 \ dune.m4 \ dune_all.m4 \ dune_autobuild.m4 \ diff --git a/m4/cxx11_conditional.m4 b/m4/cxx11_conditional.m4 new file mode 100644 index 0000000000000000000000000000000000000000..8bbe0c874e30ffb9eb0d4afa7f245db44d297788 --- /dev/null +++ b/m4/cxx11_conditional.m4 @@ -0,0 +1,25 @@ +# tests for C++11 conditional support +# the associated macro is called HAVE_STD_CONDITIONAL + +AC_DEFUN([CXX11_CONDITIONAL_CHECK],[ + AC_CACHE_CHECK([for C++11 std::conditional], dune_cv_cxx11_conditional_support, [ + AC_REQUIRE([AC_PROG_CXX]) + AC_REQUIRE([GXX0X]) + AC_LANG_PUSH([C++]) + AC_RUN_IFELSE([ + AC_LANG_PROGRAM([ + + #include <type_traits> + + ], + [ + return std::conditional<true,std::integral_constant<int,0>,void>::type::value; + ])], + dune_cv_cxx11_conditional_support=yes, + dune_cv_cxx11_conditional_support=no) + AC_LANG_POP + ]) + if test "x$dune_cv_cxx11_conditional_support" = xyes; then + AC_DEFINE(HAVE_STD_CONDITIONAL, 1, [Define to 1 if C++11 std::conditional is supported]) + fi +]) diff --git a/m4/dune_common.m4 b/m4/dune_common.m4 index 651a23e09dcdece8e674ea763e068ff5d810b3d7..639397b43e64431b75c88374f574c0e325818cab 100644 --- a/m4/dune_common.m4 +++ b/m4/dune_common.m4 @@ -24,6 +24,7 @@ AC_DEFUN([DUNE_COMMON_CHECKS], AC_REQUIRE([SHARED_PTR]) AC_REQUIRE([VARIADIC_TEMPLATES_CHECK]) AC_REQUIRE([RVALUE_REFERENCES_CHECK]) + AC_REQUIRE([CXX11_CONDITIONAL_CHECK]) AC_REQUIRE([DUNE_BOOST_BASE]) AC_REQUIRE([MAKE_SHARED]) AC_REQUIRE([DUNE_LINKCXX])