addressof.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2014-2015. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_MOVE_DETAIL_ADDRESSOF_HPP
  11. #define BOOST_MOVE_DETAIL_ADDRESSOF_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #if defined(BOOST_HAS_PRAGMA_ONCE)
  16. # pragma once
  17. #endif
  18. #include <boost/move/detail/workaround.hpp>
  19. namespace boost {
  20. namespace move_detail {
  21. #if defined(BOOST_MSVC_FULL_VER) && BOOST_MSVC_FULL_VER >= 190024215
  22. #define BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
  23. #elif defined(BOOST_GCC) && BOOST_GCC >= 70000
  24. #define BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
  25. #elif defined(__has_builtin)
  26. #if __has_builtin(__builtin_addressof)
  27. #define BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
  28. #endif
  29. #endif
  30. #ifdef BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
  31. template<class T>
  32. BOOST_MOVE_FORCEINLINE T *addressof( T & v ) BOOST_NOEXCEPT
  33. {
  34. return __builtin_addressof(v);
  35. }
  36. #else //BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
  37. template <typename T>
  38. BOOST_MOVE_FORCEINLINE T* addressof(T& obj)
  39. {
  40. return static_cast<T*>(
  41. static_cast<void*>(
  42. const_cast<char*>(
  43. &reinterpret_cast<const volatile char&>(obj)
  44. )));
  45. }
  46. #endif //BOOST_MOVE_HAS_BUILTIN_ADDRESSOF
  47. } //namespace move_detail {
  48. } //namespace boost {
  49. #endif //#ifndef BOOST_MOVE_DETAIL_ADDRESSOF_HPP