Difference between revisions of "cpp/named req/Container"
From cppreference.com
m (improved formatting) |
(improved formatting) |
||
Line 2: | Line 2: | ||
{{cpp/concept/navbar}} | {{cpp/concept/navbar}} | ||
− | A {{tt| | + | A {{tt|container}} is an object used to store other objects and taking care of the management of the memory used by the objects it contains. |
===Requirements=== | ===Requirements=== | ||
Line 35: | Line 35: | ||
|{{c|C()}}||C||creates an empty container|| Post: C().empty() == true||Constant | |{{c|C()}}||C||creates an empty container|| Post: C().empty() == true||Constant | ||
|- | |- | ||
− | |{{c|C(a)}}||C|| | + | |{{c|C(a)}}||C||creates a copy of {{ttb|a}}||Pre: T must be {{concept|CopyInsertable}}<br/>Post: a == C(a)||Linear |
|- | |- | ||
− | |{{c|a {{=}} b}}||C&||all elements of {{ttb|a}} | + | |{{c|a {{=}} b}}||C&||destroys or move-assigns all elements of {{ttb|a}} to elements of {{ttb|b}}||Post: a == b||Linear |
|- | |- | ||
− | |{{c|(&a)->~C()}}||void|| | + | |{{c|(&a)->~C()}}||void||destroys all elements of {{ttb|a}} and frees all memory|| ||Linear |
|- | |- | ||
− | |{{c|a.begin()}}||(const_)iterator||Iterator to the first element|| ||Constant | + | |{{c|a.begin()}}||(const_)iterator||Iterator to the first element of {{ttb|a}}|| ||Constant |
|- | |- | ||
− | |{{c|a.end()}}||(const_)iterator||Iterator to one past the last element|| ||Constant | + | |{{c|a.end()}}||(const_)iterator||Iterator to one past the last element of {{ttb|a}}|| ||Constant |
|- | |- | ||
|{{c|a.cbegin()}}{{mark since c++11}}||const_iterator||{{c|const_cast<const C&>(a).begin()}}|| ||Constant | |{{c|a.cbegin()}}{{mark since c++11}}||const_iterator||{{c|const_cast<const C&>(a).begin()}}|| ||Constant | ||
Line 53: | Line 53: | ||
|{{c|a !{{=}} b}} || convertible to bool || {{c|!(a {{==}} b)}} || || Linear | |{{c|a !{{=}} b}} || convertible to bool || {{c|!(a {{==}} b)}} || || Linear | ||
|- | |- | ||
− | |{{c|a.swap(b)}} || void || exchanges the values of a and b || | + | |{{c|a.swap(b)}} || void || exchanges the values of {{ttb|a}} and {{ttb|b}} || |
| Constant<ref name="array">{{mark since c++11}} Linear for {{lc|std::array}}</ref><ref name="should">{{mark until c++11}} Not strictly constant</ref> | | Constant<ref name="array">{{mark since c++11}} Linear for {{lc|std::array}}</ref><ref name="should">{{mark until c++11}} Not strictly constant</ref> | ||
|- | |- | ||
Line 60: | Line 60: | ||
|{{c|a.size()}} || size_type || {{c|distance(a.begin(), a.end())}} || || Constant<ref name="should" /> | |{{c|a.size()}} || size_type || {{c|distance(a.begin(), a.end())}} || || Constant<ref name="should" /> | ||
|- | |- | ||
− | |{{c|a.max_size()}} || size_type || b.size() where b is the largest possible container || || Constant<ref name="should" /> | + | |{{c|a.max_size()}} || size_type || {{c|b.size()}} where {{ttb|b}} is the largest possible container || || Constant<ref name="should" /> |
|- | |- | ||
|{{c|a.empty()}} || convertible to bool || {{c|a.begin() {{==}} a.end()}} || || Constant | |{{c|a.empty()}} || convertible to bool || {{c|a.begin() {{==}} a.end()}} || || Constant |
Revision as of 02:08, 3 February 2016
Template:cpp/concept/title Template:cpp/concept/navbar
A container
is an object used to store other objects and taking care of the management of the memory used by the objects it contains.
Contents |
Requirements
-
C
container type; -
T
element type; -
a
,b
objects of typeC
.
Types
name | type | notes |
---|---|---|
value_type |
T | Template:concept |
reference |
T& | |
const_reference |
const T& | |
iterator |
iterator pointing to T | Template:concept convertible to const_iterator
|
const_iterator |
const iterator pointing to T | Template:concept |
difference_type |
signed integer | must be the same as iterator_traits::difference_type for iterator and const_iterator
|
size_type |
unsigned integer | large enough to represent all positive values of difference_type
|
Methods and operators
expression | return type | semantics | conditions | complexity | |
---|---|---|---|---|---|
C() | C | creates an empty container | Post: C().empty() == true | Constant | |
C(a) | C | creates a copy of a |
Pre: T must be Template:concept Post: a == C(a) |
Linear | |
a = b | C& | destroys or move-assigns all elements of a to elements of b |
Post: a == b | Linear | |
(&a)->~C() | void | destroys all elements of a and frees all memory |
Linear | ||
a.begin() | (const_)iterator | Iterator to the first element of a |
Constant | ||
a.end() | (const_)iterator | Iterator to one past the last element of a |
Constant | ||
a.cbegin()(since C++11) | const_iterator | const_cast<const C&>(a).begin() | Constant | ||
a.cend()(since C++11) | const_iterator | const_cast<const C&>(a).end() | Constant | ||
a == b | convertible to bool | std::equal(a.begin(), a.end(), b.begin(), b.end())(since C++14) | Pre: T must be Template:concept | Constant[1] if a.size() != b.size() , linear otherwise
| |
a != b | convertible to bool | !(a == b) | Linear | ||
a.swap(b) | void | exchanges the values of a and b |
Constant[2][3] | ||
swap(a, b) | void | a.swap(b) | Constant[2] | ||
a.size() | size_type | distance(a.begin(), a.end()) | Constant[3] | ||
a.max_size() | size_type | b.size() where b is the largest possible container |
Constant[3] | ||
a.empty() | convertible to bool | a.begin() == a.end() | Constant | ||
notes | |||||
|
Given
in the expressions i == j, i != j, i < j, i <= j, i >= j, i > j, i - j, either or both may be replaced by an object of the container's |
(since C++14) |
Container data races
Other concepts
- C
- T