std::pair<T1,T2>::operator=
来自cppreference.com
| (1) | ||
| pair& operator=( const pair& other ); |
(C++20 前) | |
| constexpr pair& operator=( const pair& other ); |
(C++20 起) | |
| (2) | ||
| template< class U1, class U2 > pair& operator=( const pair<U1,U2>& other ); |
(C++11 起) (C++20 前) |
|
| template< class U1, class U2 > constexpr pair& operator=( const pair<U1,U2>& other ); |
(C++20 起) | |
| (3) | ||
| pair& operator=( pair&& other ) noexcept(/* see below */); |
(C++11 起) (C++20 前) |
|
| constexpr pair& operator=( pair&& other ) noexcept(/* see below */); |
(C++20 起) | |
| (4) | ||
| template< class U1, class U2 > pair& operator=( pair<U1,U2>&& other ); |
(C++11 起) (C++20 前) |
|
| template< class U1, class U2 > constexpr pair& operator=( pair<U1,U2>&& other ); |
(C++20 起) | |
替换 pair 的内容。
1) 复制赋值运算符。以
other 内容的副本替换内容。
|
(C++11 前) |
|
(C++11 起) |
2) 赋值
other.first 给 first , other.second 给 second 此重载仅若 std::is_assignable<first_type&, const U1&>::value 与 std::is_assignable<second_type&, const U2&>::value 均为 true 才参与重载决议。
3) 移动赋值运算符。用移动语义以
other 的内容替换内容。 此重载仅若 std::is_move_assignable<first_type>::value 与 std::is_move_assignable<second_type>::value 均为 true 才参与重载决议。
此重载仅若 std::is_assignable<first_type&, U1>::value 与 std::is_assignable<second_type&, U2>::value 均为 true 才参与重载决议。
参数
| other | - | 替换此 pair 的值的 pair
|
返回值
*this
异常
1-2) 可能抛出实现定义的异常。
3)
noexcept 规定:
noexcept(
std::is_nothrow_move_assignable<T1>::value &&
std::is_nothrow_move_assignable<T2>::value
4) 可能抛出实现定义的异常。
示例
| 本节未完成 原因:暂无示例 |
缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
| DR | 应用于 | 出版时的行为 | 正确行为 |
|---|---|---|---|
| LWG 2729 | C++11 | pair::operator= 未被约束并可能导致不必要的未定义行为
|
已约束 |