foreach

Nick Treleaven via Digitalmars-d digitalmars-d at puremagic.com
Sat Jun 14 05:19:58 PDT 2014


On 12/06/2014 18:30, Nick Treleaven wrote:
> On 12/06/2014 17:59, bearophile wrote:
>>> there is also this usage:
>>>
>>> foreach (i, _; range){...}
>>
>> I think this is a very uncommon usage. I think I have not used it so far.
>
> Perhaps with something other than a range then. There are some uses in
> Phobos:
>
> std/algorithm.d:        foreach (i, _; args)
> std/exception.d:        foreach (index, _; FieldTypeTuple!C)
> std/typecons.d:        foreach (i, _; Tup1.Types)
> std/typecons.d:        foreach (i, _; Tup1.Types)
> std/typecons.d:                foreach (i, _; Types)   // Rely on the
> field layout
> std/typecons.d:            foreach (i, _; Types)
> std/variant.d:        foreach (i, _; params)

Because _ is not a language feature, this identifier is actually less 
common. The prevailing one in Phobos is:

foreach (i, Unused; ...)

std/algorithm.d:7
std/array.d:1
std/datetime.d:1
std/parallelism.d:2
std/range.d:28
std/typecons.d:3

This is actually used more than any uses of 'foreach (_;' (2 uses) or 
'foreach (Unused;' (10 uses) in Phobos! This is true even if we treat 
std.range as an anomaly. (I also tried a case-insensitive search).





More information about the Digitalmars-d mailing list