Ranges and backward iteration

Andrew andrew.spott at gmail.com
Sun Jul 29 16:26:08 PDT 2012


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.


More information about the Digitalmars-d-learn mailing list