Search code examples
c++vectorstlcontainersboost-interprocess

Does vector resize throwing bad_alloc invalidate the original data?


After std::vector::resize() throws a std::bad_alloc exception, is the original data still valid and accessible in the std::vector object?

Does the answer hold for other allocators, e.g. if boost::interprocess::allocator is used as the allocator, and boost::interprocess::bad_alloc is thrown?


Solution

  • std::vector::resize is exception safe.

    If an exception is thrown, this function has no effect (strong exception guarantee).

    Link to the exception specification. The specification doesn't mention any particular requirement on the allocator and must hold regardless of the allocator you provide.