Skip to content

Instantly share code, notes, and snippets.

@macmade
Created June 11, 2015 22:20
Show Gist options
  • Save macmade/1e0ae368725f768e5a21 to your computer and use it in GitHub Desktop.
Save macmade/1e0ae368725f768e5a21 to your computer and use it in GitHub Desktop.
C++ Fibonacci
#include <iostream>
template< int N >
struct Fibonacci
{
static constexpr int value = Fibonacci< N - 1 >::value + Fibonacci< N - 2 >::value;
};
template<>
struct Fibonacci< 1 >
{
static constexpr int value = 1;
};
template<>
struct Fibonacci< 0 >
{
static constexpr int value = 0;
};
int main( void )
{
std::cout << Fibonacci< 40 >::value << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment