/* LatexBeginAsyncSetup */ #include #include #include #include #include "divider.h" using namespace std; using data = vector; using data_it = data::iterator; int main() { const auto thread_count{9}; vector v(100000000, 1); Divider> d{v, thread_count}; /* LatexBeginAsyncWork */ vector> partial_results; for ( unsigned i{}; i < thread_count; ++i) { partial_results.emplace_back( // execute our function in it's own thread an get a handle to the future result // Note: always specify launch::async to avoid launch::deferred execution async(launch::async, accumulate, d.begin(i), d.end(i), 0) ); } /* LatexBeginAsyncSum */ cout << "Sum: " << accumulate(begin(partial_results), end(partial_results), 0, [](int sum, future& fut){ return sum + fut.get(); }) << endl; return 0; } /* LatexEndAsync */