Boost logo

Boost :

Subject: Re: [boost] [range] adaptors vs. rvalue to lvalue& binding
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2012-03-22 10:53:29


On 3/22/2012 2:54 PM, Arno Schödl wrote:
> Hello,

>> What you want to do instead is to change the signature of your
>> function to accept both lvalue and rvalue reference:
>>
>> template<typename Range> void modifies_range(Range&& rng);
>
> So do we want to change boost::sort( Rng& ) to boost::sort( Rng&& )
> ? That would make boost::sort( std::vector() ) ok. C++ decided at
> some point to disallow binding rvalues to lvalue&. I think the reason
> is that rvalues are inaccessible for the caller, so modifying them is
> likely a bug. I am a bit hesitant to throw that out the window for
> ranges.

Well, its quite often /not/ a bug at all:

boost::push_back( a_vector, boost::sort( get_values() ) );

is entirely sensible. And once we get r-value references thoughout the
range lib, we can move the elements all the way into the vector
(so its optimally efficient and elegant to boot).

-Thorsten


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