C++ Tuple Library - swap (tuple)
Description
It exchanges the contents of two tuples.
Declaration
Following is the declaration for std::swap (tuple)
C++98
template <class... Types> void swap (tuple<Types...>& x, tuple<Types...>& y) noexcept;
C++11
template <class... Types> void swap (tuple<Types...>& x, tuple<Types...>& y) noexcept;
Parameters
x,y − These are tuple objects.
Return Value
none
Exceptions
No-throw guarantee − this member function never throws exceptions.
Data races
The members of both pair objects, x and y, are modified.
Example
In below example for std::swap (tuple).
#include <iostream>
#include <tuple>
int main () {
std::tuple<int,char> a (100,'a');
std::tuple<int,char> b (200,'b');
swap(a,b);
std::cout << "a contains: " << std::get<0>(a) << " and " << std::get<1>(a) << '\n';
return 0;
}
The output should be like this −
a contains: 200 and b
tuple.htm
Advertisements