Boost logo

Boost Users :

Subject: [Boost-users] [Range] Why adaptor stores iterator_range instead of its underlying range?
From: TONGARI (tongari95_at_[hidden])
Date: 2011-08-15 14:35:49


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?



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net