File indexing completed on 2025-01-18 09:38:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_INTRUSIVE_DETAIL_PARENT_FROM_MEMBER_HPP
0013 #define BOOST_INTRUSIVE_DETAIL_PARENT_FROM_MEMBER_HPP
0014
0015 #ifndef BOOST_CONFIG_HPP
0016 # include <boost/config.hpp>
0017 #endif
0018
0019 #if defined(BOOST_HAS_PRAGMA_ONCE)
0020 # pragma once
0021 #endif
0022
0023 #include <boost/intrusive/detail/config_begin.hpp>
0024 #include <boost/intrusive/detail/workaround.hpp>
0025 #include <cstddef>
0026
0027 #if defined(_MSC_VER)
0028 #define BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER
0029 #include <boost/static_assert.hpp>
0030 #endif
0031
0032 namespace boost {
0033 namespace intrusive {
0034 namespace detail {
0035
0036 template<class Parent, class Member>
0037 BOOST_INTRUSIVE_FORCEINLINE std::ptrdiff_t offset_from_pointer_to_member(const Member Parent::* ptr_to_member)
0038 {
0039
0040 #if defined(BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER)
0041
0042
0043 union caster_union
0044 {
0045 const Member Parent::* ptr_to_member;
0046 int offset;
0047 } caster;
0048
0049
0050
0051
0052 BOOST_STATIC_ASSERT( sizeof(caster) == sizeof(int) );
0053
0054 caster.ptr_to_member = ptr_to_member;
0055 return std::ptrdiff_t(caster.offset);
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074 #elif defined(__GNUC__) || defined(__HP_aCC) || defined(BOOST_INTEL) || \
0075 defined(__IBMCPP__) || defined(__DECCXX)
0076 const Parent * const parent = 0;
0077 const char *const member = static_cast<const char*>(static_cast<const void*>(&(parent->*ptr_to_member)));
0078 return std::ptrdiff_t(member - static_cast<const char*>(static_cast<const void*>(parent)));
0079 #else
0080
0081 union caster_union
0082 {
0083 const Member Parent::* ptr_to_member;
0084 std::ptrdiff_t offset;
0085 } caster;
0086 caster.ptr_to_member = ptr_to_member;
0087 return caster.offset - 1;
0088 #endif
0089 }
0090
0091 template<class Parent, class Member>
0092 BOOST_INTRUSIVE_FORCEINLINE Parent *parent_from_member(Member *member, const Member Parent::* ptr_to_member)
0093 {
0094 return static_cast<Parent*>
0095 (
0096 static_cast<void*>
0097 (
0098 static_cast<char*>(static_cast<void*>(member)) - offset_from_pointer_to_member(ptr_to_member)
0099 )
0100 );
0101 }
0102
0103 template<class Parent, class Member>
0104 BOOST_INTRUSIVE_FORCEINLINE const Parent *parent_from_member(const Member *member, const Member Parent::* ptr_to_member)
0105 {
0106 return static_cast<const Parent*>
0107 (
0108 static_cast<const void*>
0109 (
0110 static_cast<const char*>(static_cast<const void*>(member)) - offset_from_pointer_to_member(ptr_to_member)
0111 )
0112 );
0113 }
0114
0115 }
0116 }
0117 }
0118
0119 #include <boost/intrusive/detail/config_end.hpp>
0120
0121 #endif