
27 Jan
2005
27 Jan
'05
11:15 p.m.
Rob Stewart <stewart@sig.com> writes:
From: =?ISO-8859-1?Q?S=E9rgio_Vale_e_Pace?= <svpace.forum@gmail.com>
On Wed, 26 Jan 2005 16:48:41 +0100, Stefan Slapeta <stefan@slapeta.com> 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