Boost logo

Boost :

From: Orjan Westin (orjan.westin_at_[hidden])
Date: 2005-11-19 12:39:20


David Abrahams wrote:
> "Orjan Westin" <orjan.westin_at_[hidden]> writes:
>
>> I have a question on the indirect_iterator, and what related
>> standards say.
>>
>> I assume this class is primarily aimed for use in algorithms, which
>> is fine. An algorithm typically dereference an iterator to do its
>> thing, be it comparing or passing the dereferenced iterator on to a
>> function or functor. This is great.
>>
>> But it doesn't handle direct usage well.
>>
>> If I have an indirect_iterator i for, say, a pointer to std::string,
>> I cannot treat it as any other iterator to string and empty the
>> string with this call:
>> i->clear();
>> because the pointer operator is not changed.
>
> It certainly is changed appropriately.

My apologies, I should have said I have only read the documentation - this
question was intended for the boost user list, not the developer one.

The documentation only shows the dereferencing and talk about dereferencing,
and somehow I got the impression this was all it did. The pointer operator
is not mentioned in the documentation, as far as I could see.

>> Instead you have to dereference it and use it as a reference:
>> (*i).clear();
>
> Can you post a minimal reproducible example that shows the problem
> you're describing? Your description is not consistent with the way
> indirect_iterator was designed, so either something is wrong with your
> example or you have found a bug in the library.

No, something was wrong with my question, and possibly the documentation.
I've made a little test to confirm it, and it works as it should.

Just out of curiosity, do you ever think you (and the "you" here is the
boost community, not you David) fall for the temptation to do things more
powerful and complex than they need be? Just looking at the <counts> 14-18
includes in indirect_header.hpp is a bit scary, really, and personally I
found the code a bit hard to follow.

This is not unique to the iterator library either - I often get a feeling
when looking at things in boost and other publicly accessible libraries that
things are somethimes done not so much because that's what needs to be done,
but because they are interesting, technologically challenging or cool. I
know I sometimes find myself overengineering simply because I think
"wouldn't it be cool if..."

I apologise for the concern I caused unecessarily, and for the rambling
reply.

Orjan


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