Author image

Curiously Recurring Template Pattern


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

Here's the differences between (actual) Dynamic polymorphism and Static polymorphism (CRTP):

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.

Benefits

  • CRTP is simulating dynamic...

1