Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

These are fun.

In C++, make the compiler do your recursion:

  #include <iostream>

  template <int N>
  void pr(const std::string &msg)
  {
      std::cout << msg << std::endl;
      pr<N-1>(msg);
  }

  template <>
  void pr<0>(const std::string &msg)
  {
  }

  int main(int argc, char *argv[])
  {
      pr<100>("Hello World");
      return 0;
  }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: