3 ms·
std::move has been part of the language for 9 years. It is no longer reasonable to change std::move. To satisfy the programmer, there probably should be a std:
by dragontamer 7y ago
std::move has been part of the language for 9 years. It is no longer reasonable to change std::move.
To satisfy the programmer, there probably should be a std::dmove(x), which would be a compiler-enforced notation that would make use of x illegal after the use of std::dmove.
std::dmove(x) would be implemented as std::move, followed by a destructor, and then the compiler removes variable x from the scope. Pointers and references to that variable will have undefined behavior if they are used (compiler may find it reasonable to recycle x's memory location to another variable)
------
std::move<int> remains the same. There's no performance benefit, or even code-logic benefit, to zeroing out integers. For example, an integer may be a denominator, dividand, modulus, or multiplier. In these cases, "zeroing out" to "x = 1" makes more sense than "x=0".
Having a compiler enforced "zero" of "x=0" is arbitrary and doesn't help anybody. Its better to let the integers remain the same value they used to be.
- Someone 7y agoBut the whole point of std::move is to avoid calling, possibly expensive, destructors. The standard example is template<typename T> void swap(T& x, T& y) { T z = std::move(x); x = std::move(y); y = std::move(z); } ... std::string a[1000]; ... std::swap(&a[2], &a[7]) If std::move copy-constructs and destroys, that last line would do three allocations and three frees (recoverable by a significantly advanced compiler, but who has that?). The way std::move is specced, it can do zero allocations and zero frees.
- dragontamer 7y agoA good point. So clearly the way std::move works now is great for that situation. But there's a 2nd situation, with Herb Sutter's IndirectInt, which calls for a different behavior.