Mapping with partial

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 30 20:19:03 PDT 2015


On Mon, 30 Mar 2015 19:36:49 +0000, matovitch wrote:

>> The index is the problem. Generally, foreach doesn't do automatic
>> indices for ranges. You can use std.range.enumerate or count yourself
>> explicitly.
>>
>> foreach(i, t; myRange.enumerate) {...}
>>
>> size_t i = 0;
>> foreach(t; myRange) {... ++i;}
> 
> Is it a compiler problem or a language restriction ?

it is by design. `foreach` is not a "fancy for with hidden counter", it's 
more high-level construct. so if range isn't providing the counter, 
`foreach` will not guess why, and simply doesn't provide it too.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150331/628963f5/attachment.sig>


More information about the Digitalmars-d-learn mailing list