Boost logo

Boost :

Subject: Re: [boost] [Review] Formal Review: Boost.Move
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2010-05-26 08:08:06


On 26/05/2010 13:46, vicente.botet wrote:
> Hi,
>
> The following doesn't compiles.
> void fct(BOOST_RVALUE_REF(movable_only) mo, int x){...}
> ...
> movable_only m;
> boost::function<void()> f_one = boost::bind(&fct, boost::move(m), 1);
>
> Im not sure if the following is correct,
> boost::function<void()> f_one = boost::bind(&fct, boost::ref(boost::move(m)), 1);
>
> What is the correct way to use move semantics with Boost.Bind? Do we need some Boost.Bind adaptations?

I don't know, maybe Boost.Bind should catch rvalues differently, but
like with perfect forwarding (after all, bind is about forwarding) we'll
need some limitations or tweaks. Maybe we need some
::boost::rv_ref()/boost::rv_reference_wrapper in Boost.Ref to pass
rvalues to bind. And them Bind could forward them to the target call.
Bind documentation says:

"By default, bind makes a copy of the provided function object.
boost::ref and boost::cref can be used to make it store a reference to
the function object, rather than a copy. This can be useful when the
function object is noncopyable, expensive to copy, or contains state; of
course, in this case the programmer is expected to ensure that the
function object is not destroyed while it's still being used."

So evidently we can't pass movable-only objects unless we have some
rvalue reference wrapper.

Best,

Ion


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