c++ - Is std::list's multi-element inserts strongly exception-safe? -


in item 17 of exceptional c++, find this:

first, containers, multi-element inserts ("iterator range" inserts) never exception-safe.

but in item 1 of effective stl, find this:

if need transactional semantics multiple-element insertions (e.g., range form — see item 5), you'll want choose list, because list standard container offers transactional semantics multiple-element insertions.

and in page 249 of the c++ standard library 2th, find this:

for lists, multiple-element insert operations transaction safe.

so question 1 right? exceptional-safe means same transaction safe?

  1. which 1 right?

for overloads of std::list::insert, exception-safety guaranteed.

exceptions

if exception thrown, there no effects (strong exception guarantee).

and standard, $23.3.5.4/2 list modifiers [list.modifiers]:

if exception thrown there no effects.

then

  1. is exceptional-safe means same transaction safe?

yes. here's explanation herb sutter:

strong guarantee: if exception thrown, program state remains unchanged. level implies global commit-or-rollback semantics, including no references or iterators container invalidated if operation fails.


Comments