23 General utilities library [utilities]

23.12 Memory resources [mem.res]

23.12.3 Class template polymorphic_­allocator [mem.poly.allocator.class]

23.12.3.2 polymorphic_­allocator member functions [mem.poly.allocator.mem]

Tp* allocate(size_t n);

Returns: Эквивалентно

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

Requires: p был выделен из ресурса памяти x, равного *memory_­rsrc, с использованием x.allocate(n * sizeof(Tp), alignof(Tp)).

Effects: Эквивалентно memory_­rsrc->deallocate(p, n * sizeof(Tp), alignof(Tp)).

Throws: Ничего такого.

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

Requires: Конструкция Uses-allocator T с распределителем resource() (см. [allocator.uses.construction]) И аргументами конструктора std​::​forward<Args>(args)... сформирована правильно. [ Note: Конструкция Uses-allocator всегда хорошо сформирована для типов, которые не используют распределители. ]end note

Effects: Создайте T объект в хранилище, адрес которого представлен конструкцией p uses-allocator с resource() аргументами распределителя и конструктора std​::​forward<Args>(args)....

Throws: Ничего, кроме конструктора для T бросков.

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: Этот метод и construct последующие методы являются перегрузками для кусочного построения пар ([pairs.pair]). ]end note

Effects: Позвольте xprime быть tuple построенным из x согласно соответствующему правилу из следующего списка. [ Note: Следующее описание можно резюмировать как создание pair<T1, T2> объекта в хранилище, адрес которого представлен p, как если бы с помощью отдельной конструкции uses-allocator с allocator resource() ([allocator.uses.construction]), p->first использующей элементы x и p->second элементы y. ] end note

  • Если uses_­allocator_­v<T1,memory_­resource*> есть и есть , значит, есть . false
    is_­constructible_­v<T1,Args1...> true
    xprime x

  • В противном случае, если uses_­allocator_­v<T1,memory_­resource*> есть и есть , то есть . true
    is_­constructible_­v<T1,allocator_­arg_­t,memory_­resource*,Args1...> true
    xprime tuple_­cat(make_­tuple(allocator_­arg, resource()), std​::​move(x))

  • В противном случае, если uses_­allocator_­v<T1,memory_­resource*> есть и есть , то есть . true
    is_­constructible_­v<T1,Args1...,memory_­resource*> true
    xprime tuple_­cat(std​::​move(x), make_­tuple(resource()))

  • В противном случае программа плохо сформирована.

Позвольте yprime быть кортежем, построенным y согласно соответствующему правилу из следующего списка:

  • Если uses_­allocator_­v<T2,memory_­resource*> есть и есть , значит, есть . false
    is_­constructible_­v<T2,Args2...> true
    yprime y

  • В противном случае, если uses_­allocator_­v<T2,memory_­resource*> есть и есть , то есть . true
    is_­constructible_­v<T2,allocator_­arg_­t,memory_­resource*,Args2...> true
    yprime tuple_­cat(make_­tuple(allocator_­arg, resource()), std​::​move(y))

  • В противном случае, если uses_­allocator_­v<T2,memory_­resource*> есть и есть , то есть . true
    is_­constructible_­v<T2,Args2...,memory_­resource*> true
    yprime tuple_­cat(std​::​move(y), make_­tuple(resource()))

  • В противном случае программа плохо сформирована.

Затем, используя piecewise_­construct, xprimeи yprime в качестве аргументов конструктора, эта функция создает pair<T1, T2> объект в хранилище, адрес которого представлен как p.

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

Effects: Эквивалентен:

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: Эквивалентен:

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: Эквивалентен:

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: Эквивалентен:

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: Как будто мимо p->~T().

polymorphic_allocator select_on_container_copy_construction() const;

Returns: polymorphic_­allocator().

[ Note: Ресурс памяти не распространяется. ] end note

memory_resource* resource() const;

Returns: memory_­rsrc.