Week 13: Move Semantics
🔗 Pre-Class Learning Material
- CppCon 2019: Klaus Iglberger “Back to Basics: Move Semantics (part 1 of 2)”
- covers r- and l-value references, move constructor and assignment operator
- CppCon 2019: Klaus Iglberger “Back to Basics: Move Semantics (part 2 of 2)”
- reccomended: first half hour (discusses forwarding references)
- optional: second half hour, which has some tricky exercises
- these might be fun to talk through in class (feel free to watch ahead of time!)
These talks were part of a “Back to Basics” series at CppCon 2019, many of which I have enjoyed. It’s worth searching CppCon 2019 Back to Basics up on YouTube and perusing them!
🔗 Conversation Starters/Discussion Questions
- What (????) does this code snippet even do?
(I checked, it compiles.)
std::string s{"hi"}; s + s = s;
- What are the plusses and minuses of using
... , pi( std::move(w.pi) ) { w.pi = nullptr } ...
versus
... ,pi( std::exchange(w.pi, nullptr))
- Why is it important to make move constructors and move assignment operators noexcept?
- What is
std::swap
and how does it relate to moving? - What is the point of a function with a const return object (e.g.,
const Widget getWidget();
)? When (if ever) would this be useful? - Do you have any obervations/comments or questions about the giant “Paramater Conventions” table at 53:43?