23 Containers library [containers]

23.3 Sequence containers [sequences]

23.3.4 Class template forward_list [forwardlist]

23.3.4.5 forward_list 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> void 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: erase_after(before_begin())

iterator insert_after(const_iterator position, const T& x); iterator insert_after(const_iterator position, T&& x);

Requires: 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);

Requires: 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);

Requires: position is before_begin() or is a dereferenceable iterator in the range [begin(),end()). first and last are not 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 i1 is empty.

template <class... Args> iterator emplace_after(const_iterator position, Args&&... args);

Requires: 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);

Requires: 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);

Requires: 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); void resize(size_type sz, const value_type& c);

Effects: If sz < distance(begin(), end()), erases the last distance(begin(), end()) - sz elements from the list. Otherwise, inserts sz - distance(begin(), end()) elements at the end of the list. For the first signature the inserted elements are value-initialized, and for the second signature they are copies of c.

Requires: T shall be DefaultConstructible for the first form and it shall be CopyInsertable into *this for the second form.

void clear() noexcept;

Effects: Erases all elements in the range [begin(),end()).

Remarks: Does not invalidate past-the-end iterators.