[thread] Using lambda with unique_future
Hi all, I'm toying around with futures and I'm stumbling with the Visual Studio 2010 compiler. The following doesn't compile: #include <iostream> #include <boost/thread/future.hpp> int main() { boost::unique_future<int> the_answer = boost::async( [] () ->int { return 42; } ); std::cout << the_answer.get() << std::endl; return 0; } the error is: 1>c:\gil_contributions\sdl_test\async_test.cpp(9): error C2440: 'initializing' : cannot convert from 'boost::unique_future<R>' to 'boost::unique_future<R>' 1> with 1> [ 1> R=void 1> ] 1> and 1> [ 1> R=int 1> ] 1> No constructor could take the source type, or constructor overload resolution was ambiguous clang works just fine: http://liveworkspace.org/code/1gOYwa$2 Is this a compiler error or am I doing something wrong? Thanks, Christian
AMDG On 03/05/2013 12:16 PM, Christian Henning wrote:
I'm toying around with futures and I'm stumbling with the Visual Studio 2010 compiler.
The following doesn't compile:
boost::unique_future<int> the_answer = boost::async( [] () ->int { return 42; } );
the error is:
<snip>
clang works just fine: http://liveworkspace.org/code/1gOYwa$2
Is this a compiler error or am I doing something wrong?
I'd guess that the problem is that boost::result_of doesn't work for C++11 lambdas. clang works because decltype-based result_of is enabled for clang. In Christ, Steven Watanabe
participants (2)
-
Christian Henning
-
Steven Watanabe