Why doesn't foreach support iterating?
Adam D. Ruppe
destructionator at gmail.com
Wed Oct 17 01:23:02 UTC 2018
On Wednesday, 17 October 2018 at 01:17:40 UTC, Chris Katko wrote:
> I finally noticed in the docs it says "for arrays only." The
> question is, why?
foreach for user-defined types only allow arguments that match
what the user defined. Ranges typically do not define this (since
it generally doesn't work in all their cases, they may not have
an index at all), but you can add it on with an additional
call.....
> Is there a way around this?
Add .enumerate to it, see:
http://dpldocs.info/experimental-docs/std.range.enumerate.html#examples
More information about the Digitalmars-d-learn
mailing list