Author image

Curiously Recurring Template Pattern


Curiously Recurring Template Pattern, or CRTP for short, is ultimately a C++ only idiom. It is also known as Static Polymorphism or Simulated polymorphism.

Requirements for dynamic polymorphism:

  1. Is-a relationship between base and derived class.
  2. Base class defines a 'generic' algorithm that is used by derived class.
  3. The 'generic' algorithm is customized by the derived class.

Requirements for static polymorphism:

  1. 'Is-a' relationship between base and derived class.
  2. Base class defines a 'generic' algorithm that is used by derived class.
  3. The 'generic' algorithm is customized by the derived class.
  4. This method is pure virtual. The derived method implements it. But, to avoid run time costs:
  5. When the specialized method is invariant of the one in the base method then this resolution can be achieved...

1