If the author is reading: both complicated examples are the same.
- stupid question, since we are on the topic of c++, i finished reading through learncpp.com
- how do I take this from 0 to the guy that builds a play station 3 emulator?
- like seriously what kind of step by step projects or learning experiences in increasing order of difficulty do you recommend to get really really good at c++
Unfortunately, I don't think there's getting away from just understanding value semantics to get the correct and/or performant behavior.
Title made me think they’d just show that move is just a simple cast, nothing more
What is that makes NVRO so much more difficult to implement? Why couldn't they mandate that just like RVO? Do compilers literally just special case a simple return statement of a direct construction or something?
The HN title is incorrect. It should contain std::move.
I'd push back slightly on move — at small scale the opposite has been true for me.
Kudos to the author for explaining these concepts, but I personally find this to be a poor use of my time and mental capacity.
I dabbled in C++ programming before Rust 1.0 was released (year 2015). I have spent some time understanding things like RVO, std::move(), rvalue references, T&&, move constructors, and so on.
I began programming in Rust in 2017, and it is such a breath of fresh air. It has all the power of C++ but shed all the unnecessary baggage (e.g. confusing features, duplicate features).
In relation to this article, I like Rust's clear and simple semantics about moving objects. If x and y are variables of type T which implements the Copy trait, then `x = y;` performs a simple bitwise copy. Otherwise, `x = y;` moves the object `y` to `x` and `y` is no longer allowed to be accessed ("moved away"). Whereas in C++, the article states how copy elision behavior has changed over the years:
> You get guaranteed copy elision since C++17 in the following case [implying it wasn't guaranteed before C++17]
> Then you have named return value optimization (NRVO): [...] The latter is not subject to guaranteed copy elision. You probably don't pay for a copy or move there as well.
> While this code compiles, you will get a copy construction of the return value before C++20.
> Once you switch your compiler to C++23 mode, both cases do an implicit move. No std::move required.
This is why I prefer to deal with Rust instead of C++. And this is just my commentary on specifically the behavior of moves in C++. When I pile on other issues - like copious undefined behavior everywhere (e.g. signed integer overflow, array out-of-bounds accesses), too many footguns that result in bugs and security vulnerabilities - I developed an extreme distaste for programming in C and C++.