Advertisement
RobertDeMilo

RB5.14 async и future

Apr 17th, 2024
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <numeric>
  5. #include <future>
  6.  
  7. using namespace std;
  8.  
  9. //int SumToVectors(const vector<int>& one, const vector<int>& two)
  10. //{
  11. //  return accumulate(begin(one), end(one), 0) + accumulate(begin(two), end(two), 0);
  12. //}
  13.  
  14. int SumToVectors(const vector<int>& one, const vector<int>& two)
  15. {
  16.     future <int> f = async([&one] {return accumulate(begin(one), end(one), 0); });
  17.     int result = accumulate(begin(two), end(two), 0);
  18.     return result + f.get();
  19. }
  20.  
  21. int main()
  22. {
  23.     cout << SumToVectors({ 1,1,1,1 }, { 3,3,3 });
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement