Skip to content

Instantly share code, notes, and snippets.

@garo
Created February 27, 2015 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garo/fc07985d989bece962ac to your computer and use it in GitHub Desktop.
Save garo/fc07985d989bece962ac to your computer and use it in GitHub Desktop.
#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