[squid-dev] [PATCH] SBuf const iterator fixes

Alex Rousskov rousskov at measurement-factory.com
Mon Feb 8 19:53:15 UTC 2016


On 02/08/2016 12:38 PM, Kinkie wrote:
> On Mon, Feb 8, 2016 at 8:15 PM, Alex Rousskov
> <rousskov at measurement-factory.com> wrote:
>> On 02/08/2016 11:18 AM, Amos Jeffries wrote:
>>> The SBufIterator is mostly actually a const iterator. But not quite.
>>
>> I am not sure I understand what you are implying because you did not
>> change any const-related aspects of SBufIterator. What are the
>> requirements for being a "const iterator" class that old SBufIterator
>> violated?
> 
> It behaves like a const while not being explicitly so.

I do not understand what "not being explicitly const" means in this
context. SBufIterator is a class. There is no such thing as "const class".


> You can't do
> auto i = sbuf.begin();
> *i = 'a';

Yes, but you also cannot do that with any const_iterator, so I am not
sure why you are citing this code in this context.


>>> The point of difference from const_iterator is the operator*() API which
>>> is also different from the normal itertor API in that is returns a char
>>> instead of a char& or const char &.
>>
>> Please explain why returning char is wrong for const_iterator. I
>> understand that [all?] standard iterators return a reference, and I also
>> understand that a non-const iterator cannot return a char, but I do not
>> yet understand how that difference affects constant SBufIterator.
> 
> It behaves the same,but it's a different API.

Different compared to what? Is that a bad difference or an improvement?


> the iterator should return a char referente, 

Why should a const_iterator return a char reference?

Please note that I am not saying that there is something wrong with the
patched code -- I am trying to understand why we have to change the
return type of operator "*" [in the scope of this patch].


Thank you,

Alex.



More information about the squid-dev mailing list