fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. template <typename... Args>
  5. std::function<void(Args...)> pushToEventLoop(std::function<void(Args...)> && p_function)
  6. {
  7. auto func = [p_function](Args... args) ->void
  8. {
  9. // This is what i would do here, but requires too much source code
  10. //ThreadPool::enque(std::bind(p_function, args...));
  11. // This is what i'll do for the sake of the example.
  12. p_function(args...);
  13. };
  14. return func;
  15. }
  16.  
  17. int main()
  18. {
  19. auto function(pushToEventLoop(std::function<void(char const *)>(std::bind(std::printf, std::placeholders::_1))));
  20.  
  21. auto function2 = std::bind(function, "Hello World!\n");
  22.  
  23. function2();
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
Hello World!