foreach with a default range

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 11 05:22:08 PDT 2015


On 6/11/15 4:24 AM, Dmitry Olshansky wrote:

> Already works. Just define opSlice for container that returns a range
> and then:
>
> foreach(elem; container) {}
>
> is lowered to:
>
> foreach(elem; container[]) {}
>

I think you want to do opIndex which takes no parameters. opSlice is no 
longer supposed to be used that way (though it still works for backwards 
compatibility).

-Steve


More information about the Digitalmars-d mailing list