为什么 std::vector::resize() 的一次重载会忽略移动操作的抛出?
Why is throwing of move operation is ignored for one overload of std::vector::resize()?
在 C++ 标准中 vector.capacity section, it defines two overloads for resize()
. (see also https://en.cppreference.com/w/cpp/container/vector/resize)
此重载要求类型 T 为 MoveInsertable
且 DefaultInsertable
:
constexpr void resize(size_type sz);
另一个重载要求类型 T 是 CopyInsertable
:
constexpr void resize(size_type sz, const T& c);
标准中提到的部分的第 16 条规定了第一个重载:
If an exception is thrown other than by the move constructor of a non-Cpp17CopyInsertable T there are no effects.
但是对于第二次超载,它指出:
If an exception is thrown there are no effects.
第二个重载中没有提到 移动构造函数 的抛出。为什么?
Throwing of the move constructor is not mentioned in the second overload. why?
因为第二次重载要求类型是CopyInsertable。鉴于该要求,第二次重载不存在非 Cpp17CopyInsertable T 的情况 ",因此无需提及该情况。
在 C++ 标准中 vector.capacity section, it defines two overloads for resize()
. (see also https://en.cppreference.com/w/cpp/container/vector/resize)
此重载要求类型 T 为 MoveInsertable
且 DefaultInsertable
:
constexpr void resize(size_type sz);
另一个重载要求类型 T 是 CopyInsertable
:
constexpr void resize(size_type sz, const T& c);
标准中提到的部分的第 16 条规定了第一个重载:
If an exception is thrown other than by the move constructor of a non-Cpp17CopyInsertable T there are no effects.
但是对于第二次超载,它指出:
If an exception is thrown there are no effects.
第二个重载中没有提到 移动构造函数 的抛出。为什么?
Throwing of the move constructor is not mentioned in the second overload. why?
因为第二次重载要求类型是CopyInsertable。鉴于该要求,第二次重载不存在非 Cpp17CopyInsertable T 的情况 ",因此无需提及该情况。