Namespaces
Variants
Views
Actions

std::pair::swap

From cppreference.com
< cpp‎ | utility‎ | pair
Revision as of 13:01, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dcl ">

<td >
void swap(pair& other);
</td>

<td class="t-dcl-nopad"> </td> <td > (since C++11) </td> </tr> Template:ddcl list end

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

Contents

Parameters

other - pair of values to swap

Return value

(none)

Exceptions

noexcept specification:  
noexcept(

     noexcept(std::swap(first, p.first)) &&
     noexcept(std::swap(second, p.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