Thanks Krzysztof, Patrick!

 

While it’s 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 can’t back-track. 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 it’s adequate for my purposes. Basically, I will use that reverse_iterator for both fwd and reverse traversals by using ++ and --.

 

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 doesn’t block me – as I mentioned, I’ll just use a reverse_iter and use ++ and – on it to satisfy my needs. More of curiosity).

-          Looks like boost::reverse_iterator can’t 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 doesn’t seem to be possible. So, I’m 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, what’d be the correct approach?

 

Thanks again,

Anant

 

 

 

From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Patrick Horgan
Sent: Monday, November 01, 2010 4:34 PM
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] [Iterators] iterators over char *

 

On 11/01/2010 01:16 PM, Rao, Anant wrote:

 

Hi,

 

I have a ‘char *’. I need to be able to traverse thru the string in both fwd and reverse directions.

A char* is a reversible iterator already.  Reversible iterators are modeled to look like pointers.

Patrick



The information contained in this email message and its attachments is intended only for the private and confidential use of the recipient(s) named above, unless the sender expressly agrees otherwise. Transmission of email over the Internet is not a secure communications medium. If you are requesting or have requested the transmittal of personal data, as defined in applicable privacy laws by means of email or in an attachment to email, you must select a more secure alternate means of transmittal that supports your obligations to protect such personal data. If the reader of this message is not the intended recipient and/or you have received this email in error, you must take no action based on the information in this email and you are hereby notified that any dissemination, misuse or copying or disclosure of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by email and delete the original message.