Difference between revisions of "cpp/utility/pair/operator="
From cppreference.com
(merge noexcept) |
(P1032R1) |
||
Line 2: | Line 2: | ||
{{cpp/utility/pair/navbar}} | {{cpp/utility/pair/navbar}} | ||
{{dcl begin}} | {{dcl begin}} | ||
− | {{dcl | num=1 | | + | {{dcl rev multi|num=1|dcl1= |
pair& operator=( const pair& other ); | pair& operator=( const pair& other ); | ||
+ | |since2=c++20|dcl2= | ||
+ | constexpr pair& operator=( const pair& other ); | ||
}} | }} | ||
− | {{dcl | num=2 | | + | {{dcl rev multi|num=2|dcl1= |
template< class U1, class U2 > | template< class U1, class U2 > | ||
pair& operator=( const pair<U1,U2>& other ); | pair& operator=( const pair<U1,U2>& other ); | ||
+ | |since2=c++20|dcl2= | ||
+ | template< class U1, class U2 > | ||
+ | constexpr pair& operator=( const pair<U1,U2>& other ); | ||
}} | }} | ||
− | {{dcl | num=3 | | + | {{dcl rev multi|num=3|since1=c++11|dcl1= |
pair& operator=( pair&& other ) noexcept(/* see below */); | pair& operator=( pair&& other ) noexcept(/* see below */); | ||
+ | |since2=c++20|dcl2= | ||
+ | constexpr pair& operator=( pair&& other ) noexcept(/* see below */); | ||
}} | }} | ||
− | {{dcl | num=4 | | + | {{dcl rev multi|num=4|since1=c++11|dcl1= |
template< class U1, class U2 > | template< class U1, class U2 > | ||
pair& operator=( pair<U1,U2>&& other ); | pair& operator=( pair<U1,U2>&& other ); | ||
+ | |since2=c++20|dcl2= | ||
+ | template< class U1, class U2 > | ||
+ | constexpr pair& operator=( pair<U1,U2>&& other ); | ||
}} | }} | ||
{{dcl end}} | {{dcl end}} | ||
Line 28: | Line 38: | ||
@4@ Assigns {{c|std::forward<U1>(p.first)}} to {{tt|first}} and {{c|std::forward<U2>(p.second)}} to {{tt|second}}. | @4@ Assigns {{c|std::forward<U1>(p.first)}} to {{tt|first}} and {{c|std::forward<U2>(p.second)}} to {{tt|second}}. | ||
− | {{ | + | {{rrev multi | until1=c++17 |
− | + | |rev1= | |
The behavior of these functions is undefined unless: | The behavior of these functions is undefined unless: | ||
* For {{v|1}},{{c|std::is_copy_assignable<first_type>::value}} and {{c|std::is_copy_assignable<second_type>::value}} are both {{c|true}}. | * For {{v|1}},{{c|std::is_copy_assignable<first_type>::value}} and {{c|std::is_copy_assignable<second_type>::value}} are both {{c|true}}. | ||
Line 35: | Line 45: | ||
* For {{v|3}},{{c|std::is_move_assignable<first_type>::value}} and {{c|std::is_move_assignable<second_type>::value}} are both {{c|true}}. | * For {{v|3}},{{c|std::is_move_assignable<first_type>::value}} and {{c|std::is_move_assignable<second_type>::value}} are both {{c|true}}. | ||
* For {{v|4}},{{c|std::is_assignable<first_type&, U1&&>::value}} and {{c|std::is_assignable<second_type&, U2&&>::value}} are both {{c|true}}. | * For {{v|4}},{{c|std::is_assignable<first_type&, U1&&>::value}} and {{c|std::is_assignable<second_type&, U2&&>::value}} are both {{c|true}}. | ||
− | + | |rev2= | |
− | + | ||
These functions do not participate in overload resolution (or, for the copy assignment operator, is defined as deleted) if any required assignment operation is invalid. Specifically: | These functions do not participate in overload resolution (or, for the copy assignment operator, is defined as deleted) if any required assignment operation is invalid. Specifically: | ||
* {{v|1}} is defined as deleted unless {{c|std::is_copy_assignable_v<first_type>}} and {{c|std::is_copy_assignable_v<second_type>}} are both {{c|true}}. | * {{v|1}} is defined as deleted unless {{c|std::is_copy_assignable_v<first_type>}} and {{c|std::is_copy_assignable_v<second_type>}} are both {{c|true}}. | ||
Line 43: | Line 52: | ||
* {{v|4}} does not participate in overload resolution unless {{c|std::is_assignable_v<first_type&, U1&&>}} and {{c|std::is_assignable_v<second_type&, U2&&>}} are both {{c|true}}. | * {{v|4}} does not participate in overload resolution unless {{c|std::is_assignable_v<first_type&, U1&&>}} and {{c|std::is_assignable_v<second_type&, U2&&>}} are both {{c|true}}. | ||
}} | }} | ||
− | |||
===Parameters=== | ===Parameters=== | ||
{{par begin}} | {{par begin}} | ||
Line 72: | Line 80: | ||
{{dsc end}} | {{dsc end}} | ||
− | + | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
Revision as of 05:01, 19 November 2018
(1) | ||
pair& operator=( const pair& other ); |
(until C++20) | |
constexpr pair& operator=( const pair& other ); |
(since C++20) | |
(2) | ||
template< class U1, class U2 > pair& operator=( const pair<U1,U2>& other ); |
(until C++20) | |
template< class U1, class U2 > constexpr pair& operator=( const pair<U1,U2>& other ); |
(since C++20) | |
(3) | ||
pair& operator=( pair&& other ) noexcept(/* see below */); |
(since C++11) (until C++20) |
|
constexpr pair& operator=( pair&& other ) noexcept(/* see below */); |
(since C++20) | |
(4) | ||
template< class U1, class U2 > pair& operator=( pair<U1,U2>&& other ); |
(since C++11) (until C++20) |
|
template< class U1, class U2 > constexpr pair& operator=( pair<U1,U2>&& other ); |
(since C++20) | |
Replaces the contents of the pair.
1) Copy assignment operator. Replaces the contents with a copy of the contents of other.
2) Assigns
other.first
to first
and other.second
to second
3) Move assignment operator. Replaces the contents with those of
other
using move semantics.
The behavior of these functions is undefined unless:
|
(until C++17) |
These functions do not participate in overload resolution (or, for the copy assignment operator, is defined as deleted) if any required assignment operation is invalid. Specifically:
|
(since C++17) |
Contents |
Parameters
other | - | pair of values to replace the contents of this pair |
Return value
*this
Exceptions
1-2) (none)
3)
noexcept specification:
noexcept(
is_nothrow_move_assignable<T1>::value &&
is_nothrow_move_assignable<T2>::value
4) (none)
Example
This section is incomplete Reason: no example |