Boost logo

Boost :

From: Daniel James (daniel_james_at_[hidden])
Date: 2008-07-31 13:40:25


2008/7/31 Michael Marcin <mike.marcin_at_[hidden]>:
> I'm using the current move library in the sanbox by daniel james (which I
> believe is the 4th move emulation library I've used now). It seems to be
> very good so far and makes writing code that handles both move and copy a
> breeze. I hope this gets finalized and ready for review soon because a
> consistently used move emulation library would be a great aid to writing
> efficient libraries that work well together.

I'm pleased (and slightly surprised) that it's already getting use. To
give credit where it's due, most of it is based on work by Adobe and
David Abrahams. I also took some code from the move emulation in the
thread library and the old move library. Tracing the complete ancestry
of the library could take a while.

> However the documentation says that objects have to model the Regular
> concept in order to model the Movable concept. This seems unfortunate as
> Regular puts a lot of requirements on types that don't seem necessary to
> gain moving. It requires Assignable which requires a copy constructor and it
> requires EqualityComparable which seems unnecessary.

Sorry, the documentation is out of date, I haven't updated it for the
changes I've made. The library does supports noncopyable types. If you
can decipher it there is an example in the unit tests (in y.hpp - I'll
probably rename that file). You have to implement it a little
differently to your normal noncopyable type. The signature is
something like:

class noncopyable
{
   // Private constructor to make it noncopyable.
   // Note that it's a non-const reference
   noncopyable(noncopyable&);
public:
   noncopyable();
   ~noncopyable();
   noncopyable(boost::move_from<noncopyable>); // Move constructor
   noncopyable& operator=(noncopyable); // Move assignment
   operator boost::move_from<noncopyable>() {
       return boost::move_from<noncopyable>(*const_cast<noncopyable*>(this));
   }
};

I should warn you that the library will probably change to support
other types and hopefully rvalue references. I'll be resuming work on
it soon after this release is done.

Daniel


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