public member function

std::tuple::swap

<tuple>
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 object containing the same types of elements.

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

After the call to this member function, the elements in this object are those which were in tpl before the call, and the elements of tpl are those which were in this.

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>
#include <tuple>

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) << std::endl;

  return 0;
}


Output:
a contains: 20 and y

See also