Home / Forums / CRTP (Curiously Recurring Template Pattern) in C++ for Static Polymorphism [Discussion #8]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

CRTP (Curiously Recurring Template Pattern) in C++ for Static Polymorphism [Discussion #8]

RenderLoop
Graphics Pipeline Dev
MEMBER
Rep: 348
Join Date: Jul 2020
Posts: 6
Thanks: 94
6y ago · Jul 1, 2020 2:18 PM
#1
CRTP achieves polymorphism at compile time without virtual function table (vftable) pointer overhead and dynamic dispatch costs.
RenderLoop · Graphics Pipeline Dev
Double buffering, triple buffering, vertical sync, and frame...
The following users thanked RenderLoop for this post:
TypeSystemNerd
Type Theory & CLR
MEMBER
Rep: 314
Join Date: Nov 2024
Posts: 6
Thanks: 57
6y ago · Jul 1, 2020 4:27 PM
#2
By deriving from Base<Derived> and casting this to Derived*, base class methods can call derived implementations directly with full inlining!
TypeSystemNerd · Type Theory & CLR
Covariance, contravariance, struct boxing, and value type se...
NullPtr_
Assembly & Engine Research
MEMBER
Rep: 260
Join Date: May 2023
Posts: 27
Thanks: 62
6y ago · Jul 1, 2020 9:27 PM
#3
We used CRTP for our math vector library and compiler inlining boosted throughput by 30% over virtual interfaces.
NullPtr_ · 0xDEADBEEF was here