1// Copyright John Maddock 2011-2021.
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#ifndef BOOST_MATH_TOOLS_IS_CONSTANT_EVALUATED_HPP
7#define BOOST_MATH_TOOLS_IS_CONSTANT_EVALUATED_HPP
8
9#include <boost/math/tools/config.hpp>
10
11#ifdef __has_include
12# if __has_include(<version>)
13# include <version>
14# ifdef __cpp_lib_is_constant_evaluated
15# include <type_traits>
16# define BOOST_MATH_HAS_IS_CONSTANT_EVALUATED
17# endif
18# endif
19#endif
20
21#ifdef __has_builtin
22# if __has_builtin(__builtin_is_constant_evaluated) && !defined(BOOST_MATH_NO_CXX14_CONSTEXPR) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
23# define BOOST_MATH_HAS_BUILTIN_IS_CONSTANT_EVALUATED
24# endif
25#endif
26//
27// MSVC also supports __builtin_is_constant_evaluated if it's recent enough:
28//
29#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 192528326)
30# define BOOST_MATH_HAS_BUILTIN_IS_CONSTANT_EVALUATED
31#endif
32//
33// As does GCC-9:
34//
35#if !defined(BOOST_MATH_NO_CXX14_CONSTEXPR) && (__GNUC__ >= 9) && !defined(BOOST_MATH_HAS_BUILTIN_IS_CONSTANT_EVALUATED)
36# define BOOST_MATH_HAS_BUILTIN_IS_CONSTANT_EVALUATED
37#endif
38
39#if defined(BOOST_MATH_HAS_IS_CONSTANT_EVALUATED) && !defined(BOOST_MATH_NO_CXX14_CONSTEXPR)
40# define BOOST_MATH_IS_CONSTANT_EVALUATED(x) std::is_constant_evaluated()
41#elif defined(BOOST_MATH_HAS_BUILTIN_IS_CONSTANT_EVALUATED)
42# define BOOST_MATH_IS_CONSTANT_EVALUATED(x) __builtin_is_constant_evaluated()
43#elif !defined(BOOST_MATH_NO_CXX14_CONSTEXPR) && (__GNUC__ >= 6)
44# define BOOST_MATH_IS_CONSTANT_EVALUATED(x) __builtin_constant_p(x)
45# define BOOST_MATH_USING_BUILTIN_CONSTANT_P
46#else
47# define BOOST_MATH_IS_CONSTANT_EVALUATED(x) false
48# define BOOST_MATH_NO_CONSTEXPR_DETECTION
49#endif
50
51#endif // BOOST_MATH_TOOLS_IS_CONSTANT_EVALUATED_HPP
52

source code of boost/libs/math/include/boost/math/tools/is_constant_evaluated.hpp