File indexing completed on 2025-12-15 09:53:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef BOOST_INTRUSIVE_POINTER_TRAITS_HPP
0018 #define BOOST_INTRUSIVE_POINTER_TRAITS_HPP
0019
0020 #include <boost/intrusive/detail/config_begin.hpp>
0021 #include <boost/intrusive/detail/workaround.hpp>
0022 #include <boost/intrusive/pointer_rebind.hpp>
0023 #include <boost/move/detail/pointer_element.hpp>
0024 #include <boost/intrusive/detail/mpl.hpp>
0025 #include <cstddef>
0026
0027 #if defined(BOOST_HAS_PRAGMA_ONCE)
0028 # pragma once
0029 #endif
0030
0031 namespace boost {
0032 namespace intrusive {
0033 namespace detail {
0034
0035 #if !defined(BOOST_MSVC) || (BOOST_MSVC > 1310)
0036 BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_member_function_callable_with_pointer_to, pointer_to)
0037 BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_member_function_callable_with_dynamic_cast_from, dynamic_cast_from)
0038 BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_member_function_callable_with_static_cast_from, static_cast_from)
0039 BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(has_member_function_callable_with_const_cast_from, const_cast_from)
0040 #else
0041 BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(has_member_function_callable_with_pointer_to, pointer_to)
0042 BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(has_member_function_callable_with_dynamic_cast_from, dynamic_cast_from)
0043 BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(has_member_function_callable_with_static_cast_from, static_cast_from)
0044 BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(has_member_function_callable_with_const_cast_from, const_cast_from)
0045 #endif
0046
0047 BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(element_type)
0048 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(difference_type)
0049 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(size_type)
0050 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(reference)
0051 BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(value_traits_ptr)
0052
0053 }
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068 template <typename Ptr>
0069 struct pointer_traits
0070 {
0071 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
0072
0073
0074 typedef Ptr pointer;
0075
0076
0077
0078
0079 typedef unspecified_type element_type;
0080
0081
0082
0083 typedef unspecified_type difference_type;
0084
0085
0086
0087
0088
0089
0090
0091 template <class U> using rebind = unspecified;
0092
0093
0094
0095 typedef unspecified_type reference;
0096 #else
0097 typedef Ptr pointer;
0098
0099 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT
0100 ( boost::intrusive::detail::, Ptr, element_type
0101 , boost::movelib::detail::first_param<Ptr>) element_type;
0102
0103 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
0104 (boost::intrusive::detail::, Ptr, difference_type, std::ptrdiff_t) difference_type;
0105
0106 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
0107 ( boost::intrusive::detail::, Ptr, size_type
0108 , typename boost::move_detail::
0109 make_unsigned<difference_type>::type) size_type;
0110
0111 typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT
0112 ( boost::intrusive::detail::, Ptr, reference
0113 , typename boost::intrusive::detail::unvoid_ref<element_type>::type) reference;
0114
0115 template <class U> struct rebind_pointer
0116 {
0117 typedef typename boost::intrusive::pointer_rebind<Ptr, U>::type type;
0118 };
0119
0120 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
0121 template <class U> using rebind = typename boost::intrusive::pointer_rebind<Ptr, U>::type;
0122 #endif
0123 #endif
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133 BOOST_INTRUSIVE_FORCEINLINE static pointer pointer_to(reference r) BOOST_NOEXCEPT
0134 {
0135
0136
0137 const bool value = boost::intrusive::detail::
0138 has_member_function_callable_with_pointer_to
0139 <Ptr, Ptr (*)(reference)>::value;
0140 boost::intrusive::detail::bool_<value> flag;
0141 return pointer_traits::priv_pointer_to(flag, r);
0142 }
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152 template<class UPtr>
0153 BOOST_INTRUSIVE_FORCEINLINE static pointer static_cast_from(const UPtr &uptr) BOOST_NOEXCEPT
0154 {
0155 typedef const UPtr &RefArg;
0156 const bool value = boost::intrusive::detail::
0157 has_member_function_callable_with_static_cast_from
0158 <pointer, pointer(*)(RefArg)>::value
0159 || boost::intrusive::detail::
0160 has_member_function_callable_with_static_cast_from
0161 <pointer, pointer(*)(UPtr)>::value;
0162 return pointer_traits::priv_static_cast_from(boost::intrusive::detail::bool_<value>(), uptr);
0163 }
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173 template<class UPtr>
0174 BOOST_INTRUSIVE_FORCEINLINE static pointer const_cast_from(const UPtr &uptr) BOOST_NOEXCEPT
0175 {
0176 typedef const UPtr &RefArg;
0177 const bool value = boost::intrusive::detail::
0178 has_member_function_callable_with_const_cast_from
0179 <pointer, pointer(*)(RefArg)>::value
0180 || boost::intrusive::detail::
0181 has_member_function_callable_with_const_cast_from
0182 <pointer, pointer(*)(UPtr)>::value;
0183 return pointer_traits::priv_const_cast_from(boost::intrusive::detail::bool_<value>(), uptr);
0184 }
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194 template<class UPtr>
0195 BOOST_INTRUSIVE_FORCEINLINE static pointer dynamic_cast_from(const UPtr &uptr) BOOST_NOEXCEPT
0196 {
0197 typedef const UPtr &RefArg;
0198 const bool value = boost::intrusive::detail::
0199 has_member_function_callable_with_dynamic_cast_from
0200 <pointer, pointer(*)(RefArg)>::value
0201 || boost::intrusive::detail::
0202 has_member_function_callable_with_dynamic_cast_from
0203 <pointer, pointer(*)(UPtr)>::value;
0204 return pointer_traits::priv_dynamic_cast_from(boost::intrusive::detail::bool_<value>(), uptr);
0205 }
0206
0207
0208 private:
0209
0210 template <class T>
0211 BOOST_INTRUSIVE_FORCEINLINE static T* to_raw_pointer(T* p) BOOST_NOEXCEPT
0212 { return p; }
0213
0214 template <class Pointer>
0215 BOOST_INTRUSIVE_FORCEINLINE static typename pointer_traits<Pointer>::element_type*
0216 to_raw_pointer(const Pointer &p) BOOST_NOEXCEPT
0217 { return pointer_traits::to_raw_pointer(p.operator->()); }
0218
0219
0220 BOOST_INTRUSIVE_FORCEINLINE static pointer priv_pointer_to(boost::intrusive::detail::true_, reference r) BOOST_NOEXCEPT
0221 { return Ptr::pointer_to(r); }
0222
0223 BOOST_INTRUSIVE_FORCEINLINE static pointer priv_pointer_to(boost::intrusive::detail::false_, reference r) BOOST_NOEXCEPT
0224 { return pointer(boost::intrusive::detail::addressof(r)); }
0225
0226
0227 template<class UPtr>
0228 BOOST_INTRUSIVE_FORCEINLINE static pointer priv_static_cast_from(boost::intrusive::detail::true_, const UPtr &uptr) BOOST_NOEXCEPT
0229 { return Ptr::static_cast_from(uptr); }
0230
0231 template<class UPtr>
0232 BOOST_INTRUSIVE_FORCEINLINE static pointer priv_static_cast_from(boost::intrusive::detail::false_, const UPtr &uptr) BOOST_NOEXCEPT
0233 { return uptr ? pointer_to(*static_cast<element_type*>(to_raw_pointer(uptr))) : pointer(); }
0234
0235
0236 template<class UPtr>
0237 BOOST_INTRUSIVE_FORCEINLINE static pointer priv_const_cast_from(boost::intrusive::detail::true_, const UPtr &uptr) BOOST_NOEXCEPT
0238 { return Ptr::const_cast_from(uptr); }
0239
0240 template<class UPtr>
0241 BOOST_INTRUSIVE_FORCEINLINE static pointer priv_const_cast_from(boost::intrusive::detail::false_, const UPtr &uptr) BOOST_NOEXCEPT
0242 { return uptr ? pointer_to(const_cast<element_type&>(*uptr)) : pointer(); }
0243
0244
0245 template<class UPtr>
0246 BOOST_INTRUSIVE_FORCEINLINE static pointer priv_dynamic_cast_from(boost::intrusive::detail::true_, const UPtr &uptr) BOOST_NOEXCEPT
0247 { return Ptr::dynamic_cast_from(uptr); }
0248
0249 template<class UPtr>
0250 BOOST_INTRUSIVE_FORCEINLINE static pointer priv_dynamic_cast_from(boost::intrusive::detail::false_, const UPtr &uptr) BOOST_NOEXCEPT
0251 { return uptr ? pointer_to(dynamic_cast<element_type&>(*uptr)) : pointer(); }
0252
0253 };
0254
0255
0256
0257
0258 template <typename Ptr>
0259 struct pointer_traits<const Ptr> : pointer_traits<Ptr> {};
0260 template <typename Ptr>
0261 struct pointer_traits<volatile Ptr> : pointer_traits<Ptr> { };
0262 template <typename Ptr>
0263 struct pointer_traits<const volatile Ptr> : pointer_traits<Ptr> { };
0264
0265 template <typename Ptr>
0266 struct pointer_traits<Ptr&> : pointer_traits<Ptr> { };
0267
0268
0269
0270
0271
0272 template <typename T>
0273 struct pointer_traits<T*>
0274 {
0275 typedef T element_type;
0276 typedef T* pointer;
0277 typedef std::ptrdiff_t difference_type;
0278 typedef std::size_t size_type;
0279
0280 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
0281 typedef T & reference;
0282
0283
0284
0285
0286 template <class U> using rebind = U*;
0287 #else
0288 typedef typename boost::intrusive::detail::unvoid_ref<element_type>::type reference;
0289 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
0290 template <class U> using rebind = U*;
0291 #endif
0292 #endif
0293
0294 template <class U> struct rebind_pointer
0295 { typedef U* type; };
0296
0297
0298
0299 BOOST_INTRUSIVE_FORCEINLINE static pointer pointer_to(reference r) BOOST_NOEXCEPT
0300 { return boost::intrusive::detail::addressof(r); }
0301
0302
0303
0304 template<class U>
0305 BOOST_INTRUSIVE_FORCEINLINE static pointer static_cast_from(U *uptr) BOOST_NOEXCEPT
0306 { return static_cast<pointer>(uptr); }
0307
0308
0309
0310 template<class U>
0311 BOOST_INTRUSIVE_FORCEINLINE static pointer const_cast_from(U *uptr) BOOST_NOEXCEPT
0312 { return const_cast<pointer>(uptr); }
0313
0314
0315
0316 template<class U>
0317 BOOST_INTRUSIVE_FORCEINLINE static pointer dynamic_cast_from(U *uptr) BOOST_NOEXCEPT
0318 { return dynamic_cast<pointer>(uptr); }
0319 };
0320
0321 }
0322 }
0323
0324 #include <boost/intrusive/detail/config_end.hpp>
0325
0326 #endif