
28 Jan
2005
28 Jan
'05
12:04 a.m.
David Abrahams wrote:
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.
What about exception safety guarantees of assignment vs. swap? Personally, I'd say these are more important to think about than speed... Regards, Daniel