From: Matthias Maier Date: Sun, 24 May 2020 17:31:38 +0000 (-0500) Subject: introduce DEAL_II_HAVE_CXX20 check X-Git-Tag: v9.3.0-rc1~1565^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F10346%2Fhead;p=dealii.git introduce DEAL_II_HAVE_CXX20 check --- diff --git a/cmake/checks/check_01_cxx_features.cmake b/cmake/checks/check_01_cxx_features.cmake index db34a49260..eaa9ab20fa 100644 --- a/cmake/checks/check_01_cxx_features.cmake +++ b/cmake/checks/check_01_cxx_features.cmake @@ -20,6 +20,7 @@ # # DEAL_II_HAVE_CXX14 # DEAL_II_HAVE_CXX17 +# DEAL_II_HAVE_CXX20 # # DEAL_II_HAVE_FP_EXCEPTIONS # DEAL_II_HAVE_COMPLEX_OPERATOR_OVERLOADS @@ -50,6 +51,49 @@ MACRO(_set_up_cmake_required) ENDMACRO() +# +# Wrap the following checks into a macro to make it easier to rerun them. +# +MACRO(_test_cxx20_support) + + UNSET_IF_CHANGED(CHECK_CXX20_FEATURES_FLAGS_SAVED + "${CMAKE_REQUIRED_FLAGS}" + DEAL_II_HAVE_CXX20_FEATURES + ) + + # Strictly speaking "201709L" indicates support for a preliminary version + # of C++20 standard (which will have "202002L" when finalized). gcc-10 + # exports this version number when configured with C++20 support. + # clang-10 exports the final "202002L" version instead. + CHECK_CXX_SOURCE_COMPILES( + " + #include + #include + + #if __cplusplus < 201709L && !defined(_MSC_VER) && !defined(__INTEL_COMPILER) + # error \"insufficient support for C++20\" + #endif + + #if !(defined __cpp_lib_ranges) || (__cpp_lib_ranges < 201911) + # error \"insufficient support for C++20\" + #endif + + int main() + { + } + " + DEAL_II_HAVE_CXX20_FEATURES) + + IF(DEAL_II_HAVE_CXX20_FEATURES) + MESSAGE(STATUS "C++20 support is enabled.") + SET(DEAL_II_HAVE_CXX20 TRUE) + ELSE() + MESSAGE(STATUS "C++20 support is disabled.") + SET(DEAL_II_HAVE_CXX20 FALSE) + ENDIF() +ENDMACRO() + + # # Wrap the following checks into a macro to make it easier to rerun them. # @@ -256,6 +300,7 @@ MACRO(_test_cxx14_support) ENDIF() ENDMACRO() + # # Try to find out what we support: # @@ -281,6 +326,7 @@ IF(NOT DEAL_II_HAVE_CXX14) ENDIF() _test_cxx17_support() +_test_cxx20_support() ######################################################################## diff --git a/include/deal.II/base/config.h.in b/include/deal.II/base/config.h.in index a2c1d4cd16..836539c207 100644 --- a/include/deal.II/base/config.h.in +++ b/include/deal.II/base/config.h.in @@ -133,6 +133,7 @@ #cmakedefine DEAL_II_HAVE_CXX14 #cmakedefine DEAL_II_HAVE_CXX17 +#cmakedefine DEAL_II_HAVE_CXX20 #cmakedefine DEAL_II_HAVE_FP_EXCEPTIONS #cmakedefine DEAL_II_HAVE_COMPLEX_OPERATOR_OVERLOADS diff --git a/include/deal.II/base/std_cxx20/iota_view.h b/include/deal.II/base/std_cxx20/iota_view.h index 2411706927..c190efc302 100644 --- a/include/deal.II/base/std_cxx20/iota_view.h +++ b/include/deal.II/base/std_cxx20/iota_view.h @@ -17,7 +17,7 @@ #include -#if defined __cpp_lib_ranges && __cpp_lib_ranges >= 201911 +#ifdef DEAL_II_HAVE_CXX20 # include #else # include @@ -29,9 +29,7 @@ namespace std_cxx20 { namespace ranges { -#if defined __cpp_lib_ranges && __cpp_lib_ranges >= 201911 - using std::ranges::iota_view; -#else +#ifndef DEAL_II_HAVE_CXX20 /** * A poor-man's implementation of std::ranges::iota_view using * boost's integer_range class. The two classes are not completely @@ -46,6 +44,8 @@ namespace std_cxx20 */ template using iota_view = boost::integer_range; +#else + using std::ranges::iota_view; #endif } // namespace ranges } // namespace std_cxx20