3 ms·
Doing so would require the standard to give std::move special treatment, which sucks. The way it's specified right now let's you write your own std::move and ca
by nly 11y ago
Doing so would require the standard to give std::move special treatment, which sucks. The way it's specified right now let's you write your own std::move and call it rvalue_cast() if you wish.
- pcwalton 11y agoWhy is that an important design criterion?
- Guvante 11y agoNot everyone uses the standard libraries for lots of complicated reasons.
- AnthonyMouse 11y ago> Doing so would require the standard to give std::move special treatment Does it? Why change the behavior specifically for std::move instead of just allowing any rvalue reference to be elided when possible?
- kentonv 11y agoTo elide a return copy/move, the compiler has to know at compile time exactly which local variable is going to be returned, so that it can arrange to have that local variable constructed directly into the return location, thus avoiding the need to copy/move it later. So to elide a copy/move from an rvalue reference, the compiler would have to know at compile time that the rvalue reference always points to some particular local variable. In theory a compiler could look into the inline definition of std::move() and determine that it always returns a reference to its parameter, but that's a rather involved optimization for the spec to require of all implementations.