Files
cppdraft_translate/cppdraft/allocator/traits.md
2025-10-25 03:02:53 +03:00

12 KiB
Raw Blame History

[allocator.traits]

20 Memory management library [mem]

20.2 Memory [memory]

20.2.9 Allocator traits [allocator.traits]

20.2.9.1 General [allocator.traits.general]

1

#

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_traits supplies the entire required interface.

[Note 1:

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

— end note]

If a program declares an explicit or partial specialization of allocator_traits, the program is ill-formed, no diagnostic required.

🔗

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 using rebind_alloc = see below; template using rebind_traits = allocator_traits<rebind_alloc>; static constexpr pointer allocate(Alloc& a, size_type n); static constexpr pointer allocate(Alloc& a, size_type n, const_void_pointer hint); static constexpr allocation_result<pointer, size_type> allocate_at_least(Alloc& a, size_type n); 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); templatestatic 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.2.9.2 Member types [allocator.traits.types]

🔗

using pointer = see below;

1

#

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;

2

#

Type: Alloc::const_pointer if the qualified-id Alloc::const_pointer is valid and denotes a type ([temp.deduct]); otherwise,pointer_traits::rebind<const value_type>.

🔗

using void_pointer = see below;

3

#

Type: Alloc::void_pointer if the qualified-id Alloc::void_pointer is valid and denotes a type ([temp.deduct]); otherwise,pointer_traits::rebind<void>.

🔗

using const_void_pointer = see below;

4

#

Type: Alloc::const_void_pointer if the qualified-id Alloc::const_void_pointer is valid and denotes a type ([temp.deduct]); otherwise,pointer_traits::rebind.

🔗

using difference_type = see below;

5

#

Type: Alloc::difference_type if the qualified-id Alloc::difference_type is valid and denotes a type ([temp.deduct]); otherwise,pointer_traits::difference_type.

🔗

using size_type = see below;

6

#

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;

7

#

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;

8

#

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;

9

#

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;

10

#

Type: Alloc::is_always_equal if the qualified-id Alloc::is_always_equal is valid and denotes a type ([temp.deduct]); otherwise is_empty::type.

🔗

template<class T> using rebind_alloc = see below;

11

#

Alias template: Alloc::rebind::other if the qualified-id Alloc::rebind::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.2.9.3 Static member functions [allocator.traits.members]

🔗

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

1

#

Returns: a.allocate(n).

🔗

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

2

#

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

🔗

static constexpr allocation_result<pointer, size_type> allocate_at_least(Alloc& a, size_type n);

3

#

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

🔗

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

4

#

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

5

#

Throws: Nothing.

🔗

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

6

#

Effects: Calls a.construct(p, std::forward(args)...) if that call is well-formed; otherwise, invokes construct_at(p, std::forward(args)...).

🔗

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

7

#

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;

8

#

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);

9

#

Returns: rhs.select_on_container_copy_construction() if that expression is well-formed; otherwise, rhs.

20.2.9.4 Other [allocator.traits.other]

1

#

The class template allocation_result has the template parameters, data members, and special members specified above.

It has no base classes or members other than those specified.