Difference between revisions of "cpp/utility/tuple/operator="
(Replaced "replaces" with "assigns" because "replaces" is ambiguous for tuple of references, the standard uses the term "assigns" everywhere for tuple.) |
(P1032R1) |
||
Line 2: | Line 2: | ||
{{cpp/utility/tuple/navbar}} | {{cpp/utility/tuple/navbar}} | ||
{{dcl begin}} | {{dcl begin}} | ||
− | {{dcl | num=1 | | + | {{dcl rev multi|num=1|since1=c++11|dcl1= |
tuple& operator=( const tuple& other ); | tuple& operator=( const tuple& other ); | ||
+ | |since2=c++20|dcl2= | ||
+ | constexpr tuple& operator=( const tuple& other ); | ||
}} | }} | ||
− | {{dcl | num=2 | | + | {{dcl rev multi|num=2|since1=c++11|dcl1= |
tuple& operator=( tuple&& other ) noexcept(/* see below */); | tuple& operator=( tuple&& other ) noexcept(/* see below */); | ||
+ | |since2=c++20|dcl2= | ||
+ | constexpr tuple& operator=( tuple&& other ) noexcept(/* see below */); | ||
}} | }} | ||
− | {{dcl | num=3 | | + | {{dcl rev multi|num=3|since1=c++11|dcl1= |
template< class... UTypes > | template< class... UTypes > | ||
tuple& operator=( const tuple<UTypes...>& other ); | tuple& operator=( const tuple<UTypes...>& other ); | ||
+ | |since2=c++20|dcl2= | ||
+ | template< class... UTypes > | ||
+ | constexpr tuple& operator=( const tuple<UTypes...>& other ); | ||
}} | }} | ||
− | {{dcl | num=4 | | + | {{dcl rev multi|num=4|since1=c++11|dcl1= |
template< class... UTypes > | template< class... UTypes > | ||
tuple& operator=( tuple<UTypes...>&& other ); | tuple& operator=( tuple<UTypes...>&& other ); | ||
+ | |since2=c++20|dcl2= | ||
+ | template< class... UTypes > | ||
+ | constexpr tuple& operator=( tuple<UTypes...>&& other ); | ||
}} | }} | ||
− | {{dcl | num=5 | | + | {{dcl rev multi|num=5|since1=c++11|dcl1= |
template< class U1, class U2 > | template< class U1, class U2 > | ||
tuple& operator=( const pair<U1,U2>& p ); | tuple& operator=( const pair<U1,U2>& p ); | ||
+ | |since2=c++20|dcl2= | ||
+ | template< class U1, class U2 > | ||
+ | constexpr tuple& operator=( const pair<U1,U2>& p ); | ||
}} | }} | ||
− | {{dcl | num=6 | | + | {{dcl rev multi|num=6|since1=c++11|dcl1= |
template< class U1, class U2 > | template< class U1, class U2 > | ||
tuple& operator=( pair<U1,U2>&& p ); | tuple& operator=( pair<U1,U2>&& p ); | ||
+ | |since2=c++20|dcl2= | ||
+ | template< class U1, class U2 > | ||
+ | constexpr tuple& operator=( pair<U1,U2>&& p ); | ||
}} | }} | ||
{{dcl end}} | {{dcl end}} | ||
Line 40: | Line 56: | ||
6) Assigns {{c|std::forward<U1>(p.first)}} to the first element of {{c|*this}} and {{c|std::forward<U2>(p.second)}} to the second element of {{c|*this}}. | 6) Assigns {{c|std::forward<U1>(p.first)}} to the first element of {{c|*this}} and {{c|std::forward<U2>(p.second)}} to the second element of {{c|*this}}. | ||
− | {{ | + | {{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<T_i>::value}} is {{c|true}} for all {{tt|T_i}} in {{tt|Types}}. | * For {{v|1}}, {{c|std::is_copy_assignable<T_i>::value}} is {{c|true}} for all {{tt|T_i}} in {{tt|Types}}. | ||
Line 49: | Line 65: | ||
* For {{v|5}}, {{c|1=sizeof...(Types) == 2}} and {{c|std::is_assignable<T_0&, const U1&>::value}} and {{c|std::is_assignable<T_1&, const U2&>::value}} are both {{c|true}}, where {{tt|T_0}} and {{tt|T_1}} are the two types constituting {{tt|Types}}. | * For {{v|5}}, {{c|1=sizeof...(Types) == 2}} and {{c|std::is_assignable<T_0&, const U1&>::value}} and {{c|std::is_assignable<T_1&, const U2&>::value}} are both {{c|true}}, where {{tt|T_0}} and {{tt|T_1}} are the two types constituting {{tt|Types}}. | ||
* For {{v|6}}, {{c|1=sizeof...(Types) == 2}} and {{c|std::is_assignable<T_0&, U1&&>::value}} and {{c|std::is_assignable<T_1&, U2&&>::value}} are both {{c|true}}, where {{tt|T_0}} and {{tt|T_1}} are the two types constituting {{tt|Types}}. | * For {{v|6}}, {{c|1=sizeof...(Types) == 2}} and {{c|std::is_assignable<T_0&, U1&&>::value}} and {{c|std::is_assignable<T_1&, U2&&>::value}} are both {{c|true}}, where {{tt|T_0}} and {{tt|T_1}} are the two types constituting {{tt|Types}}. | ||
− | + | |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 or if there is a size mismatch. 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 or if there is a size mismatch. Specifically: | ||
* {{v|1}} is defined as deleted unless {{c|std::is_copy_assignable<T_i>::value}} is {{c|true}} for all {{tt|T_i}} in {{tt|Types}}. | * {{v|1}} is defined as deleted unless {{c|std::is_copy_assignable<T_i>::value}} is {{c|true}} for all {{tt|T_i}} in {{tt|Types}}. | ||
Line 59: | Line 74: | ||
* {{v|6}} does not participate in overload resolution unless {{c|std::is_assignable<T_0&, U1&&>::value}} and {{c|std::is_assignable<T_1&, U2&&>::value}} are both {{c|true}}, where {{tt|T_0}} and {{tt|T_1}} are the two types constituting {{tt|Types}}. | * {{v|6}} does not participate in overload resolution unless {{c|std::is_assignable<T_0&, U1&&>::value}} and {{c|std::is_assignable<T_1&, U2&&>::value}} are both {{c|true}}, where {{tt|T_0}} and {{tt|T_1}} are the two types constituting {{tt|Types}}. | ||
}} | }} | ||
− | |||
===Parameters=== | ===Parameters=== | ||
Line 93: | Line 107: | ||
{{dsc end}} | {{dsc end}} | ||
− | + | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
Revision as of 05:47, 19 November 2018
(1) | ||
tuple& operator=( const tuple& other ); |
(since C++11) (until C++20) |
|
constexpr tuple& operator=( const tuple& other ); |
(since C++20) | |
(2) | ||
tuple& operator=( tuple&& other ) noexcept(/* see below */); |
(since C++11) (until C++20) |
|
constexpr tuple& operator=( tuple&& other ) noexcept(/* see below */); |
(since C++20) | |
(3) | ||
template< class... UTypes > tuple& operator=( const tuple<UTypes...>& other ); |
(since C++11) (until C++20) |
|
template< class... UTypes > constexpr tuple& operator=( const tuple<UTypes...>& other ); |
(since C++20) | |
(4) | ||
template< class... UTypes > tuple& operator=( tuple<UTypes...>&& other ); |
(since C++11) (until C++20) |
|
template< class... UTypes > constexpr tuple& operator=( tuple<UTypes...>&& other ); |
(since C++20) | |
(5) | ||
template< class U1, class U2 > tuple& operator=( const pair<U1,U2>& p ); |
(since C++11) (until C++20) |
|
template< class U1, class U2 > constexpr tuple& operator=( const pair<U1,U2>& p ); |
(since C++20) | |
(6) | ||
template< class U1, class U2 > tuple& operator=( pair<U1,U2>&& p ); |
(since C++11) (until C++20) |
|
template< class U1, class U2 > constexpr tuple& operator=( pair<U1,U2>&& p ); |
(since C++20) | |
Replaces the contents of the tuple with the contents of another tuple or a pair.
1) Copy assignment operator. Assigns each element of other to the corresponding element of *this.
2) Move assignment operator. For all i
, assigns std::forward<Ti>(get<i>(other)) to get<i>(*this).
3) For all i
, assigns std::get<i>(other) to std::get<i>(*this).
4) For all i
, assigns std::forward<Ui>(std::get<i>(other)) to std::get<i>(*this).
5) Assigns p.first to the first element of *this and p.second to the second element of *this.
6) Assigns std::forward<U1>(p.first) to the first element of *this and std::forward<U2>(p.second) to the second element of *this.
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 or if there is a size mismatch. Specifically:
|
(since C++17) |
Contents |
Parameters
other | - | tuple to replace the contents of this tuple |
p | - | pair to replace the contents of this 2-tuple |
Return value
*this
Exceptions
1) (none)
2) is_nothrow_move_assignable<T0>::value &&
is_nothrow_move_assignable<T1>::value &&
is_nothrow_move_assignable<T2>::value &&
...
3-6) (none)
Example
This section is incomplete Reason: no example |