Now that's a DIP that could use some love
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sat Sep 19 14:44:18 UTC 2020
On 9/18/20 4:13 AM, Timon Gehr wrote:
> 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
Thanks. It's interesting that those who opined the constraints are
pretty easy to read didn't even notice this one's wrong. If you think
it's easy and got it wrong, it's not easy!
Second, the same argument applies to assert. Why provide a string with
the assert when all it does is it repeats the expression in human
language? Yet most asserts do provide explanatory strings, and I can
only assume many people find those useful.
The mechanics is not the design.
More information about the Digitalmars-d
mailing list