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

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
swap
Description

Performs an element by element swap of the elements in 2 sequences.

Synopsis
template<typename Seq1, typename Seq2>
void swap(Seq1& seq1, Seq2& seq2);
Parameters

Parameters

Requirement

Description

seq1, seq2

Models of Forward Sequence

The sequences whos elements we wish to swap.

Expression Semantics
swap(seq1, seq2);

Return type: void

Precondition: size(seq1) == size(seq2)

Semantics: Calls swap(a1, b1) for corresponding elements in seq1 and seq2.

/sequence/intrinsic/swap.hpp>

Example
vector<int, std::string> v1(1, "hello"), v2(2, "world");
swap(v1, v2);
assert(v1 == make_vector(2, "world"));
assert(v2 == make_vector(1, "hello"));

PrevUpHomeNext