launder.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef BOOST_CORE_LAUNDER_HPP_INCLUDED
  2. #define BOOST_CORE_LAUNDER_HPP_INCLUDED
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. // Copyright 2023 Peter Dimov
  8. // Distributed under the Boost Software License, Version 1.0.
  9. // https://www.boost.org/LICENSE_1_0.txt
  10. #include <boost/config.hpp>
  11. #if defined(__has_builtin)
  12. # if __has_builtin(__builtin_launder)
  13. # define BOOST_CORE_HAS_BUILTIN_LAUNDER
  14. # endif
  15. #endif
  16. #if defined(BOOST_MSVC) && BOOST_MSVC < 1920
  17. // msvc-14.1 suffers from internal compiler errors when using std::launder
  18. // https://github.com/boostorg/core/issues/160
  19. // https://github.com/boostorg/optional/issues/122
  20. #elif (BOOST_CXX_VERSION >= 201703L) && !defined(BOOST_CORE_HAS_BUILTIN_LAUNDER)
  21. #include <new>
  22. #if defined(__cpp_lib_launder)
  23. # define BOOST_CORE_HAS_STD_LAUNDER
  24. #endif
  25. #endif
  26. namespace boost
  27. {
  28. namespace core
  29. {
  30. #if defined(BOOST_CORE_HAS_BUILTIN_LAUNDER)
  31. template<class T> T* launder( T* p )
  32. {
  33. return __builtin_launder( p );
  34. }
  35. #elif defined(BOOST_CORE_HAS_STD_LAUNDER)
  36. template<class T> T* launder( T* p )
  37. {
  38. return std::launder( p );
  39. }
  40. #else
  41. template<class T> T* launder( T* p )
  42. {
  43. return p;
  44. }
  45. #endif
  46. } // namespace core
  47. } // namespace boost
  48. #endif // #ifndef BOOST_CORE_LAUNDER_HPP_INCLUDED