gpt4 book ai didi

c++ - std::list 的多元素插入是强异常安全的吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:51:37 25 4
gpt4 key购买 nike

exceptional c++ 的第 17 项中,我发现:

First, for all containers, multi-element inserts ("iterator range" inserts) are never strongly exception-safe.

但在 effective STL 的第 1 项中,我发现:

If you need transactional semantics for multiple-element insertions (e.g., the range form — see Item 5), you'll want to choose list, because list is the only standard container that offers transactional semantics for multiple-element insertions.

the c++ standard library 2th249 页中,我找到了这个:

For lists, even multiple-element insert operations are transaction safe.

所以我的问题是哪一个是正确的?强异常安全和事务安全是一样的吗?

最佳答案

  1. which one is right?

对于 std::list::insert 的所有重载, 强烈的异常安全得到保证。

Exceptions

If an exception is thrown, there are no effects (strong exception guarantee).

根据标准,$23.3.5.4/2 列表修饰符 [list.modifiers]:

If an exception is thrown there are no effects.

然后

  1. is strongly exceptional-safe means the same with transaction safe?

是的。 Here来自 Herb Sutter 的解释:

Strong Guarantee: If an exception is thrown, program state remains unchanged. This level always implies global commit-or-rollback semantics, including that no references or iterators into a container be invalidated if an operation fails.

关于c++ - std::list 的多元素插入是强异常安全的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36453394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com