Static Polymorphism - GerdHirsch/Cpp-TemplateBasics GitHub Wiki

Another type is static polymorphism and is based on templates.
This design can be selected if the environment variant can be selected at compile time.

However, if the variation can be selected at compile-time
and does not have to be exchanged at run-time,
static polymorphism with C++ templates can be used.
The component is defined as a template
and the abstractions are represented as template parameters.
With this technique, no virtual function table is needed
and the messages to the abstractions can be inlined, which is the advantage.

The disadvantage is that the variant cannot be exchanged at runtime.

Static Polymorphism

see the C++ Implementation of the Example
and the usage

But what to do
when the decision has been made for static polymorphism
and then some use cases occur that make it necessary to exchange the variants at runtime?
We don't want to throw away the whole design and make everything more or less new, do we?

next Dynamisation of Static Polymorphism
previous Dynamic Polymorphism