Created
April 10, 2012 10:10
-
-
Save dekosuke/2350083 to your computer and use it in GitHub Desktop.
sum by C++ template
This file contains 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 Haco{ | |
enum { val=Haco<N-1>::val+N }; | |
}; | |
template<> struct Haco<0> { | |
enum { val = 0 }; | |
}; | |
int main(){ | |
std::cout << Haco<10>::val << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment