68 lines
20 KiB
Markdown
68 lines
20 KiB
Markdown
[meta.syn]
|
||
|
||
# 21 Metaprogramming library [[meta]](./#meta)
|
||
|
||
## 21.4 Reflection [[meta.reflection]](meta.reflection#meta.syn)
|
||
|
||
### 21.4.1 Header <meta> synopsis [meta.syn]
|
||
|
||
[ð](#header:%3cmeta%3e)
|
||
|
||
#include <initializer_list> // see [[initializer.list.syn]](initializer.list.syn "17.11.2 Header <initializer_list> synopsis")namespace std {// [[meta.string.literal]](meta.string.literal "21.4.2 Checking string literals"), checking string literalsconsteval bool is_string_literal(const char* p); consteval bool is_string_literal(const wchar_t* p); consteval bool is_string_literal(const char8_t* p); consteval bool is_string_literal(const char16_t* p); consteval bool is_string_literal(const char32_t* p); // [[meta.define.static]](meta.define.static "21.4.3 Promoting to static storage strings"), promoting to static storage stringstemplate<ranges::[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R>consteval const ranges::range_value_t<R>* define_static_string(R&& r); template<ranges::[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R>consteval span<const ranges::range_value_t<R>> define_static_array(R&& r); template<class T>consteval const remove_cvref_t<T>* define_static_object(T&& r);}namespace std::meta {using info = decltype(^^::); // [[meta.reflection.exception]](meta.reflection.exception "21.4.4 Class exception"), class exceptionclass exception; // [[meta.reflection.operators]](meta.reflection.operators "21.4.5 Operator representations"), operator representationsenum class operators {*see below*; }; using enum operators; consteval operators operator_of(info r); consteval string_view symbol_of(operators op); consteval u8string_view u8symbol_of(operators op); // [[meta.reflection.names]](meta.reflection.names "21.4.6 Reflection names and locations"), reflection names and locationsconsteval bool has_identifier(info r); consteval string_view identifier_of(info r); consteval u8string_view u8identifier_of(info r); consteval string_view display_string_of(info r); consteval u8string_view u8display_string_of(info r); consteval source_location source_location_of(info r); // [[meta.reflection.queries]](meta.reflection.queries "21.4.7 Reflection queries"), reflection queriesconsteval info type_of(info r); consteval info object_of(info r); consteval info constant_of(info r); consteval bool is_public(info r); consteval bool is_protected(info r); consteval bool is_private(info r); consteval bool is_virtual(info r); consteval bool is_pure_virtual(info r); consteval bool is_override(info r); consteval bool is_final(info r); consteval bool is_deleted(info r); consteval bool is_defaulted(info r); consteval bool is_user_provided(info r); consteval bool is_user_declared(info r); consteval bool is_explicit(info r); consteval bool is_noexcept(info r); consteval bool is_bit_field(info r); consteval bool is_enumerator(info r); consteval bool is_annotation(info r); consteval bool is_const(info r); consteval bool is_volatile(info r); consteval bool is_mutable_member(info r); consteval bool is_lvalue_reference_qualified(info r); consteval bool is_rvalue_reference_qualified(info r); consteval bool has_static_storage_duration(info r); consteval bool has_thread_storage_duration(info r); consteval bool has_automatic_storage_duration(info r); consteval bool has_internal_linkage(info r); consteval bool has_module_linkage(info r); consteval bool has_external_linkage(info r); consteval bool has_c_language_linkage(info r); consteval bool has_linkage(info r); consteval bool is_complete_type(info r); consteval bool is_enumerable_type(info r); consteval bool is_variable(info r); consteval bool is_type(info r); consteval bool is_namespace(info r); consteval bool is_type_alias(info r); consteval bool is_namespace_alias(info r); consteval bool is_function(info r); consteval bool is_conversion_function(info r); consteval bool is_operator_function(info r); consteval bool is_literal_operator(info r); consteval bool is_special_member_function(info r); consteval bool is_constructor(info r); consteval bool is_default_constructor(info r); consteval bool is_copy_constructor(info r); consteval bool is_move_constructor(info r); consteval bool is_assignment(info r); consteval bool is_copy_assignment(info r); consteval bool is_move_assignment(info r); consteval bool is_destructor(info r); consteval bool is_function_parameter(info r); consteval bool is_explicit_object_parameter(info r); consteval bool has_default_argument(info r); consteval bool has_ellipsis_parameter(info r); consteval bool is_template(info r); consteval bool is_function_template(info r); consteval bool is_variable_template(info r); consteval bool is_class_template(info r); consteval bool is_alias_template(info r); consteval bool is_conversion_function_template(info r); consteval bool is_operator_function_template(info r); consteval bool is_literal_operator_template(info r); consteval bool is_constructor_template(info r); consteval bool is_concept(info r); consteval bool is_value(info r); consteval bool is_object(info r); consteval bool is_structured_binding(info r); consteval bool is_class_member(info r); consteval bool is_namespace_member(info r); consteval bool is_nonstatic_data_member(info r); consteval bool is_static_member(info r); consteval bool is_base(info r); consteval bool has_default_member_initializer(info r); consteval bool has_parent(info r); consteval info parent_of(info r); consteval info dealias(info r); consteval bool has_template_arguments(info r); consteval info template_of(info r); consteval vector<info> template_arguments_of(info r); consteval vector<info> parameters_of(info r); consteval info variable_of(info r); consteval info return_type_of(info r); // [[meta.reflection.access.context]](meta.reflection.access.context "21.4.8 Access control context"), access control contextstruct access_context; // [[meta.reflection.access.queries]](meta.reflection.access.queries "21.4.9 Member accessibility queries"), member accessibility queriesconsteval bool is_accessible(info r, access_context ctx); consteval bool has_inaccessible_nonstatic_data_members(info r, access_context ctx); consteval bool has_inaccessible_bases(info r, access_context ctx); consteval bool has_inaccessible_subobjects(info r, access_context ctx); // [[meta.reflection.member.queries]](meta.reflection.member.queries "21.4.10 Reflection member queries"), reflection member queriesconsteval vector<info> members_of(info r, access_context ctx); consteval vector<info> bases_of(info type, access_context ctx); consteval vector<info> static_data_members_of(info type, access_context ctx); consteval vector<info> nonstatic_data_members_of(info type, access_context ctx); consteval vector<info> subobjects_of(info type, access_context ctx); consteval vector<info> enumerators_of(info type_enum); // [[meta.reflection.layout]](meta.reflection.layout "21.4.11 Reflection layout queries"), reflection layout queriesstruct member_offset; consteval member_offset offset_of(info r); consteval size_t size_of(info r); consteval size_t alignment_of(info r); consteval size_t bit_size_of(info r); // [[meta.reflection.extract]](meta.reflection.extract "21.4.12 Value extraction"), value extractiontemplate<class T>consteval T extract(info); // [[meta.reflection.substitute]](meta.reflection.substitute "21.4.13 Reflection substitution"), reflection substitutiontemplate<class R>concept reflection_range = *see below*; template<[reflection_range](meta.reflection.substitute#concept:reflection_range "21.4.13 Reflection substitution [meta.reflection.substitute]") R = initializer_list<info>>consteval bool can_substitute(info templ, R&& arguments); template<[reflection_range](meta.reflection.substitute#concept:reflection_range "21.4.13 Reflection substitution [meta.reflection.substitute]") R = initializer_list<info>>consteval info substitute(info templ, R&& arguments); // [[meta.reflection.result]](meta.reflection.result "21.4.14 Expression result reflection"), expression result reflectiontemplate<class T>consteval info reflect_constant(const T& value); template<class T>consteval info reflect_object(T& object); template<class T>consteval info reflect_function(T& fn); // [[meta.reflection.array]](meta.reflection.array "21.4.15 Promoting to static storage arrays"), promoting to static storage arraystemplate<ranges::[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R>consteval info reflect_constant_string(R&& r); template<ranges::[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R>consteval info reflect_constant_array(R&& r); // [[meta.reflection.define.aggregate]](meta.reflection.define.aggregate "21.4.16 Reflection class definition generation"), class definition generationstruct data_member_options; consteval info data_member_spec(info type, data_member_options options); consteval bool is_data_member_spec(info r); template<[reflection_range](meta.reflection.substitute#concept:reflection_range "21.4.13 Reflection substitution [meta.reflection.substitute]") R = initializer_list<info>>consteval info define_aggregate(info type_class, R&&); // associated with [[meta.unary.cat]](meta.unary.cat "21.3.6.2 Primary type categories"), primary type categoriesconsteval bool is_void_type(info type); consteval bool is_null_pointer_type(info type); consteval bool is_integral_type(info type); consteval bool is_floating_point_type(info type); consteval bool is_array_type(info type); consteval bool is_pointer_type(info type); consteval bool is_lvalue_reference_type(info type); consteval bool is_rvalue_reference_type(info type); consteval bool is_member_object_pointer_type(info type); consteval bool is_member_function_pointer_type(info type); consteval bool is_enum_type(info type); consteval bool is_union_type(info type); consteval bool is_class_type(info type); consteval bool is_function_type(info type); consteval bool is_reflection_type(info type); // associated with [[meta.unary.comp]](meta.unary.comp "21.3.6.3 Composite type traits"), composite type categoriesconsteval bool is_reference_type(info type); consteval bool is_arithmetic_type(info type); consteval bool is_fundamental_type(info type); consteval bool is_object_type(info type); consteval bool is_scalar_type(info type); consteval bool is_compound_type(info type); consteval bool is_member_pointer_type(info type); // associated with [[meta.unary.prop]](meta.unary.prop "21.3.6.4 Type properties"), type propertiesconsteval bool is_const_type(info type); consteval bool is_volatile_type(info type); consteval bool is_trivially_copyable_type(info type); consteval bool is_trivially_relocatable_type(info type); consteval bool is_replaceable_type(info type); consteval bool is_standard_layout_type(info type); consteval bool is_empty_type(info type); consteval bool is_polymorphic_type(info type); consteval bool is_abstract_type(info type); consteval bool is_final_type(info type); consteval bool is_aggregate_type(info type); consteval bool is_consteval_only_type(info type); consteval bool is_signed_type(info type); consteval bool is_unsigned_type(info type); consteval bool is_bounded_array_type(info type); consteval bool is_unbounded_array_type(info type); consteval bool is_scoped_enum_type(info type); template<[reflection_range](meta.reflection.substitute#concept:reflection_range "21.4.13 Reflection substitution [meta.reflection.substitute]") R = initializer_list<info>>consteval bool is_constructible_type(info type, R&& type_args); consteval bool is_default_constructible_type(info type); consteval bool is_copy_constructible_type(info type); consteval bool is_move_constructible_type(info type); consteval bool is_assignable_type(info type_dst, info type_src); consteval bool is_copy_assignable_type(info type); consteval bool is_move_assignable_type(info type); consteval bool is_swappable_with_type(info type1, info type2); consteval bool is_swappable_type(info type); consteval bool is_destructible_type(info type); template<[reflection_range](meta.reflection.substitute#concept:reflection_range "21.4.13 Reflection substitution [meta.reflection.substitute]") R = initializer_list<info>>consteval bool is_trivially_constructible_type(info type, R&& type_args); consteval bool is_trivially_default_constructible_type(info type); consteval bool is_trivially_copy_constructible_type(info type); consteval bool is_trivially_move_constructible_type(info type); consteval bool is_trivially_assignable_type(info type_dst, info type_src); consteval bool is_trivially_copy_assignable_type(info type); consteval bool is_trivially_move_assignable_type(info type); consteval bool is_trivially_destructible_type(info type); template<[reflection_range](meta.reflection.substitute#concept:reflection_range "21.4.13 Reflection substitution [meta.reflection.substitute]") R = initializer_list<info>>consteval bool is_nothrow_constructible_type(info type, R&& type_args); consteval bool is_nothrow_default_constructible_type(info type); consteval bool is_nothrow_copy_constructible_type(info type); consteval bool is_nothrow_move_constructible_type(info type); consteval bool is_nothrow_assignable_type(info type_dst, info type_src); consteval bool is_nothrow_copy_assignable_type(info type); consteval bool is_nothrow_move_assignable_type(info type); consteval bool is_nothrow_swappable_with_type(info type1, info type2); consteval bool is_nothrow_swappable_type(info type); consteval bool is_nothrow_destructible_type(info type); consteval bool is_nothrow_relocatable_type(info type); consteval bool is_implicit_lifetime_type(info type); consteval bool has_virtual_destructor(info type); consteval bool has_unique_object_representations(info type); consteval bool reference_constructs_from_temporary(info type_dst, info type_src); consteval bool reference_converts_from_temporary(info type_dst, info type_src); // associated with [[meta.unary.prop.query]](meta.unary.prop.query "21.3.7 Type property queries"), type property queriesconsteval size_t rank(info type); consteval size_t extent(info type, unsigned i = 0); // associated with [[meta.rel]](meta.rel "21.3.8 Relationships between types"), type relationsconsteval bool is_same_type(info type1, info type2); consteval bool is_base_of_type(info type_base, info type_derived); consteval bool is_virtual_base_of_type(info type_base, info type_derived); consteval bool is_convertible_type(info type_src, info type_dst); consteval bool is_nothrow_convertible_type(info type_src, info type_dst); consteval bool is_layout_compatible_type(info type1, info type2); consteval bool is_pointer_interconvertible_base_of_type(info type_base, info type_derived); template<[reflection_range](meta.reflection.substitute#concept:reflection_range "21.4.13 Reflection substitution [meta.reflection.substitute]") R = initializer_list<info>>consteval bool is_invocable_type(info type, R&& type_args); template<[reflection_range](meta.reflection.substitute#concept:reflection_range "21.4.13 Reflection substitution [meta.reflection.substitute]") R = initializer_list<info>>consteval bool is_invocable_r_type(info type_result, info type, R&& type_args); template<[reflection_range](meta.reflection.substitute#concept:reflection_range "21.4.13 Reflection substitution [meta.reflection.substitute]") R = initializer_list<info>>consteval bool is_nothrow_invocable_type(info type, R&& type_args); template<[reflection_range](meta.reflection.substitute#concept:reflection_range "21.4.13 Reflection substitution [meta.reflection.substitute]") R = initializer_list<info>>consteval bool is_nothrow_invocable_r_type(info type_result, info type, R&& type_args); // associated with [[meta.trans.cv]](meta.trans.cv "21.3.9.2 Const-volatile modifications"), const-volatile modificationsconsteval info remove_const(info type); consteval info remove_volatile(info type); consteval info remove_cv(info type); consteval info add_const(info type); consteval info add_volatile(info type); consteval info add_cv(info type); // associated with [[meta.trans.ref]](meta.trans.ref "21.3.9.3 Reference modifications"), reference modificationsconsteval info remove_reference(info type); consteval info add_lvalue_reference(info type); consteval info add_rvalue_reference(info type); // associated with [[meta.trans.sign]](meta.trans.sign "21.3.9.4 Sign modifications"), sign modificationsconsteval info make_signed(info type); consteval info make_unsigned(info type); // associated with [[meta.trans.arr]](meta.trans.arr "21.3.9.5 Array modifications"), array modificationsconsteval info remove_extent(info type); consteval info remove_all_extents(info type); // associated with [[meta.trans.ptr]](meta.trans.ptr "21.3.9.6 Pointer modifications"), pointer modificationsconsteval info remove_pointer(info type); consteval info add_pointer(info type); // associated with [[meta.trans.other]](meta.trans.other "21.3.9.7 Other transformations"), other transformationsconsteval info remove_cvref(info type); consteval info decay(info type); template<[reflection_range](meta.reflection.substitute#concept:reflection_range "21.4.13 Reflection substitution [meta.reflection.substitute]") R = initializer_list<info>>consteval info common_type(R&& type_args); template<[reflection_range](meta.reflection.substitute#concept:reflection_range "21.4.13 Reflection substitution [meta.reflection.substitute]") R = initializer_list<info>>consteval info common_reference(R&& type_args); consteval info underlying_type(info type); template<[reflection_range](meta.reflection.substitute#concept:reflection_range "21.4.13 Reflection substitution [meta.reflection.substitute]") R = initializer_list<info>>consteval info invoke_result(info type, R&& type_args); consteval info unwrap_reference(info type); consteval info unwrap_ref_decay(info type); consteval size_t tuple_size(info type); consteval info tuple_element(size_t index, info type); consteval size_t variant_size(info type); consteval info variant_alternative(size_t index, info type); consteval strong_ordering type_order(info type_a, info type_b); // [[meta.reflection.annotation]](meta.reflection.annotation "21.4.18 Annotation reflection"), annotation reflectionconsteval vector<info> annotations_of(info item); consteval vector<info> annotations_of_with_type(info item, info type);}
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L3281)
|
||
|
||
Unless otherwise specified,
|
||
each function, and each specialization of any function template,
|
||
specified in this header
|
||
is a designated addressable function ([[namespace.std]](namespace.std "16.4.5.2.1 Namespace std"))[.](#1.sentence-1)
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L3287)
|
||
|
||
The behavior of any function specified in namespace std::meta isimplementation-defined
|
||
when a reflection of a construct not otherwise specified by this document
|
||
is provided as an argument[.](#2.sentence-1)
|
||
|
||
[*Note [1](#note-1)*:
|
||
|
||
Values of type std::meta::info can represent implementation-specific constructs ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types"))[.](#2.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[*Note [2](#note-2)*:
|
||
|
||
Many of the functions specified in namespace std::meta have semantics that can be affected by
|
||
the completeness of class types represented by reflection values[.](#2.sentence-3)
|
||
|
||
For such functions,
|
||
for any reflection r such that dealias(r) represents a specialization of a templated class with a reachable definition,
|
||
the specialization is implicitly instantiated ([[temp.inst]](temp.inst "13.9.2 Implicit instantiation"))[.](#2.sentence-4)
|
||
|
||
[*Example [1](#example-1)*: template<class T>struct X { T mem;};
|
||
|
||
static_assert(size_of(^^X<int>) == sizeof(int)); // instantiates X<int> â *end example*]
|
||
|
||
â *end note*]
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L3317)
|
||
|
||
Any function in namespace std::meta whose return type is string_view or u8string_view returns an object *V* such that*V*.data()[*V*.size()] equals '\0'[.](#3.sentence-1)
|
||
|
||
[*Example [2](#example-2)*: struct C { };
|
||
|
||
constexpr string_view sv = identifier_of(^^C);static_assert(sv == "C");static_assert(sv.data()[0] == 'C');static_assert(sv.data()[1] == '\0'); â *end example*]
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/meta.tex#L3333)
|
||
|
||
For the purpose of exposition,
|
||
throughout this clause ^^*E* is used
|
||
to indicate a reflection representing source construct *E*[.](#4.sentence-1)
|