Boost logo

Boost :

From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2008-08-25 11:34:57

Niels Dekker - mail address until 2008-12-31 wrote:
> Anyway, I was also considering a more "lightweight" way to tweak MSVC's
> Swaptimization, merely based upon tr1::has_nothrow_copy (which is
> included VC9 SP1). Because when using MSVC9, whenever a function like
> vector<T>::push_back needs to reallocate, it moves its elements /either/
> by copy-construction /or/ by default-construction + swap, depending on
> whether "Swaptimization" is turned on for type T. Isn't it reasonable
> to just do default-construction + swap, /unless/ T has no-throw
> copy-construction?
> if tr1::has_nothrow_copy<T>
> move by means of copy
> else
> move by means of default-construction + swap

Unless you have a type like boost::function apparently is currently
where default construction + swap is also not a no throw operation and
is more expensive than a direct copy.

Unless you consider swaps like boost::function's a bug I don't think it
is fair to assume swap means fast move in general. I think the only real
way to get it right in every case is to have the author of the type
specify the proper traits.

Boost list run by bdawes at, gregod at, cpdaniel at, john at