fork download
  1. template<class T, unsigned int n>
  2. class function {
  3. T result;
  4. public:
  5. function(T r) :result(r + function<T,n-1>(r)) {};
  6. operator T() {return result;}
  7. };
  8. template<class T>
  9. class function<T,0> {
  10. T result;
  11. public:
  12. function(T r) :result(0) {}
  13. operator T() {return result;}
  14. };
  15.  
  16. #include <iostream>
  17.  
  18. int main() {
  19. int input = 42;
  20. int output = function<int, 3>(input);
  21. std::cout << output << ' ' << function<int, 3>(42);
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
126 126