Why opDispatch uses SFINAE implicitly?

Dukc via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 2 04:05:44 PST 2017


On Thursday, 2 March 2017 at 08:37:40 UTC, Dukc wrote:
>> All templates have SFINAE.

No, they don't:

import std.stdio;

void main()
{   printType!uint("the type is: ");
}
void printType(T)(string precedent)
{   writeln(precedent ~ T.stringof);
}
//the type is: uint

void main()
{   printType!uint("the type is: ");
}
void printType(T)(string precedent)
{   writeln(precedent ~ T.stringOf);
}
// Error: no property 'stringOf' for type 'uint'
// Error: template instance app.printType!uint error instantiating

void main()
{   printType!uint("the type is: ");
}
void printType(T)(string precedent)
{   writeln(precedent ~ T.stringof);
}
void printType(T)(string precedent)
{   writeln(precedent ~ T.stringOf);
}
//Error: app.printType called with argument types (string) 
matches both: [snip]

If D templates had SFINAE as I understand it, the third one would 
compile. I am not 100% sure if C++ would work that way, but at 
least opDispatch seems to.

If it does not compile, compiler to look for regular templates 
and announces "no match" as if there were no implementation at 
all. But for a regular template implemented in just the same way 
it would print what in the implementation did not compile. That's 
what I'm missing with opDispatch.

I still have to test if I can get that catch-all error-printing 
opDispatch to work...


More information about the Digitalmars-d mailing list