On Tue, Apr 2, 2013 at 7:16 PM, Vicente J. Botet Escriba < vicente.botet@wanadoo.fr> wrote:
I've started to use C++11 lambda functions with Boost.Thread.
The following works with clang-3.2
boost::future<int> f1 = boost::async( []() -> int {return 123;} );
But it fails with gcc-4.6.2, 4.7.2 and 4.8.0
../example/lambda_future.cpp:**25:91: erreur: conversion from ‘boost::future<void>’ to non-scalar type ‘boost::future<int>’ requested boost::future<int> f1 = boost::async( []() -> int {return 123;} );
The current implementation of boost::async uses boost::result_of to get the result type of the callable parameter.
Is this a know bug on boost::result_of or gcc compiler?
I'm seeing exactly the same behaviour in *VS2012 Update 2*.
I'm using Boost 1.54.0 beta *r84748*
To be more precise:
1) I first was just using boost::future and tried to use the new .then(),
here is a full repro:
#include
::value, "Not the expected type!" ); static_assert( std::is_same< std::result_of
::type, int ::value, "Not the expected type!" );
// C: ALL SUCCEED
std::result_of
::value, "Not the expected type!" ); static_assert( std::is_same< boost::result_of
::type, int ::value, "Not the expected type!" ); // E: ALL FAILS boost::result_of ::type d = K()(); // error C2182: 'd' : illegal use of type 'void' boost::result_of ::type e = top(); // error C2182: 'e' : illegal use of type 'void' boost::result_of ::type f = F(); // error C2182: 'f' : illegal use of type 'void'
} This shows clearly that: 1. boost::result_of don't behave like std::result_of on this platform (and from previous discussions, on other platforms too). 2. both std::result_of and decltype() provide the result I expect from reading documentations about these. So far I'm assuming that the problem really is from boost::result_of, but I might be wrong because the differences with std::result_of are not clear to me. ---- Unfortunately this makes future.then() unusable if we expect return types. I don't know if it impacts other libraries (I suspect Boost.Log). Should I report a bug or is it known, already fixed or a misuse? Joel Lamotte