[pointer.traits] (original) (raw)
20 Memory management library [mem]
20.2 Memory [memory]
20.2.3 Pointer traits [pointer.traits]
20.2.3.1 General [pointer.traits.general]
The class template pointer_traits supplies a uniform interface to certain attributes of pointer-like types.
namespace std { template<class Ptr> struct pointer_traits { see below;};template<class T> struct pointer_traits<T*> { using pointer = T*;using element_type = T;using difference_type = ptrdiff_t;template<class U> using rebind = U*;static constexpr pointer pointer_to(see below r) noexcept;};}
20.2.3.2 Member types [pointer.traits.types]
The definitions in this subclause make use of the following exposition-only class template and concept:template<class T> struct ptr-traits-elem { };template<class T> requires requires { typename T::element_type; } struct ptr-traits-elem<T> { using type = typename T::element_type; };template<template<class...> class SomePointer, class T, class... Args> requires (!requires { typename SomePointer<T, Args...>::element_type; }) struct ptr-traits-elem<SomePointer<T, Args...>> { using type = T; };template<class Ptr> concept has-elem-type = requires { typename ptr-traits-elem<Ptr>::type; }
If Ptr satisfies has-elem-type, a specialization pointer_traits<Ptr>generated from the pointer_traits primary template has the following members as well as those described in [pointer.traits.functions]; otherwise, such a specialization has no members by any of those names.
using pointer = _see below_;
using element_type = _see below_;
Type: typename ptr-traits-elem<Ptr>::type.
using difference_type = _see below_;
Type: Ptr::difference_type if the qualified-id Ptr::difference_type is valid and denotes a type ([temp.deduct]); otherwise,ptrdiff_t.
template<class U> using rebind = _see below_;
Alias template: Ptr::rebind<U> if the qualified-id Ptr::rebind<U> is valid and denotes a type ([temp.deduct]); otherwise,SomePointer<U, Args> ifPtr is a class template instantiation of the form SomePointer<T, Args>, where Args is zero or more type arguments; otherwise, the instantiation ofrebind is ill-formed.
20.2.3.3 Member functions [pointer.traits.functions]
static pointer pointer_traits::pointer_to(_see below_ r);static constexpr pointer pointer_traits<T*>::pointer_to(_see below_ r) noexcept;
Mandates: For the first member function,Ptr::pointer_to(r) is well-formed.
Preconditions: For the first member function,Ptr::pointer_to(r) returns a pointer to rthrough which indirection is valid.
Returns: The first member function returns Ptr::pointer_to(r).
The second member function returns addressof(r).
Remarks: If element_type is cv void, the type ofr is unspecified; otherwise, it is element_type&.
20.2.3.4 Optional members [pointer.traits.optmem]
Specializations of pointer_traits may define the member declared in this subclause to customize the behavior of the standard library.
A specialization generated from the pointer_traits primary template has no member by this name.
static element_type* to_address(pointer p) noexcept;
Returns: A pointer of type element_type* that references the same location as the argument p.
[Note 1:
This function is intended to be the inverse of pointer_to.
If defined, it customizes the behavior of the non-member functionto_address ([pointer.conversion]).
— _end note_]