Boost logo

Boost Users :

Subject: Re: [Boost-users] [Range] Select forward or reverse traversal at compile time?
From: Alastair Rankine (arsptr_at_[hidden])
Date: 2011-06-29 20:23:09


On 30/06/11 02:32, Neil Groves wrote:
> On Wed, Jun 29, 2011 at 1:19 PM, Alastair Rankine
> <arsptr_at_[hidden] <mailto:arsptr_at_[hidden]>> wrote:
> Just to be clear, the desired output is:
>
> forward: abc
> reversed: abc
>
>
> Surely you mean ha the reversed output would be: cba ?

No - the point is that I want to be able to specify at compile time (via
the Reversed template argument) whether or not the range should be
processed in reverse order. In the above example "reversed" refers to an
array "cba" which has Reversed set to a true type, meaning that it
should be processed in the reverse direction, producing "abc"

Hope that is clear?

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

No, the reversing adaptor doesn't work either. Remember I want to
specify *at compile time* whether or not to reverse the range.

If hypothetically there was a "null" range adapter, I could do something
like:

typedef boost::mpl::if_<Reversed,
     boost::adaptors::reversed,
     boost::adaptors::null>::type adaptor;

boost::copy( adaptor(range) , ...);

But that doesn't seem to exist either.

> Note that you could also use the reversed_range class directly.

I make a point of never using anything in a detail namespace unless
absolutely necessary. But even in this case I don't think it will help.


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