Template Specializations and Meta Programming
Explore the concept of template specializations and meta programming in D. Understand how to use templates for compile-time code generation, including recursive template instantiations, and how meta programming can move operations from run time to compile time for better performance and code optimization.
We'll cover the following...
Template specializations
We have discussed template specializations in the templates chapter. Like type parameters, other kinds of template parameters can also be specialized. The following is the general definition of a template and its specialization for 0:
We will take advantage of template specializations in the meta programming section below.
Meta programming
As they relate to code generation, templates are among the higher-level features of D. A template is code that generates code. Writing code that generates code is called meta programming.
Due to templates being compile-time ...