fork download
  1. #include <iostream>
  2. #include <stack>
  3. #include <functional>
  4.  
  5. std::stack<std::function<void(void)>> someJobQueue;
  6.  
  7. template <typename T>
  8. void submitJobToPool(std::string from_here, T callable)
  9. {
  10. someJobQueue.push(std::bind([callable](std::string from_here){
  11. std::cout << "from_here: " << from_here << std::endl;
  12. callable(); },
  13. from_here));
  14. }
  15.  
  16. void runJobFromPool()
  17. {
  18. auto job = someJobQueue.top();
  19. someJobQueue.pop();
  20. job();
  21. }
  22.  
  23. int main() {
  24. submitJobToPool(__func__, [](){ std::cout << "It's me." << std::endl; });
  25. runJobFromPool();
  26. return 0;
  27. }
Success #stdin #stdout 0s 4388KB
stdin
Standard input is empty
stdout
from_here: main
It's me.