std:: exchange Idioms
summary
std::exchange is presented as a small C++14 utility that can be backported to C++11 and used to replace swap in common patterns, saving a move and an extra variable. Examples show replacing swap-and-iterate, using std::exchange in a lambda init-capture so the result RVOs into the capture, and a thread-safe idiom combining a lock_guard with the comma operator to swap out a container. Notes warn that using vector can force locking during iteration.
AI-written summary · about
chapters (6)
- 0:00Intro
- 0:10What is exchange
- 0:40You dont need all the swap
- 1:05You dont need swap here
- 2:00Thread safety
- 3:11Conclusion
related talks
59mThreads and Locks must Go
55mMonadic Operations in C++23
01h 05mC++11 in the Wild: Techniques from a Real Codebase
01h 02mBack to Basics: C++ Move Semantics
01h 00mSTL Features And Implementation Techniques
58mUnderstanding and Mastering C++'s Complexity
06mSafe bool idiom
01h 10mThe Three Little Dots and the Big Bad Lambdas
