"SFINAE is Evil"

Bill Baxter dnewsgroup at billbaxter.com
Thu Mar 20 22:04:28 PDT 2008


Jason House wrote:
> SFINAE - Substitution failure is not an error
> 
> This post is all about templates and their static if counterparts.  With the
> enhanced expressiveness of D, is there a need for SFINAE from C++? 
> Essentially, when a specialization exists, if the compilation of the
> specialization fails, the compiler silently gives up on it and goes to the
> next more general case.  In my mind, this is both dangerous and a loop hole
> for long compile times (as the compiler instantiates extra template
> instances).
> 
> What I want to know is this:  Who uses SFINAE in D, and why?  Is this a
> matter of convenience or a requirement.  If required, I assume it's from a
> lack of expressiveness in defining a template's conditions.  Could this be
> overcome with use of static if's instead?
> 
> PS: Post title is a quote of Russell Lewis from another thread.


How do I know if I'm using SFINAE or not?  :-)

Seriously, I might be using it.  I'm not sure.  I'm not sure how to go 
about checking.  And that in and of itself seems like an undesirable 
quality.

I will say that I have most definitely been bitten by errors that came 
from failure to instantiate the template I thought I was instantiating 
(most often due to IFTI failures).  These things can usually be debugged 
by switching the code I suspect to specify all template arguments.  Then 
I'll get the sensible error telling me why it doesn't match.

Also I've had bugs from the is-expressions not getting triggered because 
I had a typo in the is-expression which wasn't a syntax error.  Not sure 
how the compiler could help there, though.

--bb



More information about the Digitalmars-d mailing list