Boost logo

Boost Users :

Subject: Re: [Boost-users] [Range] Select forward or reverse traversal at compile time?
From: Neil Groves (neil_at_[hidden])
Date: 2011-06-29 12:32:54


On Wed, Jun 29, 2011 at 1:19 PM, Alastair Rankine
<arsptr_at_[hidden]>wrote:

> Given a bidirectional range R, is it possible to select at compile time
> whether we want to iterate forwards or backwards?
>
> Below is a test app. At the commented line, I would like to transparently
> construct a forward or reverse range, ie either [begin(range), end(range)]
> or [rbegin(range), rend(range)] respectively, depending on the definition of
> the Reversed template parameter.
>
> Just to be clear, the desired output is:
>
> forward: abc
> reversed: abc
>
>
Surely you mean ha the reversed output would be: cba ?

> I can make this work by using a functor class with partial specialisation
> to construct the iterator_range, using begin/end or rbegin/rend
> respectively. But it's a bit ugly and it would seem like something that
> boost range would provide anyway?
>
> (Note that boost::reverse() is NOT what I am after.)
>
>
What you are looking for is a reversing adaptor, hence you probably should
look at boost::adaptors::reversed, please see
http://www.boost.org/doc/libs/1_46_1/libs/range/doc/html/range/reference/adaptors/reference/reversed.html.
Note that you could also use the reversed_range class directly.

Regards,
Neil Groves



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