U_A_V

Lambda

Jul 29th, 2025 (edited)
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <functional>
  3. #include <vector>
  4.  
  5. template<class T>
  6. std::function<T (T)> makePipeline(const std::vector<std::function<T (T)>>& funcs) {
  7.     return [&funcs] (const T& arg) {
  8.        /*Your code goes here*/
  9.     };
  10. }
  11.  
  12. #ifndef RunTests
  13. int main()
  14. {
  15.     std::vector<std::function<int (int)>> functions;
  16.     functions.push_back([] (int x) -> int { return x * 3; });
  17.     functions.push_back([] (int x) -> int { return x + 1; });
  18.     functions.push_back([] (int x) -> int { return x / 2; });
  19.    
  20.     std::function<int (int)> func = makePipeline(functions);
  21.     std::cout << func(3); // should print 5
  22. }
  23. #endif
Advertisement
Add Comment
Please, Sign In to add comment