Skip to content

Instantly share code, notes, and snippets.

@hotwatermorning
Created March 26, 2012 02:36
Show Gist options
  • Save hotwatermorning/2202533 to your computer and use it in GitHub Desktop.
Save hotwatermorning/2202533 to your computer and use it in GitHub Desktop.
#include <iostream>
template<int N>
struct sum
{
enum { value = N + sum<N-1>::value };
};
template<>
struct sum<1>
{
enum { value = 1 };
};
int main()
{
std::cout << sum<100>::value << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment