On Thursday, 24 March 2016 at 21:26:00 UTC, Jack Stouffer wrote:
alias this is only useful when not using any function that
relies on the template constraints in std.traits.
For example
import std.traits;
void someFunc(N)(N val) if (isNumeric!N)
{
int b = val;
}
void main()
{
import std.typecons;
Nullable!int a = 42;
someFunc(a);
}
$ dmd test.d
test.d(13): Error: template someFunc cannot deduce function
from argument types !()(Nullable!(int))
Removing the template constraint makes it compile and run just
fine. What's a good work around for these types of issues?
It has been brought up quite a few times before and if I recall
Andrei wasn't all that concerned. For what reason I'm not sure,
as alias this is supposed to introduce a subtype yet it clearly
isn't because template constraints will fail when they shouldn't.
Basically there's no workaround aside from defining your own
isNumeric and forwarding to std.traits.isNumeric.