]> https://gitweb.dealii.org/ - dealii.git/commitdiff
introduce DEAL_II_HAVE_CXX20 check 10346/head
authorMatthias Maier <tamiko@43-1.org>
Sun, 24 May 2020 17:31:38 +0000 (12:31 -0500)
committerMatthias Maier <tamiko@43-1.org>
Sun, 24 May 2020 17:41:15 +0000 (12:41 -0500)
cmake/checks/check_01_cxx_features.cmake
include/deal.II/base/config.h.in
include/deal.II/base/std_cxx20/iota_view.h

index db34a492602131329f19ba5454743c9f650bc8a3..eaa9ab20fa0bcc9c80dc557f34ba4d859cd5e63a 100644 (file)
@@ -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 <cmath>
+    #include <ranges>
+
+    #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()
 
 
 ########################################################################
index a2c1d4cd163d1ccedc17cfe77804b8813f4f69be..836539c207d14547506f7498cbe0f910efc641a2 100644 (file)
 
 #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
index 2411706927dcc5115453db4d10adc2009c74b4dc..c190efc302a16e7543f4fdcef24100616b87e40a 100644 (file)
@@ -17,7 +17,7 @@
 
 #include <deal.II/base/config.h>
 
-#if defined __cpp_lib_ranges && __cpp_lib_ranges >= 201911
+#ifdef DEAL_II_HAVE_CXX20
 #  include <ranges>
 #else
 #  include <boost/range/irange.hpp>
@@ -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 <typename IncrementableType, typename /*BoundType*/>
     using iota_view = boost::integer_range<IncrementableType>;
+#else
+    using std::ranges::iota_view;
 #endif
   } // namespace ranges
 } // namespace std_cxx20

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.