Templates allow for generic programming by providing type or function structures that can be “filled in” by concrete types and values at compile time.

For reasons that I cannot fathom, templates terrify many C++ programmers. Not just beginners; hang around any sizable C++ community for any length of time and you will inevitably see someone who is otherwise quite competent going to irrational lengths to avoid writing a template. This fear baffles me, because templates are not really any harder to write than non-templates – in fact, in many cases you can simply replace the hard-coded types with T, add the template declaration, and you’re done. This refusal to simply go generic when it is obviously the way to go can make an otherwise potentially useful bit of code almost entirely useless. Continue Reading