parent_from_member.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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_GET_PARENT_FROM_MEMBER_HPP
  13. #define BOOST_INTRUSIVE_GET_PARENT_FROM_MEMBER_HPP
  14. #include <boost/intrusive/detail/config_begin.hpp>
  15. #include <boost/intrusive/detail/parent_from_member.hpp>
  16. namespace boost {
  17. namespace intrusive {
  18. //! Given a pointer to a member and its corresponding pointer to data member,
  19. //! this function returns the pointer of the parent containing that member.
  20. //! Note: this function does not work with pointer to members that rely on
  21. //! virtual inheritance.
  22. template<class Parent, class Member>
  23. inline Parent *get_parent_from_member(Member *member, const Member Parent::* ptr_to_member)
  24. { return ::boost::intrusive::detail::parent_from_member(member, ptr_to_member); }
  25. //! Given a const pointer to a member and its corresponding const pointer to data member,
  26. //! this function returns the const pointer of the parent containing that member.
  27. //! Note: this function does not work with pointer to members that rely on
  28. //! virtual inheritance.
  29. template<class Parent, class Member>
  30. inline const Parent *get_parent_from_member(const Member *member, const Member Parent::* ptr_to_member)
  31. { return ::boost::intrusive::detail::parent_from_member(member, ptr_to_member); }
  32. } //namespace intrusive {
  33. } //namespace boost {
  34. #include <boost/intrusive/detail/config_end.hpp>
  35. #endif //#ifndef BOOST_INTRUSIVE_GET_PARENT_FROM_MEMBER_HPP