Simple and effective approaches to constraint error messages

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 26 13:23:28 PDT 2016


On 26.04.2016 13:26, Marc Schütz wrote:
>
> Currently, there is no boolean short-cut evaluation in template
> constraints, see:
>
>      bool foo()() {
>          pragma(msg, "foo");
>          return true;
>      }
>
>      bool bar()() {
>          pragma(msg, "bar");
>          return true;
>      }
>
>      void main() {
>          static assert(__traits(compiles, foo() || bar()));
>      }
>
> Prints "foo" and "bar", even though bar() wouldn't need to be evaluated
> anymore after foo() returned true.

There sometimes is short-cut evaluation. This only prints "Foo":

template Foo(){
     pragma(msg, "Foo");
     enum Foo=true;
}
auto bar()(){
     pragma(msg, "bar");
     return true;
}
void main(){
     static assert(Foo!()||bar());
}

I don't see the point of the different behaviour for those cases.


More information about the Digitalmars-d mailing list