get_pointer.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright Peter Dimov and David Abrahams 2002.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef GET_POINTER_DWA20021219_HPP
  6. #define GET_POINTER_DWA20021219_HPP
  7. #include <boost/config.hpp>
  8. // In order to avoid circular dependencies with Boost.TR1
  9. // we make sure that our include of <memory> doesn't try to
  10. // pull in the TR1 headers: that's why we use this header
  11. // rather than including <memory> directly:
  12. #include <boost/config/no_tr1/memory.hpp> // std::auto_ptr
  13. namespace boost {
  14. // get_pointer(p) extracts a ->* capable pointer from p
  15. template<class T> T * get_pointer(T * p)
  16. {
  17. return p;
  18. }
  19. // get_pointer(shared_ptr<T> const & p) has been moved to shared_ptr.hpp
  20. #if !defined( BOOST_NO_AUTO_PTR )
  21. #if defined( __GNUC__ ) && (defined( __GXX_EXPERIMENTAL_CXX0X__ ) || (__cplusplus >= 201103L))
  22. #if defined( BOOST_GCC )
  23. #if BOOST_GCC >= 40600
  24. #define BOOST_CORE_DETAIL_DISABLE_LIBSTDCXX_DEPRECATED_WARNINGS
  25. #endif // BOOST_GCC >= 40600
  26. #elif defined( __clang__ ) && defined( __has_warning )
  27. #if __has_warning("-Wdeprecated-declarations")
  28. #define BOOST_CORE_DETAIL_DISABLE_LIBSTDCXX_DEPRECATED_WARNINGS
  29. #endif // __has_warning("-Wdeprecated-declarations")
  30. #endif
  31. #endif // defined( __GNUC__ ) && (defined( __GXX_EXPERIMENTAL_CXX0X__ ) || (__cplusplus >= 201103L))
  32. #if defined( BOOST_CORE_DETAIL_DISABLE_LIBSTDCXX_DEPRECATED_WARNINGS )
  33. // Disable libstdc++ warnings about std::auto_ptr being deprecated in C++11 mode
  34. #pragma GCC diagnostic push
  35. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  36. #define BOOST_CORE_DETAIL_DISABLED_DEPRECATED_WARNINGS
  37. #endif
  38. template<class T> T * get_pointer(std::auto_ptr<T> const& p)
  39. {
  40. return p.get();
  41. }
  42. #if defined( BOOST_CORE_DETAIL_DISABLE_LIBSTDCXX_DEPRECATED_WARNINGS )
  43. #pragma GCC diagnostic pop
  44. #undef BOOST_CORE_DETAIL_DISABLE_LIBSTDCXX_DEPRECATED_WARNINGS
  45. #endif
  46. #endif // !defined( BOOST_NO_AUTO_PTR )
  47. #if !defined( BOOST_NO_CXX11_SMART_PTR )
  48. template<class T> T * get_pointer( std::unique_ptr<T> const& p )
  49. {
  50. return p.get();
  51. }
  52. template<class T> T * get_pointer( std::shared_ptr<T> const& p )
  53. {
  54. return p.get();
  55. }
  56. #endif
  57. } // namespace boost
  58. #endif // GET_POINTER_DWA20021219_HPP