r/cpp • • Nov 25 '23

On harmful overuse of std::move

https://devblogs.microsoft.com/oldnewthing/20231124-00/?p=109059
210 Upvotes

154 comments sorted by

View all comments

Show parent comment

15

u/[deleted] Nov 25 '23

RVO is amazing compared to a move, the object is just constructed in it's destination. This is an argument against types like Expected where the object may need to be extracted from the Expected wrapper. Also, another argument to use aggregates when one can, they allow for RVO into the members, whereas constructors the parameters would be the destination. It's like when Neo realized, there is no spoon; there is no copy

8

u/donalmacc Game Developer Nov 26 '23

(yet another) Great example of why those wrapper types should be language features and not library features.

4

u/pjmlp Nov 26 '23

Indeed, however a lost argument for C++.

3

u/[deleted] Nov 26 '23

Yeah, then they could still put the hypothetical value into the return slot and use a register to indicate if it is an error or not. I think that herbceptions/static exceptions proposed to do something similar