aboutsummaryrefslogtreecommitdiff
path: root/entries/timstr/fib.cpp
blob: 08e5802d044d79c825bff43d99910a0a06e3569e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
}