launder.hpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef BHO_CORE_LAUNDER_HPP_INCLUDED
  2. #define BHO_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. #if defined(__has_builtin)
  11. # if __has_builtin(__builtin_launder)
  12. # define BHO_CORE_HAS_BUILTIN_LAUNDER
  13. # endif
  14. #endif
  15. #if (__cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)) && !defined(BHO_CORE_HAS_BUILTIN_LAUNDER)
  16. # include <new>
  17. #endif
  18. namespace bho
  19. {
  20. namespace core
  21. {
  22. #if defined(BHO_CORE_HAS_BUILTIN_LAUNDER)
  23. template<class T> T* launder( T* p )
  24. {
  25. return __builtin_launder( p );
  26. }
  27. #elif (__cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)) && defined(__cpp_lib_launder)
  28. template<class T> T* launder( T* p )
  29. {
  30. return std::launder( p );
  31. }
  32. #else
  33. template<class T> T* launder( T* p )
  34. {
  35. return p;
  36. }
  37. #endif
  38. } // namespace core
  39. } // namespace bho
  40. #endif // #ifndef BHO_CORE_LAUNDER_HPP_INCLUDED