Boost logo

Boost :

Subject: [boost] Constant iterator of Single Pass Range
From: Jan Hudec (bulb_at_[hidden])
Date: 2014-05-05 06:03:48


Hello All,

The documentation of [Single Pass Range][1] in Boost.Range says that
there should be both `iterator` and `const_iterator` associated types
and both const and non-const overloads for `begin` and `end`. However if
it is really a single-pass range, I don't see a way to implement a
`const_iterator` that would work on `const` reference to the range,
because the `operator++` of the iterator involves calling a non-const
method of the range.

For example the `std::istream_iterator::operator++` calls
`std::istream::operator>>`, which is non-const and so there is no
`const_istream_iterator`. The `istream_range` cheats around this a
little, because the range
is a wrapper around the stream, not the stream itself. But when I have
similarly behaving class that I can make itself be a range, do I really
have to work around this using a wrapper, or can the requirement be
relaxed in practice?

[1]:
http://www.boost.org/libs/range/doc/html/range/concepts/single_pass_range.html

--
Jan Hudec <bulb_at_[hidden]>

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk