Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Ranges 2.0 algorithms accepting a const reference
From: Stefano (pelux_at_[hidden])
Date: 2010-07-10 13:05:29

Mathias Gaunard <mathias.gaunard <at>> writes:

> Le 08/07/2010 22:30, Stefano Peluchetti a écrit :
> > Hi,
> >
> > the Boost.Ranges (v 1.43) documentation suggests that for each
> > algorithm there is a version accepting a reference to a range and a
> > version accepting a const reference to a range (which in my case would
> > be useful for the "non-const reference to temporary object problem"
> > when dealing for example with a
> > boost::iterator_range<std::vector<double>::iterator> range).
> >
> > However the code (take for instance the reverse algorithm) does not
> > seems to include the const reference version.
> >
> > Am I missing something, is the documentation incorrect, or it has been
> > decided against the const reference version?
> reverse modifies its input, therefore it only takes a non-const range.

Ok, but for instance find does not necessarly modify the input, and still there
is only the version accepting the non-const reference.
This is in contrast with the "Introduction" section of the documentation which
stresss that both versions of find have to be implemented due to the forwarding

Moreover, iterator_range beheaves like stl iterators (and const_iterators,
depending on the template argument used) and as such a const
iterator_range<std::vector<double>::iterator> will behave like a mutable range
(and the range_iterator class knows this).

Please notice this is in contrast with the sub_range class (something I
personally find a bit confusing :P).

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at