lundi 27 août 2018

Forwarding reference treated always as rvalue reference

So I have some piece of "sophisticated" code that looks like this:

namespace details {

template <typename T>
T do_smth_impl (T&& v) {
    // process
    return std::move (v);
}

}

template <typename T>
T do_smth (T v) {
    return details::do_smth_impl (std::move (v));
}

details::do_smth_impl() takes a forwarding reference but since it is in the details namespace and used only as implementation detail (in this case there is no need to have it in different function, but I really needed to have it separated because there were much than one do_smth_impl() function that handle different types) and I am really sure that only rvalue reference is going to be passed to impl function is there any need to return std::forward<T> (v) ?

Aucun commentaire:

Enregistrer un commentaire