【发布时间】:2014-11-30 16:23:44
【问题描述】:
boost::async()(Boost 1.56,Windows:VS2010 和 VS2012)给我带来了意想不到的结果。
#include <boost/thread/future.hpp>
...
auto func = [](){ return 123; };
auto boostFut = boost::async(func);
// boostFut = 42; // intentional error to reveal deduced type in compilation error
由于某种原因,boostFut 被推断为boost::unique_future<void> 而不是boost::unique_future<int>。
我做错了什么?
注意: 在 VS2012 上,如果我使用 std::async(func) 而不是 boost::async(func),它会按预期工作,并且未来的 type 被推断为 int。
【问题讨论】:
-
boost的版本很有用。哦,有时 boost 函数在传入的函数对象中需要result_typetypedef。 -
如上所述:Boost 1.56。您能否详细说明
result_type的建议?即使我明确定义,问题仍然存在:boost::unique_future<int> boostFut = ...在这种情况下,asyn()分配无法编译。 -
抱歉错过了。我知道一些 boost 函数适配器要求结果类型在传入的对象中是显式的,或者如果它们无法解决问题,至少会依赖该类型。你的问题会随着函数指针而消失吗?
struct foo { typedef int result_type; int operator()() const { return 42; };?没有result_type的foo? -
@AdiShavit 在包含 boost 库之前尝试添加
#define BOOST_RESULT_OF_USE_DECLTYPE -
@PiotrS.:成功了!这是在哪里记录的?把它写成答案,我会标记它。
标签: c++ boost future boost-thread