parent_from_member.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2010-2013
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/intrusive for documentation.
  10. //
  11. /////////////////////////////////////////////////////////////////////////////
  12. #ifndef BOOST_INTRUSIVE_PARENT_FROM_MEMBER_HPP
  13. #define BOOST_INTRUSIVE_PARENT_FROM_MEMBER_HPP
  14. #include <boost/intrusive/detail/config_begin.hpp>
  15. #include <boost/intrusive/detail/workaround.hpp>
  16. #include <boost/intrusive/intrusive_fwd.hpp>
  17. #include <boost/intrusive/detail/parent_from_member.hpp>
  18. #if defined(BOOST_HAS_PRAGMA_ONCE)
  19. # pragma once
  20. #endif
  21. namespace boost {
  22. namespace intrusive {
  23. //! Given a pointer to a member and its corresponding pointer to data member,
  24. //! this function returns the pointer of the parent containing that member.
  25. //! Note: this function does not work with pointer to members that rely on
  26. //! virtual inheritance.
  27. template<class Parent, class Member>
  28. BOOST_INTRUSIVE_FORCEINLINE Parent *get_parent_from_member(Member *member, const Member Parent::* ptr_to_member)
  29. { return ::boost::intrusive::detail::parent_from_member(member, ptr_to_member); }
  30. //! Given a const pointer to a member and its corresponding const pointer to data member,
  31. //! this function returns the const pointer of the parent containing that member.
  32. //! Note: this function does not work with pointer to members that rely on
  33. //! virtual inheritance.
  34. template<class Parent, class Member>
  35. BOOST_INTRUSIVE_FORCEINLINE const Parent *get_parent_from_member(const Member *member, const Member Parent::* ptr_to_member)
  36. { return ::boost::intrusive::detail::parent_from_member(member, ptr_to_member); }
  37. } //namespace intrusive {
  38. } //namespace boost {
  39. #include <boost/intrusive/detail/config_end.hpp>
  40. #endif //#ifndef BOOST_INTRUSIVE_PARENT_FROM_MEMBER_HPP