Now that's a DIP that could use some love

Timon Gehr timon.gehr at gmx.ch
Fri Sep 18 08:13:37 UTC 2020


On 17.09.20 23:55, Andrei Alexandrescu wrote:
> 
> Flag!"each" each(Range) (
>    Range r
> )
> if (!isForeachIterable!Range && (isRangeIterable!Range || 
> __traits(compiles, typeof(r.front).length)));

So `each` says it works for types that cannot be iterated with `foreach` 
but whose `front` has a `length` member? :-)

Turns out it does not:

----
import std.algorithm;
struct S{
     struct T{
         struct Q{}
         Q length;
     }
     T front;
}

void main(){
     S().each!((x){});
}
----
std/algorithm/iteration.d(966): Error: template 
`std.range.primitives.empty` cannot deduce function from argument types 
`!()(S)`, candidates are:
...
----

https://issues.dlang.org/show_bug.cgi?id=21264


More information about the Digitalmars-d mailing list