Static if a Function Exists

Jonathan Levi catanscout at gmail.com
Fri Apr 3 01:03:01 UTC 2020


I am trying to make a templated function for any arguments which 
will work for another.

Like this:
```
class Cls {
     auto opBinary(string op, T)(T b)
     if (__traits(compiles, opBinaryImpl!op(this, b)))
     {
         return opBinaryImpl!op(this, b);
     }
}

auto opBinaryImpl(string op, T)(Cls a, T b)
if (isNumeric!T)
{
     // . . .
}
```

Here I use `__traits(compiles)` but if `opBinaryImpl` has a 
compile error in the body than opBinary will claim it does not 
work.

I am looking for something like `__traits(signatureMatch,...)`.

Using std.traits.Parameters does not work because it does not 
work on templates nor does it work with overloading.



More information about the Digitalmars-d-learn mailing list