std::bad_alloc 之后 std::vector 的状态
我试图找到一个在线参考来查看几个 std 容器的异常安全性。
对于std::vector
,它是否保留push_back调用之前的状态?我假设向量的所有对象仍然有效(没有调用析构函数)。在push_back抛出std::bad_alloc
异常后,什么保证提供std::vector
?
I'm trying to find a online reference to see the exception safety of several std containers.
In the case of std::vector
, Does it keep the state previous to the push_back call? I would presume the vector has all its objects still valid (no destructors invoked). What guarantees offer std::vector
after push_back throws a std::bad_alloc
exception?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果抛出异常,向量不会改变。甚至不是
capacity()
。根据[container.requirements.general]:
If it throws, the vector isn't changed. Even not the
capacity()
.According to [container.requirements.general]: