Date: Mon, 31 Jan 2022 15:04:18 +0200
std::move() silently falls back to copying if it cannot move. This can
cause unexpected slowdown which is expensive to pinpoint.
I propose std::must_move(), with deleted overloads for const T& and
const T&&. This allows the user to request a diagnostic instead of
falling back to a copy.
Note that a copy will still happen if the type does not have a move
constructor, so the proposal only prevents errors at the call site.
Possible implementation:
template <typename T>
T&& must_move(T& x) {
return static_cast<T&&>(x);
}
template <typename T>
T&& must_move(T&& x) {
return static_cast<T&&>(x);
}
template <typename T>
T&& must_move(const T&) = delete;
template <typename T>
T&& must_move(const T&&) = delete;
cause unexpected slowdown which is expensive to pinpoint.
I propose std::must_move(), with deleted overloads for const T& and
const T&&. This allows the user to request a diagnostic instead of
falling back to a copy.
Note that a copy will still happen if the type does not have a move
constructor, so the proposal only prevents errors at the call site.
Possible implementation:
template <typename T>
T&& must_move(T& x) {
return static_cast<T&&>(x);
}
template <typename T>
T&& must_move(T&& x) {
return static_cast<T&&>(x);
}
template <typename T>
T&& must_move(const T&) = delete;
template <typename T>
T&& must_move(const T&&) = delete;
Received on 2022-01-31 13:04:22