Different parts of the compilation process take a different amount of time to complete. This is especially important for compile-time constructs. One of Odin Holmes' interns, Chiel Douwes, created the so-called Rule of Chiel based on benchmarking the compile-time costs of various template operations. This, and other type-based template metaprogramming tricks, can be seen in the Type Based Template Metaprogramming is Not Dead lecture by Odin Holmes. From fastest to slowest, they are as follows:
- Looking up a memoized type (for example, a template instantiation)
- Adding a parameter to an alias call
- Adding a parameter to a type
- Calling an alias
- Instantiating a type
- Instantiating a function template
- Using SFINAE (Substitution Failure Is Not an Error)
To demonstrate this rule, consider the following code:
template<bool>
struct conditional {
template<typename T, typename F>
using type = F;
};
template<>
struct conditional<true...