Random access range

Steven Schveighoffer schveiguy at yahoo.com
Thu Mar 8 08:54:50 PST 2012


On Thu, 08 Mar 2012 11:43:24 -0500, zeljkog <zeljkog at home.com> wrote:

> import std.stdio;
>
> struct Rar{
>    int[] data = [1,3,5];
>    int length = 3;
>    ref int opIndex(int i){ return data[i];}
> }
>
> void main() {
>    Rar x;
>    foreach (e; x)
>    writeln(e);
> }
>
> Error: invalid foreach aggregate x
> ----
>
> Is'nt Rar valid random access range?

No, a random access range must also be a bidirectional and input range.   
You need the standard range primitives.

-Steve


More information about the Digitalmars-d mailing list