This lesson summarizes the chapter.

We'll cover the following

Chapter summary

The earlier template chapter contained the following reminders:

  • Templates define the code as a pattern for the compiler to generate instances of it according to the actual uses in the program.

  • Templates are a compile-time feature.

  • Specifying template parameter lists is sufficient to make function, struct, and class definitions templates.

  • Template arguments can be specified explicitly after an exclamation mark. The parentheses are not necessary when there is only one token inside the parentheses.

  • Each template instantiation yields a different type.

  • Template arguments can only be deduced for function templates.

  • Templates can be specialized for the type that is after the : character.

  • Default template arguments are specified after the = character.

This chapter added the following concepts:

  • Templates can be defined by the full syntax or the shortcut syntax.

  • The scope of the template is a namespace.

  • A template that contains a definition with the same name as the template is called an eponymous template. The template represents that definition.

  • Templates can be of functions, classes, structs, unions, and interfaces, and every template body can contain any number of definitions.

  • Template parameters can be of type, value, this, alias, and tuple kinds.

  • typeof(this), typeof(super), and typeof(return) are useful in templates.

  • Templates can be specialized for particular arguments.

  • Meta programming is a way of executing operations at compile time.

  • Templates enable compile-time polymorphism.

  • Separate code generation for different instantiations can cause code bloat.

  • It is more readable to give names to template constraints.

  • The templated versions of opDollar, opSlice, opIndex, opIndexAssign, and opIndexOpAssign are for multi-dimensional indexing and slicing.

Get hands-on with 1200+ tech skills courses.