Suppose I want to create a function that takes both the arguments of the string lvalue and rvalue by reference, converts them to uppercase and outputs them to standard output:
void upper_print(std::string& s);
void upper_print(std::string&& s);
This works fine:
std::string s("Hello world");
upper_print(s);
upper_print(std::string("Hello world"));
upper_print("Hello world");
However, to avoid redundancy, I want to use the forwarding link instead:
template <typename T> upper_print(T&& s);
Unfortunately, I cannot call upper_printwith a string literal argument:
std::string s("Hello world");
upper_print(s);
upper_print(std::string("Hello world"));
upper_print("Hello world");
I am aware of the possibility of restricting arguments to objects std::string, for example with std::enable_ifor static_assert. But here it does not help.
Is it possible to combine link forwarding and constructor conversion functions in this sense?