std::tuple<Types...>::operator=
来自cppreference.com
| (1) | ||
| tuple& operator=( const tuple& other ); |
(C++11 起) (C++20 前) |
|
| constexpr tuple& operator=( const tuple& other ); |
(C++20 起) | |
| (2) | ||
| tuple& operator=( tuple&& other ) noexcept(/* see below */); |
(C++11 起) (C++20 前) |
|
| constexpr tuple& operator=( tuple&& other ) noexcept(/* see below */); |
(C++20 起) | |
| (3) | ||
| template< class... UTypes > tuple& operator=( const tuple<UTypes...>& other ); |
(C++11 起) (C++20 前) |
|
| template< class... UTypes > constexpr tuple& operator=( const tuple<UTypes...>& other ); |
(C++20 起) | |
| (4) | ||
| template< class... UTypes > tuple& operator=( tuple<UTypes...>&& other ); |
(C++11 起) (C++20 前) |
|
| template< class... UTypes > constexpr tuple& operator=( tuple<UTypes...>&& other ); |
(C++20 起) | |
| (5) | ||
| template< class U1, class U2 > tuple& operator=( const std::pair<U1,U2>& p ); |
(C++11 起) (C++20 前) |
|
| template< class U1, class U2 > constexpr tuple& operator=( const std::pair<U1,U2>& p ); |
(C++20 起) | |
| (6) | ||
| template< class U1, class U2 > tuple& operator=( std::pair<U1,U2>&& p ); |
(C++11 起) (C++20 前) |
|
| template< class U1, class U2 > constexpr tuple& operator=( std::pair<U1,U2>&& p ); |
(C++20 起) | |
以另一 tuple 或 pair 的内容替换 tuple 的内容。
1) 复制赋值运算符。复制赋值
other 的每个元素给 *this 的对应元素。
- 定义此重载为被删除,除非 std::is_copy_assignable<T_i>::value 对
Types中所有T_i为 true 。
2) 移动赋值运算符。对所有
i ,赋值 std::forward<Ti>(get<i>(other)) 给 get<i>(*this) 。
- 此重载仅若 std::is_move_assignable<T_i>::value 对
Types中所有T_i为 true 才参与重载决议。
3) 对所有
i ,赋 std::get<i>(other) 给 std::get<i>(*this) 。
- 此重载仅若 sizeof...(UTypes) == sizeof...(Types) 且 std::is_assignable<T_i&, const U_i&>::value 对所有
Types中的T_i和UTypes中的U_i的对应对均为 true 才参与重载决议。
4) 对所有
i ,赋 std::forward<Ui>(std::get<i>(other)) 给 std::get<i>(*this) 。
- 此重载仅若 sizeof...(UTypes) == sizeof...(Types) 且 std::is_assignable<T_i&, U_i>::value 对所有
Types中的T_i和UTypes中的U_i的对应对均为 true 才参与重载决议。
5) 赋 p.first 给 *this 的首元素并赋 p.second 给 *this 的第二元素。
- 此重载仅若 sizeof...(Types) == 2 且 std::is_assignable<T_0&, const U1&>::value 与 std::is_assignable<T_1&, const U2&>::value 均为 true 才参与重载决议,其中
T_0与T_1是组成Types的二个类型。
6) 赋 std::forward<U1>(p.first) 给 *this 的首元素并赋 std::forward<U2>(p.second) 给 *this 的第二元素。
- 此重载仅若 sizeof...(Types) == 2 且 std::is_assignable<T_0&, U1>::value 与 std::is_assignable<T_1&, U2>::value 均为 true 才参与重载决议,其中
T_0与T_1是组成Types的二个类型。
参数
| other | - | 要替换此 tuple 内容的 tuple
|
| p | - | 要替换此 2-tuple 内容的 pair
|
返回值
*this
异常
1) 可能抛出实现定义的异常。
2)
noexcept 规定:
noexcept(
std::is_nothrow_move_assignable<T0>::value &&
std::is_nothrow_move_assignable<T1>::value &&
std::is_nothrow_move_assignable<T2>::value &&
...
3-6) 可能抛出实现定义的异常。
示例
| 本节未完成 原因:暂无示例 |
缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
| DR | 应用于 | 出版时的行为 | 正确行为 |
|---|---|---|---|
| LWG 2729 | C++11 | tuple::operator= 未被约束并可能导致不必要的未定义行为
|
已约束 |