Item-44 Factor parameter-independent code out of templates
· โ˜• 6 min read

Templates generate multiple classes and multiple functions, so any template code not dependent on a template parameter (either non-type template parameters or type parameters) causes bloat: eliminate bloat due to non-type template parameters by replacing template parameters with function parameters or class data members; reduce bloat caused from type parameters by sharing implementations for instantiation types with identical binary representations.


Item-42 Understand the two meanings of typename
· โ˜• 4 min read

When declaring template parameters, both class and typename are interchangeable. When identifying nested dependent type names, use typename, except in base class lists or as a base class identifier in a member initialization list.


Item-41 Understand inplicit interfaces and compile time polymorphism
· โ˜• 4 min read

Classes support explicit interfaces based on function signatures, as well as runtime polymorphism through virtual functions; templates support implicit interfaces based on valid expressions, as well as compile-time polymorphism through template instantiation and function overloading resolution.