It is my understanding that if you use T&& and std::forward<T> with templates, you create perfect forwarding, in that you can pass both lvalues and rvalues to a single function without overloads or conversions. For a large project I've been doing, I designed the following class and I've written the following code to test it. Why doesn't it work in 3 of the 5 cases?
> if you use T&& and std::forward<T> with templates, you create perfect forwarding
> I designed the following class and I've written the following code to test it.
voidoperator() ( T&& ... t ) is not a function template; it is a non-template member function of a class template.
Make it
1 2 3 4
template < typename... U > voidoperator() ( U&&... t )
{
queuedFunctions.push ( std::bind ( task, std::forward<U> ( t )... ) );
}
Thank you, that works perfectly, and all 5 types now work. Why is it that that works?
EDIT: I actually googled it rather than just asking. Is it because I specified the template in the class as an std::string, but if it was deduced in the function call, it would have been either std::string& or std::string&&, both of which are handled by reference collapsing?
> but if it was deduced in the function call, it would have been either std::string& or std::string&&,
> both of which are handled by reference collapsing?