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


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.


    vector<int> v = {1, 2, 3};
    auto view = v | filtered(...);
    v.push_back(4); // X

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, kalb at, bjorn.karlsson at, gregod at, wekempf at