
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, so it is preferable to copy assignment. There are also types for which swap() exists and copy assignment doesn't. There are also those types with neither swap() nor copy assignment, but which do have a reset() member function. The point is that several versions will be needed and specialization will be needed, too. -- Rob Stewart stewart@sig.com Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;