This is my learning notes from the course - Mastering C++ Standard Library Features.
Perfect Forwarding
- Forwarding references
- std::forward
When no template argument deduction is happening, &
means “lvalue reference
“ and &&
means “rvalue reference
“.
1 | void take_lvalue(int&); |
In the context of template argument deduction, &&
has a different meaning: “forwarding reference
“.
1 | template <typename T> |
In the function signature above, T&&
does NOT mean rvalue reference
. Instead, it means “forwarding reference
“.
A “forwarding reference
“ binds to everything and remembers the original value category of the passed object. Here’s an example: