function template
std::swap (tuple)
<tuple>
template <class... Types>
void swap (tuple<Types...>& lhs, tuple<Types...>& rhs) noexcept ( /* see below */ );
Exchanges the contents of two tuples
The contents of the tuple object lhs are exchanged with those of rhs. Both objects must be of the same type (i.e., contain the same types of elements).
This is done by calling swap on each pair of respective elements.
After the call to this function, the elements in lhs are those which were in rhs before the call, and the elements of rhs are those which were in lhs.
This member is only noexcept if the swap function that operates between each of the element types is itself noexcept.
swap exists also as a member function: tuple::swap.
Parameters
- lhs,rhs
- tuple objects (to the left- and right-hand side of the operator, respectively), containing both the same types of elements.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
// swap tuples
#include <iostream>
#include <tuple>
int main ()
{
std::tuple<int,char> a (10,'x');
std::tuple<int,char> b (20,'y');
swap(a,b);
std::cout << "a contains: " << std::get<0>(a);
std::cout << " and " << std::get<1>(a) << std::endl;
return 0;
}
|
Output:
See also
- tuple::swap
- Swap content (public member function)
- swap
- Exchange values of two objects (function template)
- tuple::operator=
- Assign content (public member function)