foreach seems to work with opIndex()

Tofu Ninja via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Feb 6 07:11:57 PST 2016


On Saturday, 6 February 2016 at 15:02:16 UTC, H. S. Teoh wrote:
> Not really sure, but opIndex() with no arguments is supposed to 
> be the current way of implement the [] slicing operator for 
> user-defined types. I'm not sure when foreach started 
> supporting that, but it's certainly a nice thing!
>
>
> T

It feels a little weird because none of the range functions like 
map support calling opIndex so you can omit the [] in foreach but 
not with map. Just feels inconsistent.


More information about the Digitalmars-d-learn mailing list