12/16/2007

A small example of compute Fibonacci's formula statically in C++

static unsigned int const value = Fibonacci<N-1>::value + Fibonacci<N-2>::value;
};

template<>
struct Fibonacci<1> {
static unsigned int const value = 1u;
};

template<>
struct Fibonacci<2> {
static unsigned int const value = 2u;
};

int main(int argc, char *argv[]) {
unsigned int v3 = Fibonacci<3>::value;
unsigned int v9 = Fibonacci<9>::value;

return (0);
}


No comments: