Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 527
ezod Avatar asked Jan 20 '26 15:01

ezod


1 Answers

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.

like image 116
François Andrieux Avatar answered Jan 22 '26 05:01

François Andrieux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!