Boost logo

Boost :

Subject: Re: [boost] [move] Library uploaded to sandbox
From: Christian Holmquist (c.holmquist_at_[hidden])
Date: 2009-02-18 20:53:08


2009/2/18 Mathias Gaunard <mathias.gaunard_at_[hidden]>

> Christian Holmquist wrote :
>
>> I think the doc_file_descriptor example should show how to create an
>> object
>> directly in the vector<file_descriptor> using emplace functions, as
>> boost::move can't detect true rvalues as in c+0x.
>>
>> boost::interprocess::vector<file_descriptor> v;
>> v.push_back(file_descriptor("filename")); // <- Fails
>>
>
> Why does it fail?
> I thought rvalues were properly detected.
>
>
>
The chosen overload is
void vector<T>::push_back(const T& x),

I don't think it's possible to detect a difference between
foo(T()) -> const T&
const T x; foo(x); -> const T&

and one don't want to automatically be able to move const&.

The following works, although a bit verbose
v.push_back(const_cast<file_descriptor&>(file_descriptor("")));

/ Christian


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