std::async with std::unique doesn't compile

后端 未结 1 1572
我寻月下人不归
我寻月下人不归 2021-01-20 16:15
#include 
#include 
#include 

using namespace std;

unique_ptr uq(new int);

void foo(unique_ptr q         


        
相关标签:
1条回答
  • 2021-01-20 16:35

    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.

    0 讨论(0)
提交回复
热议问题