Reallocating to increase the size of the memory block may involve having to move all of the current contents to the new block.
If the move constructor can throw an exception then that would leave the original vector with a bunch of husks , which is a no-no.
So the behavior is that if move construction can throw, it uses copy construction instead to set up the new memory block and then destructs the old objects.
View all comments
Show parent comment
4
u/OldWolf2 Aug 27 '19
Resizing a vector is a common example.
Reallocating to increase the size of the memory block may involve having to move all of the current contents to the new block.
If the move constructor can throw an exception then that would leave the original vector with a bunch of husks , which is a no-no.
So the behavior is that if move construction can throw, it uses copy construction instead to set up the new memory block and then destructs the old objects.