Back to Basics: Cpp Value Semantics
summary
Argues for preferring value semantics over reference semantics, replacing pointer-and-inheritance visitor code with a std::variant-based vector of values, std::function for callables, and std::optional for fallible results; demonstrates a benchmark (10,000 random shapes) where variant beats the classic visitor by quite a margin, shows span causing undefined behavior after vector reallocation, and notes simpler code, fewer allocations, and better memory locality no virtual functions no lifetime juggling.
AI-written summary · about
chapters (10)
- 0:00Introduction
- 4:24Structure
- 8:16Disadvantages
- 10:05Value Semantics
- 14:47Advantages
- 26:05Remove function
- 29:13Standard Library
- 34:11Optional
- 42:22Memory usage
- 43:52Variants
related talks
49mA Journey Into Non-Virtual Polymorphism in C++
59mFunctional Programming: data
01h 02mBack to Basics: Almost Always Vector
01h 01mC++ Design Patterns - The Most Common Misconceptions (2 of N)
01h 00mThe Implementation of Value Types
59mstd variant and the power of pattern matching
01h 04mBack to Basics: Move Semantics
01h 30m50 shades of C++
