【发布时间】:2017-03-16 10:37:02
【问题描述】:
注意:即使在 C++17 中,以下也是非法的!
#include <thread>
#include <future>
#include <experimental/future>
using namespace std;
int step1(experimental::future<int>)
{
return {};
}
int step2(experimental::future<int>)
{
return {};
}
int step3(experimental::future<int>)
{
return {};
}
int main()
{
return async([](){ return {}; })
.then(step1)
.then(step2)
.then(step3)
.get();
}
C++1z提供了两种future:
std::futurestd:experimental::future
但是,std::async 只返回std::future,所以上面的代码是非法的。如果std::async返回std:experimental::future,那就没问题了。
我的问题是:
有没有办法将std::async 与std::experimental::future 一起使用,使上面的代码在C++1z 下合法?
【问题讨论】:
-
其实the concurrency TS是不包含在C++17中的。
-
想知道它是如何编译的,对我来说,它在包含
<experimental/future>处显示错误,尽管我使用了1z标志
标签: c++ multithreading concurrency synchronization c++17