Chapter 1 - Function Template
How to define a function template
Template constraints
How to inline a function template
How to instantiate a function template
How to use a template parameter in multiple call parameters
How to define multiple template parameters
How to define a default template argument
How to define a default call argument
Template argument deduction
How to use the deduced template argument
How to define a nontype template parameter
How to overload a function template
How to fully specialize a function template
How to partially specialize a function template
How to grant friendship to a function template
How to define a member function template
Function pointers as template arguments
Implicit cast
Unsigned-to-signed cast
Lexical cast
How to prevent deletion of an incomplete type
How to take the address of something without using operator&()
References
Lab
Chapter 2 - Class Template
How to define a class template
How to inline a class template member function, version 1
How to inline a class template member function, version 2
How to define a class template nonmember function
How to instantiate a class template
How to define multiple template parameters
How to define a default template argument
Template argument deduction
How to define a nontype template parameter
How to overload a class template
How to fully specialize a class template
How to partially specialize a class template
How to partially specialize a class template with multiple template parameters.
How to grant friendship to a class template
How to define a member function template
How to define a member function template in a class template
Function pointers as template arguments
How to define a template template parameter
How to export a function from a class template
How to export a value from a class template
Static const data member or enumerator?
How to export a type from a class template
How to export "if (expression) then type1 else type2"
How to inherit from a class template
Inheritance versus templates
Different kinds of polymorphism
References
Lab
Chapter 4 - Dimensional Analysis
What is dimensional analysis?
The Goal
The Implementation
References
Lab
Chapter 5 - Smart Pointer
What is a smart pointer?
Resource management
Single owner, scoped, scalar
Single owner, scoped, array
Single owner, non-scoped, scalar
Multiple owners in parallel, scalar
More variations of non-intrusive reference counting
Copy on write
Multiple owners in serial, scalar
Can smart pointers support address arithmetic?
Can smart pointers support comparisons?
Can smart pointers support conversions?
Can smart pointers completely replace dumb pointers?
References
Lab
Chapter 6 - Variant Type
Heterogeneous container
Infinite union
Variant type
Variant's interface
Variant's implementation
References
Lab
Chapter 7 - Traits Class
How to ask questions about a type using overloading
How to ask questions about a type using templates
How to ask questions about a type using overloading when the answer is a type
How to ask questions about a type using templates when the answer is a type
Character traits in the Standard
Numeric traits in the Standard
Iterator traits in the Standard
Functor traits in the Standard
How to test a type for being the same as another type
How to test a type for being convertible to another type
How to test a type for being a subclass of another type
How to test a type for being integral
How to test a type for being floating
How to test a type for being arithmetic
How to test a type for being void
How to test a type for being fundamental
How to test a type for being a function
How to test a type for being a pointer
How to test a type for being a pointer to a function
How to test a type for being a pointer to a variable
How to test a type for being a pointer to a member function
How to test a type for being a pointer to a member variable
How to test a type for being a pointer to a member
How to test a type for being a reference
How to test a type for being an array
How to test a type for being a struct/union/class
How to test a type for being an enum
How to test a type for being a scalar
How to test a type for being a compound
How to test a type for being an object
How to test a type for being POD (Plain Old Data)
How to test one thing first and another thing second
How to test a type for being an empty class
How to test a type for being const
How to test a type for being volatile
How to map from a type to a string
How to remove const from a type
How to remove volatile from a type
How to remove const and volatile from a type
How to remove pointer from a type
How to remove reference from a type
How to add const to a type
How to add volatile to a type
How to add const and volatile to a type
How to add pointer to a type
How to add reference to a type
Function traits (class type, arity, result type, argument N type)
Parameter traits
Array traits
References
Lab
Chapter 8 - Policy Class
Combinatorial explosion
How to avoid combinatorial explosion
Policy class
Advantages of policy classes
Disadvantages of policy classes
How to convert object creation into a policy
Another way to delegate behavior at compile-time
References
Lab
Chapter 9 - Type List
What is a type_list?
How to create a type_list
How to output a type_list
How to compute the length of a type_list
How to get the Nth type from a type_list
How to get the index of a type from a type_list
How to append a type_list to a type_list
How to remove one occurrence of a type from a type_list
How to remove all occurrences of a type from a type_list
How to remove duplicates from a type_list
How to replace one occurrence of a type in a type_list
How to replace all occurrences of a type in a type_list
How to reverse a type_list
How to sort the types in a type_list by inheritance
How to use a type_list to sort values in a container
How to create overloaded member functions from a type_list
What is "friend name injection"?
References
Lab
Chapter 10 - Tuple
What is a value_tuple?
How to create a value_tuple
How to output a value_tuple
How to compute the length of a value_tuple
How to get the Nth type from a value_tuple
How to get the index of a type from a value_tuple
How to append a value_tuple to a value_tuple
Template as a qualifier
How to get the Nth value from a value_tuple
How to make a value_tuple from values
How to compare two value_tuples
How to create a reference_tuple
How to output a reference_tuple
How to unpack a value_tuple into variables
How to create a unified tuple
How to output a unified tuple
How to make a unified tuple from values
How to unpack a unified tuple into variables
Tuples and STL
When to use tuples
References
Lab
Chapter 11 - Refactoring Commonality Via Templates
How to enforce that != is always !(==)
What is a shim class?
How to make a shim class
How to make a shim class that clones
STL unary_function and binary_function
Curiously recurring template pattern (CRTP)
References
Lab
Chapter 12 - Expression Template
How to determine the context of operator[]()
How to defer the evaluation of an expression
How to support expressions of any type
How to support expressions containing literals
How to apply an expression to a value
How an array class loses performance
How to defer computing the + of two arrays
How to combine expression templates and STL vectors
An expression template is a STL container and has STL iterators
A better way to determine the result type of an operator
References
Lab
Chapter 13 - Template Metaprogramming
Turing-complete language
Factorial as a function
Factorial as a class template
Evaluation is lazy at run-time but not at compile-time
Metafunction
Numeric metafunctions
Turing conditional
Turing looping construct
Meta-if statement
Meta-switch statement
Meta-for statement
How to use the induction variable in a meta-for statement
How to bubble-sort an array of integers at run-time
How to bubble-sort an array of integers at compile-time
How to compute prime numbers at compile-time
References
Lab