|
Boost Users : |
Subject: [Boost-users] Range_iterator - char* - reverse
From: Rao, Anant (Anant.Rao_at_[hidden])
Date: 2010-12-10 11:47:53
Hi,
I need to iterate over a char string and I wrote the code as follows:
char *s = "abcdefg";
iterator_range<char*> ir( &s[0], &s[ strlen(s) ] );
char *cp;
for (cp = (char*)ir.begin(); cp != (char*)ir.end(); ++cp)
{
cout << "cp in ri [" << *cp << "]\n";
}
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++
}
Thanks so much in advance,
Anant
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.
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