[Boost][Range] Non-mutating algorithm on non const qualified range
Hello,
In the users mailing list I have remarked that this piece of code:
https://gist.github.com/Kojirion/9714131
will fail to compile, without providing 'mutable' iterators.
I have since found out it will also compile by simply const qualifying
the dummy object. (ie const Dummy dummy;)
The reason is that without it this:
is_const<Dummy> gets evaluated to false, resulting in
boost::mpl::eval_if_c
AMDG On 03/24/2014 12:06 AM, Albert Yiamakis wrote:
In the users mailing list I have remarked that this piece of code:
https://gist.github.com/Kojirion/9714131
will fail to compile, without providing 'mutable' iterators. I have since found out it will also compile by simply const qualifying the dummy object. (ie const Dummy dummy;)
The reason is that without it this:
is_const<Dummy> gets evaluated to false, resulting in
boost::mpl::eval_if_c
Surely this is not intended behavior and it should be possible to use a range that has only const iterators in a non-mutating algorithm without const qualifying it?
This is the expected behavior. A range must provide both const and non-const iterators. For an immutable range, they can be the same, but you still need to provide both. (Note that you don't need to provide overloads for range_begin/range_end as the implicit conversion will work there.) http://www.boost.org/libs/range/doc/html/range/concepts/single_pass_range.ht... http://www.boost.org/libs/range/doc/html/range/reference/extending/method_2.... In Christ, Steven Watanabe
participants (2)
-
Albert Yiamakis
-
Steven Watanabe