C++ Tuple Library - swap



Description

It exchanges the content of the tuple object by the content of tpl, which is another tuple of the same type.

Declaration

Following is the declaration for std::tuple::swap.

C++98

	
void swap (tuple& tpl) noexcept

C++11

void swap (tuple& tpl) noexcept

Parameters

tpl − It is an another tuple object of the same type.

Return Value

none

Exceptions

No-throw guarantee − this member function never throws exceptions.

Data races

The members of both tuple objects are modified.

Example

In below example for std::tuple::swap.

#include <iostream>
#include <tuple>

int main () {
   std::tuple<int,char> a (50,'a');
   std::tuple<int,char> b (200,'b');

   a.swap(b);

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

   return 0;
}

The output should be like this −

a contains: 200 and b
tuple.htm
Advertisements