diff options
-rw-r--r-- | entries/timstr/fib.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/entries/timstr/fib.cpp b/entries/timstr/fib.cpp new file mode 100644 index 0000000..08e5802 --- /dev/null +++ b/entries/timstr/fib.cpp @@ -0,0 +1,35 @@ +#include <iostream> +#include <cstdint> + +template<std::size_t N> +struct fib { + static constexpr std::size_t value = fib<N - 1>::value + fib<N - 2>::value; +}; + +template<> +struct fib<0> { + static constexpr std::size_t value = 1; +}; + +template<> +struct fib<1> { + static constexpr std::size_t value = 1; +}; + +template<std::size_t N> +constexpr std::size_t fib_v = fib<N>::value; + +template<std::size_t N> +struct print_fib : print_fib<N - 1> { + print_fib() noexcept { + std::cout << fib_v<N - 1> << '\n'; + } +}; + +template<> +struct print_fib<0> {}; + +int main() { + print_fib<32>{}; + return 0; +}
\ No newline at end of file |