mercredi 25 octobre 2017

How to get different overloads for rvalue and lvalue references with a template-deduced type?

I have a function foo taking a parameter by reference, and I want it to act differently on rvalue and on lvalue references. (It doesn't change the refered-to value, might I add) I know that if I write:

template <typename T> foo(T&& x);

I've declared a universal reference, rather than an rvalue reference, meaning that this way:

template <typename T> foo(const T& x);
template <typename T> foo(T&& x);

likely won't get me what I want.

So, my question is: What's the right way to affect different behavior between the two kinds of references?

Aucun commentaire:

Enregistrer un commentaire