<tuple>

tuple

public member function
<tuple>

std::tuple::swap

void swap (tuple& tpl) noexcept( /* see below */ );
Swap content
Exchanges the content of the tuple object by the content of tpl, which is another tuple of the same type (containing objects of the same types in the same order).

This is done by calling swap (unqualified) on each pair of respective elements.

This member is only noexcept if the swap function that operates between each of the element types is itself noexcept.

Parameters

tpl
Another tuple object of the same type (i.e., with the same class template parameters).

Return value

none

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// tuple::swap
#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');

  a.swap(b);

  std::cout << "a contains: " << std::get<0>(a);
  std::cout << " and " << std::get<1>(a) << '\n';

  return 0;
}


Output:
a contains: 20 and y

Data races

The members of both tuple objects are modified.

Exception safety

If all the element types have a swap function defined and this is noexcept, this member 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 tuple objects involved end up in a valid state in case of exception (basic guarantee).

See also