std::pair::swap
STD::对:交换
void swap(pair& other | | (since C++11) |
---|
掉期first
带着other.first
和second
带着other.second
...
This function does not participate in overload resolution unless std::is_swappable_v | (since C++17) |
---|
参数
other | - | pair of values to swap |
---|
返回值
%280%29
例外
例
二次
#include <iostream>
#include <utility>
#include <string>
int main()
{
std::pair<int, std::string> p1, p2;
p1 = std::make_pair(10, "test"
p2.swap(p1
std::cout << "(" << p2.first << ", " << p2.second << ")\n";
}
二次
产出:
二次
(10, test)
二次
另见
noexcept specification: noexcept( noexcept(std::swap(first, other.first)) && noexcept(std::swap(second, other.second)). ) | (until C++17) |
---|---|
noexcept specification: noexcept( std::is_nothrow_swappable<first_type>::value) && std::is_nothrow_swappable<second_type>::value). ) | (since C++17) |
swap | swaps the values of two objects (function template) |
---|
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。