-
Notifications
You must be signed in to change notification settings - Fork 71
/
main.cpp
98 lines (85 loc) · 2.25 KB
/
main.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <USRefl/USRefl.h>
#include <iostream>
#include <cassert>
using namespace Ubpa::USRefl;
using namespace std;
struct A { float a; };
struct B : virtual A { float b; };
struct C : virtual A { float c; };
struct D : B, C { float d; };
template<>
struct Ubpa::USRefl::TypeInfo<A> :
TypeInfoBase<A>
{
static constexpr AttrList attrs = {};
static constexpr FieldList fields = {
Field {TSTR("a"), &Type::a},
};
};
template<>
struct Ubpa::USRefl::TypeInfo<B> :
TypeInfoBase<B, Base<A, true>>
{
static constexpr AttrList attrs = {};
static constexpr FieldList fields = {
Field {TSTR("b"), &Type::b},
};
};
template<>
struct Ubpa::USRefl::TypeInfo<C> :
TypeInfoBase<C, Base<A, true>>
{
static constexpr AttrList attrs = {};
static constexpr FieldList fields = {
Field {TSTR("c"), &Type::c},
};
};
template<>
struct Ubpa::USRefl::TypeInfo<D> :
TypeInfoBase<D,
Base<B>,
Base<C>
>
{
static constexpr AttrList attrs = {};
static constexpr FieldList fields = {
Field {TSTR("d"), &Type::d},
};
};
int main() {
cout << "// not fully support in MSVC++ 19.26 because of a bug (2020/07/17)" << endl;
cout << "// https://developercommunity.visualstudio.com/content/problem/1116835/member-pointer-of-a-class-with-a-virtual-base-1.html" << endl;
cout << "[Virtual Bases]" << endl;
constexpr auto vbs = TypeInfo<D>::VirtualBases();
vbs.ForEach([](auto info) {
cout << info.name << endl;
});
cout << "[Tree]" << endl;
TypeInfo<D>::DFS_ForEach([](auto t, std::size_t depth) {
for (std::size_t i = 0; i < depth; i++)
cout << " ";
cout << t.name << endl;
});
cout << "[field]" << endl;
TypeInfo<D>::DFS_ForEach([](auto t, std::size_t) {
t.fields.ForEach([](auto field) {
cout << field.name << endl;
});
});
cout << "[var]" << endl;
D d;
d.a = 1;
d.b = 2;
d.c = 3;
d.d = 4;
cout << "[var : left]" << endl;
TypeInfo<D>::ForEachVarOf(std::move(d), [](auto field, auto&& var) {
static_assert(std::is_rvalue_reference_v<decltype(var)>);
cout << var << endl;
});
cout << "[var : right]" << endl;
TypeInfo<D>::ForEachVarOf(d, [](auto field, auto&& var) {
static_assert(std::is_lvalue_reference_v<decltype(var)>);
cout << field.name << " : " << var << endl;
});
}