There’s a number of fun C++ ones similar in spirit: std::move, for example.
template<typename _Tp>
constexpr typename std::remove_reference<_Tp>::type&&
move(_Tp&& __t) noexcept
{ return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); }I'll be honest, neither of those are my top issue with that in terms of why I think it's ugly.
Would do the same in C++ for values held by unique_ptr: take ownership of the pointer and then free it.
Am I missing something? Does it not work with std::move?
void drop(std::unique_ptr<T> x) {}
Or, you know, just call someX.reset(); or do someX = nullptr;. The drop call would be way noisier: drop(std::move(someX));
template <class T>
void drop(T&) = delete; // force callers to move
template <class T>
void drop(T&& x) {
T drop_me(std::move(x));
}
edit: fixed. template <class T>
void drop(T) {}
(Moving into a local in `drop(T&&)` also works.)