fork(3) download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. std::pair<std::function<int()>, std::function<int()>> addSome() {
  5. auto numbers = std::make_shared<std::pair<int, int>>(0, 0);
  6.  
  7. return std::make_pair([numbers] {
  8. ++numbers->first;
  9. ++numbers->second;
  10. return numbers->first + numbers->second;
  11. }, [numbers] {
  12. return numbers->first;
  13. });
  14. }
  15.  
  16. int main() {
  17. auto f = addSome();
  18. std::cout << f.first();
  19. std::cout << " " << f.second();
  20. return 0;
  21. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
2 1