Boost logo

Boost :

From: Andrey Semashev (andysem_at_[hidden])
Date: 2008-04-10 17:56:34

Thorsten Ottosen wrote:
> Andrey Semashev skrev:
>> Thorsten Ottosen wrote:
>>> Comments?
>> Your approach requires the T to be default constructible which is not
>> always the case.
> Why is this better than the far more expensive copy-construction?

1. It adds a new requirement to T. I'd rather not have it since, as
other noted, optional is frequently used with non-default-constructible
types. You'll simply restrict swap to be available only for
default-constructible types, which is not the case ATM.
2. I'd rather not assume what is more or less expensive. The opposite
case is quite common too (shared pimpl object is an example).

>> Besides, to my mind, the current implementation is more
>> obvious for the user.
> No user expects swap to throw or invalidate iterators or references like
> the current implementation does.

Default constructor may throw as well, you won't gain anything here. And
I'm not sure I understand what you meant with iterators or references

Boost list run by bdawes at, gregod at, cpdaniel at, john at