Boost logo

Boost Users :

Subject: [Boost-users] [Boost.Thread] Compile error: boost::promise<T>::set_value(const T&) doesn't exist
From: Rob Desbois (rob.desbois_at_[hidden])
Date: 2014-08-07 06:28:48


Hi all,

I'm having problems compiling with Boost.Thread's futures I can't seem
to pass anything but a primitive type into make_ready_future. I've had
problems with other parts of Thread (packaged_task, promise,
unique/shared_future) that have produced horrendously unhelpful
compile errors.

Here is a minimal testcase:
    #include <boost/thread/future.hpp>

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

    int main()
    {
        // A const future ref 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 at http://pastebin.com/0sePWBWr):

    ../../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 at http://pastebin.com/jBwiJLeC):

    ../../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? I'm unable to switch to C++11 mode
unfortunately, but this seems such a big problem I can only assume
I've done something wrong.
I still get similar compile errors trying with Clang 3.4, and also
with Boost 1.54 (g++ or Clang).

-- 
Rob Desbois
http://theotherbranch.wordpress.com/

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net