Obviously it is possible to pass an rvalue reference to std::thread
constructor. My problem is with definition of this constructor in cppreference. It says that this constructor:
template< class Function, class... Args >
explicit thread( Function&& f, Args&&... args );
Creates new std::thread object and associates it with a thread of execution. First the constructor copies/moves all arguments (both the function object f and all args...) to thread-accessible storage as if by the function:
template <class T>
typename decay<T>::type decay_copy(T&& v) {
return std::forward<T>(v);
}
As far as I can check:
std::is_same<int, std::decay<int&&>::type>::value
returns true. This means std::decay<T>::type
will drop rvalue reference part of argument. Then how std::thread
constructor knows that which argument is passed by lvalue or rvalue references? Because all T&
and T&&
will be converted to T
by std::decay<T>::type