On Sunday, 29 July 2012 at 23:26:09 UTC, Andrew wrote:
I have a use case where I would like to be able to pass both a
forward and backward iteration of an array to a function:
void foo(InputR, OutputR)(InputR i, OutputR j)
if (isInputRange!InputR && isOutputRange!(OutputR, InputR))
{
...
}
main()
{
//forward:
foo(a[1..n], b[1..n]);
//backward:
foo(retro(a[n..$]), retro(b[n..$]));
//do stuff with b as it has been constructed now...
}
This doesn't work (retro doesn't appear to return a Range, but
rather an object of type "Result", which I don't understand),
but
the intent should be clear.
How do I do this? What am I missing? There doesn't seem to be a
"backward iterator" equivalent in std.range.
isBidirectionalRange perhaps?
[quote]
Returns true if R is a bidirectional range. A bidirectional range
is a forward range that also offers the primitives back and
popBack. The following code should compile for any bidirectional
range.
[/quote]