Created
February 25, 2012 16:50
-
-
Save cesarblum/1909485 to your computer and use it in GitHub Desktop.
Print numbers from 1 to 1000 without a loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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