|
Boost Users : |
Subject: Re: [Boost-users] [Range] Strange!
From: Neil Groves (neil_at_[hidden])
Date: 2014-08-28 18:49:21
On 28 August 2014 22:35, Krzysztof Czainski <1czajnik_at_[hidden]> wrote:
> 2014-08-28 23:29 GMT+02:00 Robert Jones <robertgbjones_at_[hidden]>:
>
> On 28 August 2014 22:22, Neil Groves <neil_at_[hidden]> wrote:
>>
>>>
>>> The counting_range instance is a unnamed temporary,,,,
>>>
>>
>> So the earlier lines are flawed too, just working by chance?
>>
>
> Yes, combinations of counting_range with reversed. But not because
> counting_range is a temporary.
>
You are completely right in this instance. I've seen too many functions
return a collection by value and then be used as the left-most operand in a
chain of range adaptors! This is not applicable here.
>
> I think the problem is counting_iterator returns a reference to an int it
> owns. Iterators shouldn't do that.
>
This is exactly what is causing the issue.
>
> Iterators should either:
> - return a reference to something they don't own, or
> - return by value.
>
Your logic for return type makes a lot of sense. Unfortunately there are
conflated requirements upon the return type of dereference operations for
the various iterator traversals. See
http://www.boost.org/doc/libs/1_56_0/libs/multi_array/doc/iterator_categories.html.
I imagine that this is why the counting_iterator is implemented to return a
true reference.
This leaves us with rather a thorny problem, a counting_iterator can't have
the dereference operator return by value and model the Bidirectional
Iterator Concept. Therefore if counting_iterator were to return by value we
wouldn't be allowed to reverse (if we constrained ourselves to the Standard
iterator traversal categories). It might be that there is room for
improvement while working with the Boost traversal tags rather than the
iterator traversal tags.
>
> Regards,
> Kris
>
Thanks for pointing this out, I hadn't spotted this issue with the
counting_iterator. After giving this some more thought I shall raise a
ticket for Boost.Iterator.
Regards,
Neil Groves
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net