|
Boost : |
From: Daniel Frey (d.frey_at_[hidden])
Date: 2005-01-27 19:04:21
David Abrahams wrote:
> Rob Stewart <stewart_at_[hidden]> writes:
>
>>From: =?ISO-8859-1?Q?S=E9rgio_Vale_e_Pace?= <svpace.forum_at_[hidden]>
>>
>>>On Wed, 26 Jan 2005 16:48:41 +0100, Stefan Slapeta <stefan_at_[hidden]> wrote:
>>>
>>>>do we have a non-member reset() somewhere? Something like
>>>>
>>>>template <typename T>
>>>>void reset(T& t)
>>>>{
>>>> std::swap(t, T());
>>>>}
>>>>
>>>>(of course to be refined...)
>>>
>>>why not :
>>>
>>>template <typename T>
>>>void reset(T& t)
>>>{
>>> t = T();
>>>}
>>
>>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?
Personally, I'd say these are more important to think about than speed...
Regards, Daniel
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk