Boost logo

Boost :

Subject: Re: [boost] C++03 unique_ptr emulation
From: David Abrahams (dave_at_[hidden])
Date: 2009-01-09 10:59:16


on Fri Jan 09 2009, Ion Gaztañaga <igaztanaga-AT-gmail.com> wrote:

> David Abrahams wrote:
>> on Thu Jan 08 2009, Ion Gaztañaga <igaztanaga-AT-gmail.com> wrote:
>>
>>> The same happens when implementing forwarding functions, so I'm starting to think
> that
>>> putting T() in functions taking movable-only types by value is not a bad idea ;-)
>>
>> Sorry, but what do you mean by "putting T() in functions?"
>>
>> putting-milk-in-his-T'ly y'rs,
>
> void function (movable m);
>
> int main()
> {
> movable m;
> function(movable(boost::move(m)));
> function(movable());
> return 0;
> }
>
> I mean that to pass movable-only objects per-value you need to put movable() in the
> argument.

do you mean, generically, "movable(...)"? I couldn't tell whether you
think the default-ctor-ness of that has significance.

> This is needed if boost::move returns boost::detail::rv<T> instead of
> T.

But boost::move should return T.

> Whether we return T or rv<T>, returning a movable type must types must
> construct a movable object in the return statement (see the attached
> test case and change the #define BOOST_MOVE_RETURN_OPTION define to
> play with both approaches):
>
> movable move_return_function ()
> {
> if(cond){
> return movable();
> }
> else(cond){
> movable m;
> return movable(boost::move(m));
> }
> }
>
> This won't work in both cases:
>
> movable move_return_function ()
> {
> movable m;
> return movable;
> }

If movable is a move-only type, no, it won't work. I'm not sure what
point you're trying to make here.

> Returning T from move() avoids the need of explicitly specify
> movable() when passing arguments by value but makes forwarding really
> hard.

I don't see how it impacts forwarding.

> On the other hand returning rv<T> makes forwarding easy

I don't see that either. You'll deduce rv<T> in a generic forwarding
signature instead of T, which has a lot of potential to screw thinigs
up.

> but passing by value ugly. Of course, the question is if we can return
> something from move() that can be different from T so that forwarding
> is easy but has no need to specify movable() when passing by value.

Still lost.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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