Skip to content

Instantly share code, notes, and snippets.

@lukaskollmer
Created June 19, 2019 13:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lukaskollmer/f853375b5fe2b0e3b31e5c7950c228c9 to your computer and use it in GitHub Desktop.
// run w/ `CXX -DX=VAL`, where VAL is the input value
// https://godbolt.org/z/KgRth3
template <int N>
struct Fib {
enum {
value = Fib<N-1>::value + Fib<N-2>::value
};
};
template <>
struct Fib<0> {
enum {
value = 0
};
};
template <>
struct Fib<1> {
enum {
value = 1
};
};
int main() {
return Fib<X>::value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment