- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
// fib.h
#pragma once
using ull = unsigned long long;
inline constexpr ull fib(size_t n, ull first, ull second) {
return n == 0 ? first : fib(n - 1, second, first + second);
}
inline constexpr ull fib(size_t n) {
return fib(n, 0, 1);
}
// fibs.h
#pragma once
#include "fib.h"
#include <array>
enum class fibs : ull {
#define FIB(i, val) fib##i = val,
#define COUNT(val) COUNT = val
#include "fibs.inl"
#undef COUNT
#undef FIB
};
std::array<ull, static_cast<size_t>(fibs::COUNT)> const & fibs_values() {
static std::array<ull, static_cast<size_t>(fibs::COUNT)> values = {
#define FIB(i, val) val,
#define COUNT(val)
#include "fibs.inl"
#undef COUNT
#undef FIB
};
return values;
}
// main.cpp
#include "fibs.h"
#include <iostream>
int main() {
using namespace std;
for (auto fib : fibs_values()) {
cout << fib << "," << endl;
}
return 0;
}
// fibs.inl = gen.exe > fibs.inl
// gen.cpp
#include "fib.h"
#include <iostream>
int main() {
using namespace std;
size_t i;
for (i = 0; i < 94; i++) {
cout << "FIB(" << i << ", " << fib(i) << ")" << endl;
}
cout << "COUNT(" << i << ")";
return 0;
}