template <class... Types>
void swap (tuple<Types...>& x, tuple<Types...>& y) noexcept ( /* see below */ );
Exchanges the contents of two tuples
The contents of the tuple object x are exchanged with those of y. Both objects must be of the same type (i.e., contain the same types of elements).
This is an overload of the generic swap that improves its performance by calling tuple::swap as in:
- tuple objects (to the left- and right-hand side of the operator, respectively), containing both the same types of elements in the same order.
// swap tuples
#include <iostream> // std::cout
#include <tuple> // std::tuple, std::get
int main ()
std::tuple<int,char> a (10,'x');
std::tuple<int,char> b (20,'y');
std::cout << "a contains: " << std::get<0>(a) << " and " << std::get<1>(a) << '\n';
The members of both pair objects, x and y, are modified.
If all the element types have a swap function defined and this is noexcept, this function never throws exceptions (no-throw guarantee).
Otherwise, if at least one of them swaps with move semantics, the operation may leave either or both tuple objects in an invalid state in case of exception (no guarantees).
Otherwise, the operation guarantees that both x and y end up in a valid state in case of exception (basic guarantee).
- Swap content (public member function
- Exchange values of two objects (function template
- Assign content (public member function