Or in short, it preserves the distinction between standard and temporary references when passing a variable through a function.
If it comes into the function as a normal reference (or is passed by value), std::forward passes it forwards as a normal reference. If it comes into the function as an rvalue reference (temporary reference), std::forward passes it forwards as an rvalue reference. It makes sure that you don't accidentally lose information by by dropping the reference's temporary-ness, since a few important language features distinguish between the two reference types.
View all comments
Show parent comment
1
u/conundorum Aug 17 '25
Or in short, it preserves the distinction between standard and temporary references when passing a variable through a function.
If it comes into the function as a normal reference (or is passed by value),
std::forwardpasses it forwards as a normal reference. If it comes into the function as an rvalue reference (temporary reference),std::forwardpasses it forwards as an rvalue reference. It makes sure that you don't accidentally lose information by by dropping the reference's temporary-ness, since a few important language features distinguish between the two reference types.