Boost logo

Boost :

From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2006-07-24 05:37:45


Hi to all,

   The rvalue reference is likely to be accepted for the next standard
and the standard library is also likely to be modified to implement move
semantics. Googling around, the only thing I've found related to Boost
and move semantics is Jonathan Turkanis' Boost Move Ptr
(http://www.kangaroologic.com/move_ptr/).

   This move ptr and Howard's unique_ptr emulation code
(http://home.twcny.rr.com/hinnant/cpp_extensions/unique_ptr_03.html) are
similar and offer a good new smart pointer. However, I was wondering if
we could try to sketch an emulation of "std::move()" for objects that
are not unique_ptr/move_ptr. Something that would allow at least to
define (portably, perhaps with a macro that in the future, with
compilers that implement move semantics, can be expanded to the proper
&& signature) move constructors and assignments:

    boost::movable_t movable_source(...);
    boost::movable_t movable_target(boost::move(movable_source));

We won't have perfect forwarding but we could start playing with move
semantics to see how it feels. We would need an explicit move from
temporaries, if rvalue catching can't be emulated:

  boost::movable_t produce_movable();
  boost::movable_t movable_target(boost::move(produce_movable()));

The idea would be to define some macros that would allow some kind of
emulation and that would become proper rvalue references in future
compilers:

  my_class(BOOST_NAMED_RVALUE_REF(my_class) move_src)
   : m_member(BOOST_NAMED_RVALUE_REF_GET(move_src).member)
  {}

BOOST_RVALUE_REF might be a class holding a pointer to the move
sourceand BOOST_RVALUE_REF_GET an operator returning a reference to the
pointed object:

  #define BOOST_NAMED_RVALUE_REF(class_name) rvalue_emulation<class_name>
  #define BOOST_NAMED_RVALUE_REF_GET(object_name) (*object_name)

in the future those would be expanded to:

  #define BOOST_NAMED_RVALUE_REF(class_name) class_name &&
  #define BOOST_NAMED_RVALUE_REF_GET(object_name) object_name

As far as know, only Codewarrior (don't know if an experimental version
or officially released one) has move semantics implemented under an
explicit pragma. I've read about efforts to implement this on gcc but I
haven't heard anything recently. Does any booster ideas for emulating
move semantics or is there any ongoing effort? I'm ready to help a bit
about this, but I would want to know if I might be duplicating efforts.

Regards,

Ion


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