Skip to the content.

Week 13: Move Semantics

🔗 Pre-Class Learning Material

  1. CppCon 2019: Klaus Iglberger “Back to Basics: Move Semantics (part 1 of 2)”
    • covers r- and l-value references, move constructor and assignment operator
  2. 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

  1. What (????) does this code snippet even do? (I checked, it compiles.)
    std::string s{"hi"};
    s + s = s;
    
  2. What are the plusses and minuses of using
    ...
    , pi( std::move(w.pi) )
    { w.pi = nullptr }
    ...
    

    versus

    ... ,pi( std::exchange(w.pi, nullptr))
    
  3. Why is it important to make move constructors and move assignment operators noexcept?
  4. What is std::swap and how does it relate to moving?
  5. What is the point of a function with a const return object (e.g., const Widget getWidget();)? When (if ever) would this be useful?
  6. Do you have any obervations/comments or questions about the giant “Paramater Conventions” table at 53:43?