Namespaces
Variants
Views
Actions

std::tuple::swap

From cppreference.com
< cpp‎ | utility‎ | tuple
Revision as of 11:02, 2 November 2012 by P12bot (Talk | contribs)

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

<td>
Defined in header <tuple>
</td>

<td></td> <td></td> <tr class="t-dcl ">

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

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

Calls std::swap for each element in *this and its corresponding element in other.

Contents

Parameters

other - tuple of values to swap

Return value

(none)

Exceptions

noexcept specification:  
noexcept(

    noexcept(swap(std::declval<T0&>>(), std::declval<T0&>())) &&
    noexcept(swap(std::declval<T1&>>(), std::declval<T1&>())) &&
    noexcept(swap(std::declval<T2&>>(), std::declval<T2&>())) &&
    ...

)

Example

#include <iostream>
#include <tuple>
#include <string>
 
int main()
{
    std::tuple<int, std::string, float> p1, p2;
    p1 = std::make_tuple(10, "test", 3.14);
    p2.swap(p1);
    std::cout << "("  << std::get<0>(p2)
              << ", " << std::get<1>(p2)
              << ", " << std::get<2>(p2) << ")\n";
}

Output:

(10, test, 3.14)

See also