fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. template <class F>
  5. struct pipeable {
  6. private:
  7. F f;
  8. public:
  9. pipeable(F&& f) : f(std::forward<F>(f)) {}
  10. template<class... Xs>
  11. auto operator()(Xs&&... xs) ->
  12. decltype(std::bind(f, std::placeholders::_1, std::forward<Xs>(xs)...))
  13. {
  14. return std::bind(f, std::placeholders::_1, std::forward<Xs>(xs)...);
  15. }
  16. };
  17.  
  18. template <class F>
  19. pipeable<F> piped(F&& f) {
  20. return pipeable<F>{std::forward<F>(f)};
  21. }
  22.  
  23. template<class T, class F>
  24. auto operator>>(T&& x, const F& f) -> decltype(f(std::forward<T>(x))) {
  25. return f(std::forward<T>(x));
  26. }
  27.  
  28. int main() {
  29. auto add = piped([](int x, int y){ return x + y; });
  30. int a = 10 >> add(20) ;
  31. std::cout << a << std::endl;
  32. return 0;
  33. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
30