std::pair::swap

From Cppreference

Jump to: navigation, search
void swap(pair& other);
(C++11 feature)

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

Contents

[edit] Parameters

other - pair of values to swap

[edit] Return value

(none)

[edit] Exceptions

noexcept specification:  (C++11 feature)

noexcept(

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

)

[edit] 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)

[edit] See also