Boost logo

Boost Users :

Subject: Re: [Boost-users] Range_iterator - char* - reverse
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2010-12-10 11:59:47


2010/12/10 Rao, Anant <Anant.Rao_at_[hidden]>

>
> 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



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