小编Xlv*_*Xlv的帖子

为什么对于 std::vector::resize() 的一个重载忽略了移动操作的抛出?

在 C++ 标准vector.capacity部分,它为 定义了两个重载resize()。(另见https://en.cppreference.com/w/cpp/container/vector/resize

此重载要求类型 T 是MoveInsertableand DefaultInsertable

constexpr void resize(size_type sz);
Run Code Online (Sandbox Code Playgroud)

另一个重载要求类型 T 是CopyInsertable

constexpr void resize(size_type sz, const T& c);
Run Code Online (Sandbox Code Playgroud)

标准中提到的部分的第 16 条规定了第一次重载:

如果非 Cpp17CopyInsertable T的移动构造函数引发异常,则不会产生任何影响。

但是对于第二次重载,它指出:

如果抛出异常,则没有任何影响。

第二个重载中没有提到移动构造函数的抛出。为什么?

c++ stdvector move-semantics

1
推荐指数
1
解决办法
70
查看次数

标签 统计

c++ ×1

move-semantics ×1

stdvector ×1