Boost logo

Boost :

Subject: Re: [boost] [move][container] Fast-track reviews for Move and Container?
From: Thomas Klimpel (Thomas.Klimpel_at_[hidden])
Date: 2009-08-17 16:00:53


Ion Gaztañaga wrote:
> Thomas Klimpel escribió:
>
> > But I have a question about Boost.Move: Because the problem
> > Boost.Move addresses is so important, and Boost.Move wasn't around,
> > my existent code uses efficient implementations of "swap" as a
> > substitute. The documentation shows that Boost.Move can be used to
> > implement an efficient swap. But what about the other direction? Can
> > Boost.Move exploit an existent efficient swap?
>
> Boost.Move calls user defined constructors to operate, so you can
> implement your move constructors using your efficient swap:
>
> Type(BOOST_RV_REV(Type) t)
> : ...() //Empty construction
> {
> this->swap(t);
> }

I hope I can omit the empty construction, since some of my classes have many member variables. But on second thought, I should at least initialize the pointers to zero, to avoid undefined behavior in the destructor.

> Ditto for move assignment:
>
> Type & operator=(BOOST_RV_REV(Type) t)
> {
> Type tmp(boost::move(t));
> this->swap(tmp);
> }

I hope I can omit the temporary, because two calls to swap are less efficient than a single call to swap. I can't find any second thought that forces me to create a temporary. Do I miss something?

Regards,
Thomas


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