This is a followup from function template does not recognize lvalue
Lets play with the following code:
#include <iostream>
template <class T>
void func(T&&) {
std::cout<<"in rvalue\n";
}
template <class T>
void func(const T&) {
std::cout<<"in lvalue\n";
}
int main()
{
double n=3;
func<double>(n);
func(n);
}
It prints:
in lvalue
in rvalue
I don't understand what's happening in the second call. How the compiler resolve the template parameter ? Why isn't there any ambiguity ?