fork(1) download
  1. #include <iostream>
  2. #include <typeinfo>
  3. using namespace std;
  4.  
  5.  
  6. template<typename Lambda>
  7. struct lambda_member : Lambda
  8. {
  9.  
  10. Lambda& f_;
  11. lambda_member(Lambda& f) : Lambda(f),
  12. f_(f)
  13. {}
  14.  
  15. auto& get_value1()
  16. {
  17. return f_.__value1;
  18. }
  19.  
  20. };
  21.  
  22.  
  23. int main(){
  24. auto test = [value1 =0]() mutable {value1+=1; return value1;};
  25.  
  26. lambda_member<decltype(test)> lm{test};
  27.  
  28. std::cout << test() << std::endl;
  29. std::cout << lm.get_value1() << std::endl;
  30. lm.get_value1() = 22;
  31. std::cout << test() << std::endl;
  32.  
  33. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
1
1
23