Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-01-28 11:38:40


Daniel Frey <d.frey_at_[hidden]> writes:

> David Abrahams wrote:
>> Daniel Frey <d.frey_at_[hidden]> writes:
>>
>>>David Abrahams wrote:
>>>
>>>>Rob Stewart <stewart_at_[hidden]> writes:
>>>>
>>>>
>>>>> swap() is typically as fast as or faster than copy assignment,
>>>>
>>>>Not for many types that one might like to reset, such as pointers,
>>>>shared_ptr<T>, and integral types.
>>>
>>> What about exception safety guarantees of assignment vs. swap?
>> What about 'em? Speaking generally, both are basic guarantee
>> operations.
>
> I thought that swap is often (not always) a function which doesn't
> throw, e.g. containers' x.swap( y ).

Often == sometimes == never guaranteed to be. Same for operator=.

> If it is, it would make reset a function with the strong instead of
> the basic exception guarantee.
>
> But then, this might not be general enough to be worth the trouble...
> OK, forget about it :)

Premature strengthening of exception guarantees is a common source of
inefficiency.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk