Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-01-27 18:15:16


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.

-- 
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