There is a template function that takes an argument of arbitrary type. I want to make a specialization of this function for strings, but at the same time pass a string not by value, but by const reference.
For example:
#include <iostream> template<typename T> void f(T param) { std::cout << "General" << std::endl; } template<> void f(const std::string& param) { std::cout << "const std::string&" << std::endl; } void g(const std::string& str) { f(str); } int main() { std::string str; f(str); g(str); } In this example, unfortunately, the specialization does not work. A non-specialized function is always called.
Tell me, please, how best to make such a specialization or overload?