this post was submitted on 25 Nov 2023
20 points (95.5% liked)

C++

1773 readers
3 users here now

The center for all discussion and news regarding C++.

Rules

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] QuadriLiteral@programming.dev 1 points 11 months ago (10 children)

I wonder if the language could be updated so these extra std::move invocations actually become harmless? return std::move is something that I see used quite a bit.

[–] lysdexic@programming.dev 1 points 11 months ago (7 children)

I wonder if the language could be updated so these extra std::move invocations actually become harmless? return std::move is something that I see used quite a bit.

These std::move invocations are harmless, as they only cast objects to their rvalue reference.

The destructive bit takes place in the type they are assigned to, as it invokes either a move constructor or a move assignment operator, and calling those implies that the object you just passed to std::move will be invalidated after the call and should not be used subsequently.

[–] QuadriLiteral@programming.dev 1 points 11 months ago

I mean harmless in a way that using std::move on the return type doesn't prevent RVO?

load more comments (6 replies)
load more comments (8 replies)