【发布时间】:2014-05-05 01:11:57
【问题描述】:
我想使用boost::future 和boost::when_all / boost::when_any。
Boost trunk - 不是 1.55 - 包括后者的实现(仿照 here 提案,即将用于 C++14/17 和 Boost 1.56)。
This 是我所拥有的(并且它无法编译):
#include <iostream>
#define BOOST_THREAD_PROVIDES_FUTURE
#define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
#define BOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY
#include <boost/thread/future.hpp>
using namespace boost;
int main() {
future<int> f1 = async([]() { return 1; });
future<int> f2 = async([]() { return 2; });
auto f3 = when_all(f1, f2);
f3.then([](decltype(f3)) {
std::cout << "done" << std::endl;
});
f3.get();
}
Clang 3.4 使用 this 退出 - 这是一段摘录:
/usr/include/c++/v1/memory:1685:31: error: call to deleted constructor of 'boost::future<int>'
::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
是我做错了还是这是一个错误?
【问题讨论】:
-
我认为你需要
get从then返回的future而不是f3,即auto f4 = f3.then(...); f4.get(); -
没有帮助 :( gist.github.com/oberstet/9785088
-
如果我阅读正确找到的源代码,
when_all会使用迭代器。您没有使用迭代器。您是否尝试将期货放入向量中并改为调用when_all(vec.begin(), vec.end())? -
与gist.github.com/oberstet/9785331 完全相同的问题(“调用已删除的构造函数”)另外,至少链接的提案(论文)提到了
when_all的2 个重载版本.. 一个采用位置参数,其他迭代器。 -
gist.github.com/oberstet/9785331 有同样的问题,因为来自
std::intializer_list的std::vector构造函数试图复制期货。
标签: c++ c++11 boost future continuations