function template parameter loses const when template argument is explicity passed?
问题 template <typename T> void test(const T& x) {} int a {}; int& ref = a; const int& c_ref = a; test(c_ref) // T = int, x = const int& test<int&>(ref); // T = int& , x = int& Why does the function template parameter x loses the const qualifier? 回答1: In the explicit (non-deduced) instantiation test<int&>(ref); this is the (theoretical) signature you get void test<int&>(const (int&)& x) which shows that the const -qualification applies to the whole (int&) , and not only the int . const applies to