raw_ptr.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Copyright 2003-2015 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See http://www.boost.org/libs/multi_index for library home page.
  7. */
  8. #ifndef BOOST_MULTI_INDEX_DETAIL_RAW_PTR_HPP
  9. #define BOOST_MULTI_INDEX_DETAIL_RAW_PTR_HPP
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
  14. #include <boost/mpl/bool.hpp>
  15. #include <boost/type_traits/is_same.hpp>
  16. namespace boost{
  17. namespace multi_index{
  18. namespace detail{
  19. /* gets the underlying pointer of a pointer-like value */
  20. template<typename RawPointer>
  21. inline RawPointer raw_ptr(RawPointer const& p,mpl::true_)
  22. {
  23. return p;
  24. }
  25. template<typename RawPointer,typename Pointer>
  26. inline RawPointer raw_ptr(Pointer const& p,mpl::false_)
  27. {
  28. return p==Pointer(0)?0:&*p;
  29. }
  30. template<typename RawPointer,typename Pointer>
  31. inline RawPointer raw_ptr(Pointer const& p)
  32. {
  33. return raw_ptr<RawPointer>(p,is_same<RawPointer,Pointer>());
  34. }
  35. } /* namespace multi_index::detail */
  36. } /* namespace multi_index */
  37. } /* namespace boost */
  38. #endif