January 2020
Intermediate to advanced
454 pages
11h 25m
English
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), ...