Question Details

No question body available.

Tags

c++ reference rvalue-reference

Answers (1)

Accepted Answer Available
Accepted Answer
January 31, 2026 Score: 5 Rep: 103,080 Quality: High Completeness: 70%

Your function is already correct (or as correct as possible). The test cases that you marked not ok also don't compile without the function, so there is no issue here.

There are some other cases where there is difference, but those are impossible to fix:

  • C &&c = manipulate(C{}); doesn't extend the lifetime of the temporary, but it would without the function.

  • C c = manipulate(C{}); requires one move, and doesn't compile if C is non-movable. Without the function, the copy would've been elided (so there would be 0 moves, and the class wouldn't be required to be movable).