sp_cxx20_constexpr.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #ifndef BOOST_SMART_PTR_DETAIL_SP_CXX20_CONSTEXPR_HPP_INCLUDED
  2. #define BOOST_SMART_PTR_DETAIL_SP_CXX20_CONSTEXPR_HPP_INCLUDED
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. #pragma once
  6. #endif
  7. // detail/sp_noexcept.hpp
  8. //
  9. // Copyright 2025 Mathias Stearn
  10. //
  11. // Distributed under the Boost Software License, Version 1.0.
  12. // See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt
  14. // This macro is used to mark functions as constexpr if the compiler supports
  15. // constexpr destructors. Since you can't have a constexpr smart pointer object,
  16. // everything except null constructors are guided behind this macro. Because
  17. // this also guards a use of dynamic_cast, we need to check for its availability
  18. // as well. It isn't worth splitting out since all known compilers that support
  19. // constexpr dynamic_cast also support constexpr destructors.
  20. //
  21. // WARNING: This does not check for changing active member of a union in
  22. // constant expressions which is allowed in C++20. If that is needed, we
  23. // need to raise the checked version to 202002L.
  24. #if defined(__cpp_constexpr_dynamic_alloc) && __cpp_constexpr_dynamic_alloc >= 201907L \
  25. && defined(__cpp_constexpr) && __cpp_constexpr >= 201907L
  26. #define BOOST_SP_CXX20_CONSTEXPR constexpr
  27. #else
  28. #define BOOST_SP_CXX20_CONSTEXPR
  29. #define BOOST_SP_NO_CXX20_CONSTEXPR
  30. #endif
  31. #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_CXX20_CONSTEXPR_HPP_INCLUDED