What are most important things you know about templates: hidden features, common mistakes, best and most useful practices, tips…common mistakes/oversight/assumptions
I am starting to implement most of my library/API using templates and would like to collect most common patterns, tips, etc., found in practice.
Let me formalize the question: What is the most important thing you’ve learned about templates?
Please try to provide examples — it would be easier to understand, as opposed to convoluted and overly dry descriptions
Thanks
From ‘Exceptional C++ style’, Item 7: function overload resolution happens before templates specialization. Do not mix overloaded function and specializations of template functions, or you are in for a nasty surprise at which function actually gets called.
On top of Item 7:
Worse yet, if you omit the type in template specialization, a different function template might get specialized depending on the order of definition and as a result a specialized function may or may not be called.
Case 1:
Case 2: