fork download
  1. #include <iostream>
  2. #include <utility>
  3. #include <typeinfo>
  4. using namespace std;
  5.  
  6. auto func() {
  7. int a = 0 ;
  8.  
  9. auto increase = [ &a ]( int i = 1 ){ a += i ; } ;
  10. auto print = [ &a ](){ cout << a << '\n' ; } ;
  11. /*
  12. cout << typeid( decltype( print ) ).name() << '\n'
  13. << typeid( decltype( increase ) ).name() << '\n' ;
  14. */
  15. pair< decltype(increase), decltype(print) > p = make_pair( increase, print ) ;
  16. return p ;
  17. }
  18.  
  19. int main() {
  20.  
  21. auto lambdas = func() ;
  22.  
  23. auto increase = lambdas.first ;
  24. auto print = lambdas.second ;
  25.  
  26. print() ;
  27. increase() ;
  28. print() ;
  29. increase( 123456 ) ;
  30. print() ;
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
-1218965939
-1218965938
-1218842482