Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | named req
m (tweak)
m (Shorten template names. Use {{lc}} where appropriate.)
Line 21: Line 21:
  
 
===Requirements===
 
===Requirements===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list h1|Legend}}
+
{{dsc h1|Legend}}
{{dcl list item|{{ttb|X}}|Container type}}
+
{{dsc|{{ttb|X}}|Container type}}
{{dcl list item|{{ttb|T}}|Element type}}
+
{{dsc|{{ttb|T}}|Element type}}
{{dcl list item|{{ttb|A}}|Allocator for {{ttb|T}} }}
+
{{dsc|{{ttb|A}}|Allocator for {{ttb|T}} }}
{{dcl list item|{{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)}}
{{dcl list item|{{ttb|t}}|Object of type {{ttb|T}} (lvalue or const rvalue) }}
+
{{dsc|{{ttb|t}}|Object of type {{ttb|T}} (lvalue or const rvalue) }}
{{dcl list item|{{ttb|rv}}|Object of type {{ttb|T}} (non-const rvalue) }}
+
{{dsc|{{ttb|rv}}|Object of type {{ttb|T}} (non-const rvalue) }}
{{dcl list item|{{ttb|m}}|Object of type {{ttb|A}} }}
+
{{dsc|{{ttb|m}}|Object of type {{ttb|A}} }}
{{dcl list item|{{ttb|Q}}| Allocator type }}
+
{{dsc|{{ttb|Q}}| Allocator type }}
{{dcl list end}}
+
{{dsc end}}
  
  
Line 71: Line 71:
  
 
===Standard library===
 
===Standard library===
All standard library containers except {{c|std::array}} are {{concept|AllocatorAwareContainer}}s:
+
All standard library containers except {{lc|std::array}} are {{concept|AllocatorAwareContainer}}s:
* {{c|std::basic_string}}
+
* {{lc|std::basic_string}}
* {{c|std::deque}}
+
* {{lc|std::deque}}
* {{c|std::forward_list}}
+
* {{lc|std::forward_list}}
* {{c|std::list}}
+
* {{lc|std::list}}
* {{c|std::vector}}
+
* {{lc|std::vector}}
* {{c|std::map}}
+
* {{lc|std::map}}
* {{c|std::multimap}}
+
* {{lc|std::multimap}}
* {{c|std::set}}
+
* {{lc|std::set}}
* {{c|std::multiset}}
+
* {{lc|std::multiset}}
* {{c|std::unordered_map}}
+
* {{lc|std::unordered_map}}
* {{c|std::unordered_multimap}}
+
* {{lc|std::unordered_multimap}}
* {{c|std::unordered_set}}
+
* {{lc|std::unordered_set}}
* {{c|std::unordered_multiset}}
+
* {{lc|std::unordered_multiset}}

Revision as of 18:35, 31 May 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 T (lvalue or const rvalue)
rv Object of type T (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; u.empty() == true && u.get_allocator() == A() constant
X u(m); u.empty() == true && u.get_allocator() == m constant
X u(t,m); 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); 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& a == t linear
a = rv X& All existing elements of a are either move assigned to or destroyed 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: