scoped_allocator_adaptor Class
Represents a nest of allocators.
template <class Outer, class... Inner>
class scoped_allocator_adaptor;
The class template encapsulates a nest of one or more allocators. Each such class has an outermost allocator of type outer_allocator_type
, a synonym for Outer
, which is a public base of the scoped_allocator_adaptor
object. Outer
is used to allocate memory to be used by a container. You can obtain a reference to this allocator base object by calling outer_allocator
.
The remainder of the nest has type inner_allocator_type
. An inner allocator is used to allocate memory for elements within a container. You can obtain a reference to the stored object of this type by calling inner_allocator
. If Inner...
isn't empty, inner_allocator_type
has type scoped_allocator_adaptor<Inner...>
, and inner_allocator
designates a member object. Otherwise, inner_allocator_type
has type scoped_allocator_adaptor<Outer>
, and inner_allocator
designates the entire object.
The nest behaves as if it has arbitrary depth, replicating its innermost encapsulated allocator as needed.
Several concepts that aren't a part of the visible interface aid in describing the behavior of this class template. An outermost allocator mediates all calls to the construct and destroy methods. It's effectively defined by the recursive function OUTERMOST(X)
, where OUTERMOST(X)
is one of the following.
If
X.outer_allocator()
is well formed, thenOUTERMOST(X)
isOUTERMOST(X.outer_allocator())
.Otherwise,
OUTERMOST(X)
isX
.
Three types are defined for the sake of exposition:
Type | Description |
---|---|
Outermost |
The type of OUTERMOST(*this) . |
Outermost_traits |
allocator_traits<Outermost> |
Outer_traits |
allocator_traits<Outer> |
Name | Description |
---|---|
scoped_allocator_adaptor | Constructs a scoped_allocator_adaptor object. |
Name | Description |
---|---|
const_pointer |
This type is a synonym for the const_pointer that is associated with the allocator Outer . |
const_void_pointer |
This type is a synonym for the const_void_pointer that is associated with the allocator Outer . |
difference_type |
This type is a synonym for the difference_type that is associated with the allocator Outer . |
inner_allocator_type |
This type is a synonym for the type of the nested adaptor scoped_allocator_adaptor<Inner...> . |
outer_allocator_type |
This type is a synonym for the type of the base allocator Outer . |
pointer |
This type is a synonym for the pointer associated with the allocator Outer . |
propagate_on_container_copy_assignment |
The type holds true only if Outer_traits::propagate_on_container_copy_assignment holds true or inner_allocator_type::propagate_on_container_copy_assignment holds true. |
propagate_on_container_move_assignment |
The type holds true only if Outer_traits::propagate_on_container_move_assignment holds true or inner_allocator_type::propagate_on_container_move_assignment holds true. |
propagate_on_container_swap |
The type holds true only if Outer_traits::propagate_on_container_swap holds true or inner_allocator_type::propagate_on_container_swap holds true. |
size_type |
This type is a synonym for the size_type associated with the allocator Outer . |
value_type |
This type is a synonym for the value_type associated with the allocator Outer . |
void_pointer |
This type is a synonym for the void_pointer associated with the allocator Outer . |
Name | Description |
---|---|
scoped_allocator_adaptor::rebind Struct | Defines the type Outer::rebind\<Other>::other as a synonym for scoped_allocator_adaptor\<Other, Inner...> . |
Name | Description |
---|---|
allocate | Allocates memory by using the Outer allocator. |
construct | Constructs an object. |
deallocate | Deallocates objects by using the outer allocator. |
destroy | Destroys a specified object. |
inner_allocator | Retrieves a reference to the stored object of type inner_allocator_type . |
max_size | Determines the maximum number of objects that can be allocated by the outer allocator. |
outer_allocator | Retrieves a reference to the stored object of type outer_allocator_type . |
select_on_container_copy_construction | Creates a new scoped_allocator_adaptor object with each stored allocator object initialized by calling select_on_container_copy_construction for each corresponding allocator. |
Operator | Description |
---|---|
operator= | |
operator== | |
operator!= |
Header: <scoped_allocator>
Namespace: std
Allocates memory by using the Outer
allocator.
pointer allocate(size_type count);pointer allocate(size_type count, const_void_pointer hint);
count
The number of elements for which sufficient storage is to be allocated.
hint
A pointer that might assist the allocator object by locating the address of an object allocated prior to the request.
The first member function returns Outer_traits::allocate(outer_allocator(), count)
. The second member function returns Outer_traits::allocate(outer_allocator(), count, hint)
.
Constructs an object.
template <class Ty, class... Atypes>
void construct(Ty* ptr, Atypes&&... args);
template <class Ty1, class Ty2, class... Atypes1, class... Atypes2>
void construct(pair<Ty1, Ty2>* ptr, piecewise_construct_t,
tuple<Atypes1&&...>
first, tuple<Atypes1&&...> second);
template <class Ty1, class Ty2>
void construct(pair<Ty1, Ty2>* ptr);
template <class Ty1, class Ty2, class Uy1, class Uy2>
void construct(pair<Ty1, Ty2>* ptr,
class Uy1&& first, class Uy2&& second);
template <class Ty1, class Ty2, class Uy1, class Uy2>
void construct(pair<Ty1, Ty2>* ptr, const pair<Uy1, Uy2>& right);
template <class Ty1, class Ty2, class Uy1, class Uy2>
void construct(pair<Ty1, Ty2>* ptr, pair<Uy1, Uy2>&& right);
ptr
A pointer to the memory location where the object is to be constructed.
args
A list of arguments.
first
An object of the first type in a pair.
second
An object of the second type in a pair.
right
An existing object to be moved or copied.
The first method constructs the object at ptr by calling Outermost_traits::construct(OUTERMOST(*this), ptr, xargs...)
, where xargs...
is one of the following.
If
uses_allocator<Ty, inner_allocator_type>
holds false, thenxargs...
isargs...
.If
uses_allocator<Ty, inner_allocator_type>
holds true, andis_constructible<Ty, allocator_arg_t, inner_allocator_type, args...>
holds true, thenxargs...
isallocator_arg, inner_allocator(), args...
.If
uses_allocator<Ty, inner_allocator_type>
holds true, andis_constructible<Ty, args..., inner_allocator()>
holds true, thenxargs...
isargs..., inner_allocator()
.
The second method constructs the pair object at ptr by calling Outermost_traits::construct(OUTERMOST(*this), &ptr->first, xargs...)
, where xargs...
is first...
modified as in the above list, and Outermost_traits::construct(OUTERMOST(*this), &ptr->second, xargs...)
, where xargs...
is second...
modified as in the above list.
The third method behaves the same as this->construct(ptr, piecewise_construct, tuple<>, tuple<>)
.
The fourth method behaves the same as this->construct(ptr, piecewise_construct, forward_as_tuple(std::forward<Uy1>(first), forward_as_tuple(std::forward<Uy2>(second))
.
The fifth method behaves the same as this->construct(ptr, piecewise_construct, forward_as_tuple(right.first), forward_as_tuple(right.second))
.
The sixth method behaves the same as this->construct(ptr, piecewise_construct, forward_as_tuple(std::forward<Uy1>(right.first), forward_as_tuple(std::forward<Uy2>(right.second))
.
Deallocates objects by using the outer allocator.
void deallocate(pointer ptr, size_type count);
ptr
A pointer to the starting location of the objects to be deallocated.
count
The number of objects to deallocate.
Destroys a specified object.
template <class Ty>
void destroy(Ty* ptr)
ptr
A pointer to the object to be destroyed.
Outermost_traits::destroy(OUTERMOST(*this), ptr)
Retrieves a reference to the stored object of type inner_allocator_type
.
inner_allocator_type& inner_allocator() noexcept;
const inner_allocator_type& inner_allocator() const noexcept;
A reference to the stored object of type inner_allocator_type
.
Determines the maximum number of objects that can be allocated by the outer allocator.
size_type max_size();
Outer_traits::max_size(outer_allocator())
scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default;
scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default;
template <class OuterA1, class OuterA2, class... InnerAllocs>
bool operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
template <class OuterA1, class OuterA2, class... InnerAllocs>
bool operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
Retrieves a reference to the stored object of type outer_allocator_type
.
outer_allocator_type& outer_allocator() noexcept;
const outer_allocator_type& outer_allocator() const noexcept;
A reference to the stored object of type outer_allocator_type
.
Defines the type Outer::rebind\<Other>::other
as a synonym for scoped_allocator_adaptor\<Other, Inner...>
.
struct rebind{ typedef Other_traits::rebind<Other> Other_alloc; typedef scoped_allocator_adaptor<Other_alloc, Inner...> other; };
Constructs a scoped_allocator_adaptor
object. Also includes a destructor.
scoped_allocator_adaptor();
scoped_allocator_adaptor(const scoped_allocator_adaptor& right) noexcept;
template <class Outer2>
scoped_allocator_adaptor(
const scoped_allocator_adaptor<Outer2, Inner...>& right) noexcept;
template <class Outer2>
scoped_allocator_adaptor(
scoped_allocator_adaptor<Outer2, Inner...>&& right) noexcept;
template <class Outer2>
scoped_allocator_adaptor(Outer2&& al,
const Inner&... rest) noexcept;
~scoped_allocator_adaptor();
right
An existing scoped_allocator_adaptor
.
al
An existing allocator to be used as the outer allocator.
rest
A list of allocators to be used as the inner allocators.
The first constructor default constructs its stored allocator objects. Each of the next three constructors constructs its stored allocator objects from the corresponding objects in right. The last constructor constructs its stored allocator objects from the corresponding arguments in the argument list.
Creates a new scoped_allocator_adaptor
object with each stored allocator object initialized by calling select_on_container_copy_construction
for each corresponding allocator.
scoped_allocator_adaptor select_on_container_copy_construction();
This method effectively returns scoped_allocator_adaptor(Outer_traits::select_on_container_copy_construction(*this), inner_allocator().select_on_container_copy_construction())
. The result is a new scoped_allocator_adaptor
object with each stored allocator object initialized by calling al.select_on_container_copy_construction()
for the corresponding allocator al.