...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::intrusive::pointer_traits
// In header: <boost/intrusive/pointer_traits.hpp> template<typename Ptr> struct pointer_traits { // types typedef Ptr pointer; typedef unspecified_type element_type; typedef unspecified_type difference_type; typedef unspecified rebind; typedef element_type & reference; // public static functions static pointer pointer_to(reference); template<typename UPtr> static pointer static_cast_from(const UPtr &); template<typename UPtr> static pointer const_cast_from(const UPtr &); template<typename UPtr> static pointer dynamic_cast_from(const UPtr &); };
pointer_traits is the implementation of C++11 std::pointer_traits class with some extensions like castings.
pointer_traits supplies a uniform interface to certain attributes of pointer-like types.
pointer_traits
public
typesThe pointer type queried by this pointer_traits instantiation
typedef unspecified_type element_type;
Ptr::element_type if such a type exists; otherwise, T if Ptr is a class template instantiation of the form SomePointer<T, Args>, where Args is zero or more type arguments ; otherwise , the specialization is ill-formed.
typedef unspecified_type difference_type;
Ptr::difference_type if such a type exists; otherwise, std::ptrdiff_t.
Ptr::rebind<U> if such a type exists; otherwise, SomePointer<U, Args> if Ptr is a class template instantiation of the form SomePointer<T, Args>, where Args is zero or more type arguments ; otherwise, the instantiation of rebind is ill-formed.
For portable code for C++03 and C++11, <preformatted>typename rebind_pointer<U>::type</preformatted> shall be used instead of rebind<U> to obtain a pointer to U.
typedef element_type & reference;
Ptr::rebind<U> if such a type exists; otherwise, SomePointer<U, Args> if Ptr is a class template instantiation of the form SomePointer<T, Args>, where Args is zero or more type arguments ; otherwise, the instantiation of rebind is ill-formed.
pointer_traits
public static functionsstatic pointer pointer_to(reference r);
Remark: If element_type is (possibly cv-qualified) void, r type is unspecified; otherwise, it is element_type &.
Returns: A dereferenceable pointer to r obtained by calling Ptr::pointer_to(r). Non-standard extension: If such function does not exist, returns pointer(addressof(r));
template<typename UPtr> static pointer static_cast_from(const UPtr & uptr);
Remark: Non-standard extension.
Returns: A dereferenceable pointer to r obtained by calling Ptr::static_cast_from(r). If such function does not exist, returns pointer_to(static_cast<element_type&>(*uptr))
template<typename UPtr> static pointer const_cast_from(const UPtr & uptr);
Remark: Non-standard extension.
Returns: A dereferenceable pointer to r obtained by calling Ptr::const_cast_from(r). If such function does not exist, returns pointer_to(const_cast<element_type&>(*uptr))
template<typename UPtr> static pointer dynamic_cast_from(const UPtr & uptr);
Remark: Non-standard extension.
Returns: A dereferenceable pointer to r obtained by calling Ptr::dynamic_cast_from(r). If such function does not exist, returns pointer_to(dynamic_cast<element_type>(&*uptr))