Nobody understands templates?

Sean Kelly sean at invisibleduck.org
Tue Mar 4 12:56:23 PST 2014


On Friday, 28 February 2014 at 18:42:57 UTC, Steve Teale wrote:
> All the D aficionados seem to wet their pants over
> meta-programming, but I struggle to find a place to use it.
>
> IIRC, I used it in a couple of places when I was trying to write
> library stuff for MySQL, but in my current project, I use it 
> only
> once. That's when I want to stuff something onto my undo stack.
>
> For that I have two template functions - push(T)(MybaseClass* p,
> T t, int ID), and pushC, which is just the same except that it
> checks the top of the stack to see if the ID there is the same 
> as what it is wanting to push.
>
> This has served me very reliably, but I struggle to find other
> places in the whole application where I would benefit from
> templates.
>
> Is this typical - libraries use templates, applications don't, 
> or am I just being unimaginative?

This is certainly my experience with C++ and is why I wrote the
chapter on templates in the "Tango with D" book.  Personally
though, I use templates constantly.  For functions, the most
common case is to eliminate code duplication where I might
normally overload for different parameter types.


More information about the Digitalmars-d-learn mailing list