"SFINAE is Evil"

Russell Lewis webmaster at villagersonline.com
Mon Mar 24 07:53:28 PDT 2008


Jason House wrote:
 > It looks like your first compiler error is correct... There is no 
function.

You were right.  I've seen that error so many times before, in cases, 
where a function did exist, that I didn't look closely enough.  Here's a 
better example.  The following code will produce useless "not a function 
template errors."

Obviously, if you comment out the "static assert(false);", it works just 
fine.


BEGIN dmd OUTPUT
sfinae.d(3): template sfinae.foo(int I) is not a function template
sfinae.d(22): template sfinae.foo(int I) cannot deduce template function 
from argument types !(5)()
END OUTPUT


BEGIN CODE
import std.stdio;

template foo(int I)
{
   static if(I == 1)
   {
     void foo() {};
   }
   else
   {
     void foo()
     {
       static assert(false);
       foo!(1)();
       foo!(I-1)();
     }
   }
}

void main()
{
   foo!(5)();
}
END CODE



More information about the Digitalmars-d mailing list