Yes, constraints can have helpful error messages!
vit
vit at vit.vit
Sat Apr 9 08:10:38 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?
>
> [...]
There is another big problem with your solution:
```d
template isInt(T){
static assert(is(T == int), "T is not int" );
enum isInt = is(T == int);
}
void test(T)(T val)
if(isInt!T){
}
void test(double val){
}
void main() {
test(int.init);
test(double.init);
}
```
Function overloading doesn't work .
More information about the Digitalmars-d
mailing list