2
votes

c++ newbie here.

I've tried to initialize and set boost::unique_future variable value:

boost::unique_future<bool> result;
result = boost::async([this](){return false;});

But I've got next error on the second code string: Error: no operator "=" matches these operands, operand types are: boost::unique_future< bool> = boost::unique_future< void>.

And here user ikh successfully did this:

boost::unique_future<int> fu2 = boost::async([]{ return 43; });

But I've got the same error: Error: no operator "=" matches these operands, operand types are: boost::unique_future< int> = boost::unique_future< void>.

Where is my mistake?

1
The compiler cannot deduce template arguments from lambda expressions and the way boost::async deduces the return type of the future result_of<decay<F>::type>::type it gets void. Try using boost::async<bool ()>([] { return false; }); - Muepe
boost::async<bool()>([] { return false; }); this follows with: Error: no instance of overloaded function "boost::async" matches the argument list argument types are: (lamda []bool()->bool). result = boost::async<bool>([] { return false; }); gave me "Error 10 error C2665: 'boost::async' : none of the 2 overloads could convert all the argument types" - J. Leeroy

1 Answers

1
votes

I think you haven't define BOOST_RESULT_OF_USE_DECLTYPE.

#define BOOST_RESULT_OF_USE_DECLTYPE
#include <boost/thread.hpp>