##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::pair::swap

From cppreference.com
< cpp‎ | utility‎ | pair

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

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

### [edit] Parameters

other | - | pair of values to swap

### [edit] Return value

(none)

### [edit] Exceptions

(none) | (until C++11)
`noexcept` specification: (since C++11) noexcept( noexcept(std::swap(first, p.first)) && noexcept(std::swap(second, p.second)) ) | (since C++11)

### [edit] Example

Run this code

    #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

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/utility/pair/swap&oldid=64817"