fork download
  1. #include <iostream>
  2.  
  3. template <typename T1, typename T2>
  4. struct gattai2{
  5. T1 a;
  6. T2 b;
  7. decltype(b(a())) operator ()() { return b(a()); }
  8. };
  9.  
  10. template <typename T>
  11. struct gattai1{
  12. T a;
  13. decltype(a()) operator ()() { return a(); }
  14.  
  15. template <typename T2>
  16. friend gattai2<T, T2> operator +(const gattai1<T> &g, const T2 &b){
  17. return {g.a, b};
  18. }
  19. };
  20.  
  21. struct gattai{
  22. template <typename T>
  23. friend gattai1<T> operator +(const gattai &g, const T &a){
  24. return {a};
  25. }
  26. };
  27.  
  28. int main(){
  29. auto atama = [](){ return 1; };
  30. auto mune = [](int i){ return "tekitou"; };
  31. auto robo = gattai() + atama + mune;
  32. std::cout << robo() << std::endl;
  33. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
tekitou