|
Boost : |
From: Rob Stewart (stewart_at_[hidden])
Date: 2005-01-28 15:53:17
From: David Abrahams <dave_at_[hidden]>
> Rob Stewart <stewart_at_[hidden]> writes:
> >
> > 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.
I was trying to make the case that a one size fits all reset() is
not likely to work. However, in my zeal, I overstated the case
for swap(), particularly as it applies to simple types, and you
were right to call me on it.
swap() on those simple types, of course, involves a temporary and
two assignments, which I was neglecting and, yes, those are the
most likely candidates for reset(), at least for the purpose
being discussed.
Note, however, that a namespace scope reset() can be construed as
meaning different things to different types. For example, it
could be specialized to provide the fastest means to reset any
object to its initial state. Thus, it might do
std::vector<T>().swap(v) or something uglier for other types.
Thus, reset() should be designed and documented to be
customizable for a reasonable meaning of "reset" for any type.
-- 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