Search⌘ K
AI Features

Templates: CRTP

Explore how the Curiously Recurring Template Pattern CRTP in Modern C++ enables static polymorphism and mixins. Understand its application in embedded and system programming to improve performance and design flexibility by compiling method dispatch at compile-time, avoiding runtime overhead.

We'll cover the following...

CRTP

The acronym CRTP stands for the C++ idiom Curiously Recurring Template Pattern. CRTP is a technique in Modern C++ in which a Derived class derives from a class template Base. The key is that Base has Derived as a template argument.

Let’s have a look at an example:

template<class T> 
class Base{
  
...