forked from Ubpa/USRefl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vec.h
38 lines (33 loc) · 885 Bytes
/
Vec.h
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
#include <tuple>
namespace Ubpa::Nested {
template<typename T> // template
struct [[size(sizeof(T))]] /*compile-time attr*/ Vec {
// default constructor
Vec() : x{ 0.f }, y{ 0.f } {}
// overload constructor
Vec(T x, T y) : x{ x }, y{ y } {}
// destructor
~Vec() {}
[[not_serialize]] // non-value attr
T x;
[[info("hello"), maximum(10.f)]] // attr list
T y;
// static member variable
inline static size_t num{ 0 };
// non-static member function
float Sum() const {
return x + y;
}
// overload function, default value
float Sum(float z, float o = 1.f) const {
return x + y + z + o;
}
// static member function
static T Dot(const Vec& lhs, const Vec& rhs) {
return lhs.x * rhs.x + lhs.y * rhs.y;
}
};
}
// CMake will generate this file before building
// it contains the reflection declaration of Vec
#include "Vec_AutoRefl.inl"