A Journey Into Non-Virtual Polymorphism in C++
Talkat CppCon 2023 · on Wednesday, 2023-10-04· at 09:00· Adams, 6700 North Gaylord Rockies Boulevard·
summary
Shows concrete code using std::variant with std::visit and pointers to avoid copying, rejects std::any for embedded systems due to dynamic allocation, and demonstrates the overload idiom to dispatch lambdas. Treats std::tuple/std::apply as a container‑like, loop‑unroll mechanism and notes measurable speedup in heavy loops. Presents CRTP examples (including a wait pattern) and how C++23 deducing this removes many static_casts, with runnable GCC 13.2 sample code and a robot serial‑message parser proving the ideas work.
AI-written summary · about
chapters (24)
- 0:00Welcome
- 1:25Turbo C++ journey
- 3:12Understanding polymorphism in C++
- 4:36Avoid inheritance
- 7:28Embedded systems example
- 9:17Polymorphic variables challenge
- 10:21std::any limitations
- 13:32std::variant for type safety
- 16:43std::variant walkthrough
- 20:01Overload idiom
- 23:59Overload in robotics
- 27:37std::variant vs std::any
- 27:58std::tuple for polymorphism
- 31:12Tuple-like traits
- 32:43Loop unrolling with std::array
- 34:33Curiously Recurring Template Pattern basics
- 37:05CRTP shapes design
- 38:49CRTP efficiency
- 39:53CRTP with existing classes
- 40:36CRTP in robotics
- 42:46Explicit object parameter
- 44:10When to use non-virtual
- 44:52Summary
- 45:13Q&A
related talks
01h 01mUsing Modern C++ to Eliminate Virtual Functions
01h 18mMeta Polymorphism
48mBack to Basics: Cpp Value Semantics
01h 01mC++ Design Patterns - The Most Common Misconceptions (2 of N)
59mstd variant and the power of pattern matching
59mFunctional Programming: data
01h 10mThe Three Little Dots and the Big Bad Lambdas
59mPolymorphism with Unions
