gpt4 book ai didi

c++ - 编译错误:boost::promise::set_value(const T&) 不存在

转载 作者:太空狗 更新时间:2023-10-29 21:42:45 24 4
gpt4 key购买 nike

我在使用 Boost.Thread 的 futures 时遇到问题:我似乎只能将原始类型放入 promise、future 或打包任务中。

这是一个最小的测试用例:

#include <boost/thread/future.hpp>

struct foo
{
foo(int i_): i(i_) {}
int i;
};

int main()
{
// A const future isn't much use, but I needed to prove
// the problem wasn't me trying to copy a unique_future
const boost::unique_future<foo>& fut = boost::make_ready_future( foo(42) );
}

在包含 Boost.Future header 之前定义了 BOOST_THREAD_USES_MOVE 我在 gcc 4.8.2 和 Boost 1.55 中得到以下错误(完整输出 here ):

../../deps/boost/include/boost/thread/future.hpp:3634:5: error: no matching function for call to ‘boost::promise<foo>::set_value(const foo&)’
p.set_value(boost::forward<future_value_type>(value));
^

似乎没有采用 const 左值引用的 promise::set_value() 重载。查看 future.hpp 中的 promisefuture_traits 似乎 const 左值引用重载仅在 BOOST_NO_CXX11_RVALUE_REFERENCES 时存在未定义。然而,这对我来说毫无意义......当没有右值引用时,肯定需要 const 左值引用重载吗? (请注意,即使我将可变左值引用传递给 make_ready_future(),也会发生这种情况)。

如果我没有定义 BOOST_THREAD_USES_MOVE,编译将失败并出现以下错误(完整输出 here ):

../../deps/boost/include/boost/thread/detail/move.hpp:183:54: error: no matching function for call to boost::unique_future<foo>::unique_future(boost::unique_future<foo>)’
#define BOOST_THREAD_MAKE_RV_REF(RVALUE) RVALUE.move()
^

我错过了什么吗?

最佳答案

从 boost-users 邮件列表看来,这是 Boost 中的一个错误,并且也出现在 1.56 中 - 看起来它在 C++03 模式下根本被破坏了。

错误报告:https://svn.boost.org/trac/boost/ticket/10340

关于c++ - 编译错误:boost::promise<T>::set_value(const T&) 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25178325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com