I came across a Youtube video on c++11 concurrency (part 3) and the following code, which compiles and generates correct result in the video.
However, I got a compi
What is returned from std::move
is indeed an rvalue reference, but that doesn't matter because the thread
constructor does not use perfect forwarding for its arguments. First it copies/moves them to storage owned by the new thread. Then, inside the new thread, the supplied function is called using the copies.
Since the copies are not temporary objects, this step won't bind to rvalue-reference parameters.
What the Standard says (30.3.1.2):
The new thread of execution executes
INVOKE( DECAY_COPY(std::forward
(f)), DECAY_COPY(std::forward (args))... ) with the calls to
DECAY_COPY
being evaluated in the constructing thread.
and
In several places in this Clause the operation
DECAY_COPY(x)
is used. All such uses mean call the functiondecay_copy(x)
and use the result, wheredecay_copy
is defined as follows:template
decay_t decay_copy(T&& v) { return std::forward (v); }
The value category is lost.