Template metaprogramming recursion up limits?

Annex B specifies recommended minimum limits; for recursively nested template instantiations the recommended minimum limit is 1024. Your implementation appears to have a limit of 500; this is still compliant, as the recommended minimum limits are only guidelines.

Your compiler may have a command line flag or other option to increase its recursively nested template instantiation limit.

The simplest fix is to use a nonrecursive algorithm; in your case,

template<int N>
class Sum
{
    public:
        enum {value = N * (N + 1) / 2 };
};

If you are using GCC, you can set the template recursion depth with -ftemplate-depth=X, where X is the required depth:

g++ ...... -ftemplate-depth=750

Bear in mind that this is not just some limit that you can set arbitrarily high. At some point you will run into OS and hardware limitations.

Concerning your actual sum function, there is a well known analytical solution to the Sum of the first N positive integers.

(i.e. n*(n+1)/2)