Defined in header <tuple> | ||
---|---|---|
void swap( tuple& other ) noexcept(/* see below */); | (since C++11) (until C++20) | |
constexpr void swap( tuple& other ) noexcept(/* see below */); | (since C++20) |
Calls swap
(which might be std::swap
, or might be found via ADL) for each element in *this
and its corresponding element in other
.
other | - | tuple of values to swap |
(none).
noexcept specification: noexcept( In the expression above, the identifier | (until C++17) |
noexcept specification: noexcept( | (since C++17) |
#include <iostream> #include <tuple> #include <string> int main() { std::tuple<int, std::string, float> p1, p2; p1 = std::make_tuple(10, "test", 3.14); p2.swap(p1); std::cout << "(" << std::get<0>(p2) << ", " << std::get<1>(p2) << ", " << std::get<2>(p2) << ")\n"; }
Output:
(10, test, 3.14)
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 2456 | C++11 | the noexcept specification is ill-formed | made to work |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/utility/tuple/swap