addressof.hpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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_CONTAINER_DETAIL_ADDRESSOF_HPP
  11. #define BOOST_CONTAINER_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 <cstddef>
  19. namespace boost {
  20. namespace container {
  21. namespace dtl {
  22. template <typename T>
  23. BOOST_CONTAINER_FORCEINLINE T* addressof(T& obj)
  24. {
  25. return static_cast<T*>(
  26. static_cast<void*>(
  27. const_cast<char*>(
  28. &reinterpret_cast<const volatile char&>(obj)
  29. )));
  30. }
  31. } //namespace dtl {
  32. } //namespace container {
  33. } //namespace boost {
  34. #endif //#ifndef BOOST_CONTAINER_DETAIL_ADDRESSOF_HPP