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