Project

General

Profile

Feature #818

Add class for CRTP

Added by Maximilian Seesslen 3 months ago.

Status:
Neu
Priority:
Normal
Target version:
-
Start date:
07/08/2026
Due date:
% Done:

0%

Estimated time:
CS Zielversion:

Description

Curiously Recurring Template Pattern: statischen Polymorphismus

#define CRTP_METHOD(name, args...) \
void name() \ { \
derived().name##_impl( , ##args ); \
}

// VA_ARGS

#define CRTP_HELPERS(Derived) \
Derived& derived() \ { \
return static_cast<Derived&>(*this); \
} \
\
const Derived& derived() const \ { \
return static_cast<const Derived&>(*this); \
}

template<class Derived>
class CClassA {
CRTP_HELPERS(Derived);

public:
CRTP_METHOD(name, int i1, int i2);
void callback()
   {
name();
}
};

class CClassB;

class CClassB :public CClassA < CClassB > {
public:
void name_impl() {
printf("Callback\n");
}
};

Also available in: Atom PDF