21 Metaprogramming library [meta]

21.4 Reflection [meta.reflection]

21.4.16 Reflection type traits [meta.reflection.traits]

This subclause specifies consteval functions to query the properties of types ([meta.unary]), query the relationships between types ([meta.rel]), or transform types ([meta.trans]), during program translation.
Each consteval function declared in this class has an associated class template declared elsewhere in this document.
Every function and function template declared in this subclause has the following conditions required for a call to that function or function template to be a constant subexpression ([defns.const.subexpr]):
  • For every parameter p of type info, is_type(p) is true.
  • For every parameter r whose type is constrained on reflection_range, ranges​::​​all_of(​r, is_type) is true.
// associated with [meta.unary.cat], primary type categories consteval 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], composite type categories consteval 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], type properties consteval 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 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 type_dst, info type_src); consteval bool is_swappable_type(info type); consteval bool is_destructible_type(info type); template<reflection_range 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 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 type_dst, info type_src); 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.rel], type relations consteval 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 R = initializer_list<info>> consteval bool is_invocable_type(info type, R&& type_args); template<reflection_range R = initializer_list<info>> consteval bool is_invocable_r_type(info type_result, info type, R&& type_args); template<reflection_range R = initializer_list<info>> consteval bool is_nothrow_invocable_type(info type, R&& type_args); template<reflection_range R = initializer_list<info>> consteval bool is_nothrow_invocable_r_type(info type_result, info type, R&& type_args); // associated with [meta.trans.cv], const-volatile modifications consteval 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], reference modifications consteval info remove_reference(info type); consteval info add_lvalue_reference(info type); consteval info add_rvalue_reference(info type); // associated with [meta.trans.sign], sign modifications consteval info make_signed(info type); consteval info make_unsigned(info type); // associated with [meta.trans.arr], array modifications consteval info remove_extent(info type); consteval info remove_all_extents(info type); // associated with [meta.trans.ptr], pointer modifications consteval info remove_pointer(info type); consteval info add_pointer(info type); // associated with [meta.trans.other], other transformations consteval info remove_cvref(info type); consteval info decay(info type); template<reflection_range R = initializer_list<info>> consteval info common_type(R&& type_args); template<reflection_range R = initializer_list<info>> consteval info common_reference(R&& type_args); consteval info underlying_type(info type); template<reflection_range 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);
Ech function or function template declared above has the following behavior based on the signature and return type of that function or function template.
[Note 1: 
The associated class template need not be instantiated.
— end note]
Table 64 — Reflection type traits [tab:meta.reflection.traits]
Signature and Return Type
Returns
bool meta​::​UNARY(info type);
bool meta​::​UNARY_type(info type);
std​::​UNARY_v<T>, where T is the type or type alias represented by type
bool meta​::​BINARY(info type);
bool meta​::​BINARY_type(info type);
std​::​BINARY_v<T1, T2>, where T1 and T2 are the types or type aliases represented by t1 and t2, respectively
template<reflection_range R>
bool meta​::​VARIADIC_type(info type, R&& args);
std​::​VARIADIC_v<T, U...>, where T is the type or type alias represented by type and U... is the pack of types or type aliases whose elements are represented by the corresponding elements of args
template<reflection_range R>
bool meta​::​VARIADIC_type(info t1, info t2, R&& args);
std​::​VARIADIC_v<T1, T2, U...>, where T1 and T2 are the types or type aliases represented by t1 and t2, respectively, and U... is the pack of types or type aliases whose elements are represented by the corresponding elements of args
info meta​::​UNARY(info type);
info meta​::​UNARY(info type);
A reflection representing the type denoted by std​::​UNARY_t<T>, where T is the type or type alias represented by type
template<reflection_range R>
info meta​::​VARIADIC(R&& args);
A reflection representing the type denoted by std​::​VARIADIC_t<T...>, where T... is the pack of types or type aliases whose elements are represented by the corresponding elements of args
template<reflection_range R>
info meta​::​VARIADIC(info type, R&& args);
A reflection representing the type denoted by std​::​VARIADIC_t<T, U...>, where T is the type or type alias represented by type and U... is the pack of types or type aliases whose elements are represented by the corresponding elements of args
[Note 2: 
For those functions or function templates which return a reflection, that reflection always represents a type and never a type alias.
— end note]
[Note 3: 
If t is a reflection of the type int and u is a reflection of an alias to the type int, then t == u is false but is_same_type(t, u) is true.
Also, t == dealias(u) is true.
— end note]
consteval size_t rank(info type);
Returns: rank_v<T>, where T is the type represented by dealias(type).
consteval size_t extent(info type, unsigned i = 0);
Returns: extent_v<T, I>, where T is the type represented by dealias(type) and I is a constant equal to i.
consteval size_t tuple_size(info type);
Returns: tuple_size_v<T>, where T is the type represented by dealias(type).
consteval info tuple_element(size_t index, info type);
Returns: A reflection representing the type denoted by tuple_element_t<I, T>, where T is th type represented by dealias(type), and I is a constant equal to index.
consteval size_t variant_size(info type);
Returns: variant_size_v<T>, where T is the type represented by dealias(type).
consteval info variant_alternative(size_t index, info type);
Returns: A reflection representing the type denoted by variant_alternative_t<I, T>, where T is the type represented by dealias(type) and I is a consant equal to index.
consteval strong_ordering type_order(info t1, info t2);
Returns: type_order_v<T1, T2>, where T1 and T2 are the types represented by dealias(t1) and dealias(t2), respectively.