is_constant_evaluated.hpp 1.9 KB

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