Is there a way to write a function in C++ that accepts both lvalue and rvalue arguments, without making it a template?
For example, suppose I write a function
Another rather ugly alternative is to make the function a template and explicitly instantiate both versions:
template
void print(T&&) { /* ... */ }
template void print(istream&);
template void print(istream&&);
This can be compiled separately. The client code only needs the declaration of the template.
I'd personaly just stick with what Andy Prowl suggests, though.