From cppreference.com:
When used according to the following recipe in a function template, forwards the argument to another function exactly as it was passed to the calling function.
template<typename T> wrapper(T&& arg) { foo(std::forward<T>(arg)); }
So in your snippet
struct B {
template<class T>
void func(T&& t) {
C c;
c.func(std::forward<T>(t));
}
};
The std::foward<T>(t)
will simply forward your T&&
object to c.func()
exactly as B::func()
was called. This doesn't require a move, which is why you are seeing fewer moves using std::forward<T>
.
I would really recommend checking out Scott Meyer's blog post on this topic of std::move
and std::forward
: http://scottmeyers.blogspot.com/2012/11/on-superfluousness-of-stdmove.html