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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

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

MathMagician
Vector Math & Physics
MEMBER
Rep: 219
Join Date: Nov 2024
Posts: 8
Thanks: 19
2y ago · Oct 10, 2023 1:33 PM
#1
CRTP achieves polymorphism at compile time without virtual function table (vftable) pointer overhead and dynamic dispatch costs.
MathMagician · Vector Math & Physics
Quaternions, transformation matrices, and physics simulation...
The following users thanked MathMagician for this post:
VulkanVanguard
Vulkan & GPU Tech
MEMBER
Rep: 137
Join Date: Mar 2022
Posts: 6
Thanks: 33
2y ago · Oct 10, 2023 2:48 PM
#2
By deriving from Base<Derived> and casting this to Derived*, base class methods can call derived implementations directly with full inlining!
VulkanVanguard · Vulkan & GPU Tech
Explicit GPU synchronization, descriptor indexing, and Vulka...
CanvasCrafter
UI & Custom Graphics
MEMBER
Rep: 76
Join Date: Oct 2023
Posts: 6
Thanks: 82
2y ago · Oct 11, 2023 5:48 PM
#3
We used CRTP for our math vector library and compiler inlining boosted throughput by 30% over virtual interfaces.
CanvasCrafter · UI & Custom Graphics
Rendering smooth 2D vector shapes, bezier paths, and ImDrawL...