SHARE
TWEET

Untitled

a guest Jun 25th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <functional>
  5. using namespace std;
  6.  
  7. void run_within_for_each(std::function<void (int)> func)
  8. {
  9.     vector<int> numbers{ 1, 2, 3, 4, 5, 10, 15, 20, 25, 35, 45, 50 };
  10.  
  11.     for_each(numbers.begin(), numbers.end(), func);
  12. }
  13.  
  14. int main()
  15. {
  16.     auto func1 = [](int y)
  17.     {
  18.         cout << y << endl;
  19.     };
  20.  
  21.     auto func2 = [](int z)
  22.     {
  23.         cout << z * 2 << endl;
  24.     };
  25.  
  26.     run_within_for_each(func1);
  27.     run_within_for_each(func2);
  28. }
  29.      
  30. std::function<bool(int)> create_function()
  31. {
  32.     return [](int x)
  33.     {
  34.         return (x < 100);
  35.     };
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top