Does it really give the rvalue reference so no copy of argument is created?
If that is right why is it better than writing just const int&?(I do not copy anything here either.
In fact, for a simple
int, you shouldn’t even be passing by reference. They’re small enough that a nice simple pass-by-copy is preferable (and, oddly, perhaps easier to optimise).
Rvalue references are useful for implementing move semantics (with classes that have indirect resources that can be transferred) and perfect forwarding, not for simple non-mutating function arguments.
Your example has nothing to do with perfect forwarding; it’s just passing a reference to a function.
I always see “&&” after the any type
You shouldn’t see it “always”.
CLICK HERE to find out more related problems solutions.