std::pointer_traits (3) - Linux Manuals
std::pointer_traits: std::pointer_traits
NAME
std::pointer_traits - std::pointer_traits
Synopsis
Defined in header <memory>
template< class Ptr > struct pointer_traits; (1) (since C++11)
template< class T > struct pointer_traits<T*>; (2) (since C++11)
The pointer_traits class template provides the standardized way to access certain properties of pointer-like types (fancy_pointers, such as boost::interprocess::offset_ptr). The standard template std::allocator_traits relies on pointer_traits to determine the defaults for various typedefs required by Allocator.
1) The non-specialized pointer_traits declares the following types:
Member types
Type Definition
pointer Ptr
element_type Ptr::element_type if present. Otherwise T if Ptr is a template instantiation Template<T, Args...>
difference_type Ptr::difference_type if present, otherwise std::ptrdiff_t
Member alias templates
Template Definition
template <class U> using rebind Ptr::rebind<U> if exists, otherwise Template<U, Args...> if Ptr is a template instantiation Template<T, Args...>
Member functions
pointer_to obtains a dereferenceable pointer to its argument
[static]
2) A specialization is provided for pointer types, T*, which declares the following types
Member types
Type Definition
pointer T*
element_type T
difference_type std::ptrdiff_t
Member alias templates
Template Definition
template< class U > using rebind U*
Member functions
pointer_to obtains a dereferenceable pointer to its argument
[static]
3) A specialization for user-defined fancy pointer types may define an additional static member function
Optional Member functions
to_address obtains a raw pointer from a fancy pointer (inverse of pointer_to)
[static] (C++20)
Notes
The rebind member template alias makes it possible, given a pointer-like type that points to T, to obtain the same pointer-like type that points to U. For example,
Example
// Run this code
Output:
See also
allocator_traits provides information about allocator types
(C++11)
addressof obtains actual address of an object, even if the & operator is overloaded
(C++11)