Boost logo

Boost :

Subject: Re: [boost] C++03 unique_ptr emulation
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2009-01-09 11:11:01


David Abrahams <dave_at_[hidden]> writes:

> 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.

Sorry for jumping in here, but I'm not sure that it should. Consider

movable m;
boost::move(m);

In C++0x, move(m) is equivalent to static_cast<movable&&>(m), which
just obtains a reference. If boost::move<T> returns a T then the code
above will create a temporary which moves the data out of m, and then
destroy that temporary, leaving m a hollow shell.

Anthony

-- 
Anthony Williams
Author of C++ Concurrency in Action | http://www.manning.com/williams
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Just Software Solutions Ltd, Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK

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