Template condition evaluation (shortcircuit)

rumbu rumbu at rumbu.ro
Wed Mar 21 17:42:34 UTC 2018


I tried to define a template:

enum isFoo(alias T) =
     T.stringof.length >= 3 && T.stringof[0..3] == "abc";

int i;
pragma(msg, isFoo!i);

Error: string slice [0 .. 3] is out of bounds
Error: template object.__equals cannot deduce function from 
argument types !()(string, string), candidates are:
[...]

Is it normal that the condition is not short circuited at first 
test? Of course, I can throw there a bunch of static ifs in an 
eponymous template, but I don't see the point of this verbosity.





More information about the Digitalmars-d-learn mailing list