Yes, constraints can have helpful error messages!

vit vit at vit.vit
Sat Apr 9 05:01:51 UTC 2022


On Saturday, 9 April 2022 at 01:03:32 UTC, Marvin Hannott wrote:
> I was a bit surprised, reading the discussions about how 
> constraints aren't very helpful when it comes to figuring out 
> what is wrong. And I was even more surprised that of all things 
> `pragma` was called to the rescue. But isn't there a much 
> better, simpler way?
>
> [...]

Many constraitns are one use only and crating special templates 
for them is cumbersome. It create template bloat and for example 
your code doesn't work with templates or generic lambdas:

```d

bool pred_a(int i){return false;}

bool pred_b(T)(auto ref T x){return true;}



void main(){
     static assert(isFilter!(pred_a));
     static assert(isFilter!(pred_b));	//fail

}
```

Now you must forawrd parameters to isFilter and make more checks, 
template bloat is even bigger, interface of isFilter break 
because parameters must be variadic...


More information about the Digitalmars-d mailing list