@@ -32,7 +32,7 @@ enum class Color { red, green, blue };
3232template <typename E >
3333 requires std::is_enum_v<E >
3434constexpr std::string_view to_string(E value) {
35- template for (constexpr auto e : std::meta::enumerators_of(^^E)) { // 型から列挙子のリストを取得
35+ template for (constexpr auto e : std::define_static_array(std:: meta::enumerators_of(^^E)) { // 型から列挙子のリストを取得
3636 if (value == [ :e:] ) {
3737 return std::meta::identifier_of(e); // 列挙子の名前を文字列として取得
3838 }
@@ -93,10 +93,12 @@ struct S {
9393 void f(double);
9494};
9595
96- // members_of()で個々のオーバーロードを取得
97- constexpr auto members = std::meta::members_of(
98- ^^S, std::meta::access_context::unchecked());
99- // フィルタリングで特定のオーバーロードを選択できる
96+ consteval {
97+ // members_of()で個々のオーバーロードを取得
98+ auto members = std::meta::members_of(
99+ ^^S, std::meta::access_context::unchecked());
100+ // フィルタリングで特定のオーバーロードを選択できる
101+ }
100102```
101103* std::meta::members_of[ link /reference/meta/members_of.md]
102104* std::meta::access_context[ link /reference/meta/access_context.md]
@@ -132,13 +134,16 @@ constexpr std::meta::info rv = ^^value;
132134
133135``` cpp
134136struct S { int x; int y; };
135- S s{1, 2};
136137
137- constexpr auto members = std::meta::nonstatic_data_members_of(
138- ^^S, std::meta::access_context::unchecked());
138+ consteval void example() {
139+ S s{1, 2};
140+
141+ auto members = std::meta::nonstatic_data_members_of(
142+ ^^S, std::meta::access_context::unchecked());
139143
140- int a = s.[ : members [ 0] :] ; // s.x と等価。a == 1
141- int b = s.[ : members [ 1] :] ; // s.y と等価。b == 2
144+ int a = s.[ : members [ 0] :] ; // s.x と等価。a == 1
145+ int b = s.[ : members [ 1] :] ; // s.y と等価。b == 2
146+ }
142147```
143148* std::meta::nonstatic_data_members_of[link /reference/meta/nonstatic_data_members_of.md]
144149* std::meta::access_context[link /reference/meta/access_context.md]
@@ -151,10 +156,12 @@ int b = s.[:members[1]:]; // s.y と等価。b == 2
151156struct Base { int b; };
152157struct Derived : Base { int d; };
153158
154- Derived obj{{42}, 100};
155- constexpr auto bases = std::meta::bases_of(
156- ^^Derived, std::meta::access_context::unchecked());
157- Base& base_ref = obj.[:bases[0]:]; // 基底クラスのサブオブジェクトへの参照
159+ consteval void example() {
160+ Derived obj{{42}, 100};
161+ auto bases = std::meta::bases_of(
162+ ^^Derived, std::meta::access_context::unchecked());
163+ Base& base_ref = obj.[:bases[0]:]; // 基底クラスのサブオブジェクトへの参照
164+ }
158165```
159166* std::meta::bases_of[ link /reference/meta/bases_of.md]
160167* std::meta::access_context[ link /reference/meta/access_context.md]
@@ -237,9 +244,9 @@ struct [[=Name{std::define_static_string("点")}]] Point {
237244
238245// メンバのアノテーションを取得
239246template for (constexpr auto m :
240- std::meta::nonstatic_data_members_of(^^Point,
241- std::meta::access_context::unchecked())) {
242- constexpr auto annots = std::meta::annotations_of_with_type(m, ^^Name);
247+ std::define_static_array(std:: meta::nonstatic_data_members_of(^^Point,
248+ std::meta::access_context::unchecked()))) {
249+ auto annots = std::meta::annotations_of_with_type(m, ^^Name);
243250 if constexpr (annots.size() > 0) {
244251 std::println("{}: {}", [ : annots [ 0] :] .value,
245252 std::meta::identifier_of(m));
@@ -263,17 +270,16 @@ template for (constexpr auto m :
263270template <typename E>
264271 requires std::is_enum_v<E>
265272constexpr std::string_view enum_to_string(E value) {
266- template for (constexpr auto e : std::meta::enumerators_of(^^E)) {
273+ template for (constexpr auto e : std::define_static_array(std:: meta::enumerators_of(^^E) )) {
267274 if (value == [:e:]) {
268- return std::define_static_string(std:: meta::identifier_of(e) );
275+ return std::meta::identifier_of(e);
269276 }
270277 }
271278 return "<unknown>";
272279}
273280```
274281* std::meta::enumerators_of[ link /reference/meta/enumerators_of.md]
275282* std::meta::identifier_of[ link /reference/meta/identifier_of.md]
276- * std::define_static_string[ link /reference/meta/define_static_string.md]
277283
278284
279285## リフレクションのエラー処理
@@ -297,8 +303,8 @@ int main() {
297303 Point p{10, 20, "origin"};
298304
299305 template for (constexpr auto m :
300- std::meta::nonstatic_data_members_of(^^Point,
301- std::meta::access_context::unchecked())) {
306+ std::define_static_array(std:: meta::nonstatic_data_members_of(^^Point,
307+ std::meta::access_context::unchecked()))) {
302308 std::println("{}: {}", std::meta::identifier_of(m), p.[ :m : ] );
303309 }
304310}
@@ -327,7 +333,7 @@ enum class Color { red, green, blue };
327333template <typename E>
328334 requires std::is_enum_v<E>
329335constexpr std::string_view to_string(E value) {
330- template for (constexpr auto e : std::meta::enumerators_of(^^E)) {
336+ template for (constexpr auto e : std::define_static_array(std:: meta::enumerators_of(^^E) )) {
331337 if (value == [:e:]) {
332338 return std::meta::identifier_of(e);
333339 }
361367void process (int id, double value, const char* name) {}
362368
363369int main() {
364- template for (constexpr auto p : std::meta::parameters_of(^^process)) {
370+ template for (constexpr auto p : std::define_static_array(std:: meta::parameters_of(^^process) )) {
365371 std::println("パラメータ: {} (型: {})",
366372 std::meta::identifier_of(p),
367373 std::meta::display_string_of(std::meta::type_of(p)));
0 commit comments