-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcase_2.h
More file actions
43 lines (33 loc) · 1.26 KB
/
Copy pathcase_2.h
File metadata and controls
43 lines (33 loc) · 1.26 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
//
// Created by belov on 14.07.2026.
//
#pragma once
namespace case_2 {
struct Data {
std::string_view name;
std::uint16_t age;
bool busy;
};
void case_2() {
constexpr auto ctx = std::meta::access_context::current();
static constexpr auto members = std::define_static_array(std::meta::nonstatic_data_members_of(^^Data, ctx));
std::array<std::string_view, members.size()> names;
auto equal = []<typename T>(const T& a,const T& b) constexpr -> bool {
constexpr auto ctx = std::meta::access_context::current();
template for (constexpr auto m : std::define_static_array(std::meta::nonstatic_data_members_of(^^T, ctx))) {
if (a.[:m:] != b.[:m:])
return false;
}
return true;
};
Data d{.name="Ivan", .age=17, .busy=false};
std::size_t i = 0;
template for (constexpr auto m : members) {
names[i++] = std::meta::identifier_of(m);
}
constexpr auto check1 = std::array<std::string_view, 3>{"name", "age", "busy"};
assert(names == check1);
constexpr auto check2 = std::array<std::string_view, 3>{"name", "age1", "busy"};
assert(names != check2);
}
}