Skip to content

Instantly share code, notes, and snippets.

@chriscasola
Created April 25, 2018 16:07
Show Gist options
  • Save chriscasola/10889c721415999e1ff9c7eaa03bbf94 to your computer and use it in GitHub Desktop.
Save chriscasola/10889c721415999e1ff9c7eaa03bbf94 to your computer and use it in GitHub Desktop.
template<unsigned n> class Fib {
public:
enum {
value_type = Fib<n-1>::value_type + Fib<n-2>::value_type
};
};
template <> class Fib<1> {
public:
enum { value_type = 1 };
};
template <> class Fib<0> {
public:
enum { value_type = 0 };
};
int main() {
std::cout << "Fib(10): " << Fib<10>::value_type << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment