Skip to content

Instantly share code, notes, and snippets.

@cesarblum
Created February 25, 2012 16:50
Show Gist options
  • Save cesarblum/1909485 to your computer and use it in GitHub Desktop.
Save cesarblum/1909485 to your computer and use it in GitHub Desktop.
Print numbers from 1 to 1000 without a loop
#include <iostream>
template <int N> struct P
{
P()
{
P<N - 1>();
std::cout << N << std::endl;
}
};
template <> struct P<1>
{
P() { std::cout << 1 << std::endl; }
};
int main()
{
P<1000>();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment