fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <signal.h>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <iostream>
  8.  
  9.  
  10. static int _argc;
  11. static char **_argv;
  12. using std::vector;
  13. using std::begin;
  14. using std::end;
  15.  
  16. struct Transform {
  17. const vector<int> &items;
  18.  
  19. explicit Transform(vector<int> const &items) : items{items} {}
  20.  
  21. const Transform &operator>>(std::string const &val) const {
  22. std::cout << val << ": ";
  23. return *this;
  24. }
  25.  
  26. const Transform &operator>>(vector<int>(FUNC)(vector<int>)) const{
  27. auto const ret = FUNC(items);
  28. std::cout << "(";
  29. std::for_each(begin(ret), end(ret), [](auto const &v) {
  30. std::cout << v << ",";
  31. });
  32. std::cout << "\b)" << std::endl;
  33. return *this;
  34. // It segfaults here on function exit
  35. }
  36. };
  37.  
  38. int main() {
  39. vector<int> items {1, 2, 3, 4, 4, 5, 6, 7};
  40. auto _ = Transform(items);
  41. _ >> "example" >> [](vector<int> src) -> vector<int> {
  42. return src;
  43. };
  44.  
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
example: (1,2,3,4,4,5,6,7,)