When std::vector reallocate its memory array, what kind of copy / move constructor is used to copy / move elements to new houses?
If the move-constructor exists and is noexcept
then it is used. Otherwise the copy-constructor is used.
Using a move-constructor that might throw is undesirable as it might happen that some objects are moved to the new storage and then an exception prevents the rest of the objects being moved.
The cppreference.com site does say that if the object is non-copyable , but has a non-noexcept move constructor, then it will use that move-constructor, with "unspecified behaviour" if an exception is thrown. I guess that means elements may be lost from the vector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With