fork(1) download
  1. #include <string>
  2. #include <iostream>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. template <typename F, typename... Fs>
  7. auto lambdaList(F f, Fs... fs)
  8. {
  9. return [=] (auto&... args) { f(args...); lambdaList(fs...)(args...); };
  10. }
  11.  
  12. template <typename F>
  13. auto lambdaList(F f)
  14. {
  15. return [=] (auto&... args) { f(args...); };
  16. }
  17.  
  18. struct Window
  19. {
  20. Window (int, int, int, int) {}
  21. };
  22.  
  23. int main()
  24. {
  25. auto printStarBefore = [] (const std::string& str) {
  26. std::cout << "* " + str;
  27. };
  28. auto printStarAfter = [] (const std::string& str) {
  29. std::cout << str + " *" << std::endl;
  30. };
  31.  
  32. auto colorBG = [] (const Window&) {
  33. std::cout << "BG set ";
  34. };
  35.  
  36. auto colorFG = [] (const Window&) {
  37. std::cout << "FG set\n";
  38. };
  39.  
  40. auto composed = lambdaList(printStarBefore,printStarAfter);
  41. std::vector<std::string> vec = {"1","2","3","4"};
  42. std::for_each(std::begin(vec), std::end(vec), composed);
  43.  
  44. auto composed2 = lambdaList(colorBG, colorFG);
  45. Window win(2,25,5,0);
  46. composed2(win);
  47. }
  48.  
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
* 11 *
* 22 *
* 33 *
* 44 *
BG set FG set