简体   繁体   中英

Compile error: boost::promise<T>::set_value(const T&) doesn't exist

I'm having problems with Boost.Thread's futures: I can't seem to put anything but a primitive type into a promise, future, or packaged task.

Here is a minimal testcase:

#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) );
}

With BOOST_THREAD_USES_MOVE defined before including the Boost.Future header I get the following error with gcc 4.8.2 and Boost 1.55 (full output 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));
     ^

There seems to be no overload of promise::set_value() that takes a const lvalue reference. Looking at promise and future_traits in future.hpp it seems that the const lvalue ref overload will only exist when BOOST_NO_CXX11_RVALUE_REFERENCES is undefined. That makes no sense to me however...surely the const lvalue ref overload is needed precisely when there are no rvalue references? (Note this happens even if I pass a mutable lvalue ref to make_ready_future() ).

If I don't define BOOST_THREAD_USES_MOVE it fails compilation with the following error (full output 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()
                                                     ^

Have I missed something?

It seems from the boost-users mailing list that this is a bug in Boost and is also present in 1.56 - looks like it's fundamentally broken in C++03 mode.

Bug report: https://svn.boost.org/trac/boost/ticket/10340

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM