Skip to content
Snippets Groups Projects
Commit 277db90f authored by Steffen Müthing's avatar Steffen Müthing Committed by Oliver Sander
Browse files

Check for std::conditional and pull it into the Dune namespace

If not found, our own fallback implementation will be used.
parent afe1b449
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@ set(modules DuneBoost.cmake
DuneTestMacros.cmake
DuneTests.cmake
FindBoostFusion.cmake
FindCXX11Conditional.cmake
FindCXX11Features.cmake
FindGMP.cmake
FindInkscape.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)
......
# 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)
......@@ -10,6 +10,7 @@ MODULES = DuneBoost.cmake \
DuneTestMacros.cmake \
DuneTests.cmake \
FindBoostFusion.cmake \
FindCXX11Conditional.cmake \
FindCXX11Features.cmake \
FindGMP.cmake \
FindInkscape.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
......
......@@ -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")
......
......@@ -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
......
......@@ -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 \
......
# 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
])
......@@ -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])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment