How do I make template type deduction work with references?
问题 I have a template function, func : template<typename T> void func(T p) { f(p); } And a set of functions f : f(SomeType&); f(int); ... If I instantiate the template function, func , using a reference as function argument p , without explicitly specifying template parameter T , then the type deduced will not be the reference type of p , but rather the type p is a reference to, for example: SomeType s; SomeType& ref_to_s = s; func(ref_to_s); // Type deduction results in: func<SomeType>(ref_to_s)