3 ms·
But 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)
by Someone 7y ago
But 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.