Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/named req/AllocatorAwareContainer"

From cppreference.com
< cpp‎ | named req
m (Shorten template names. Use {{lc}} where appropriate.)
(Correct to agree with standard)
Line 27: Line 27:
 
{{dsc|{{ttb|A}}|Allocator for {{ttb|T}} }}
 
{{dsc|{{ttb|A}}|Allocator for {{ttb|T}} }}
 
{{dsc|{{ttb|a}}, {{ttb|b}}|Objects of type {{ttb|X}} (non-const lvalue)}}
 
{{dsc|{{ttb|a}}, {{ttb|b}}|Objects of type {{ttb|X}} (non-const lvalue)}}
{{dsc|{{ttb|t}}|Object of type {{ttb|T}} (lvalue or const rvalue) }}
+
{{dsc|{{ttb|t}}|Object of type {{ttb|X}} (lvalue or const rvalue) }}
{{dsc|{{ttb|rv}}|Object of type {{ttb|T}} (non-const rvalue) }}
+
{{dsc|{{ttb|rv}}|Object of type {{ttb|X}} (non-const rvalue) }}
 
{{dsc|{{ttb|m}}|Object of type {{ttb|A}} }}
 
{{dsc|{{ttb|m}}|Object of type {{ttb|A}} }}
 
{{dsc|{{ttb|Q}}| Allocator type }}
 
{{dsc|{{ttb|Q}}| Allocator type }}
Line 41: Line 41:
 
|{{c|get_allocator()}}||{{ttb|A}}|| || || constant
 
|{{c|get_allocator()}}||{{ttb|A}}|| || || constant
 
|-
 
|-
|{{c|X u;}} || || || {{c|u.empty() {{==}} true && u.get_allocator() {{==}} A()}}  || constant
+
|{{c|X u;}} || ||{{ttb|A}} is {{concept|DefaultConstructible}}|| {{c|u.empty() {{==}} true && u.get_allocator() {{==}} A()}}  || constant
 
|-
 
|-
 
|{{c|X u(m);}} || || || {{c|u.empty() {{==}} true && u.get_allocator() {{==}} m}} || constant
 
|{{c|X u(m);}} || || || {{c|u.empty() {{==}} true && u.get_allocator() {{==}} m}} || constant
 
|-
 
|-
|{{c|X u(t,m);}} || || || {{c|u {{==}} t && u.get_allocator() {{==}} m}} || linear
+
|{{c|X u(t,m);}} ||  
 +
| {{ttb|T}} is {{concept|CopyInsertable}} into {{ttb|X}}
 +
|{{c|u {{==}} t && u.get_allocator() {{==}} m}} || linear
 
|-
 
|-
|{{c|X u(rv);}} ||  
+
|{{c|X u(rv);}} ||
 
| Move constructor of {{ttb|A}} must not throw exceptions  
 
| Move constructor of {{ttb|A}} must not throw exceptions  
 
| {{ttb|u}} has the same elements and an equal allocator as {{ttb|rv}} had before the construction || constant
 
| {{ttb|u}} has the same elements and an equal allocator as {{ttb|rv}} had before the construction || constant
 
|-
 
|-
|{{c|X u(rv,m);}}|| || || The elements of {{ttb|u}} are the same or copies of those of {{ttb|rv}} and {{c|u.get_allocator() {{==}} m}}
+
|{{c|X u(rv,m);}}||  
 +
|{{ttb|T}} is {{concept|MoveInsertable}} into {{ttb|X}}
 +
| The elements of {{ttb|u}} are the same or copies of those of {{ttb|rv}} and {{c|u.get_allocator() {{==}} m}}
 
| constant if {{c|m {{==}} rv.get_allocator()}}, otherwise linear
 
| constant if {{c|m {{==}} rv.get_allocator()}}, otherwise linear
 
|-
 
|-
|{{c|a {{=}} t}}||{{c|X&}}|| ||{{c|a {{==}} t}} || linear
+
|{{c|a {{=}} t}}||{{c|X&}}
 +
|{{c|{{ttb|T}} is {{concept|CopyInsertable}} into {{ttb|X}} and {{concept|CopyAssignable}} ||{{c|a {{==}} t}} || linear
 
|-
 
|-
|{{c|a {{=}} rv}}||{{c|X&}}|| ||All existing elements of {{ttb|a}} are either move assigned to or destroyed || linear
+
|{{c|a {{=}} rv}}||{{c|X&}}
 +
|If the allocator will <i>not</i> be replaced by move-assignment (see above), then {{ttb|T}} is {{concept|MoveInsertable}} into {{ttb|X}} and {{concept|MoveAssignable}}
 +
|All existing elements of {{ttb|a}} are either move assigned to or destroyed; {{ttb|a}} is equal to the value that {{ttb|rv}} had before the assignment|| linear
 
|-
 
|-
 
|{{c|a.swap(b)}}||void|| || Exchanges the contents of {{ttb|a}} and {{ttb|b}} || constant
 
|{{c|a.swap(b)}}||void|| || Exchanges the contents of {{ttb|a}} and {{ttb|b}} || constant

Revision as of 21:14, 16 December 2013

Template:cpp/concept/title Template:cpp/concept/navbar

An Template:concept is a Template:concept that holds an instance of an Template:concept and uses that instance to allocate and deallocate memory in all of its member functions.

The following rules apply to object construction

  • Copy constructors of Template:concepts obtain their instances of the allocator by calling std::allocator_traits<allocator_type>::select_on_container_copy_construction.
  • Move constructors obtain their instances of allocators by move-constructing from the allocator belonging to the old container.
  • All other constructors take an allocator parameter.

The only way to replace an allocator is copy-assignment, move-assignment, and swap:

  • Copy-assignment will replace the allocator only if std::allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value is true
  • Move-assignment will replace the allocator only if std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value is true
  • Swap will replace the allocator only if std::allocator_traits<allocator_type>::propagate_on_container_swap::value is true. Specifically, it will exchange the allocator instances through an unqualified call to the non-member function swap, see Template:concept.

Note: swapping two containers with unequal allocators if propagate_on_container_swap is false is undefined behavior.

  • The accessor get_allocator() obtains a copy of the allocator that was used to construct the container or installed by the most recent allocator replacement operation.

Contents

Requirements

Legend

X Container type
T Element type
A Allocator for T
a, b Objects of type X (non-const lvalue)
t Object of type X (lvalue or const rvalue)
rv Object of type X (non-const rvalue)
m Object of type A
Q Allocator type


expression return type pre/requirements post/effects complexity
allocator_type A allocator_type::value_type must be the same as X::value_type constant
get_allocator() A constant
X u; A is Template:concept u.empty() == true && u.get_allocator() == A() constant
X u(m); u.empty() == true && u.get_allocator() == m constant
X u(t,m); T is Template:concept into X u == t && u.get_allocator() == m linear
X u(rv); Move constructor of A must not throw exceptions u has the same elements and an equal allocator as rv had before the construction constant
X u(rv,m); T is Template:concept into X The elements of u are the same or copies of those of rv and u.get_allocator() == m constant if m == rv.get_allocator(), otherwise linear
a = t X& T is Template:concept into X and Template:concept a == t linear
a = rv X& If the allocator will not be replaced by move-assignment (see above), then T is Template:concept into X and Template:concept All existing elements of a are either move assigned to or destroyed; a is equal to the value that rv had before the assignment linear
a.swap(b) void Exchanges the contents of a and b constant

Concept requirements

A
T
X

Standard library

All standard library containers except std::array are Template:concepts: