|
// Compile time Generative Nested Recursion
#include <iostream>
template <int m, int n>
struct Ackermann
{
// nested recursive call
enum { value = Ackermann<m-1, Ackermann<m, n-1>::value>::value };
};
template <int m> struct Ackermann<m, 0>
{
// linear recursive call
enum { value = Ackermann<m-1, 1>::value };
};
// termination condition
template <int n>
struct Ackermann<0, n>
{
enum { value = n + 1 };
};
int main()
{
std::cout << Ackermann<2, 3>::value << std::endl;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.