|
Boost : |
From: Alberto Barbati (abarbati_at_[hidden])
Date: 2004-03-09 00:07:40
Pavel Vozenilek wrote:
> "Alberto Barbati" <abarbati_at_[hidden]> wrote
>
> [snip assignement prefereble over destruct/construct]
>
>
>>2) with the dtor/ctor idiom, if the ctor throws an exception, the old
>>element is lost and you can't do anything about it, so the container
>>cannot provide more than the basic guarantee for any method that might
>>overwrite elements. However, the user might implement assigment with the
>>strong guarantee, the container might leverage on that and provide the
>>strong guarantee too at least for methods that might overwrite a single
>>element such as push_back/push_front. (Of course, the user might
>>implement assignment so badly that it doesn't provide even the basic
>>guarantee and the container could not recover from that, but a library
>>such not try to outsmart the user... too much ;).
>>
>
> This argument isn't valid.
>
> push_back() will construct elements when there's space
> available in circular buffer.
>
> Therefore using assignement won't give the method
> strong guarantee (in all cases).
If there is space, the buffer tries to copy construct an element in an
empty (uninitialized) space, then the internal state of the buffer is
updated (this operation does not throw). If the copy ctor throws an
exception, no object is constructed and the buffer state is not modified
=> the buffer is in the exact state it was before the call => strong
guarantee.
If there is not enough space, the buffer tries to replace one value by
invoking operator=, then the internal state is updated (this operation
doesn't throw). *If operator= provides the strong guarantee* and throws,
the element already in the buffer is not modified and the buffer state
is not modified either => the buffer is in the exact state it was before
the call => strong guarantee.
It seems to me that this cover all cases and you always get strong
guarantee. Am I missing something?
Alberto
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk