State std :: vector after std :: bad_alloc

I am trying to find an online link to see the safety of exceptions from multiple std containers.

In the case of std::vector , does the previous push_back call keep state? I would suggest that a vector has all of its objects still valid (no destructors called). What guarantees do std::vector offer after push_back throws a std::bad_alloc ?

+4
source share
1 answer

If it throws, the vector does not change. Not even capacity() .

According to [container.requirements.general]:

Unless otherwise specified (see 23.2.4.1, 23.2.5.1, 23.3.3.4 and 23.3.6.5), all types of containers defined in this document The article satisfies the following additional requirements:

[...]

- if an exception is thrown by the push_back () or push_front () function, this function has no effects.

+7
source

Source: https://habr.com/ru/post/1391518/


All Articles