|
Boost Users : |
Subject: Re: [Boost-users] [Iterators] iterators over char *
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2010-11-02 06:04:13
2010/11/2 Rao, Anant <Anant.Rao_at_[hidden]>:
> While its true that a char* seems to be equivalent to an iterator (in this
> case), I prefer the iterator/reverse_iterator much better. For example, if I
> use an iterator and it reaches end(), I can do
> --it to get to the last char.
> In a char * model, once I reach the NULL ptr (at the end of the string), I
> cant back-track.
I think You are confusing NULL pointer with null character.
> Similarly, rbegin()/reverse_iter. Maintaining a sentinel
> value for the start of a string is more difficult (other than indices).
> IMHO, those are the solid advantages I see with an iterator.
>
> I re-read the article published by David Abrahams et al on
> reverse_iterator
> (http://www.boost.org/doc/libs/1_44_0/libs/iterator/doc/reverse_iterator.html_)
>
> and felt its adequate for my purposes. Basically, I will use that
> reverse_iterator for both fwd and reverse traversals by using ++ and --.
I think You are confusing bidirectional iterator with reverse iterator
> A couple of simple questions I have:
>
> - Why is it not possible to define a boost::iterator as easily as a
> boost::reverse_iterator on a char * string as in the above web link?
> (Again, it doesnt block me as I mentioned, Ill just use a reverse_iter
> and use ++ and on it to satisfy my needs. More of curiosity).
Because char* is an iterator itself.
> - Looks like boost::reverse_iterator cant be assigned to; can only
> be created. If I need to define it as a class member that needs to be made
> to point to diff strings as the program progresses, it doesnt seem to be
> possible. So, Im thinking of using a ptr to a boost::reverse_iterator so
> that I can re-seat the reverse_iterator to diff strings. Is this a
> convoluted approach or correct approach (given my needs)? If former, whatd
> be the correct approach?
I think it can be assigned to, but that is irrelevant, because You
don't seem to need it anyway.
Regards,
Kris.
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