4 ms·
As someone who only does a little C++, the advice of "that’s pretty much the only time you should write std::move" seems overly simplistic when I read things li
by favorited 7y ago
As someone who only does a little C++, the advice of "that’s pretty much the only time you should write std::move" seems overly simplistic when I read things like this[0] from over the weekend.
The gist seems to be that newer standards simplify move semantics, so GCC introduced a warning when you write `return std::move(result);` because the manual move is redundant (and could actually slow down your code).
However, if you need your code to run on older compilers, you can get hard-errors by, for example, older versions of GCC not binding the move constructor on a return.
Also, because not all compilers have implemented the newer move semantics, you could get copies rather than moves even on newer compilers.
So while I'm sure "only call std::move in this one circumstance" will be great advice one day, in the real world at the moment the situation seems decidedly more complex.
[0]http://lists.llvm.org/pipermail/cfe-dev/2020-February/064662.html http://lists.llvm.org/pipermail/cfe-dev/2020-February/064662... (mid-thread)