Search⌘ K

Template Parameters: Type and Value

Explore type and value template parameters in D programming. Understand how value parameters like size_t and strings enable flexible, compile-time constant templates. Learn to create adaptable structs such as polygons and multi-dimensional points, and generate XML output using template strings.

The template parameters that we have discussed so far have all been type parameters. Previously, parameters like T and ColorT represented types. For example, T meant int, double, Student, etc. depending on the instantiation of the template.

There are other kinds of template parameters like value, this, alias, and tuple.

Type template parameters

All of the templates that you have seen so far have had type parameters.

Value template parameters

Value template parameters allow flexibility on certain values used in the template implementation.

Since templates are a compile-time feature, the values for the value template parameters must be known at ...