fork download
  1. #include <functional>
  2. #include <iostream>
  3.  
  4. struct foo {} x;
  5.  
  6. void run(std::function<std::string(const foo&)> func)
  7. {
  8. std::cout << func(x);
  9. }
  10.  
  11.  
  12. int main(){
  13.  
  14. auto get_functor = [&](const bool check) {
  15. return [&](const foo& sr)->std::string {
  16. if(check){
  17. return "some string";
  18. }
  19. return "another string";
  20. };
  21. };
  22. run(get_functor(true));
  23. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
another string