Created
February 27, 2015 18:29
-
-
Save garo/fc07985d989bece962ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
template <unsigned N> | |
struct Fibonacci | |
{ | |
enum | |
{ | |
value = Fibonacci<N-1>::value + Fibonacci<N-2>::value | |
}; | |
}; | |
template <> | |
struct Fibonacci<1> | |
{ | |
enum | |
{ | |
value = 1 | |
}; | |
}; | |
template <> | |
struct Fibonacci<0> | |
{ | |
enum | |
{ | |
value = 0 | |
}; | |
}; | |
int main(void) | |
{ | |
const int f = 45; | |
std::cout << "Fibonacci(" << f << ") = " << Fibonacci<f>::value << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment