#include
#include
#include
using namespace std;
unique_ptr uq(new int);
void foo(unique_ptr q
This should work according to the standard and it does work on gcc.
The reason it fails on VS is probably because std::async
is allowed to store internal copies of its arguments, which will then get passed on to the called function at a later point.
In this case, that would require two moves on the unique_ptr: One to construct the intermediate object for async and then a second one when passing the argument on to foo
. One of the two probably fails. The Standard however explicitly states that the arguments to async
must only be MoveConstructible (§ 30.6.8.2), which unique_ptr
is.
So I would say this is a bug in VS2012's implementation of the standard library.