-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcase_3.h
More file actions
78 lines (59 loc) · 2.38 KB
/
Copy pathcase_3.h
File metadata and controls
78 lines (59 loc) · 2.38 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
//
// Created by belov on 14.07.2026.
//
#pragma once
namespace case_3 {
struct [[nodiscard]] Save {};
struct [[nodiscard]] NoSave {};
struct [[nodiscard]] Author {
char name[10];
std::uint16_t age;
};
struct [[=Save{}]] GameState {
[[=Save{}]]
int level = 1;
[[=Save{}]]
int score = 0;
[[=Save{}]]
float health = 100.f;
[[=Author{.name="Ivan", .age=18}]]
int personAge = 18;
[[=NoSave{}]]
int temp = 0;
bool loading = false;
};
template <typename A>
consteval bool has_annotation(std::meta::info info) {
return not std::meta::annotations_of_with_type(info, ^^A).empty();
}
consteval bool has_annotation_set(std::meta::info info, std::initializer_list<std::meta::info> annotationList) {
for (auto a : std::meta::annotations_of(info)) {
for (auto cA : annotationList) {
if (std::meta::dealias(std::meta::remove_cvref(std::meta::type_of(a))) != std::meta::dealias(cA))
return false;
}
}
return true;
}
void case_3() {
static_assert(has_annotation_set(^^GameState, {^^Save}));
static_assert(not has_annotation_set(^^GameState, {^^Save, ^^NoSave}));
static_assert(has_annotation<Save>(^^GameState));
static_assert(not has_annotation<NoSave>(^^GameState));
static_assert(has_annotation<Save>(^^GameState::level));
static_assert(not has_annotation<NoSave>(^^GameState::level));
static_assert(has_annotation<Author>(^^GameState::personAge));
{
static constexpr auto annotationList = std::define_static_array(std::meta::annotations_of_with_type(^^GameState::personAge, ^^Author));
static_assert(annotationList.size() == 1);
static constexpr auto author = annotationList[0];
static_assert(std::string_view(std::meta::extract<Author>(author).name) != "SomeName");
static_assert(std::string_view(std::meta::extract<Author>(author).name) == "Ivan");
static_assert(std::meta::extract<Author>(author).age == 18);
}
static constexpr std::array<std::meta::info, 2> types{^^Save, ^^NoSave};
template for (constexpr auto t : types) {
static_assert(not has_annotation<typename[:t:]>(^^GameState::loading));
}
}
}