Skip to content

Instantly share code, notes, and snippets.

@dekosuke
Created April 10, 2012 10:10
Show Gist options
  • Save dekosuke/2350083 to your computer and use it in GitHub Desktop.
Save dekosuke/2350083 to your computer and use it in GitHub Desktop.
sum by C++ template
#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