Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2005-01-27 15:49:41


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, 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_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk