20 General utilities library [utilities]

20.12 Memory resources [mem.res]

20.12.3 Class template polymorphic_allocator [mem.poly.allocator.class]

20.12.3.2 polymorphic_allocator member functions [mem.poly.allocator.mem]

Tp* allocate(size_t n);

Returns: Equivalent to

return static_cast<Tp*>(memory_rsrc->allocate(n * sizeof(Tp), alignof(Tp)));

void deallocate(Tp* p, size_t n);

Requires: p was allocated from a memory resource x, equal to *memory_rsrc, using x.allocate(n * sizeof(Tp), alignof(Tp)).

Effects: Equivalent to memory_rsrc->deallocate(p, n * sizeof(Tp), alignof(Tp)).

Throws: Nothing.

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

Requires: Uses-allocator construction of T with allocator resource() (see [allocator.uses.construction]) and constructor arguments std::forward<Args>(args)... is well-formed. [ Note: Uses-allocator construction is always well formed for types that do not use allocators. — end note ]

Effects: Construct a T object in the storage whose address is represented by p by uses-allocator construction with allocator resource() and constructor arguments std::forward<Args>(args)....

Throws: Nothing unless the constructor for T throws.

template <class T1, class T2, class... Args1, class... Args2> void construct(pair<T1,T2>* p, piecewise_construct_t, tuple<Args1...> x, tuple<Args2...> y);

Note: This method and the construct methods that follow are overloads for piecewise construction of pairs ([pairs.pair]).  — end note ]

Effects: Let xprime be a tuple constructed from x according to the appropriate rule from the following list. [ Note: The following description can be summarized as constructing a pair<T1, T2> object in the storage whose address is represented by p, as if by separate uses-allocator construction with allocator resource() ([allocator.uses.construction]) of p->first using the elements of x and p->second using the elements of y.  — end note ]

  • If uses_allocator_v<T1,memory_resource*> is false
    and is_constructible_v<T,Args1...> is true,
    then xprime is x.

  • Otherwise, if uses_allocator_v<T1,memory_resource*> is true
    and is_constructible_v<T1,allocator_arg_t,memory_resource*,Args1...> is true,
    then xprime is tuple_cat(make_tuple(allocator_arg, resource()), std::move(x)).

  • Otherwise, if uses_allocator_v<T1,memory_resource*> is true
    and is_constructible_v<T1,Args1...,memory_resource*> is true,
    then xprime is tuple_cat(std::move(x), make_tuple(resource())).

  • Otherwise the program is ill formed.

Let yprime be a tuple constructed from y according to the appropriate rule from the following list:

  • If uses_allocator_v<T2,memory_resource*> is false
    and is_constructible_v<T,Args2...> is true,
    then yprime is y.

  • Otherwise, if uses_allocator_v<T2,memory_resource*> is true
    and is_constructible_v<T2,allocator_arg_t,memory_resource*,Args2...> is true,
    then yprime is tuple_cat(make_tuple(allocator_arg, resource()), std::move(y)).

  • Otherwise, if uses_allocator_v<T2,memory_resource*> is true
    and is_constructible_v<T2,Args2...,memory_resource*> is true,
    then yprime is tuple_cat(std::move(y), make_tuple(resource())).

  • Otherwise the program is ill formed.

Then, using piecewise_construct, xprime, and yprime as the constructor arguments, this function constructs a pair<T1, T2> object in the storage whose address is represented by p.

template <class T1, class T2> void construct(pair<T1,T2>* p);

Effects: Equivalent to:

construct(p, piecewise_construct, tuple<>(), tuple<>());

template <class T1, class T2, class U, class V> void construct(pair<T1,T2>* p, U&& x, V&& y);

Effects: Equivalent to:

construct(p, piecewise_construct,
          forward_as_tuple(std::forward<U>(x)),
          forward_as_tuple(std::forward<V>(y)));

template <class T1, class T2, class U, class V> void construct(pair<T1,T2>* p, const pair<U, V>& pr);

Effects: Equivalent to:

construct(p, piecewise_construct,
          forward_as_tuple(pr.first),
          forward_as_tuple(pr.second));

template <class T1, class T2, class U, class V> void construct(pair<T1,T2>* p, pair<U, V>&& pr);

Effects: Equivalent to:

construct(p, piecewise_construct,
          forward_as_tuple(std::forward<U>(pr.first)),
          forward_as_tuple(std::forward<V>(pr.second)));

template <class T> void destroy(T* p);

Effects: As if by p->~T().

polymorphic_allocator select_on_container_copy_construction() const;

Returns: polymorphic_allocator().

Note: The memory resource is not propagated.  — end note ]

memory_resource* resource() const;

Returns: memory_rsrc.