File: has_is_constant_evaluated.cpp

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (43 lines) | stat: -rw-r--r-- 1,860 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//  Copyright John Maddock 2013.
//  Use, modification and distribution are subject to the
//  Boost Software License, Version 1.0. (See accompanying file
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

// This program determines if std::is_constant_evaluated  is available to switch within a function to use compile-time constexp calculations.
// See https://en.cppreference.com/w/cpp/types/is_constant_evaluated
// and https://en.cppreference.com/w/cpp/compiler_support
// Currently only GCC 9 and Clang 9 and <cxxflags>-std=c++2a or  b2 cxxstd=2a

// https://clang.llvm.org/docs/LanguageExtensions.html#builtin-macros

// From Clang 10 onwards, __has_builtin(__X) can be used.  but also works for Clang 9

// 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

#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>

#include <boost/multiprecision/number.hpp>

#ifdef __has_builtin
BOOST_PRAGMA_MESSAGE (" __has_builtin is defined.")

#  if __has_builtin(__builtin_is_constant_evaluated)
BOOST_PRAGMA_MESSAGE (" __has_builtin(__builtin_is_constant_evaluated), so BOOST_MP_NO_CONSTEXPR_DETECTION should NOT be defined.")
#  endif // __has_builtin(__builtin_is_constant_evaluated)

#endif // __has_builtin

#ifdef BOOST_MP_HAS_IS_CONSTANT_EVALUATED
BOOST_PRAGMA_MESSAGE ("BOOST_MP_HAS_IS_CONSTANT_EVALUATED defined.")
#else
BOOST_PRAGMA_MESSAGE ("BOOST_MP_HAS_IS_CONSTANT_EVALUATED is NOT defined, so no std::is_constant_evaluated() from std library.")
#endif

#ifdef BOOST_NO_CXX14_CONSTEXPR
BOOST_PRAGMA_MESSAGE ("BOOST_NO_CXX14_CONSTEXPR is defined.")
#endif

#ifdef BOOST_MP_NO_CONSTEXPR_DETECTION
#  error 1  "std::is_constant_evaluated is NOT available to determine if a calculation can use constexpr."
#endif