[sequence.reqmts] (original) (raw)
Table 77: Sequence container requirements (in addition to container) [tab:container.seq.req]
Expression
Return type
Assertion/note
pre-/post-condition
X(n, t)
X u(n, t);
Preconditions: T isCpp17CopyInsertable into X.
Postconditions: distance(begin(), end()) == n
Effects: Constructs a sequence container with n copies of t
X(i, j)
X u(i, j);
Preconditions: T is Cpp17EmplaceConstructible into X from *i.
For vector, if the iterator does not meet the Cpp17ForwardIterator requirements ([forward.iterators]), T is alsoCpp17MoveInsertable into X.
Postconditions: distance(begin(), end()) == distance(i, j)
Effects: Constructs a sequence container equal to the range [i, j).
Each iterator in the range [i, j) is dereferenced exactly once.
X(il)
Equivalent to X(il.begin(), il.end())
a = il
X&
Preconditions: T isCpp17CopyInsertable into X and Cpp17CopyAssignable.
Effects: Assigns the range [il.begin(), il.end()) into a.
All existing elements of a are either assigned to or destroyed.
a.emplace(p, args)
iterator
Preconditions: T is Cpp17EmplaceConstructible into X from args.
For vector and deque,T is alsoCpp17MoveInsertable into X and Cpp17MoveAssignable.
Effects: Inserts an object of type T constructed withstd::forward<Args>(args)... before p.
[ Note
:
args may directly or indirectly refer to a value in a.
— end note
]
a.insert(p,t)
iterator
Preconditions: T isCpp17CopyInsertable into X.
For vector and deque,T is also Cpp17CopyAssignable.
Effects: Inserts a copy of t before p.
a.insert(p,rv)
iterator
Preconditions: T isCpp17MoveInsertable into X.
For vector and deque,T is also Cpp17MoveAssignable.
Effects: Inserts a copy of rv before p.
a.insert(p,n,t)
iterator
Preconditions: T isCpp17CopyInsertable into X and Cpp17CopyAssignable.
Effects: Inserts n copies of t before p.
a.insert(p,i,j)
iterator
Preconditions: T is Cpp17EmplaceConstructible into X from *i.
For vector and deque, T is alsoCpp17MoveInsertable into X, Cpp17MoveConstructible, Cpp17MoveAssignable, and swappable ([swappable.requirements]).
Neither i nor j are iterators into a.
Effects: Inserts copies of elements in [i, j) before p.
Each iterator in the range [i, j) shall be dereferenced exactly once.
a.insert(p, il)
iterator
a.insert(p, il.begin(), il.end()).
a.erase(q)
iterator
Preconditions: For vector and deque,T is Cpp17MoveAssignable.
Effects: Erases the element pointed to by q.
a.erase(q1,q2)
iterator
Preconditions: For vector and deque,T is Cpp17MoveAssignable.
Effects: Erases the elements in the range [q1, q2).
a.clear()
void
Effects: Destroys all elements in a.
Invalidates all references, pointers, and iterators referring to the elements of a and may invalidate the past-the-end iterator.
Postconditions: a.empty() is true.
a.assign(i,j)
void
Preconditions: T is Cpp17EmplaceConstructible into X from *i and assignable from *i.
For vector, if the iterator does not meet the forward iterator requirements ([forward.iterators]), T is alsoCpp17MoveInsertable into X.
Neither i nor j are iterators into a.
Effects: Replaces elements in a with a copy of [i, j).
Invalidates all references, pointers and iterators referring to the elements of a.
For vector and deque, also invalidates the past-the-end iterator.
Each iterator in the range [i, j) shall be dereferenced exactly once.
a.assign(il)
void
a.assign(il.begin(), il.end()).
a.assign(n,t)
void
Preconditions: T isCpp17CopyInsertable into X and Cpp17CopyAssignable.
t is not a reference into a.
Effects: Replaces elements in a with n copies of t.
Invalidates all references, pointers and iterators referring to the elements of a.
For vector and deque, also invalidates the past-the-end iterator.