This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Implementing clean and simple move symantics
On Wed, Nov 24, 2004 at 05:21:18PM +0000, chris wrote:
> Having said that as I said before, "memmove"ing is better than swap (by
> about a factor of 2) even for those types where swap is efficent, like
> vector and list. However writing algorithms which work with both memmove
> and normal assignment is tricky for a couple of (I think not
> insumantable) reasons, in particular you probably shouldn't memmove to
> and from local variables, so it might be necessary use "containers"
> which can be used like a local variable and allocated on the stack, but
> isn't automatically either created or destroyed, so they can be
> "memmoved" in and out of. (tr1::array does this kind of thing, so it
> shouldn't be hard. I wonder if g++ might lose some optimisation from it tho)
Your approach is more ambitious than what I was thinking of; for example,
to have std::vector take advantage of memmove, I might have two different
versions of insertion, erasure, and resizing methods, with the appropriate
version selected on the basis of a type trait. It seems that you want to
come up with one unified way to handle everything.