|
Boost : |
Subject: Re: [boost] [Range] Range adaptor approach for temporary range lifetime issue
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2012-06-18 04:59:57
On 17-06-2012 14:33, Michel Morin wrote:
> Michel Morin wrote:
>> I implemented this approach as a range adaptor (with the aid of
>> rvalue references and decltype C++11 features):
>>
>> for (auto x : std::string("Hello world!") | moved | reversed) { /*...*/ }
>>
>> When an rvalue range is piped to `moved` adaptor, it returns `moved_range`.
>
> Side note:
>
> * There is also a fully automatic approach (i.e. when an rvalue range
> is adapted,
> `moved_range` is automatically used without piping it to `moved` adaptor).
> But this approach incurs unnecessary overhead when passing them to functions,
> because function arguments do not have the lifetime issue and we don't need
> to use `moved_range`.
I'm not sure this is true, that is, that sub-expressions of function
arguments are guaranteed not to be destroyed before the function ends.
-Thorsten
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk