diff options
-rw-r--r-- | entries/timstr/fib.cpp | 35 | ||||
-rw-r--r-- | people.json | 11 |
2 files changed, 46 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 diff --git a/people.json b/people.json index 3790d95..676cade 100644 --- a/people.json +++ b/people.json @@ -586,5 +586,16 @@ "link": "./entries/jj/nim/fib.nim" } ] + }, + { + "github": "timstr", + "name": "Tim Straubinger", + "title": "MSc, UBC", + "entries": [ + { + "name": "C++ template meta-programming", + "link": "./entries/timstr/fib.cpp" + } + ] } ] |