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