In the previous section, you learned how packaged_task can be used in an elegant way. I love lambda functions a lot. They look a lot like mathematics. But not everyone likes lambda functions as they degrade readability to some extent. Hence, it isn't mandatory to use lambda functions with a concurrent task if you don't prefer lambdas. In this section, you'll understand how to use a concurrent task with the thread support library, as shown in the following code:
#include <iostream>
#include <future>
#include <thread>
#include <functional>
using namespace std;
int add ( int firstInput, int secondInput ) {
return firstInput + secondInput;
}
int main ( ) {
packaged_task<int (int, int)> addTask( add);
future<int> output = addTask.get_future( );
thread addThread ( move(addTask), 15, 10 );
addThread.join( );
cout << "The sum of 15 + 10 is " << output.get() << endl;
return 0;
}