//: C05:Fibonacci.cpp // From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison. // (c) 1995-2004 MindView, Inc. All Rights Reserved. // See source code use permissions stated in the file 'License.txt', // distributed with the code package available at www.MindView.net. #include using namespace std; template struct Fib { enum { val = Fib::val + Fib::val }; }; template<> struct Fib<1> { enum { val = 1 }; }; template<> struct Fib<0> { enum { val = 0 }; }; int main() { cout << Fib<5>::val << endl; // 6 cout << Fib<20>::val << endl; // 6765 } ///:~