![]() |
Home | Libraries | People | FAQ | More |
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; template<typename U> using rebind = U *; // member classes/structs/unions template<typename U> struct rebind_pointer { // types typedef U * type; }; // public static functions static pointer pointer_to(reference) noexcept; template<typename U> static pointer static_cast_from(U *) noexcept; template<typename U> static pointer const_cast_from(U *) noexcept; template<typename U> static pointer dynamic_cast_from(U *) noexcept; };
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.
Note: When defining a custom family of pointers or references to be used with BI library, make sure the public static conversion functions accessed through the pointer_traits interface (*_cast_from and pointer_to) can properly convert between const and nonconst referred member types without the use of implicit constructor calls. It is suggested these conversions be implemented as function templates, where the template argument is the type of the object being converted from.
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.
template<typename U> using rebind = U *;
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, use typename rebind_pointer<U>::type instead of rebind<U> !to obtain a pointer to U. template <class U> using rebind = unspecified;
!Ptrreference if such a type exists (non-standard extension); otherwise, element_type & ! typedef unspecified_type reference;
#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
! 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(reference). ! Non-standard extension: If such function does not exist, returns pointer(addressof(r)); ! ! Note: For non-conforming compilers only the existence of a member function called ! pointer_to is checked. inline static pointer pointer_to(reference r) noexcept { Non-standard extension, it does not require Ptr::pointer_to. If not present tries to converts &r to pointer. const bool value = boost::intrusive::detail:: has_member_function_callable_with_pointer_to <Ptr, Ptr (*)(reference)>::value; boost::intrusive::detail::bool_<value> flag; return pointer_traits::priv_pointer_to(flag, r); }
! Remark: Non-standard extension. ! ! Returns: A dereferenceable pointer to r obtained by calling the static template function ! Ptr::static_cast_from(UPpr/const UPpr &). ! If such function does not exist, returns pointer_to(static_cast<element_type&>(*uptr)) ! ! Note: For non-conforming compilers only the existence of a member function called ! static_cast_from is checked. template<class UPtr> inline static pointer static_cast_from(const UPtr &uptr) noexcept { typedef const UPtr &RefArg; const bool value = boost::intrusive::detail:: has_member_function_callable_with_static_cast_from <pointer, pointer(*)(RefArg)>::value || boost::intrusive::detail:: has_member_function_callable_with_static_cast_from <pointer, pointer(*)(UPtr)>::value; return pointer_traits::priv_static_cast_from(boost::intrusive::detail::bool_<value>(), uptr); }
! Remark: Non-standard extension. ! ! Returns: A dereferenceable pointer to r obtained by calling the static template function ! Ptr::const_cast_from<UPtr>(UPpr/const UPpr &). ! If such function does not exist, returns pointer_to(const_cast<element_type&>(*uptr)) ! ! Note: For non-conforming compilers only the existence of a member function called ! const_cast_from is checked. template<class UPtr> inline static pointer const_cast_from(const UPtr &uptr) noexcept { typedef const UPtr &RefArg; const bool value = boost::intrusive::detail:: has_member_function_callable_with_const_cast_from <pointer, pointer(*)(RefArg)>::value || boost::intrusive::detail:: has_member_function_callable_with_const_cast_from <pointer, pointer(*)(UPtr)>::value; return pointer_traits::priv_const_cast_from(boost::intrusive::detail::bool_<value>(), uptr); }
! Remark: Non-standard extension. ! ! Returns: A dereferenceable pointer to r obtained by calling the static template function ! Ptr::dynamic_cast_from<UPtr>(UPpr/const UPpr &). ! If such function does not exist, returns pointer_to(dynamic_cast<element_type>(&*uptr)) ! ! Note: For non-conforming compilers only the existence of a member function called ! dynamic_cast_from is checked. template<class UPtr> inline static pointer dynamic_cast_from(const UPtr &uptr) noexcept { typedef const UPtr &RefArg; const bool value = boost::intrusive::detail:: has_member_function_callable_with_dynamic_cast_from <pointer, pointer(*)(RefArg)>::value || boost::intrusive::detail:: has_member_function_callable_with_dynamic_cast_from <pointer, pointer(*)(UPtr)>::value; return pointer_traits::priv_dynamic_cast_from(boost::intrusive::detail::bool_<value>(), uptr); }
/
};
/
! Specialization of pointer_traits for raw pointers ! template <typename T> struct pointer_traits<T*> { typedef T element_type; typedef T* pointer; typedef std::ptrdiff_t difference_type; typedef std::size_t size_type;
typedef T & reference;
!typedef for U * ! !For portable code for C++03 and C++11, use !typename rebind_pointer<U>::type instead of rebind<U> to obtain a pointer to U.
pointer_traits public static functionsstatic pointer pointer_to(reference r) noexcept;
Returns: addressof(r)
template<typename U> static pointer static_cast_from(U * uptr) noexcept;
Returns: static_cast<pointer>(uptr)
template<typename U> static pointer const_cast_from(U * uptr) noexcept;
Returns: const_cast<pointer>(uptr)
template<typename U> static pointer dynamic_cast_from(U * uptr) noexcept;
Returns: dynamic_cast<pointer>(uptr)