22 Containers library [containers]

22.3 Sequence containers [sequences]

22.3.9 Class template forward_­list [forwardlist]

22.3.9.5 Modifiers [forwardlist.modifiers]

None of the overloads of insert_­after shall affect the validity of iterators and references, and erase_­after shall invalidate only iterators and references to the erased elements.
If an exception is thrown during insert_­after there shall be no effect.
Inserting n elements into a forward_­list is linear in n, and the number of calls to the copy or move constructor of T is exactly equal to n.
Erasing n elements from a forward_­list is linear in n and the number of calls to the destructor of type T is exactly equal to n.
template<class... Args> reference emplace_front(Args&&... args);
Effects: Inserts an object of type value_­type constructed with value_­type(std​::​forward<Args>(​args)...) at the beginning of the list.
void push_front(const T& x); void push_front(T&& x);
Effects: Inserts a copy of x at the beginning of the list.
void pop_front();
Effects: As if by erase_­after(before_­begin()).
iterator insert_after(const_iterator position, const T& x); iterator insert_after(const_iterator position, T&& x);
Preconditions: position is before_­begin() or is a dereferenceable iterator in the range [begin(), end()).
Effects: Inserts a copy of x after position.
Returns: An iterator pointing to the copy of x.
iterator insert_after(const_iterator position, size_type n, const T& x);
Preconditions: position is before_­begin() or is a dereferenceable iterator in the range [begin(), end()).
Effects: Inserts n copies of x after position.
Returns: An iterator pointing to the last inserted copy of x or position if n == 0.
template<class InputIterator> iterator insert_after(const_iterator position, InputIterator first, InputIterator last);
Preconditions: position is before_­begin() or is a dereferenceable iterator in the range [begin(), end()).
Neither first nor last are iterators in *this.
Effects: Inserts copies of elements in [first, last) after position.
Returns: An iterator pointing to the last inserted element or position if first == last.
iterator insert_after(const_iterator position, initializer_list<T> il);
Effects: insert_­after(p, il.begin(), il.end()).
Returns: An iterator pointing to the last inserted element or position if il is empty.
template<class... Args> iterator emplace_after(const_iterator position, Args&&... args);
Preconditions: position is before_­begin() or is a dereferenceable iterator in the range [begin(), end()).
Effects: Inserts an object of type value_­type constructed with value_­type(std​::​forward<Args>(​args)...) after position.
Returns: An iterator pointing to the new object.
iterator erase_after(const_iterator position);
Preconditions: The iterator following position is dereferenceable.
Effects: Erases the element pointed to by the iterator following position.
Returns: An iterator pointing to the element following the one that was erased, or end() if no such element exists.
Throws: Nothing.
iterator erase_after(const_iterator position, const_iterator last);
Preconditions: All iterators in the range (position, last) are dereferenceable.
Effects: Erases the elements in the range (position, last).
Returns: last.
Throws: Nothing.
void resize(size_type sz);
Preconditions: T is Cpp17DefaultInsertable into *this.
Effects: If sz < distance(begin(), end()), erases the last distance(begin(), end()) - sz elements from the list.
Otherwise, inserts sz - distance(begin(), end()) default-inserted elements at the end of the list.
void resize(size_type sz, const value_type& c);
Preconditions: T is Cpp17CopyInsertable into *this.
Effects: If sz < distance(begin(), end()), erases the last distance(begin(), end()) - sz elements from the list.
Otherwise, inserts sz - distance(begin(), end()) copies of c at the end of the list.
void clear() noexcept;
Effects: Erases all elements in the range [begin(), end()).
Remarks: Does not invalidate past-the-end iterators.