-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefine_struct.cpp
More file actions
80 lines (70 loc) · 2 KB
/
Copy pathdefine_struct.cpp
File metadata and controls
80 lines (70 loc) · 2 KB
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
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>
#include <stare/reflect.hpp>
#include <stare/reflection.hpp>
#include <stare/template_arg.hpp>
template<class T>
struct vec3
{
[[no_unique_address]] T x;
[[no_unique_address]] T y;
[[no_unique_address]] T z;
};
template<typename T>
STARE_CONSTEVAL auto reflect(std::in_place_type_t<vec3<T>>) noexcept
{
return stare::make_reflection_for<vec3<T>>()
.field(
std::in_place_type<T>, "x", offsetof(vec3<T>, x), alignof(T), true)
.field(
std::in_place_type<T>, "y", offsetof(vec3<T>, y), alignof(T), true)
.field(
std::in_place_type<T>, "z", offsetof(vec3<T>, z), alignof(T), true)
.build();
}
template<typename T>
struct vec2
{
[[no_unique_address]] T x;
[[no_unique_address]] T y;
friend STARE_CONSTEVAL auto reflect(std::in_place_type_t<vec2<T>>) noexcept
{
return stare::make_reflection_for<vec2<T>>()
.field(std::in_place_type<T>,
"x",
offsetof(vec2<T>, x),
alignof(T),
true)
.field(std::in_place_type<T>,
"y",
offsetof(vec2<T>, y),
alignof(T),
true)
.build();
}
};
struct color : vec3<uint8_t>
{
friend STARE_CONSTEVAL auto reflect(std::in_place_type_t<color>) noexcept
{
return stare::make_reflection_for<color>()
.template base<vec3<uint8_t>>()
.build();
}
};
TEST_CASE("struct")
{
SUBCASE("vec3")
{
using std::get;
constexpr auto refl = stare::reflect<vec3<float>>();
static_assert(get<0>(refl.fields()).offset() == 0);
static_assert(get<1>(refl.fields()).offset() == 4);
static_assert(refl.name() == "vec3<float>");
}
SUBCASE("vec4")
{
constexpr auto color_refl = stare::reflect<color>();
static_assert(color_refl.name() == "color");
}
}