When I have a code which looks like this:
template<class T> void f_(const T& arg) { cout << "void f(const T& arg): Cannot modify\n"; } template<class T> void f_(T&& arg) { cout << "void f(T&& arg): Can modify\n"; } and in main I call it:
int main() { MemoryBlock block; f_(block); f_(MemoryBlock()); return 0; } The output is:
"void f(T&& arg): Can modify\n";
"void f(T&& arg): Can modify\n";
But when I change this code to non-generic, that is instead of function templates I'll have regular functions,
void f(const MemoryBlock&) { cout << "In f(const MemoryBlock&). This version cannot modify the parameter.\n"; } void f(MemoryBlock&&) { cout << "In f(MemoryBlock&&). This version can modify the parameter.\n"; } the output is more "intuitive":
"In f(const MemoryBlock&). This version cannot modify the parameter.";
"In f(MemoryBlock&&). This version can modify the parameter.";
It looks to me that only by changing functions from being templates to non templates changes totally the deduction rules for rvalue references.
Will be really greateful if somebody would explain that to me.
Tmaps toMemoryBlock.