A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/tuple/tuple/swap/ below:

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:


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
swap (tuple)
Exchanges the contents of two tuples (function template)
swap
Exchange values of two objects (function template)
tuple::operator=
Assign content (public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4