fork(1) download
  1. #include <iostream>
  2.  
  3. template <class T>
  4. struct sum
  5. {
  6. T val;
  7. sum(T a) : val(a) {}
  8.  
  9. template <class T2>
  10. auto operator()(T2 a) -> sum<decltype(val + a)> { return val + a; }
  11.  
  12. //sum operator()(T a) { return val + a; }
  13.  
  14. operator T() { return val; }
  15. };
  16.  
  17. template <class T>
  18. sum<T> f(T a)
  19. {
  20. return a;
  21. }
  22.  
  23. int main()
  24. {
  25. std::cout << f(1)(2.5)(3.1f)(4) << std::endl;
  26. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
10.6