How it works...
In this recipe, we will learn why a const&& constructor or operator doesn't make sense and will result in unexpected behavior. A move transfers resources, which is why it is marked as non-const. This is because a transfer assumes that both instances are written to (one instance receives the resource while the other has the resource taken away). A copy creates resources, which is why they are not always marked as noexcept (creating resources absolutely could throw) and they are marked const (because the original instance is being copied, not modified). A const&& constructor is claiming to be a move that doesn't transfer, which must be a copy (if you are not writing to the original instance, you are not moving—you are copying), ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access