“The Nightmare of Move Semantics for Trivial Classes”
summary
Examines a simple Customer class with three members and counts actual string allocations for various constructor designs: naive const-ref approach produces up to four mallocs for two literals, exhaustive overloads yield the optimal five mallocs for common cases, pass-by-value plus std::move cuts overloads and gets near-optimal behavior, and a single-template forwarding-ref solution uses perfect forwarding but requires enable_if SFINAE gymnastics to avoid hijacking copy construction and derived types; recommends pass-by-value+move as the pragmatic winner.
AI-written summary · about
chapters (18)
- 0:00Introduction
- 1:04Problem Statement
- 4:06Overload
- 6:13Move Semantics
- 13:05Passing by Value
- 17:07Universal Reference
- 17:41Forwarding Reference
- 18:45Perfect Following
- 20:15No viable conversion
- 24:13Copy constructor
- 27:47Enable if
- 31:24Error
- 32:57Ampersand
- 34:17VIP Customers
- 41:37C20 requires
- 43:07No further trap
- 43:57Pass strings by value
- 51:02Discussion
related talks
54mBack to Basics: Move Semantics (part 2 of 2)
55mBack to Basics: Move Semantics (part 1 of 2)
01h 04m“Sane and Safe C++ Classes”
01h 23mRethink Polymorphism in C++
52mC++ Performance Tips - Cutting Down on Unnecessary Objects
01h 13mNothing is better than copy or move
55mBreaking Dependencies: Type Erasure - The Implementation Details
44mC++ Performance and Optimisation
