Back to Basics: Algebraic Data Types
summary
C++17 algebraic data types are shown as concrete tools: std::pair and std::tuple are product types with predictable memory footprint and padding; std::variant is a sum type that stores an index (so usually a few bytes larger) and supports std::visit for type-safe pattern dispatch; std::optional is a one-bit-ish sum (T + 1) that enables deferred, heap-free lifetime via emplace. The talk warns about valueless by exception on bad emplace, recommends named structs over returning tuples, and explains get/get_if and in-place construction.
AI-written summary · about
chapters (13)
- 0:00Introduction
- 1:15Motivation and overview
- 8:21Product types explained
- 11:07Sum types explained
- 16:03Where to use pair and tuple
- 19:35Why use optional
- 25:21Common vocabulary
- 31:21In-place construction
- 41:33Optional deep dive
- 49:58Detecting variant alternatives
- 56:38Pair and tuple patterns
- 1:04:24Named types over tuples
- 1:06:31Conclusion and Q&A
related talks
01h 01mtuple<>: What's New and How it Works
35mAlgebraic Data Types
01h 23mHow C++20 Can Simplify std::tuple
58mC++, Abstract Algebra and Practical Applications
54mC++17 Features (part 2 of 2)
58mC++17 in Practice - The good and the ugly
51mA Tale of Two Tuples - A Story of the C++ Revolution
55m“Variants: Past, Present, and Future"
