vector resize throwing bad_alloc 是否会使原始数据无效?
Does vector resize throwing bad_alloc invalidate the original data?
std::vector::resize()
抛出std::bad_alloc
异常后,std::vector
对象中的原始数据是否仍然有效且可访问?
答案是否适用于其他分配器,例如如果 boost::interprocess::allocator
被用作分配器,并且 boost::interprocess::bad_alloc
被抛出?
std::vector::resize
是异常安全的。
If an exception is thrown, this function has no effect (strong exception guarantee).
Link to the exception specification.规范未提及对分配器的任何特定要求,并且无论您提供什么分配器都必须满足。
is the original data still valid and accessible in the std::vector
object?
是的,std::vector::resize
有很强的异常保证(下面提到的情况除外)。 §26.3.11.3/15 vector capacity [vector.capacity]:
If an exception is thrown other than by the move constructor of a non-CopyInsertable T there are no effects.
保证与指定的分配器类型无关;所以它总是正确的。
std::vector::resize()
抛出std::bad_alloc
异常后,std::vector
对象中的原始数据是否仍然有效且可访问?
答案是否适用于其他分配器,例如如果 boost::interprocess::allocator
被用作分配器,并且 boost::interprocess::bad_alloc
被抛出?
std::vector::resize
是异常安全的。
If an exception is thrown, this function has no effect (strong exception guarantee).
Link to the exception specification.规范未提及对分配器的任何特定要求,并且无论您提供什么分配器都必须满足。
is the original data still valid and accessible in the
std::vector
object?
是的,std::vector::resize
有很强的异常保证(下面提到的情况除外)。 §26.3.11.3/15 vector capacity [vector.capacity]:
If an exception is thrown other than by the move constructor of a non-CopyInsertable T there are no effects.
保证与指定的分配器类型无关;所以它总是正确的。