• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  Copyright John Maddock 2013.
2 //  Use, modification and distribution are subject to the
3 //  Boost Software License, Version 1.0. (See accompanying file
4 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 // This program determines if std::is_constant_evaluated  is available to switch within a function to use compile-time constexp calculations.
7 // See https://en.cppreference.com/w/cpp/types/is_constant_evaluated
8 // and https://en.cppreference.com/w/cpp/compiler_support
9 // Currently only GCC 9 and Clang 9 and <cxxflags>-std=c++2a or  b2 cxxstd=2a
10 
11 // https://clang.llvm.org/docs/LanguageExtensions.html#builtin-macros
12 
13 // From Clang 10 onwards, __has_builtin(__X) can be used.  but also works for Clang 9
14 
15 // boost\libs\multiprecision\config>b2 has_is_constant_evaluated toolset=clang-win-9.0.0 cxxstd=2a address-model=64 release  >  mp_is_const_eval_30Sep2019.log
16 
17 #include <boost/config.hpp>
18 #include <boost/config/pragma_message.hpp>
19 
20 #include <boost/multiprecision/number.hpp>
21 
22 #ifdef __has_builtin
23 BOOST_PRAGMA_MESSAGE (" __has_builtin is defined.")
24 
25 #  if __has_builtin(__builtin_is_constant_evaluated)
26 BOOST_PRAGMA_MESSAGE (" __has_builtin(__builtin_is_constant_evaluated), so BOOST_MP_NO_CONSTEXPR_DETECTION should NOT be defined.")
27 #  endif // __has_builtin(__builtin_is_constant_evaluated)
28 
29 #endif // __has_builtin
30 
31 #ifdef BOOST_MP_HAS_IS_CONSTANT_EVALUATED
32 BOOST_PRAGMA_MESSAGE ("BOOST_MP_HAS_IS_CONSTANT_EVALUATED defined.")
33 #else
34 BOOST_PRAGMA_MESSAGE ("BOOST_MP_HAS_IS_CONSTANT_EVALUATED is NOT defined, so no std::is_constant_evaluated() from std library.")
35 #endif
36 
37 #ifdef BOOST_NO_CXX14_CONSTEXPR
38 BOOST_PRAGMA_MESSAGE ("BOOST_NO_CXX14_CONSTEXPR is defined.")
39 #endif
40 
41 #ifdef BOOST_NO_CXX17_CONSTEXPR
42 BOOST_PRAGMA_MESSAGE ("BOOST_NO_CXX17_CONSTEXPR is defined.")
43 #endif
44 
45 #ifdef BOOST_MP_NO_CONSTEXPR_DETECTION
46 #  error 1  "std::is_constant_evaluated is NOT available to determine if a calculation can use constexpr."
47 #endif
48