Generalised Double Dispatch
summary
Implements a CRTP visitor set that replaces dynamic_cast and two-vtable lookups with compile-time resolution, using template recursion and boost::callable_traits to accept lambdas as visitors. Benchmarks claim dynamic_cast is an order of magnitude slower than a vtable lookup and the generated code drops from about 1600 assembly lines to 2 with optimizations enabled. The concrete classes simply static_cast themselves into the visitor base; the mechanism compiles errors for missing cases and produces identical runtime behavior while eliminating extra indirection and heap allocation.
AI-written summary · about
related talks
13mIs there life without RTTI or how to write your own dynamic_cast
57mA Tour of Polymorphism Techniques in C++
04mAvoiding Virtual Call in CRTP
22mLink-Time Optimization of Dynamic Casts in C++ Programs
55mHow to "OO" in C++
01h 07mDynamic Polymorphism With Code Injection and Metaclasses
22mEffective replacement of dynamic polymorphism with std::variant
01h 23mRethink Polymorphism in C++
