forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmeta
820 lines (681 loc) · 25.5 KB
/
meta
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Copyright 2024 Bloomberg Finance L.P.
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP_EXPERIMENTAL_META
#define _LIBCPP_EXPERIMENTAL_META
/*
experimental/meta synopsis
// C++2c
namespace std
{
namespace meta
{
inline namespace reflection_v2
{
// std::meta::info
using info = decltype(^int);
// name and location
consteval auto name_of(info) -> string_view;
consteval auto display_name_of(info) -> string_view;
consteval auto source_location_of(info r) -> source_location;
// type queries
consteval auto type_of(info) -> info;
consteval auto parent_of(info) -> info;
consteval auto dealias(info) -> info;
// template queries
consteval auto template_of(info r) -> info;
consteval auto template_arguments_of(info r) -> vector<info>;
// member queries
template <typename... Preds>
consteval auto members_of(info class_type, Preds... filters) -> vector<info>;
typename <template... Preds>
consteval auto bases_of(info class_type, Preds... filters) -> vector<info>;
consteval auto static_data_members_of(info class_type) -> vector<info>;
consteval auto nonstatic_data_members_of(info class_type) -> vector<info>;
consteval auto subobjects_of(info class_type) -> vector<info>;
consteval auto enumerators_of(info enum_type) -> vector<info>;
// substitute
consteval auto substitute(info, span<info const>) -> info;
// value_of
template <typename Ty>
consteval auto value_of(info) -> T;
// test_type
consteval auto test_type(info templ, info type) -> bool;
consteval auto test_types(info templ, span<info const> types) -> bool;
// other type predicates
consteval auto is_public(info) -> bool;
consteval auto is_protected(info) -> bool;
consteval auto is_private(info) -> bool;
consteval auto is_accessible(info) -> bool;
consteval auto is_virtual(info) -> bool;
consteval auto is_pure_virtual(info) -> bool;
consteval auto is_override(info) -> bool;
consteval auto is_deleted(info) -> bool;
consteval auto is_defaulted(info) -> bool;
consteval auto is_explicit(info) -> bool;
consteval auto is_bit_field(info) -> bool;
consteval auto has_static_storage_duration(info) -> bool;
consteval auto has_internal_linkage(info) -> bool;
consteval auto has_external_linkage(info) -> bool;
consteval auto has_linkage(info) -> bool;
consteval auto is_class_member(info) -> bool;
consteval auto is_namespace_member(info) -> bool;
consteval auto is_nonstatic_data_member(info) -> bool;
consteval auto is_static_member(info) -> bool;
consteval auto is_base(info) -> bool;
consteval auto is_namespace(info) -> bool;
consteval auto is_function(info) -> bool;
consteval auto is_variable(info) -> bool;
consteval auto is_type(info) -> bool;
consteval auto is_alias(info) -> bool;
consteval auto is_incomplete_type(info) -> bool;
consteval auto is_template(info) -> bool;
consteval auto is_function_template(info) -> bool;
consteval auto is_variable_template(info) -> bool;
consteval auto is_class_template(bool) -> bool;
consteval auto is_alias_template(bool) -> bool;
consteval auto is_concept(info) -> bool;
consteval auto has_template_arguments(info) -> bool;
consteval auto is_constructor(info) -> bool;
consteval auto is_destructor(info) -> bool;
consteval auto is_special_member(info) -> bool;
// reflect_value
template <typename Ty>
consteval auto reflect_value(T value) -> info;
// reflect_invoke
consteval auto reflect_invoke(info target, span<info const> args) -> info;
// define_class
struct data_member_options_t;
consteval auto data_member_spec(info class_type,
data_member_options = {}) -> info;
consteval auto define_class(info class_type, span<info const>) -> info;
// data layout
consteval auto offset_of(info) -> size_t;
consteval auto size_of(info) -> size_t;
consteval auto bit_offset_of(info) -> size_t;
consteval auto bit_size_of(info) -> size_t;
consteval auto alignment_of(info) -> size_t;
} // namespace reflection_v2
} // namespace meta
} // namespace std
*/
#include <experimental/__config>
#include <optional>
#include <source_location>
#include <span>
#include <string_view>
#include <vector>
#if __has_feature(reflection)
_LIBCPP_BEGIN_NAMESPACE_META_V2
// An opaque handle to a reflected entity.
using info = decltype(^int);
namespace detail {
enum : unsigned {
// non-exposed metafunctions
__metafn_get_begin_enumerator_decl_of,
__metafn_get_get_next_enumerator_decl_of,
__metafn_get_ith_base_of,
__metafn_get_ith_template_argument_of,
__metafn_get_begin_member_decl_of,
__metafn_get_next_member_decl_of,
__metafn_map_decl_to_entity,
// exposed metafunctions
__metafn_name_of,
__metafn_display_name_of,
__metafn_source_location_of,
__metafn_type_of,
__metafn_parent_of,
__metafn_dealias,
__metafn_template_of,
__metafn_substitute,
__metafn_value_of,
__metafn_is_public,
__metafn_is_protected,
__metafn_is_private,
__metafn_is_accessible,
__metafn_is_virtual,
__metafn_is_pure_virtual,
__metafn_is_override,
__metafn_is_deleted,
__metafn_is_defaulted,
__metafn_is_explicit,
__metafn_is_bit_field,
__metafn_has_static_storage_duration,
__metafn_has_internal_linkage,
__metafn_has_external_linkage,
__metafn_has_linkage,
__metafn_is_class_member,
__metafn_is_namespace_member,
__metafn_is_nonstatic_data_member,
__metafn_is_static_member,
__metafn_is_base,
__metafn_is_namespace,
__metafn_is_function,
__metafn_is_variable,
__metafn_is_type,
__metafn_is_alias,
__metafn_is_incomplete_type,
__metafn_is_template,
__metafn_is_function_template,
__metafn_is_variable_template,
__metafn_is_class_template,
__metafn_is_alias_template,
__metafn_is_concept,
__metafn_has_template_arguments,
__metafn_is_constructor,
__metafn_is_destructor,
__metafn_is_special_member,
__metafn_reflect_value,
__metafn_reflect_invoke,
__metafn_data_member_spec,
__metafn_define_class,
__metafn_offset_of,
__metafn_size_of,
__metafn_bit_offset_of,
__metafn_bit_size_of,
__metafn_alignment_of,
};
} // namespace detail
namespace __range_of_infos {
constexpr struct always_true_fn {
consteval bool operator()(info) {
return true;
}
} always_true;
struct sentinel {};
template <typename Front, typename Next, typename Map,
typename Pred = always_true_fn>
class iterator {
static constexpr Front m_front = { };
static constexpr Next m_next = { };
// The reflected entity passed to the underlying range
info m_reflectedEntity{^sentinel};
// The current meta::info within the range: e.g. if we are
// doing template_arguments_of(^std::vector<int, double, std::string>)
// m_currInfoItr can be either ^int, ^double and ^std::string
info m_currInfoItr{^sentinel};
Pred m_pred;
Map m_mapFn;
size_t m_nextIndex {0};
consteval void advance() {
while ((m_currInfoItr != ^sentinel) && !m_pred(m_mapFn(m_currInfoItr)))
m_currInfoItr = m_next(m_currInfoItr, m_reflectedEntity, m_nextIndex++);
}
public:
using value_type = info;
using reference = info;
using pointer = info;
using difference_type = ptrdiff_t;
using iterator_category = forward_iterator_tag;
using filter_type = Pred;
consteval iterator(Pred pred)
: m_currInfoItr{^sentinel}
, m_pred{pred}
, m_mapFn{}
{ }
consteval iterator(meta::info reflectedEntity, Pred pred)
: m_reflectedEntity{reflectedEntity}
, m_currInfoItr{m_front(reflectedEntity)}
, m_pred{pred}
, m_nextIndex{1} // after we fetch the front, next index is 1
{
advance();
}
consteval info operator*() const {
return m_mapFn(m_currInfoItr);
}
// pre-incr ++itr;
consteval iterator operator++() {
m_currInfoItr = m_next(m_currInfoItr, m_reflectedEntity, m_nextIndex++);
advance();
return *this;
}
// post-incr itr++;
consteval iterator operator++(int) {
iterator tmp = *this;
operator++();
return tmp;
}
consteval Pred filter() const {
return m_pred;
}
consteval friend bool operator==(iterator a, iterator b) {
return a.m_currInfoItr == b.m_currInfoItr;
}
consteval friend bool operator!=(iterator a, iterator b) {
return a.m_currInfoItr != b.m_currInfoItr;
}
};
template <typename Iter>
class range {
Iter m_first;
Iter m_last;
public:
using iterator = Iter;
using filter_type = typename Iter::filter_type;
consteval range(info reflection, filter_type pred = {})
: m_first(reflection, pred) , m_last(pred)
{ }
consteval iterator begin() const
{
return m_first;
}
consteval iterator end() const
{
return m_last;
}
};
template <typename Front, typename Next, typename Map, typename Pred>
consteval ptrdiff_t distance(iterator<Front, Next, Map, Pred> first,
iterator<Front, Next, Map, Pred> last) {
ptrdiff_t n = 0;
for (; first != last; ++first)
++n;
return n;
}
constexpr struct next_member_of_fn {
consteval info operator()(info currItrInfo, auto /* reflectedEntity */,
auto /* idx */) const {
return __metafunction(detail::__metafn_get_next_member_decl_of, currItrInfo,
^sentinel);
}
} next_member;
constexpr struct front_member_of_fn {
consteval info operator()(info reflectedEntity) const {
return __metafunction(detail::__metafn_get_begin_member_decl_of,
reflectedEntity, ^sentinel);
}
} front_member;
constexpr struct map_decl_to_entity_fn {
consteval info operator()(info reflectedDecl) const {
return __metafunction(detail::__metafn_map_decl_to_entity, reflectedDecl);
}
} map_decl_to_entity;
constexpr struct map_identity_fn {
consteval info operator()(info reflectedDecl) const {
return reflectedDecl;
}
} map_identity;
constexpr struct next_targ_fn {
consteval info operator()(auto /* currItrInfo */, info reflectedEntity,
size_t idx) const {
return __metafunction(detail::__metafn_get_ith_template_argument_of,
reflectedEntity, ^sentinel, idx);
}
} next_targ;
constexpr struct front_targ_fn {
consteval info operator()(info reflectedEntity) const {
return __metafunction(detail::__metafn_get_ith_template_argument_of,
reflectedEntity, ^sentinel, 0);
}
} front_targ;
constexpr struct next_base_of_fn {
consteval info operator()(auto /* currItrInfo */, info reflectedEntity,
size_t idx) const {
return __metafunction(detail::__metafn_get_ith_base_of,
reflectedEntity, ^sentinel, idx);
}
} next_base;
constexpr struct front_base_of_fn {
consteval info operator()(info reflectedEntity) const {
return __metafunction(detail::__metafn_get_ith_base_of,
reflectedEntity, ^sentinel, 0);
}
} front_base;
constexpr struct next_enumerator_of_fn {
consteval info operator()(info currItrInfo, auto /* reflectedEntity */,
auto /* idx */ ) const {
return __metafunction(detail::__metafn_get_get_next_enumerator_decl_of,
currItrInfo, ^sentinel);
}
} next_enumerator;
constexpr struct front_enumerator_of_fn {
consteval info operator()(info reflectedEntity) const {
return __metafunction(detail::__metafn_get_begin_enumerator_decl_of,
reflectedEntity, ^sentinel);
}
} front_enumerator;
} // namespace __range_of_infos
// -----------------------------------------------------------------------------
// Metafunctions
// -----------------------------------------------------------------------------
// Returns the name of the reflected entity, or the empty string if it has none.
consteval auto name_of(info r) -> string_view {
return __metafunction(detail::__metafn_name_of, r);
}
// Returns a name for the reflected entity.
consteval auto display_name_of(info r) -> string_view {
return __metafunction(detail::__metafn_display_name_of, r);
}
// Returns the source location of the reflected entity.
consteval auto source_location_of(info r) -> source_location {
auto ptr = __metafunction(detail::__metafn_source_location_of, r);
return source_location::current(ptr);
}
// Returns the type of the provided reflection of an expression.
consteval auto type_of(info r) -> info {
return __metafunction(detail::__metafn_type_of, r);
}
// Returns the containing class or namespace of a class or namespace member.
consteval auto parent_of(info r) -> info {
return __metafunction(detail::__metafn_parent_of, r);
}
// Returns a reflection of the canonical type for the reflected type.
consteval auto dealias(info r) -> info {
return __metafunction(detail::__metafn_dealias, r);
}
// Returns a reflection of the template from which the reflected entity was
// instantiated.
consteval auto template_of(info r) -> info {
return __metafunction(detail::__metafn_template_of, r);
}
consteval auto template_arguments_of(info r) -> vector<info> {
using iterator =
__range_of_infos::iterator<__range_of_infos::front_targ_fn,
__range_of_infos::next_targ_fn,
__range_of_infos::map_identity_fn>;
using range = __range_of_infos::range<iterator>;
auto rng = range{r};
return vector<info>{rng.begin(), rng.end()};
}
// Returns whether the reflected entity is a member of a class.
consteval auto is_class_member(info r) -> bool {
return __metafunction(detail::__metafn_is_class_member, r);
}
// Returns whether the reflected entity is a non-static data member.
consteval auto is_nonstatic_data_member(info r) -> bool {
return is_class_member(r) &&
__metafunction(detail::__metafn_is_nonstatic_data_member, r);
}
// Returns whether the reflected entity is a static member.
consteval auto is_static_member(info r) -> bool {
return is_class_member(r) &&
__metafunction(detail::__metafn_is_static_member, r);
}
// Returns whether the reflected entity is a base class specifier.
consteval auto is_base(info r) -> bool {
return __metafunction(detail::__metafn_is_base, r);
}
template <typename Pred>
consteval auto members_of(info r, Pred pred) {
using iterator =
__range_of_infos::iterator<__range_of_infos::front_member_of_fn,
__range_of_infos::next_member_of_fn,
__range_of_infos::map_decl_to_entity_fn, Pred>;
using range = __range_of_infos::range<iterator>;
auto rng = range{r, pred};
return vector<info>{rng.begin(), rng.end()};
}
template <typename... Preds>
consteval auto members_of(info r, Preds... preds) {
return members_of(r, [&](info r) {
return (preds(r) && ...);
});
}
consteval auto members_of(info r) -> vector<info> {
return members_of(r, __range_of_infos::always_true);
}
// Returns whether the reflected entity is a namespace.
consteval auto is_namespace(info r) -> bool {
return __metafunction(detail::__metafn_is_namespace, r);
}
template <typename Pred>
consteval auto bases_of(info r, Pred pred) -> vector<info> {
if (is_namespace(r))
throw "Namespaces cannot have base classes";
using iterator =
__range_of_infos::iterator<__range_of_infos::front_base_of_fn,
__range_of_infos::next_base_of_fn,
__range_of_infos::map_identity_fn, Pred>;
using range = __range_of_infos::range<iterator>;
auto rng = range{r, pred};
return vector<info>{rng.begin(), rng.end()};
}
template <typename... Preds>
consteval auto bases_of(info r, Preds... preds) -> vector<info> {
return bases_of(r, [&](info r) {
return (preds(r) && ...);
});
}
consteval auto bases_of(info r) -> vector<info> {
return bases_of(r, __range_of_infos::always_true);
}
// Returns whether the reflected entity is a variable.
consteval auto is_variable(info r) -> bool {
return __metafunction(detail::__metafn_is_variable, r);
}
consteval auto static_data_members_of(info r) -> vector<info> {
if (is_namespace(r))
throw "Namespaces cannot have static data members";
return members_of(r, is_class_member, is_variable);
}
consteval auto nonstatic_data_members_of(info r) -> vector<info> {
if (is_namespace(r))
throw "Namespaces cannot have non-static data members";
return members_of(r, is_nonstatic_data_member);
}
consteval auto subobjects_of(info r) -> vector<info> {
if (is_namespace(r))
throw "Namespaces cannot have subobjects";
auto subobjects = bases_of(r);
subobjects.append_range(nonstatic_data_members_of(r));
return subobjects;
}
consteval auto enumerators_of(info r) -> vector<info> {
using iterator =
__range_of_infos::iterator<__range_of_infos::front_enumerator_of_fn,
__range_of_infos::next_enumerator_of_fn,
__range_of_infos::map_identity_fn>;
using range = __range_of_infos::range<iterator>;
auto rng = range{r};
return vector<info>{rng.begin(), rng.end()};
}
// Returns a reflection representing the template instantiation of the entity
// reflected by 'templ' with the entities reflected by 'args'.
consteval auto substitute(info templ, span<info const> args) -> info {
return __metafunction(detail::__metafn_substitute, templ,
args.data(), args.size());
}
// Returns the value of 'r' if 'r' is a reflection of a value having type 'T'.
template <typename Ty> requires (!std::is_rvalue_reference_v<Ty>)
consteval auto value_of(info r) -> Ty {
return __metafunction(detail::__metafn_value_of, ^Ty, r);
}
consteval auto test_types(info templ, span<info const> args) -> bool {
return value_of<bool>(substitute(templ, args));
}
consteval auto test_type(info templ, info type) -> bool {
info args[1] = {type};
return test_types(templ, args);
}
// Returns whether the reflected entity is a public class member.
consteval auto is_public(info r) -> bool {
return __metafunction(detail::__metafn_is_public, r);
}
// Returns whether the reflected entity is a protected class member.
consteval auto is_protected(info r) -> bool {
return __metafunction(detail::__metafn_is_protected, r);
}
// Returns whether the reflected entity is a private class member.
consteval auto is_private(info r) -> bool {
return __metafunction(detail::__metafn_is_private, r);
}
// Returns whether the reflected entity can be accessed from the callsite.
consteval auto is_accessible(info r) -> bool {
return __metafunction(detail::__metafn_is_accessible, r);
}
// Returns whether the reflected entity is a virtual member function or a
// virtual base class.
consteval auto is_virtual(info r) -> bool {
return __metafunction(detail::__metafn_is_virtual, r);
}
// Returns whether the reflected class member function is pure virtual.
consteval auto is_pure_virtual(info r) -> bool {
return __metafunction(detail::__metafn_is_pure_virtual, r);
}
// Returns whether the reflected class member function overrides a virtual
// member function from a base class.
consteval auto is_override(info r) -> bool {
return __metafunction(detail::__metafn_is_override, r);
}
// Returns whether the reflected class member function is deleted.
consteval auto is_deleted(info r) -> bool {
return __metafunction(detail::__metafn_is_deleted, r);
}
// Returns whether the reflected class member function is defaulted.
consteval auto is_defaulted(info r) -> bool {
return __metafunction(detail::__metafn_is_defaulted, r);
}
// Returns whether the reflected class member function is explicit.
consteval auto is_explicit(info r) -> bool {
return __metafunction(detail::__metafn_is_explicit, r);
}
// Returns whether the reflected class data member is a bit field.
consteval auto is_bit_field(info r) -> bool {
return __metafunction(detail::__metafn_is_bit_field, r);
}
// Returns whether the reflected entity is a variable having static storage
// duration.
consteval auto has_static_storage_duration(info r) -> bool {
return __metafunction(detail::__metafn_has_static_storage_duration, r);
}
// Returns whether the reflected entity has internal linkage.
consteval auto has_internal_linkage(info r) -> bool {
return __metafunction(detail::__metafn_has_internal_linkage, r);
}
// Returns whether the reflected entity has external linkage.
consteval auto has_external_linkage(info r) -> bool {
return __metafunction(detail::__metafn_has_external_linkage, r);
}
// Returns whether the reflected entity has linkage.
consteval auto has_linkage(info r) -> bool {
return __metafunction(detail::__metafn_has_linkage, r);
}
// Returns whether the reflected entity is a member of a namespace.
consteval auto is_namespace_member(info r) -> bool {
return __metafunction(detail::__metafn_is_namespace_member, r);
}
// Returns whether the reflected entity is a function.
consteval auto is_function(info r) -> bool {
return __metafunction(detail::__metafn_is_function, r);
}
// Returns whether the reflected entity is a type.
consteval auto is_type(info r) -> bool {
return __metafunction(detail::__metafn_is_type, r);
}
// Returns true if the reflected entity is an alias.
consteval auto is_alias(info r) -> bool {
return __metafunction(detail::__metafn_is_alias, r);
}
// Returns true if the reflected entity is an incomplete type.
consteval auto is_incomplete_type(info r) -> bool {
return __metafunction(detail::__metafn_is_incomplete_type, r);
}
// Returns true if the reflected entity is a template.
consteval auto is_template(info r) -> bool {
return __metafunction(detail::__metafn_is_template, r);
}
// Returns true if the reflected entity is a function template.
consteval auto is_function_template(info r) -> bool {
return __metafunction(detail::__metafn_is_function_template, r);
}
// Returns true if the reflected entity is a variable template.
consteval auto is_variable_template(info r) -> bool {
return __metafunction(detail::__metafn_is_variable_template, r);
}
// Returns true if the reflected entity is a class template.
consteval auto is_class_template(info r) -> bool {
return __metafunction(detail::__metafn_is_class_template, r);
}
// Returns true if the reflected entity is an alias template.
consteval auto is_alias_template(info r) -> bool {
return __metafunction(detail::__metafn_is_alias_template, r);
}
// Returns true if the reflected entity is a concept.
consteval auto is_concept(info r) -> bool {
return __metafunction(detail::__metafn_is_concept, r);
}
// Returns if the type has template arguments
consteval auto has_template_arguments(info r) -> bool {
return __metafunction(detail::__metafn_has_template_arguments, r);
}
// Returns whether the reflected entity is a constructor.
consteval auto is_constructor(info r) -> bool {
return __metafunction(detail::__metafn_is_constructor, r);
}
// Returns whether the reflected entity is a destructor.
consteval auto is_destructor(info r) -> bool {
return __metafunction(detail::__metafn_is_destructor, r);
}
// Returns whether the reflected entity is a special member function.
consteval auto is_special_member(info r) -> bool {
return __metafunction(detail::__metafn_is_special_member, r);
}
// Returns a reflection of the constant value held by the provided argument.
template <typename Ty>
consteval auto reflect_value(Ty r) -> info {
return __metafunction(detail::__metafn_reflect_value, r);
}
// Returns a reflection of the constant value obtained from calling
// target(args...)
consteval auto reflect_invoke(info target, span<info const> args) -> info {
return __metafunction(detail::__metafn_reflect_invoke, target,
args.data(), args.size());
}
// Representation of a data member which may be passed to 'data_member_spec'.
struct data_member_options_t {
optional<string_view> name = nullopt;
bool is_static = false;
optional<int> alignment = nullopt;
optional<int> width = nullopt;
};
// Returns a reflection representing a description of a data member, which may
// be used with 'define_class' to define a record type.
consteval auto data_member_spec(info member_type,
data_member_options_t options = {}) -> info {
string_view name = options.name.value_or("");
bool is_static = options.is_static;
int alignment = options.alignment.value_or(0);
int width = options.width.value_or(0);
return __metafunction(detail::__metafn_data_member_spec,
member_type, is_static,
options.name.has_value(), name.size(), name.data(),
options.alignment.has_value(), alignment,
options.width.has_value(), width);
}
// Completes the definition of the record type reflected by 'class_type' with
// the members described by the reflections in the provided span.
consteval auto define_class(info class_type,
span<info const> members) -> info {
return __metafunction(detail::__metafn_define_class, class_type,
members.size(), members.data());
}
// Returns the offset of the reflected entity.
consteval auto offset_of(info r) -> size_t {
return __metafunction(detail::__metafn_offset_of, r);
}
// Returns the size of the reflected entity.
consteval auto size_of(info r) -> size_t {
return __metafunction(detail::__metafn_size_of, r);
}
consteval auto bit_offset_of(info r) -> size_t {
return __metafunction(detail::__metafn_bit_offset_of, r);
}
// Returns the size of the reflected entity in bits.
consteval auto bit_size_of(info r) -> size_t {
return __metafunction(detail::__metafn_bit_size_of, r);
}
// Returns the alignment of the reflected entity.
consteval auto alignment_of(info r) -> size_t {
return __metafunction(detail::__metafn_alignment_of, r);
}
_LIBCPP_END_NAMESPACE_META_V2
#endif // __has_feature(reflection)
#endif // _LIBCPP_EXPERIMENTAL_META