"SFINAE is Evil"
Bill Baxter
dnewsgroup at billbaxter.com
Sat Mar 22 01:44:42 PDT 2008
Jason House wrote:
> I should probably expand this question...
>
> Who uses templates in D? What is the most complex use you've done? Do you ever plan to get more complex? Would SFINAE make your life easier or harder?
>
> I've written templates classes that have one definition, and used static if as needed for specialization. I don't forsee more complex usage and view SFINAE as something that would mask bugs.
I don't have time to write more right now, but
Lutz Kettner gives a pretty good examples of using SFINAE here:
http://www.mpi-inf.mpg.de/~kettner/courses/lib_design_03/notes/meta.html#Constraining
http://www.mpi-inf.mpg.de/~kettner/courses/lib_design_03/notes/meta.html#Classification
Certainly the Enable_if template can be replaced by a simple static if.
Maybe the other one too.
The main problem I have with templates in D is that traits templates are
severely limited by the inability to define specializations for a
template in different modules. Like the IsVector_2 template Lutz talks
about. If all specializations have to be in one file, then the library
designer has to know in advance all the types that can ever be used as a
Vector2 and clearly that limits the utility of it.
Maybe this is coming in D2. I think I did a test recently and it still
didn't work.
--bb
More information about the Digitalmars-d
mailing list