【发布时间】:2019-08-09 18:31:52
【问题描述】:
如果在将对象移动到 std::vector 时内存分配失败,并抛出 bad_alloc,std::vector 是否保证从对象移出的对象不变/仍然有效?
例如:
std::string str = "Hello, World!";
std::vector<std::string> vec;
vec.emplace_back(std::move(str));
/* Is str still valid and unaltered if the previous line throws? */
【问题讨论】:
标签: c++ stdvector exception-safety