Advertisement
Tucancitto

Pb12. Lambda expresii

Jul 1st, 2021
974
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <functional>
  5. using namespace std;
  6.  
  7. int main2()
  8. {
  9.     int a = 10;
  10.     auto test = [&a](int b)
  11.     {
  12.         a += 5;
  13.         b += a;
  14.         return b;
  15.     };
  16.  
  17.     cout << a << " " << test(25) << "\n";
  18.     return 0;
  19. }
  20.  
  21. int main3()
  22. {
  23.     vector<int> v;
  24.     for (int index = 0; index < 5; ++index)
  25.     {
  26.         int x;
  27.         cin >> x;
  28.         v.push_back(x);
  29.     }
  30.  
  31.     sort(v.begin(), v.end(), [](int x, int y) {return x > y;});
  32.  
  33.     for (int index = 0; index < 5; ++index)
  34.         cout << v[index] << ' ';
  35.     v.clear();
  36.     return 0;
  37. }
  38.  
  39. int main()
  40. {
  41.     int x = 5, y = 10;
  42.     function<int(void)> f = [&x, y]() {return x + y;};
  43.     x += 5;
  44.     y += 5;
  45.     cout << f();
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement