22 Containers library [containers]

22.2 Container requirements [container.requirements]

22.2.1 General container requirements [container.requirements.general]

Table 73: Container requirements [tab:container.req]
Expression
Return type
Operational
Assertion/note
Complexity
semantics
pre-/post-condition
X​::​value_­type
T
Preconditions: T is Cpp17Erasable from X (see [container.requirements.general], below)
compile time
X​::​reference
T&
compile time
X​::​const_­reference
const T&
compile time
X​::​iterator
iterator type whose value type is T
any iterator category that meets the forward iterator requirements.
convertible to X​::​const_­iterator.
compile time
X​::​const_­iterator
constant iterator type whose value type is T
any iterator category that meets the forward iterator requirements.
compile time
X​::​difference_­type
signed integer type
is identical to the difference type of X​::​iterator and X​::​const_­iterator
compile time
X​::​size_­type
unsigned integer type
size_­type can represent any non-negative value of difference_­type
compile time
X u;
Postconditions: u.empty()
constant
X()
Postconditions: X().empty()
constant
X(a)
Preconditions: T is Cpp17CopyInsertable into X (see below).

Postconditions: a == X(a).
linear
X u(a);
X u = a;
Preconditions: T is Cpp17CopyInsertable into X (see below).

Postconditions: u == a
linear
X u(rv);
X u = rv;
Postconditions: u is equal to the value that rv had before this construction
(Note B)
a = rv
X&
All existing elements of a are either move assigned to or destroyed
Postconditions: a is equal to the value that rv had before this assignment
linear
a.~X()
void
Effects: destroys every element of a; any memory obtained is deallocated.
linear
a.begin()
iterator; const_­iterator for constant a
constant
a.end()
iterator; const_­iterator for constant a
constant
a.cbegin()
const_­iterator
const_­cast<​X const&>(a).begin();
constant
a.cend()
const_­iterator
const_­cast<​X const&>(a).end();
constant
i <=> j
strong_­ordering
Constraints: X​::​iterator meets the random access iterator requirements.
constant
a == b
convertible to bool
== is an equivalence relation.
equal(​a.begin(), a.end(), b.begin(), b.end())
Preconditions: T meets the Cpp17EqualityComparable requirements
Constant if a.size() != b.size(), linear otherwise
a != b
convertible to bool
Equivalent to !(a == b)
linear
a.swap(b)
void
Effects: exchanges the contents of a and b
(Note A)
swap(a, b)
void
Equivalent to a.swap(b)
(Note A)
r = a
X&
Postconditions: r == a.
linear
a.size()
size_­type
distance(​a.begin(), a.end())
constant
a.max_­size()
size_­type
distance(​begin(), end()) for the largest possible container
constant
a.empty()
convertible to bool
a.begin() == a.end()
constant