Boost logo

Boost :

Subject: [boost] [range] Should ranges really propagate constess to the data ?
From: Samuel Debionne (debionne_at_[hidden])
Date: 2011-07-22 10:31:55

Hello everyone,
Here is an example code that motivates my question :

typedef std::vector<int> vector_t;

boost::sub_range<vector_t> three_first(vector_t& _v) {return
boost::make_iterator_range(_v.begin(), _v.begin() + 3); }

int main(int argc, char* argv[])
     vector_t v;
     boost::fill(three_first(v), 1); // Fail : you cannot assign to a
variable that is const

     return 0;

Taken from Boost.GIL documentation, the definition of image views is :

An image view is a generalization of STL's range concept to multiple
dimensions. Similar to ranges (and iterators), image views are shallow,
don't own the underlying data and don't propagate their constness over
the data. For example, a constant image view cannot be resized, but may
allow modifying the pixels. For pixel-immutable operations, use
constant-value image view (also called non-mutable image view).

I expected the range concept to follow these lines regarding constness,
but I'm not very sure anymore...

for instance sub_range have :

iterator begin() { return base::begin(); }
*const_iterator* begin() const { return base::begin(); }

and boost::begin() is :

inline range_iterator<T>::type begin( T& r ) {...}
inline range_iterator<*const* T>::type begin( const T& r ) {...}

which means that I'm probably wrong. Am I missing something ?


Boost list run by bdawes at, gregod at, cpdaniel at, john at