Obviously, you can pass the rvalue reference to the std::thread constructor. My problem is defining this constructor in cppreference . He says this constructor:
template< class Function, class... Args > explicit thread( Function&& f, Args&&... args );
Creates a new std :: thread object and associates it with thread execution. First, the constructor copies / moves all the arguments (both the object of the function f and all the arguments ...) to the storage accessible by the stream, as if by 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 that std::decay<T>::type will discard the reference part of the rvalue value of the argument. Then how does the std::thread constructor know which argument is passed by lvalue or rvalue references? Since all T& and T&& will be converted to T on std::decay<T>::type
source share