From: Howard Hinnant (hinnant_at_[hidden])
Date: 2002-02-05 13:53:50
On Tuesday, February 5, 2002, at 01:36 PM, Hamish Mackenzie wrote:
>> However if the vector uses 1 (move construct) to move the elements out
>> of the way, and an exception is thrown while copy assigning x into
>> place, then the vector is still in a valid state. There are no holes
>> uninitialized memory. Basic exception safety has been maintained.
> But even 1 will leave the source damaged will it not? So an exception
> could still lead to double destruction of the same object.
Nope. Use of #1 to move elements from the end into the unused capacity
leaves a vector that is longer than the original with a region of
elements in a (for example) default state in the middle. With #3 these
middle elements are destructed. This half way state must either be
valid, or it must be clean-up-able as one starts to copy the argument x
in. I much prefer to keep the vector in a valid state at all times.
This approach produces much cleaner, tighter code than doing a try/catch
and then putting things back in order in the catch clause.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk