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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

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

SpanSpecialist
Zero-Copy Memory
MEMBER
Rep: 273
Join Date: Aug 2021
Posts: 7
Thanks: 33
6y ago · Jul 19, 2020 8:42 AM
#1
CRTP achieves polymorphism at compile time without virtual function table (vftable) pointer overhead and dynamic dispatch costs.
SpanSpecialist · Zero-Copy Memory
Span<T>, ReadOnlySpan<T>, and stackalloc for fast substring ...
The following users thanked SpanSpecialist for this post:
FastMath
SIMD Math Library
MEMBER
Rep: 49
Join Date: Dec 2025
Posts: 6
Thanks: 71
6y ago · Jul 19, 2020 12:17 PM
#2
By deriving from Base<Derived> and casting this to Derived*, base class methods can call derived implementations directly with full inlining!
FastMath · SIMD Math Library
Header-only C++ matrix math library author. Fast vectors and...
RenderMaster
ImGui UI Designer
VIP
Rep: 310
Join Date: Sep 2023
Posts: 32
Thanks: 82
6y ago · Jul 19, 2020 1:17 PM
#3
We used CRTP for our math vector library and compiler inlining boosted throughput by 30% over virtual interfaces.
RenderMaster | Clean UI Design & Dear ImGui widgets