Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. — Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

string::swap (2 of 2 overloads)
PrevUpHomeNext

Swap the contents.

Synopsis
void
swap(
    string& other);
Description

Exchanges the contents of this string with another string. Ownership of the respective memory_resource objects is not transferred.

  • If *other.storage() == *this->storage(), ownership of the underlying memory is swapped in constant time, with no possibility of exceptions. All iterators and references remain valid.
  • If *other.storage() != *this->storage(), the contents are logically swapped by making copies, which can throw. In this case all iterators and references are invalidated.
Complexity

Constant or linear in size() plus other.size().

Precondition
&other != this
Exception Safety

Strong guarantee. Calls to memory_resource::allocate may throw.

Parameters

Name

Description

other

The string to swap with If this == &other, this function call has no effect.


PrevUpHomeNext