Skip to content

Commit 3058e20

Browse files
committed
reflection : define_static_arrayが不足していた
1 parent bacfeed commit 3058e20

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

lang/cpp26/reflection.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ struct S { int x; int y; };
142142
consteval void example() {
143143
S s{1, 2};
144144

145-
constexpr auto members = std::meta::nonstatic_data_members_of(
146-
^^S, std::meta::access_context::unchecked());
145+
constexpr auto members = std::define_static_array(
146+
std::meta::nonstatic_data_members_of(
147+
^^S, std::meta::access_context::unchecked()));
147148

148149
int a = s.[:members[0]:]; // s.x と等価。a == 1
149150
int b = s.[:members[1]:]; // s.y と等価。b == 2
@@ -162,8 +163,9 @@ struct Derived : Base { int d; };
162163
163164
consteval void example() {
164165
Derived obj{{42}, 100};
165-
constexpr auto bases = std::meta::bases_of(
166-
^^Derived, std::meta::access_context::unchecked());
166+
constexpr auto bases = std::define_static_array(
167+
std::meta::bases_of(
168+
^^Derived, std::meta::access_context::unchecked()));
167169
Base& base_ref = obj.[:bases[0]:]; // 基底クラスのサブオブジェクトへの参照
168170
}
169171
```
@@ -250,7 +252,8 @@ struct [[=Name{std::define_static_string("点")}]] Point {
250252
template for (constexpr auto m :
251253
std::define_static_array(std::meta::nonstatic_data_members_of(^^Point,
252254
std::meta::access_context::unchecked()))) {
253-
constexpr auto annots = std::meta::annotations_of_with_type(m, ^^Name);
255+
constexpr auto annots = std::define_static_array(
256+
std::meta::annotations_of_with_type(m, ^^Name));
254257
if constexpr (annots.size() > 0) {
255258
// アノテーションは値のリフレクションではないため、
256259
// constant_of()で値を取り出してからスプライスする

0 commit comments

Comments
 (0)