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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

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

GlowShader
Shader & Overlay Artist
MEMBER
Rep: 185
Join Date: Oct 2023
Posts: 36
Thanks: 46
3y ago · Apr 1, 2023 4:51 PM
#1
CRTP achieves polymorphism at compile time without virtual function table (vftable) pointer overhead and dynamic dispatch costs.
GlowShader | Shaders, Stencils & DirectX DrawLists
The following users thanked GlowShader for this post:
NoRecoilDev
Input & Recoil Math
MEMBER
Rep: 130
Join Date: Nov 2024
Posts: 20
Thanks: 32
3y ago · Apr 1, 2023 9:32 PM
#2
By deriving from Base<Derived> and casting this to Derived*, base class methods can call derived implementations directly with full inlining!
NoRecoilDev | Smoothing Algorithms & Input Events
ImGuiStyler
ImGui Animation Specialist
MEMBER
Rep: 210
Join Date: Mar 2024
Posts: 22
Thanks: 55
3y ago · Apr 2, 2023 12:32 AM
#3
We used CRTP for our math vector library and compiler inlining boosted throughput by 30% over virtual interfaces.
ImGuiStyler | Clean Custom UI Controls & Easing