I tried implementing std::move
, which uses std::remove_reference
, however it seems to work without it. Please, give me an example in which my implementation will fails whithout std::remove_reference
.
template <class type> type && move(type & source) { return (type &&) source; }
template <class type> type && move(type && source) { return (type &&) source; }
Is std::remove_reference
used only to avoid overloading std::move
?
Here is a test class to help you:
class test {
public :
test() { }
test(const test & source) { std::cout << "copy.\n"; }
test(test && source) { std::cout << "move.\n"; }
};
Not a duplicate of How does std::move() transfer values into RValues? because my question includes an example that seems to show that std::remove_reference
is useless in this case + the sub-question.
static_cast
over c-style cast (as this may fall back toreinterpret_cast
). – Sikstd::remove_reference
so it should mean that it is usefull. – Altruistremove_reference
is deemed "addressable" for whatever reason (since you're not allowed to take its address otherwise). – Faeriestd::move
, including its return type and what shall it actually return: eel.is/c++draft/forward. I don't think that the implementation is allowed not to follow this prescription even if it would be indistinguishable under the as-if rule. – Maser