From b843442b2b69125a7b184c37dbc0bb9d8da7c170 Mon Sep 17 00:00:00 2001 From: timstr Date: Sun, 30 Oct 2022 18:06:16 -0700 Subject: Fibonacci in C++ using compile-time template meta-programming and inheritance-based templated loop unrolling --- entries/timstr/fib | Bin 0 -> 21048 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 entries/timstr/fib (limited to 'entries') diff --git a/entries/timstr/fib b/entries/timstr/fib new file mode 100755 index 0000000..92c6b66 Binary files /dev/null and b/entries/timstr/fib differ -- cgit v1.2.3-70-g09d2 From 2ceccb698b01ad56ca75f2b99235bb23806a000e Mon Sep 17 00:00:00 2001 From: timstr Date: Sun, 30 Oct 2022 18:06:26 -0700 Subject: Fibonacci in C++ using compile-time template meta-programming and inheritance-based templated loop unrolling --- entries/timstr/fib.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 entries/timstr/fib.cpp (limited to 'entries') 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 +#include + +template +struct fib { + static constexpr std::size_t value = fib::value + fib::value; +}; + +template<> +struct fib<0> { + static constexpr std::size_t value = 1; +}; + +template<> +struct fib<1> { + static constexpr std::size_t value = 1; +}; + +template +constexpr std::size_t fib_v = fib::value; + +template +struct print_fib : print_fib { + print_fib() noexcept { + std::cout << fib_v << '\n'; + } +}; + +template<> +struct print_fib<0> {}; + +int main() { + print_fib<32>{}; + return 0; +} \ No newline at end of file -- cgit v1.2.3-70-g09d2 From d162d6cce3aebc3a375496f029b36ccee0224e32 Mon Sep 17 00:00:00 2001 From: timstr Date: Sun, 30 Oct 2022 18:07:19 -0700 Subject: Delete build artefact --- entries/timstr/fib | Bin 21048 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100755 entries/timstr/fib (limited to 'entries') diff --git a/entries/timstr/fib b/entries/timstr/fib deleted file mode 100755 index 92c6b66..0000000 Binary files a/entries/timstr/fib and /dev/null differ -- cgit v1.2.3-70-g09d2