
15 Aug
2011
15 Aug
'11
6:35 p.m.
Hi, I've had this question for a long time, but I still haven't seen others asked the same question. I wonder what's the rationale for range adaptor holding an iterator_range, instead of storing the underlying range (by reference when the range is a container) and calculating begin() and end() on the fly. For C++11 code, it's not unusual to store the temporary expression aside and use it more than once. E.g. vector<int> v = {1, 2, 3}; auto view = v | filtered(...); do_something(view); v.push_back(4); // X do_something(view); Above code is broken since 'v''s iterator is invalidated after X. Could anybody shed some light on this matter?