我想使用boost::future
延續和boost::when_all
/boost::when_any
。使用boost :: future延續和boost :: when_all
升壓中繼 - 不是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();
}
鏘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)...);
我做它錯誤還是這是一個錯誤?
我認爲你需要從'然後'而不是'f3'返回的'future',即'auto f4 = f3.then(...); f4.get();' – Casey
沒有幫助:(https://gist.github.com/oberstet/9785088 – oberstet
'when_all'需要迭代器,如果我閱讀了我找到的源代碼,你沒有使用迭代器。你嘗試把期貨放在一個向量中,並調用'when_all(vec.begin(),vec.end())'而不是? – stefan