fork download
  1. #include <iostream>
  2.  
  3. //A functor to store the input functions and call them
  4. template <typename LEFT, typename RIGHT>
  5. struct combine_functions {
  6. private:
  7. LEFT left;
  8. RIGHT right;
  9. public:
  10. combine_functions(const LEFT &left, const RIGHT &right)
  11. : left(left), right(right) {}
  12.  
  13. template <typename ...ARGS>
  14. auto operator()(ARGS&... args) const
  15. -> decltype(left(args...), static_cast<void>(right(args...)))
  16. {
  17. left(args...);
  18. right(args...);
  19. }
  20.  
  21. };
  22.  
  23. //I should probably have an enable if that checks the arguments
  24. //are function pointers or functors
  25. template <typename LEFT, typename RIGHT>
  26. combine_functions<
  27. std::decay_t<LEFT>,
  28. std::decay_t<RIGHT>
  29. >
  30. concat(
  31. const LEFT &left,
  32. const RIGHT &right
  33. ) {
  34. return {left, right};
  35. }
  36.  
  37. int main()
  38. {
  39. concat([](const auto& t) {std::cout << t;},
  40. [](const auto& t) {std::cerr << t;})
  41. ("Hello world");
  42. }
Success #stdin #stdout #stderr 0s 16064KB
stdin
Standard input is empty
stdout
Hello world
stderr
Hello world