object::stable_erase

Erase an element preserving order.

Synopsis

object::iterator
stable_erase(
    object::const_iterator pos) noexcept; (1)

std::size_t
stable_erase(
    string_view key) noexcept; (2)

Description

  • (1) Remove the element pointed to by pos, which must be valid and dereferenceable. References and iterators from pos to end(), both included, are invalidated. Other iterators and references are not invalidated.

  • (2) Remove the element which matches key, if it exists. All references and iterators are invalidated.

The relative order of remaining elements is preserved.

The end() iterator (which is valid but cannot be dereferenced) cannot be used as a value for pos.

Complexity

Linear in size().

Exception Safety

No-throw guarantee.

Return Value

  • An iterator following the removed element.

  • The number of elements removed, which will be either 0 or 1.

Parameters

Name Description

pos

An iterator pointing to the element to be removed.

key

The key to match.