A SequenceContainer is a Container that stores objects of the same type in a linear arrangement.
[edit] RequirementsGiven the following types and values:
Type DefinitionC
a sequence container class T
the element type of C
A
the allocator type of C
:
C::allocator_type
if it exists,R
(since C++23) a type that models container-compatible-range <T>
Args
(since C++11) a template parameter pack Iter
C::iterator
Ref
C::reference
CRef
C::const_reference
Value Definition v a value of type C
cv a value of type const C i, j LegacyInputIterators such that [
i,
j)
is a valid range and that the iterators refer to elements implicitly convertible to C::value_type
rg (since C++23) a value of type R
il (since C++11) a value of type std::initializer_list<C::value_type> n a value of type C::size_type
p a valid const iterator into v q a valid dereferenceable const iterator into v q1, q2 const iterators into v such that [
q1,
q2)
is a valid range t a value(until C++11)an lvalue or const rvalue(since C++11) of type C::value_type
rv (since C++11) a non-const rvalue of type C::value_type
args (since C++11) a function parameter pack with the pattern Arg&&
C
satisfies the requirements of SequenceContainer if all following conditions are satisfied:
C
satisfies the requirements of Container.T
is CopyInsertable into C
.
[
i,
j)
.
[
i,
j)
is dereferenced exactly once.T
is EmplaceConstructible into C
from *i.
C
Effect Constructs the sequence container equal, element-wise, to the range rg.
T
is EmplaceConstructible into X
from *ranges::begin(rg). Postcondition std::distance(begin(), end()) is ranges::distance(rg). C(il)
C
Equivalent to C(il.begin(), il.end()). v = il
C&
Effect Assigns the range represented by il into v.[2] Return value *this Precondition T
is CopyInsertable into C
and CopyAssignable. Postcondition Existing elements of v are either destroyed or assigned to. v.emplace(p, args)
Iter
Effect Insert an object of type T
, constructed with std::forward<Args>(args)... before p. Return value An iterator that points to the new element constructed from args into v. Precondition T
is EmplaceConstructible into C
from args. v.insert(p, t) Iter
Effect Inserts a copy of t before p. Return value An iterator that points to the copy of t inserted into v. Precondition
T
is CopyInsertable into C
.
Iter
Effect Inserts a copy of rv before p, possibly using move semantics. Return value An iterator that points to the copy of rv inserted into v. Precondition T
is MoveInsertable into C
. v.insert(p, n, t) Iter
Effect Inserts n copies of t before p. Return value An iterator that points to the copy of the first element inserted into v, or p if n is â0â. Precondition
T
is CopyInsertable into C
and CopyAssignable.
Iter
Effect Inserts copies of elements in [
i,
j)
before p.
[
i,
j)
is dereferenced exactly once.T
is EmplaceConstructible into C
from *i.Iter
Effect Inserts copies of elements in rg before p.
T
is EmplaceConstructible into C
from *ranges::begin(rg).Iter
Equivalent to v.insert(p, il.begin(), il.end()). v.erase(q) Iter
Effect Erases the element pointed to by q. Return value An iterator that points to the element immediately following q prior to the element being erased, or v.end() if no such element exists. v.erase(q1, q2) Iter
Effect Erases elements in [
q1,
q2)
. Return value An iterator that points to the element pointed to by q2 prior to any elements being erased, or v.end() if no such element exists. v.clear() void Effect Destroys all elements in v.
[
i,
j)
.
[
i,
j)
is dereferenced exactly once.T
is EmplaceConstructible into C
from *i.T
is assignable from *i.
<T&, ranges::range_reference_t<R>> is not modeled, the program is ill-formed.T
is EmplaceConstructible into C
from *ranges::begin(rg).T
is CopyInsertable into C
and CopyAssignable.
std::
) Expression Type Semantics v.front() Ref
Containers basic_string, array, vector, inplace_vector, deque, list, forward_list
Return value *v.begin() cv.front() CRef
Containers basic_string, array, vector, inplace_vector, deque, list, forward_list
Return value *cv.begin() v.back() Ref
Containers basic_string, array, vector, inplace_vector, deque, list
Equivalent to auto tmp = v.end(); --tmp; return *tmp;[4]. cv.back() CRef
Containers basic_string, array, vector, inplace_vector, deque, list
Equivalent to auto tmp = cv.end(); --tmp; return *tmp;[5]. v.emplace_front(args)
deque, list, forward_list
Effect Prepends an object of type T
constructed with std::forward<Args>(args).... Return value v.front() Precondition T
is EmplaceConstructible into C
from args. v.emplace_back(args)
vector, inplace_vector, deque, list
Effect Appends an object of type T
constructed with std::forward<Args>(args).... Return value v.back() Precondition T
is EmplaceConstructible into C
from args. v.push_front(t) void Containers deque, list, forward_list
Effect Prepends a copy of t. Precondition
T
is CopyInsertable into C
.
deque, list, forward_list
Effect Prepends a copy of rv, possibly using move semantics. Precondition T
is MoveInsertable into C
. v.prepend_range(rg)
deque, list, forward_list
Effect Inserts[6] copies of elements in rg before v.begin().
T
is EmplaceConstructible into C
from *ranges::begin(rg). v.push_back(t) void Containers basic_string, vector, inplace_vector, deque, list
Effect Appends a copy of t. Precondition
T
is CopyInsertable into C
.
basic_string, vector, inplace_vector, deque, list
Effect Appends a copy of rv, possibly using move semantics. Precondition T
is MoveInsertable into C
. v.append_range(rg)
vector, inplace_vector, deque, list
Effect Inserts[6] copies of elements in rg before v.end().
T
is EmplaceConstructible into C
from *ranges::begin(rg). v.pop_front() void Containers deque, list, forward_list
Effect Destroys the first element. Precondition a.empty() is false. v.pop_back() void Containers basic_string, vector, inplace_vector, deque, list
Effect Destroys the last element. Precondition a.empty() is false. v[n] Ref
Containers basic_string, array, vector, inplace_vector, deque
Equivalent to return *(v.begin() + n);. cv[n] CRef
Containers basic_string, array, vector, inplace_vector, deque
Equivalent to return *(cv.begin() + n);. v.at(n) Ref
Containers basic_string, array, vector, inplace_vector, deque
Return value *(v.begin() + n) Exceptions Throws std::out_of_range if n >= v.size() is true. cv.at(n) CRef
Containers basic_string, array, vector, inplace_vector, deque
Return value *(cv.begin() + n) Exceptions Throws std::out_of_range if n >= cv.size() is true. Notes
prepend_range
and append_range
(since C++23) take amortized constant time.C::iterator
.C::const_iterator
.Additionally, for every sequence container:
insert
, append
, assign
, replace
that take two input iterators do not participate in overload resolution if the corresponding template argument does not satisfy LegacyInputIterator.Allocator
template parameter does not participate in overload resolution if the type that does not qualify as an input iterator or an allocator respectively is deduced for that parameter.The following standard library string types and containers satisfy the SequenceContainer requirements:
[edit] Usage notes Container Pros Cons std::vector Fast access, contiguous storage Mostly inefficient insertions/deletions std::inplace_vector Fast access, inplace contiguous storage Fixed capacity and mostly inefficient insertions/deletions std::array Fast access, inplace contiguous storage Fixed number of elements and no insertion/deletion std::deque Fast access, efficient insertion/deletion at the beginning/end Inefficient insertion/deletion in the middle of the sequence std::listThe following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 139 C++98 the optional operations were not required toIter
while
Iter
LWG 151 C++98 q1 was required to be dereferenceable[1] it can be non-dereferenceable LWG 355 C++98 calling v.back() or v.pop_back() would
C::value_type
they are implicitly
C::value_type
LWG 2194 C++11 std::queue, std::priority_queue and
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4