-
Notifications
You must be signed in to change notification settings - Fork 0
/
Codegen.hpp
52 lines (48 loc) · 1.49 KB
/
Codegen.hpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
#include <iostream>
template <bool HasComma = true>
void gen_apply(const char* name, int n, int start_off = 0) {
constexpr auto lit = HasComma ? ", " : " ";
if(n == start_off) return;
std::cout << name << "(" << start_off << ")";
for(int idx = (start_off + 1); idx < n; ++idx)
std::cout << lit << name
<< "(" << idx << ")";
}
void gen_overload_bases(int count = 32) {
for(int n = 1; n <= count; ++n) {
std::cout << "template <";
gen_apply("TY_", n);
std::cout << ">\nstruct OverloadSet<";
gen_apply("N_", n);
std::cout << ">\n : ";
gen_apply("N_", n);
std::cout << " {\n ";
gen_apply<false>("OV_", n);
std::cout << "\n};\n" << std::endl;
}
}
void gen_tuple_bases(int count = 32) {
for(int n = 1; n <= count; ++n) {
std::cout << "template <";
gen_apply("TY_", n);
// std::cout << ">\nstruct TupleBranch<IdSeq<";
// gen_apply("ID_", n);
// std::cout << ">, ";
std::cout << ">\nstruct TupleBranch<";
gen_apply("ID_", n);
std::cout << ">\n : ";
gen_apply("N_", n);
std::cout << " {\n" <<
" static constexpr bool isArray_ = false;\n"
" static constexpr SzType size = " << n << ";\n"
" TupleBranch() = default;\n"
" TupleBranch(const TupleBranch&) = default;\n"
" TupleBranch(TupleBranch&&) = default;\n ";
std::cout << "constexpr TupleBranch(";
gen_apply("ARG_", n);
std::cout << ")\n : ";
gen_apply("IN_", n);
std::cout << " { }\n};\n" << std::endl;
}
}