std::swap(std::pair)

< cpp‎ | utility‎ | pair
在标头 <utility> 定义
(1)
template< class T1, class T2 >
void swap( std::pair<T1,T2>& x, std::pair<T1,T2>& y ) noexcept(/* see below */);
(C++11 起)
(C++20 前)
template< class T1, class T2 >

constexpr void swap( std::pair<T1,T2>& x, std::pair<T1,T2>& y )

    noexcept(/* see below */);
(C++20 起)
template< class T1, class T2 >

constexpr void swap( const std::pair<T1,T2>& x, const std::pair<T1,T2>& y )

    noexcept(/* see below */);
(2) (C++23 起)

交换 xy 的内容。等价于 x.swap(y)

1) 此重载只有在 std::is_swappable_v<first_type> && std::is_swappable_v<second_type>true 时才参与重载决议。
2) 此重载只有在 std::is_swappable_v<const first_type> && std::is_swappable_v<const second_type>true 时才参与重载决议。
(C++17 起)

参数

x, y - 要交换内容的 pair

返回值

(无)

异常

noexcept 说明:  
noexcept(noexcept(x.swap(y)))

参阅

交换两个对象的值
(函数模板)
特化 std::swap 算法
(函数模板)