std::pair::swap

void swap(pair& other);
(since C++11)

Swaps first with other.first and second with other.second.

Parameters

other - pair of values to swap

Return value

(none).

Exceptions

noexcept specification:
noexcept(

noexcept(std::swap(first, other.first)) &&
noexcept(std::swap(second, other.second))
.

)

Example

#include <iostream>
#include <utility>
#include <string>
int main()
{
    std::pair<int, std::string> p1, p2;
    p1 = std::make_pair(10, "test");
    p2.swap(p1);
    std::cout << "(" << p2.first << ", " << p2.second << ")\n";
}

Output:

(10, test)

See also

swaps the values of two objects
(function template)
doc_CPP
2016-10-11 10:05:38
Comments
Leave a Comment

Please login to continue.