[allocator.traits] (original) (raw)

20 General utilities library [utilities]

20.10 Memory [memory]

20.10.9 Allocator traits [allocator.traits]

The class template allocator_­traits supplies a uniform interface to all allocator types.

An allocator cannot be a non-class type, however, even if allocator_­traitssupplies the entire required interface.

[ Note

:

Thus, it is always possible to create a derived class from an allocator.

end note

]

namespace std { template struct allocator_traits { using allocator_type = Alloc;

using value_type         = typename Alloc::value_type;

using pointer            = see below;
using const_pointer      = see below;
using void_pointer       = see below;
using const_void_pointer = see below;

using difference_type    = see below;
using size_type          = see below;

using propagate_on_container_copy_assignment = see below;
using propagate_on_container_move_assignment = see below;
using propagate_on_container_swap            = see below;
using is_always_equal                        = see below;

template<class T> using rebind_alloc = see below;
template<class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;

[[nodiscard]] static constexpr pointer allocate(Alloc& a, size_type n);
[[nodiscard]] static constexpr pointer allocate(Alloc& a, size_type n,
                                                const_void_pointer hint);

static constexpr void deallocate(Alloc& a, pointer p, size_type n);

template<class T, class... Args>
  static constexpr void construct(Alloc& a, T* p, Args&&... args);

template<class T>
  static constexpr void destroy(Alloc& a, T* p);

static constexpr size_type max_size(const Alloc& a) noexcept;

static constexpr Alloc select_on_container_copy_construction(const Alloc& rhs);

}; }

20.10.9.1 Member types [allocator.traits.types]

using pointer = see below;

Type: Alloc​::​pointer if the qualified-id Alloc​::​pointer is valid and denotes a type ([temp.deduct]); otherwise, value_­type*.

using const_pointer = see below;

Type: Alloc​::​const_­pointer if the qualified-id Alloc​::​const_­pointer is valid and denotes a type ([temp.deduct]); otherwise,pointer_­traits<pointer>​::​rebind<​const value_­type>.

using void_pointer = see below;

Type: Alloc​::​void_­pointer if the qualified-id Alloc​::​void_­pointer is valid and denotes a type ([temp.deduct]); otherwise,pointer_­traits<pointer>​::​rebind<​void>.

using const_void_pointer = see below;

Type: Alloc​::​const_­void_­pointer if the qualified-id Alloc​::​const_­void_­pointer is valid and denotes a type ([temp.deduct]); otherwise,pointer_­traits<pointer>​::​​rebind<const void>.

using difference_type = see below;

Type: Alloc​::​difference_­type if the qualified-id Alloc​::​difference_­type is valid and denotes a type ([temp.deduct]); otherwise,pointer_­traits<pointer>​::​difference_­type.

using size_type = see below;

Type: Alloc​::​size_­type if the qualified-id Alloc​::​size_­type is valid and denotes a type ([temp.deduct]); otherwise,make_­unsigned_­t<difference_­type>.

using propagate_on_container_copy_assignment = see below;

Type: Alloc​::​propagate_­on_­container_­copy_­assignment if the qualified-id Alloc​::​propagate_­on_­container_­copy_­assignment is valid and denotes a type ([temp.deduct]); otherwisefalse_­type.

using propagate_on_container_move_assignment = see below;

Type: Alloc​::​propagate_­on_­container_­move_­assignment if the qualified-id Alloc​::​propagate_­on_­container_­move_­assignment is valid and denotes a type ([temp.deduct]); otherwisefalse_­type.

using propagate_on_container_swap = see below;

Type: Alloc​::​propagate_­on_­container_­swap if the qualified-id Alloc​::​propagate_­on_­container_­swap is valid and denotes a type ([temp.deduct]); otherwisefalse_­type.

using is_always_equal = see below;

Type: Alloc​::​is_­always_­equal if the qualified-id Alloc​::​is_­always_­equalis valid and denotes a type ([temp.deduct]); otherwise is_­empty<Alloc>​::​type.

template<class T> using rebind_alloc = see below;

Alias template: Alloc​::​rebind<T>​::​other if the qualified-id Alloc​::​rebind<T>​::​other is valid and denotes a type ([temp.deduct]); otherwise,Alloc<T, Args> if Alloc is a class template instantiation of the form Alloc<U, Args>, where Args is zero or more type arguments; otherwise, the instantiation of rebind_­alloc is ill-formed.

20.10.9.2 Static member functions [allocator.traits.members]

[[nodiscard]] static constexpr pointer allocate(Alloc& a, size_type n);

[[nodiscard]] static constexpr pointer allocate(Alloc& a, size_type n, const_void_pointer hint);

Returns: a.allocate(n, hint) if that expression is well-formed; otherwise, a.allocate(n).

static constexpr void deallocate(Alloc& a, pointer p, size_type n);

Effects:Calls a.deallocate(p, n).

template<class T, class... Args> static constexpr void construct(Alloc& a, T* p, Args&&... args);

Effects:Calls a.construct(p, std​::​forward<Args>(args)...)if that call is well-formed; otherwise, invokes construct_­at(p, std​::​forward<Args>(args)...).

template<class T> static constexpr void destroy(Alloc& a, T* p);

Effects:Calls a.destroy(p) if that call is well-formed; otherwise, invokesdestroy_­at(p).

static constexpr size_type max_size(const Alloc& a) noexcept;

Returns: a.max_­size() if that expression is well-formed; otherwise,numeric_­limits<size_­type>​::​​max()/sizeof(value_­type).

static constexpr Alloc select_on_container_copy_construction(const Alloc& rhs);

Returns: rhs.select_­on_­container_­copy_­construction() if that expression is well-formed; otherwise, rhs.