Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/utility/pair/swap2"

From cppreference.com
< cpp‎ | utility‎ | pair
(p0185r1, langlinks)
(P1032R1, shorten)
Line 1: Line 1:
 
{{cpp/title | swap<small>(std::pair)</small>}}
 
{{cpp/title | swap<small>(std::pair)</small>}}
 
{{cpp/utility/pair/navbar}}
 
{{cpp/utility/pair/navbar}}
{{ddcl | header=utility | since=c++11 |
+
{{dcl begin}}
 +
{{dcl header | utility}}
 +
{{dcl rev multi | since1=c++11 | dcl1=
 
template< class T1, class T2 >
 
template< class T1, class T2 >
void swap( pair<T1,T2>& lhs, pair<T1,T2>& rhs ) noexcept(/* see below */);
+
void swap( pair<T1,T2>& x, pair<T1,T2>& y ) noexcept(/* see below */);
 +
| since2=c++20 | dcl2=
 +
template< class T1, class T2 >
 +
constexpr void swap( pair<T1,T2>& x, pair<T1,T2>& y ) noexcept(/* see below */);
 
}}
 
}}
 +
{{dcl end}}
  
Swaps the contents of {{tt|lhs}} and {{tt|rhs}}. Equivalent to {{c|lhs.swap(rhs)}}.
+
Swaps the contents of {{tt|x}} and {{tt|y}}. Equivalent to {{c|x.swap(y)}}.
  
{{rev begin}}
+
{{rrev|since=c++17|
{{rev|since=c++17|
+
 
This function does not participate in overload resolution unless {{c|std::is_swappable_v<first_type> && std::is_swappable_v<second_type>}} is {{c|true}}.
 
This function does not participate in overload resolution unless {{c|std::is_swappable_v<first_type> && std::is_swappable_v<second_type>}} is {{c|true}}.
 
}}
 
}}
{{rev end}}
 
  
 
===Parameters===
 
===Parameters===
 
{{par begin}}
 
{{par begin}}
{{par | lhs, rhs | pairs whose contents to swap}}
+
{{par | x, y | pairs whose contents to swap}}
 
{{par end}}  
 
{{par end}}  
  
Line 23: Line 27:
  
 
===Exceptions===
 
===Exceptions===
{{noexcept|noexcept(lhs.swap(rhs))}}
+
{{noexcept|noexcept(x.swap(y))}}
  
 
===See also===
 
===See also===

Revision as of 21:32, 18 November 2018

 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
 
 
Defined in header <utility>
template< class T1, class T2 >
void swap( pair<T1,T2>& x, pair<T1,T2>& y ) noexcept(/* see below */);
(since C++11)
(until C++20)
template< class T1, class T2 >
constexpr void swap( pair<T1,T2>& x, pair<T1,T2>& y ) noexcept(/* see below */);
(since C++20)

Swaps the contents of x and y. Equivalent to x.swap(y).

This function does not participate in overload resolution unless std::is_swappable_v<first_type> && std::is_swappable_v<second_type> is true.

(since C++17)

Contents

Parameters

x, y - pairs whose contents to swap

Return value

(none)

Exceptions

noexcept specification:  
noexcept(noexcept(x.swap(y)))

See also

swaps the values of two objects
(function template) [edit]