diff --git a/cmake/modules/FindCXX11Features.cmake b/cmake/modules/FindCXX11Features.cmake index 4486fc203d72e0374a0b6d5d34bef557abb800b6..1f200fa4a951e89a4f6afd5050831064c4d489dd 100644 --- a/cmake/modules/FindCXX11Features.cmake +++ b/cmake/modules/FindCXX11Features.cmake @@ -9,6 +9,7 @@ # HAS_ATTRIBUTE_UNUSED True if attribute unused is supported # HAS_ATTRIBUTE_DEPRECATED True if attribute deprecated is supported # HAS_ATTRIBUTE_DEPRECATED_MSG True if attribute deprecated("msg") is supported +# HAVE_INTEGRAL_CONSTANT True if compiler supports integral_constant # HAVE_STATIC_ASSERT True if static_assert is available # HAVE_VARIADIC_TEMPLATES True if variadic templates are supprt # HAVE_VARIADIC_CONSTRUCTOR_SFINAE True if variadic constructor sfinae is supported @@ -67,6 +68,17 @@ CHECK_CXX_SOURCE_COMPILES(" " HAVE_ARRAY ) +# Check whether if std::integral_constant< T, v > is supported and casts into T +CHECK_CXX_SOURCE_COMPILES(" + #include <type_traits> + void f( int ){} + + int main(void){ + f( std::integral_constant< int, 42 >() ); + } +" HAVE_INTEGRAL_CONSTANT +) + # __attribute__((always_inline)) CHECK_CXX_SOURCE_COMPILES(" void __attribute__((always_inline)) foo(void) {} diff --git a/config.h.cmake b/config.h.cmake index 6f1a1aa800ef9c2eaf609b4c135ef4a734cbfa43..c07e8e9009d64174982dc14e476915a7d518298c 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -83,6 +83,11 @@ /* Define to 1 if you have the <tr1/type_traits> header file. */ #cmakedefine HAVE_TR1_TYPE_TRAITS 1 +/* Define to 1 if std::integral_constant< T, v > is supported + * and casts into T + */ +#cmakedefine HAVE_INTEGRAL_CONSTANT 1 + /* Define to 1 if you have the <tuple> header file. */ #cmakedefine HAVE_TUPLE 1 diff --git a/dune/common/sllist.hh b/dune/common/sllist.hh index 88a1d008ead4812f12c5b2c3f385bb47813f495b..2e694e6b4f7be8c58f0b2e77c03338065c76ec81 100644 --- a/dune/common/sllist.hh +++ b/dune/common/sllist.hh @@ -68,7 +68,7 @@ namespace Dune typedef SLListIterator<T,A> iterator; /** - * @brief The mutable iterator of the list. + * @brief The constant iterator of the list. */ typedef SLListConstIterator<T,A> const_iterator; diff --git a/dune/common/typetraits.hh b/dune/common/typetraits.hh index 40c1f67f2129ac89ab6b85c41ccf4aae4f130014..561086be632e88eb429b28b1cf6b5a4bb32deb35 100644 --- a/dune/common/typetraits.hh +++ b/dune/common/typetraits.hh @@ -395,15 +395,11 @@ namespace Dune // // integral_constant (C++0x 20.7.3 "Helper classes") // -#if defined HAVE_TYPE_TRAITS +#if HAVE_INTEGRAL_CONSTANT using std::integral_constant; using std::true_type; using std::false_type; -#elif defined HAVE_TR1_TYPE_TRAITS - using std::tr1::integral_constant; - using std::tr1::true_type; - using std::tr1::false_type; -#else +#else // #if HAVE_INTEGRAL_CONSTANT //! Generate a type for a given integral constant /** * \tparam T Type of the constant. @@ -425,7 +421,7 @@ namespace Dune typedef integral_constant<bool, true> true_type; //! type for false typedef integral_constant<bool, false> false_type; -#endif +#endif // #else // #if HAVE_INTEGRAL_CONSTANT /** @} */ } diff --git a/m4/cxx0x_compiler.m4 b/m4/cxx0x_compiler.m4 index d15c57ad7086ec8adef64501da8480cc211c4e73..ac8f22b988c158cb3a33c700933e75053c589176 100644 --- a/m4/cxx0x_compiler.m4 +++ b/m4/cxx0x_compiler.m4 @@ -1,30 +1,60 @@ -# whether g++ accepts -std=c++0x +# whether compiler accepts -std=c++11 or -std=c++0x +# can be disabled by --disable-gxx0xcheck AC_DEFUN([GXX0X],[ ac_save_CXX="$CXX" - AC_CACHE_CHECK([whether g++ accepts -std=c++0x], dune_cv_gplusplus_accepts_cplusplus0x, [ + + # try flag -std=c++11 + AC_CACHE_CHECK([whether $CXX accepts -std=c++11], dune_cv_gplusplus_accepts_cplusplus11, [ AC_REQUIRE([AC_PROG_CXX]) AC_ARG_ENABLE(gxx0xcheck, AC_HELP_STRING([--disable-gxx0xcheck], - [try to enable c++0x feature for g++ [[default=yes]]]), + [try flag -std=c++11 to enable C++11 features [[default=yes]]]), [gxx0xcheck=$enableval], [gxx0xcheck=yes]) if test "x$GXX" = xyes && test "x$gxx0xcheck" = xyes; then AC_LANG_PUSH([C++]) - CXX="$CXX -std=c++0x" + CXX="$CXX -std=c++11" AC_TRY_COMPILE([ #include <iostream> #include <array> ], [], - dune_cv_gplusplus_accepts_cplusplus0x=yes, - dune_cv_gplusplus_accepts_cplusplus0x=no) - AC_LANG_POP + dune_cv_gplusplus_accepts_cplusplus11=yes, + dune_cv_gplusplus_accepts_cplusplus11=no) + AC_LANG_POP([C++]) fi ]) - if test "x$dune_cv_gplusplus_accepts_cplusplus0x" == "xyes" ; then - CXX="$ac_save_CXX -std=c++0x" - CXXCPP="$CXXCPP -std=c++0x" + if test "x$dune_cv_gplusplus_accepts_cplusplus11" == "xyes" ; then + CXX="$ac_save_CXX -std=c++11" + CXXCPP="$CXXCPP -std=c++11" else CXX="$ac_save_CXX" + + # try flag -std=c++0x instead + AC_CACHE_CHECK([whether $CXX accepts -std=c++0x], dune_cv_gplusplus_accepts_cplusplus0x, [ + AC_REQUIRE([AC_PROG_CXX]) + AC_ARG_ENABLE(gxx0xcheck, + AC_HELP_STRING([--disable-gxx0xcheck], + [try flag -std=c++0x to enable C++11 features [[default=yes]]]), + [gxx0xcheck=$enableval], + [gxx0xcheck=yes]) + if test "x$GXX" = xyes && test "x$gxx0xcheck" = xyes; then + AC_LANG_PUSH([C++]) + CXX="$CXX -std=c++0x" + AC_TRY_COMPILE([ + #include <iostream> + #include <array> + ], [], + dune_cv_gplusplus_accepts_cplusplus0x=yes, + dune_cv_gplusplus_accepts_cplusplus0x=no) + AC_LANG_POP([C++]) + fi + ]) + if test "x$dune_cv_gplusplus_accepts_cplusplus0x" == "xyes" ; then + CXX="$ac_save_CXX -std=c++0x" + CXXCPP="$CXXCPP -std=c++0x" + else + CXX="$ac_save_CXX" + fi fi ]) diff --git a/m4/dune_compiler.m4 b/m4/dune_compiler.m4 index fb30a3917d7996760c9f494a9561095c38087438..7a83a276ef857a8460296854ac3afa62e615c005 100644 --- a/m4/dune_compiler.m4 +++ b/m4/dune_compiler.m4 @@ -8,7 +8,7 @@ AC_ARG_ENABLE(compilercheck, [disable check for supported compilers]), [compilercheck=$enableval], [compilercheck=yes]) -SUPPORTED_COMPILER="gcc (>= 3.4.1) or icc (>= 7.0)" +SUPPORTED_COMPILER="gcc (>= 4.1), should work with recent versions of icc and clang (>= 3.0)" AC_REQUIRE([AC_PROG_CXX]) cat >conftest.cc <<_ACEOF @@ -19,13 +19,16 @@ cat >conftest.cc <<_ACEOF #define CXX_SUPPORTED "icc %2.2f", 1.0*__ICC/100 #endif #endif +#if defined __clang__ && ! defined CXX_SUPPORTED + #if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 0) + #define CXX_SUPPORTED \ + "clang %i.%i.%i", __clang_major__, __clang_minor__, __clang_patchlevel__ + #endif +#endif #if defined __GNUC__ && ! defined CXX_SUPPORTED - #if __GNUC__ > 3 || \ - (__GNUC__ == 3 && (__GNUC_MINOR__ > 4 || \ - (__GNUC_MINOR__ == 4 && \ - __GNUC_PATCHLEVEL__ >= 1))) + #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) #define CXX_SUPPORTED \ - "gcc %i.%i.%i", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ + "gcc %i.%i.%i", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ #endif #endif #ifndef CXX_SUPPORTED @@ -51,5 +54,5 @@ AS_IF([test "x$compilercheck" = "xno"], ]) AS_IF([test -z "$COMPILER_NAME"],[ - COMPILER_NAME="unknown compiler"]) + COMPILER_NAME="unknown compiler"]) ]) diff --git a/m4/dune_tr1_headers.m4 b/m4/dune_tr1_headers.m4 index ec04516ce9f9236d41a40b359626119172417dfa..d9a0807aacb5fd6a0cf1b989d7dd438684f55274 100644 --- a/m4/dune_tr1_headers.m4 +++ b/m4/dune_tr1_headers.m4 @@ -20,6 +20,23 @@ AC_DEFUN([DUNE_TR1_HEADERS], [ AS_IF([test "x$dune_cv_array_cplusplus0x" != "xno"], [AC_DEFINE([HAVE_ARRAY], 1, [Define to 1 if the <array> C++0x is available and support array::fill]) ]) + AC_CACHE_CHECK([whether integral_constant conforming to C++11 is supported], dune_cv_integral_constant_cplusplus11, [ + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([ + #include <type_traits> + void f( int ); + ],[ + f( std::integral_constant< int, 42 >() ); + ]) + ],[ + dune_cv_integral_constant_cplusplus11=yes + ],[ + dune_cv_integral_constant_cplusplus11=no + ]) + ]) + AS_IF([test "x$dune_cv_integral_constant_cplusplus11" != "xno"],[ + AC_DEFINE([HAVE_INTEGRAL_CONSTANT], 1, [Define to 1 if std::integral_constant< T, v > is supported and casts into T]) + ]) ]) AC_LANG_POP([C++]) ])