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 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 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 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 From 56f532b893e233603312dd212a669e1add4a2b53 Mon Sep 17 00:00:00 2001 From: timstr Date: Sun, 30 Oct 2022 18:12:31 -0700 Subject: Add timstr to people.json --- people.json | 11 +++++++++++ 1 file changed, 11 insertions(+) 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" + } + ] } ] -- cgit v1.2.3-70-g09d2