Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Struct template pointer_traits

boost::intrusive::pointer_traits

Synopsis

// 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 unspecified_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 &);
};

Description

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 types

  1. typedef Ptr pointer;

    The pointer type queried by this pointer_traits instantiation

  2. 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.

  3. typedef unspecified_type difference_type;

    Ptr::difference_type if such a type exists; otherwise, std::ptrdiff_t.

  4. typedef unspecified rebind;

    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.

  5. typedef unspecified_type reference;

    Ptr::reference if such a type exists (non-standard extension); otherwise, element_type &

pointer_traits public static functions

  1. static 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(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.

  2. template<typename UPtr> static pointer static_cast_from(const UPtr & uptr);

    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.

  3. template<typename UPtr> static pointer const_cast_from(const UPtr & 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.

  4. template<typename UPtr> static pointer dynamic_cast_from(const UPtr & 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.


PrevUpHomeNext