Hi Kris,

Thanks for a quick response!

This is part of a larger issue that I’m addressing.

 

So, there’s absolutely no way to use the same ptr to traverse backwards? I tried the options based on my limited knowledge, but if there’re other options, please let me know (using the same ptr).

It’s ironic a simple pointer could go fwd, but not back.

Anant

 

 

From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Krzysztof Czainski
Sent: Friday, December 10, 2010 9:00 AM
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] Range_iterator - char* - reverse

 

2010/12/10 Rao, Anant <Anant.Rao@ironmountain.com>

 

      char *s = "abcdefg";

     

      iterator_range<char*> ir( &s[0], &s[ strlen(s) ] );

      char *cp;

 

      boost::range_reverse_iterator< char*>::type irb = boost::rbegin( ir );

      boost::range_reverse_iterator< char*>::type ire = boost::rend( ir );

 

      for (; irb != ire; ++irb)

      {

            cout << "reverse cp [" << *irb << "]\n";

      }

 

This works like a charm – both in fwd and reverse traversal.

 

However, what I want is – in reverse traversal also, I want to use the same pointer (“cp” in this case). In other words, I want to use the same pointer to traverse in both directions.

Here’s what I want to be able to write, but get a compile error with both attempts and I was wondering if you could help.

 

Option  1:

for (cp = boost::rbegin(ir); cp != boost::rend(ir); ++cp)

{

      cout << "cp reverse in ri [" << *cp << "]\n";

}

 

Option 2:

while( cp != ire )

{

  //Do something

  cp++

}


I think You can't do neither. Why do You want to do that?

Regards, Kris



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.