|
Boost : |
From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2008-09-01 06:19:20
On Mon, Sep 1, 2008 at 10:18 AM, Thorsten Ottosen
<thorsten.ottosen_at_[hidden]> wrote:
> Giovanni Piero Deretta skrev:
>
>>>> Stacking them naively would have 2^N storage
>>>> growth, rather than 4^N, and we still don't need to worry about range
>>>> lifetime.
>>>
>>> I've been trying to say that generic algorithms *can't* worry about the
>>> range lifetime; they have to assume that the iterators they're passed
>>> will not be invalidated before they're destroyed.
>>
>> I think that the OP is talking about a different problem: let say you
>> want to name the result of stacked applications of range adaptors:
>>
>> template<typename Range>
>> void my_algo(Range& r) {
>> auto stacked_range = r | filtered(filter) | mapped(mapper);
>> // use stacked_range
>> }
>>
>> This may lead iterator lifetime problems, not because r iterators may
>> be invalid, but because the iterators of the range returned by
>> filtered(...) may become invalid as that temporary has been
>> destructed.
>
> I don't see how this happens. The iterators are stored by value in each new
> range that is generated.
>
But it doesn't need to be so. And that's exactly what all the
discussion is about :)
-- gpd
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk