##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::tuple::swap

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

Defined in header `<tuple>` |  |
void swap( tuple& other ); |  | (since C++11)

Calls `swap` (which might be std::swap, or might be found via ADL) for each element in *this and its corresponding element in `other`.

### [edit] Parameters

other | - | tuple of values to swap

### [edit] Return value

(none)

### [edit] 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&>())) && ... ) | (until C++17)
`noexcept` specification: noexcept( std::is_nothrow_swappable<T0>::value && std::is_nothrow_swappable<T1>::value && std::is_nothrow_swappable<T2>::value && ... ) | (since C++17)

### [edit] Example

Run this code

    #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)

### [edit] See also

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

- conditionally noexcept

Hidden categories:

- Pages with unreviewed conditional noexcept template
- Pages with unreviewed noexcept template