Using MSVC2012,
The following code will compile and run as expected
std::packaged_task< int() > task( []()->int{ std::cout << \"hello
This works in gcc 4.7.2:
#include
#include
#include
int main() {
std::packaged_task< void() > task( [](){ std::cout << "hello world" << std::endl; } );
std::thread t( std::move(task) );
t.join();
std::packaged_task< int() > task2( []()->int{ std::cout << "hello world" << std::endl; return 0; } );
std::thread t2( std::move(task2) );
t2.join();
}
Together with @WhozCraig 's archeology implies that this is probably a bug in MSVC2012.
For a workaround, try using struct Nothing {};
or nullptr_t
as your return value?