When I consider the two following overloads:
template <class... T> void f(const T&... x);
template <class T> void f(const T& x);
I have the guarantee that f(x)
will always call the second function and will never lead to an ambiguity. In a sense the second version is universally prioritized compared to the first one for one argument whatever its type is.
Now consider the situation where there is a universal reference and a const reference versions of a function:
template <class T> void f(T&& x);
template <class T> void f(const T& x);
My question is: is their a universal priority between these two functions regardless of the type of x (r-value reference, reference, cv-qualifiers, pointer...) like in the previous case? (and if yes, what is the priority ?)
There is not a universal priority between these two functions. They compete equally in the overload resolution algorithm. In general the so-called "universal reference" wins unless
const T&
is an exact match, and there theconst T&
wins.Good advice is to never overload like this.