Enough TMP to write a Variant
summary
Claims a working std::variant reimplementation in C++20 that fits less than 500 lines and can be taught in an hour, with real support for multiple-dispatch, constexpr, noexcept and return-type deduction. Implementation uses a tagged union, std::construct_at/std::destroy_at, index_sequence math, unrolled get-by-index and a macro-generated jump-table switcher to avoid indirect calls. Error reporting uses a common-type-with-error-tag trick so SFINAE/Concept checks give compact messages. The result compiles and runs and the visit machinery produces optimized direct jumps rather than function-pointer indirection.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 7:13Template metaprogramming basics
- 11:28Utility library for TMP
- 21:05Custom Union type
- 25:59Compile-time switch
- 31:15Variant data structure
- 36:14Return types and errors
- 41:12Finalizing visit
- 44:04Integrating components
- 46:10Summary
- 46:36Q&A
related talks
57mHow to Design a Slimmer Vector of Variants in C++
49mApplied Modern C++: beyond type erasure and visitor pattern
57mDesign Patterns - The Most Common Misconceptions (2 of N)
01h 02mBreaking Dependencies - The Visitor Design Pattern in Cpp
06mLightning Talk: Cute Approach for Polymorphism in C++
01h 13mModernizing Finite State Machines in C++ - Empower Simplicity & Boost Performance With std::variant
58mApplied Modern C++: The problem of messages versioning in API
01h 00mMissing (and future?) C++ range concepts
