constexpr_feature_detect.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2020-2023 Daniel Lemire
  2. // Copyright 2023 Matt Borland
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // https://www.boost.org/LICENSE_1_0.txt
  5. //
  6. // Derivative of: https://github.com/fastfloat/fast_float
  7. #ifndef BOOST_CHARCONV_DETAIL_FASTFLOAT_CONSTEXPR_FEATURE_DETECT_HPP
  8. #define BOOST_CHARCONV_DETAIL_FASTFLOAT_CONSTEXPR_FEATURE_DETECT_HPP
  9. #ifdef __has_include
  10. #if __has_include(<version>)
  11. #include <version>
  12. #endif
  13. #endif
  14. // Testing for https://wg21.link/N3652, adopted in C++14
  15. #if __cpp_constexpr >= 201304
  16. #define BOOST_CHARCONV_FASTFLOAT_CONSTEXPR14 constexpr
  17. #else
  18. #define BOOST_CHARCONV_FASTFLOAT_CONSTEXPR14
  19. #endif
  20. #if defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L
  21. #define BOOST_CHARCONV_FASTFLOAT_HAS_BIT_CAST 1
  22. #else
  23. #define BOOST_CHARCONV_FASTFLOAT_HAS_BIT_CAST 0
  24. #endif
  25. #if defined(__cpp_lib_is_constant_evaluated) && __cpp_lib_is_constant_evaluated >= 201811L
  26. #define BOOST_CHARCONV_FASTFLOAT_HAS_IS_CONSTANT_EVALUATED 1
  27. #else
  28. #define BOOST_CHARCONV_FASTFLOAT_HAS_IS_CONSTANT_EVALUATED 0
  29. #endif
  30. // Testing for relevant C++20 constexpr library features
  31. #if BOOST_CHARCONV_FASTFLOAT_HAS_IS_CONSTANT_EVALUATED \
  32. && BOOST_CHARCONV_FASTFLOAT_HAS_BIT_CAST \
  33. && __cpp_lib_constexpr_algorithms >= 201806L /*For std::copy and std::fill*/
  34. #define BOOST_CHARCONV_FASTFLOAT_CONSTEXPR20 constexpr
  35. #define BOOST_CHARCONV_FASTFLOAT_IS_CONSTEXPR 1
  36. #else
  37. #define BOOST_CHARCONV_FASTFLOAT_CONSTEXPR20
  38. #define BOOST_CHARCONV_FASTFLOAT_IS_CONSTEXPR 0
  39. #endif
  40. #endif // BOOST_CHARCONV_FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H