{"id":10109,"date":"2024-09-30T10:14:19","date_gmt":"2024-09-30T10:14:19","guid":{"rendered":"https:\/\/www.modernescpp.com\/?p=10109"},"modified":"2025-07-04T14:25:43","modified_gmt":"2025-07-04T14:25:43","slug":"reflection-in-c26-metafunctions","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/reflection-in-c26-metafunctions\/","title":{"rendered":"Reflection in C++26: Metafunctions"},"content":{"rendered":"\n<p>Reflection offers many metafunctions that run at compile time. <\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"696\" height=\"537\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/09\/Time26Reflection.png\" alt=\"\" class=\"wp-image-10083\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/09\/Time26Reflection.png 696w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2024\/09\/Time26Reflection-300x231.png 300w\" sizes=\"auto, (max-width: 696px) 100vw, 696px\" \/><\/figure>\n\n\n\n<p>The metafunctions are declared as <code><a href=\"https:\/\/www.modernescpp.com\/index.php\/c-20-consteval-and-constinit\/\">consteval<\/a><\/code>. <code>consteval <\/code>creates a so-called immediate function. Each invocation of an immediate function creates a compile-time constant. To say it more directly. A <code>consteval <\/code>(immediate) function is executed at compile-time.<\/p>\n\n\n\n<p>Read more about <code>consteval <\/code>and <code>constinit <\/code>in my previous post: <a href=\"https:\/\/www.modernescpp.com\/index.php\/c-20-consteval-and-constinit\/\">Two new Keywords in C++20: consteval and constinit<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What we Know so far:<\/h2>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #f0f3f3; overflow:auto;width:auto;gray;border-width:.1em .1em .1em .8em\"><pre style=\"margin: 0; line-height: 125%\"> constexpr <span style=\"color: #006699; font-weight: bold\">auto<\/span> r <span style=\"color: #555555\">=<\/span> <span style=\"color: #555555\">^<\/span><span style=\"color: #007788; font-weight: bold\">int<\/span>;\n    <span style=\"color: #006699; font-weight: bold\">typename<\/span>[<span style=\"color: #555555\">:<\/span>r<span style=\"color: #555555\">:<\/span>] x <span style=\"color: #555555\">=<\/span> <span style=\"color: #FF6600\">42<\/span>;       <span style=\"color: #0099FF; font-style: italic\">\/\/ Same as: int x = 42;<\/span>\n    <span style=\"color: #006699; font-weight: bold\">typename<\/span>[<span style=\"color: #555555\">:^<\/span><span style=\"color: #007788; font-weight: bold\">char<\/span><span style=\"color: #555555\">:<\/span>] c <span style=\"color: #555555\">=<\/span> <span style=\"color: #CC3300\">&#39;*&#39;<\/span>;  <span style=\"color: #0099FF; font-style: italic\">\/\/ Same as: char c = &#39;*&#39;;<\/span>\n<\/pre><\/div>\n\n\n\n<p>The reflection operator (<code><strong>^<\/strong><\/code>) produces out of the grammatical element (C++ element) a reflection value. The type of the reflection value<code> std::meta::info.<\/code> The reflection value (the reflection) can be an argument of the metafunctions or the splicers (<code><strong>[: refl :]<\/strong><\/code>). The splicers create grammatical elements.<\/p>\n\n\n\n<p> So reflection value can be defined as follows:<\/p>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #f0f3f3; overflow:auto;width:auto;gray;border-width:.1em .1em .1em .8em\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #006699; font-weight: bold\">namespace<\/span> std {\n  <span style=\"color: #006699; font-weight: bold\">namespace<\/span> meta {\n    <span style=\"color: #006699; font-weight: bold\">using<\/span> info <span style=\"color: #555555\">=<\/span> decltype(<span style=\"color: #555555\">^::<\/span>);\n  }\n}\n<\/pre><\/div>\n\n\n\n<p>So, what is missing? Of course, the metafunctions. I will present you all of them for two reasons:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li> There are many metafunctions.<\/li>\n\n\n\n<li> There is no official listing of all the meta functions (October 2024)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Metafunctions<\/h2>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #f0f3f3; overflow:auto;width:auto;gray;border-width:.1em .1em .1em .8em\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #006699; font-weight: bold\">namespace<\/span> std<span style=\"color: #555555\">::<\/span>meta {\n  <span style=\"color: #006699; font-weight: bold\">using<\/span> info <span style=\"color: #555555\">=<\/span> decltype(<span style=\"color: #555555\">^::<\/span>);\n\n  <span style=\"color: #006699; font-weight: bold\">template<\/span> <span style=\"color: #555555\">&lt;<\/span><span style=\"color: #006699; font-weight: bold\">typename<\/span> R<span style=\"color: #555555\">&gt;<\/span>\n  concept reflection_range <span style=\"color: #555555\">=<\/span> <span style=\"color: #0099FF; font-style: italic\">\/* see above *\/<\/span>;\n\n  <span style=\"color: #0099FF; font-style: italic\">\/\/ name and location<\/span>\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> identifier_of(info r) <span style=\"color: #555555\">-&gt;<\/span> string_view;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> u8identifier_of(info r) <span style=\"color: #555555\">-&gt;<\/span> u8string_view;\n\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> display_string_of(info r) <span style=\"color: #555555\">-&gt;<\/span> string_view;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> u8display_string_of(info r) <span style=\"color: #555555\">-&gt;<\/span> u8string_view;\n\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> source_location_of(info r) <span style=\"color: #555555\">-&gt;<\/span> source_location;\n\n  <span style=\"color: #0099FF; font-style: italic\">\/\/ type queries<\/span>\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> type_of(info r) <span style=\"color: #555555\">-&gt;<\/span> info;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> parent_of(info r) <span style=\"color: #555555\">-&gt;<\/span> info;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> dealias(info r) <span style=\"color: #555555\">-&gt;<\/span> info;\n\n  <span style=\"color: #0099FF; font-style: italic\">\/\/ object and value queries<\/span>\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> object_of(info r) <span style=\"color: #555555\">-&gt;<\/span> info;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> value_of(info r) <span style=\"color: #555555\">-&gt;<\/span> info;\n\n  <span style=\"color: #0099FF; font-style: italic\">\/\/ template queries<\/span>\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> template_of(info r) <span style=\"color: #555555\">-&gt;<\/span> info;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> template_arguments_of(info r) <span style=\"color: #555555\">-&gt;<\/span> vector<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;<\/span>;\n\n  <span style=\"color: #0099FF; font-style: italic\">\/\/ member queries<\/span>\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> members_of(info type_class) <span style=\"color: #555555\">-&gt;<\/span> vector<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> bases_of(info type_class) <span style=\"color: #555555\">-&gt;<\/span> vector<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> static_data_members_of(info type_class) <span style=\"color: #555555\">-&gt;<\/span> vector<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> nonstatic_data_members_of(info type_class) <span style=\"color: #555555\">-&gt;<\/span> vector<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> subobjects_of(info type_class) <span style=\"color: #555555\">-&gt;<\/span> vector<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> enumerators_of(info type_enum) <span style=\"color: #555555\">-&gt;<\/span> vector<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;<\/span>;\n\n  <span style=\"color: #0099FF; font-style: italic\">\/\/ member access<\/span>\n  <span style=\"color: #006699; font-weight: bold\">struct<\/span> access_context {\n    <span style=\"color: #006699; font-weight: bold\">static<\/span> consteval access_context current() noexcept;\n    consteval access_context() noexcept;\n  };\n\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> <span style=\"color: #CC00FF\">is_accessible<\/span>(\n          info r,\n          acess_context from <span style=\"color: #555555\">=<\/span> access_context<span style=\"color: #555555\">::<\/span>current());\n\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> accessible_members_of(\n          info target,\n          access_context from <span style=\"color: #555555\">=<\/span> access_context<span style=\"color: #555555\">::<\/span>current()) <span style=\"color: #555555\">-&gt;<\/span> vector<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> accessible_bases_of(info target,\n          info target,\n          access_context from <span style=\"color: #555555\">=<\/span> access_context<span style=\"color: #555555\">::<\/span>current()) <span style=\"color: #555555\">-&gt;<\/span> vector<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> accessible_nonstatic_data_members_of(\n          info target,\n          access_context from <span style=\"color: #555555\">=<\/span> access_context<span style=\"color: #555555\">::<\/span>current()) <span style=\"color: #555555\">-&gt;<\/span> vector<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> accessible_static_data_members_of(\n          info target,\n          access_context from <span style=\"color: #555555\">=<\/span> access_context<span style=\"color: #555555\">::<\/span>current()) <span style=\"color: #555555\">-&gt;<\/span> vector<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> accessible_subobjects_of(\n          info target,\n          access_context from <span style=\"color: #555555\">=<\/span> access_context<span style=\"color: #555555\">::<\/span>current()) <span style=\"color: #555555\">-&gt;<\/span> vector<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;<\/span>;\n\n  <span style=\"color: #0099FF; font-style: italic\">\/\/ substitute<\/span>\n  <span style=\"color: #006699; font-weight: bold\">template<\/span> <span style=\"color: #555555\">&lt;<\/span>reflection_range R <span style=\"color: #555555\">=<\/span> initializer_list<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;&gt;<\/span>\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> can_substitute(info templ, R<span style=\"color: #555555\">&amp;&amp;<\/span> args) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  <span style=\"color: #006699; font-weight: bold\">template<\/span> <span style=\"color: #555555\">&lt;<\/span>reflection_range R <span style=\"color: #555555\">=<\/span> initializer_list<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;&gt;<\/span>\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> substitute(info templ, R<span style=\"color: #555555\">&amp;&amp;<\/span> args) <span style=\"color: #555555\">-&gt;<\/span> info;\n\n  <span style=\"color: #0099FF; font-style: italic\">\/\/ reflect_invoke<\/span>\n  <span style=\"color: #006699; font-weight: bold\">template<\/span> <span style=\"color: #555555\">&lt;<\/span>reflection_range R <span style=\"color: #555555\">=<\/span> initializer_list<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;&gt;<\/span>\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> reflect_invoke(info target, R<span style=\"color: #555555\">&amp;&amp;<\/span> args) <span style=\"color: #555555\">-&gt;<\/span> info;\n  <span style=\"color: #006699; font-weight: bold\">template<\/span> <span style=\"color: #555555\">&lt;<\/span>reflection_range R1 <span style=\"color: #555555\">=<\/span> initializer_list<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;<\/span>, reflection_range R2 <span style=\"color: #555555\">=<\/span> initializer_list<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;&gt;<\/span>\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> reflect_invoke(info target, R1<span style=\"color: #555555\">&amp;&amp;<\/span> tmpl_args, R2<span style=\"color: #555555\">&amp;&amp;<\/span> args) <span style=\"color: #555555\">-&gt;<\/span> info;\n\n  <span style=\"color: #0099FF; font-style: italic\">\/\/ reflect expression results<\/span>\n  <span style=\"color: #006699; font-weight: bold\">template<\/span> <span style=\"color: #555555\">&lt;<\/span><span style=\"color: #006699; font-weight: bold\">typename<\/span> T<span style=\"color: #555555\">&gt;<\/span>\n    consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> reflect_value(T value) <span style=\"color: #555555\">-&gt;<\/span> info;\n  <span style=\"color: #006699; font-weight: bold\">template<\/span> <span style=\"color: #555555\">&lt;<\/span><span style=\"color: #006699; font-weight: bold\">typename<\/span> T<span style=\"color: #555555\">&gt;<\/span>\n    consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> reflect_object(T<span style=\"color: #555555\">&amp;<\/span> value) <span style=\"color: #555555\">-&gt;<\/span> info;\n  <span style=\"color: #006699; font-weight: bold\">template<\/span> <span style=\"color: #555555\">&lt;<\/span><span style=\"color: #006699; font-weight: bold\">typename<\/span> T<span style=\"color: #555555\">&gt;<\/span>\n    consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> reflect_function(T<span style=\"color: #555555\">&amp;<\/span> value) <span style=\"color: #555555\">-&gt;<\/span> info;\n\n  <span style=\"color: #0099FF; font-style: italic\">\/\/ extract<\/span>\n  <span style=\"color: #006699; font-weight: bold\">template<\/span> <span style=\"color: #555555\">&lt;<\/span><span style=\"color: #006699; font-weight: bold\">typename<\/span> T<span style=\"color: #555555\">&gt;<\/span>\n    consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> extract(info) <span style=\"color: #555555\">-&gt;<\/span> T;\n\n  <span style=\"color: #0099FF; font-style: italic\">\/\/ other type predicates (see the wording)<\/span>\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_public(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_protected(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_private(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_virtual(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_pure_virtual(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_override(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_final(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_deleted(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_defaulted(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_explicit(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_noexcept(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_bit_field(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_enumerator(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_const(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_volatile(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_lvalue_reference_qualified(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_rvalue_reference_qualified(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> has_static_storage_duration(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> has_thread_storage_duration(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> has_automatic_storage_duration(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> has_internal_linkage(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> has_module_linkage(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> has_external_linkage(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> has_linkage(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_class_member(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_namespace_member(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_nonstatic_data_member(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_static_member(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_base(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_data_member_spec(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_namespace(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_function(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_variable(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_type(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_type_alias(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_namespace_alias(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_complete_type(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_template(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_function_template(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_variable_template(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_class_template(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_alias_template(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_conversion_function_template(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_operator_function_template(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_literal_operator_template(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_constructor_template(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_concept(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_structured_binding(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_value(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_object(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> has_template_arguments(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> has_default_member_initializer(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_special_member(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_conversion_function(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_operator_function(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_literal_operator(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_constructor(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_default_constructor(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_copy_constructor(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_move_constructor(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_assignment(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_copy_assignment(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_move_assignment(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_destructor(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> is_user_provided(info r) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">bool<\/span>;\n\n  <span style=\"color: #0099FF; font-style: italic\">\/\/ define_class<\/span>\n  <span style=\"color: #006699; font-weight: bold\">struct<\/span> <span style=\"color: #007788; font-weight: bold\">data_member_options_t<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> data_member_spec(info type_class,\n                                  <span style=\"color: #007788; font-weight: bold\">data_member_options_t<\/span> options <span style=\"color: #555555\">=<\/span> {}) <span style=\"color: #555555\">-&gt;<\/span> info;\n  <span style=\"color: #006699; font-weight: bold\">template<\/span> <span style=\"color: #555555\">&lt;<\/span>reflection_range R <span style=\"color: #555555\">=<\/span> initializer_list<span style=\"color: #555555\">&lt;<\/span>info<span style=\"color: #555555\">&gt;&gt;<\/span>\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> define_class(info type_class, R<span style=\"color: #555555\">&amp;&amp;<\/span>) <span style=\"color: #555555\">-&gt;<\/span> info;\n\n  <span style=\"color: #0099FF; font-style: italic\">\/\/ define_static_string<\/span>\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> define_static_string(string_view str) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #006699; font-weight: bold\">const<\/span> <span style=\"color: #007788; font-weight: bold\">char<\/span> <span style=\"color: #555555\">*<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> define_static_string(u8string_view str) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #006699; font-weight: bold\">const<\/span> <span style=\"color: #007788; font-weight: bold\">char8_t<\/span> <span style=\"color: #555555\">*<\/span>;\n\n  <span style=\"color: #0099FF; font-style: italic\">\/\/ data layout<\/span>\n  <span style=\"color: #006699; font-weight: bold\">struct<\/span> member_offsets {\n    <span style=\"color: #007788; font-weight: bold\">size_t<\/span> bytes;\n    <span style=\"color: #007788; font-weight: bold\">size_t<\/span> bits;\n    constexpr <span style=\"color: #006699; font-weight: bold\">auto<\/span> total_bits() <span style=\"color: #006699; font-weight: bold\">const<\/span> <span style=\"color: #555555\">-&gt;<\/span> . double quote. double quote. double quote. double quote. <span style=\"color: #007788; font-weight: bold\">size_t<\/span>;\n    <span style=\"color: #006699; font-weight: bold\">auto<\/span> <span style=\"color: #006699; font-weight: bold\">operator<\/span><span style=\"color: #555555\">&lt;=&gt;<\/span>(member_offsets <span style=\"color: #006699; font-weight: bold\">const<\/span><span style=\"color: #555555\">&amp;<\/span>) <span style=\"color: #006699; font-weight: bold\">const<\/span> <span style=\"color: #555555\">=<\/span> <span style=\"color: #006699; font-weight: bold\">default<\/span>;\n  };\n\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> offset_of(info entity) <span style=\"color: #555555\">-&gt;<\/span> member_offsets;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> size_of(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">size_t<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> alignment_of(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">size_t<\/span>;\n  consteval <span style=\"color: #006699; font-weight: bold\">auto<\/span> bit_size_of(info entity) <span style=\"color: #555555\">-&gt;<\/span> <span style=\"color: #007788; font-weight: bold\">size_t<\/span>;\n\n}\n<\/pre><\/div>\n\n\n\n<p>First of all, the metafunctions may remind you of the <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/header\/type_traits\">type traits<\/a> metafunctions. There&#8217;s a big difference. The type traits metafunctions are declared as <code>constexpr<\/code>, but the reflection metafunctions as <code>consteval<\/code>. This means the type traits metafunctions can run at compile time, but the reflection metafunctions must run at compile time. Consequently, the arguments must be constant expressions.<\/p>\n\n\n\n<p>Now, let&#8217;s have a closer look<\/p>\n\n\n\n<p>The reflection library has metafunctions for<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Returns the name or location<\/li>\n\n\n\n<li>Returns the reflection value from a type, object and value, template, and member<\/li>\n\n\n\n<li>Returns the member access <\/li>\n\n\n\n<li>Returns the reflection on the template arguments <\/li>\n\n\n\n<li>Returns the result of a call expression<\/li>\n\n\n\n<li>Returns the result of the evaluated expression<\/li>\n\n\n\n<li>Extract in the value similar to the splicers<\/li>\n<\/ul>\n\n\n\n<p>Furthermore, the reflection library has more than 50 compile time predicates. A compile time predicate is a callable which returns <code>bool <\/code>at compile time.<\/p>\n\n\n\n<p>Additionally, there are metafunctions to define a class.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s next?<\/h2>\n\n\n\n<p> In my next post, I will apply the metafunctions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Reflection offers many metafunctions that run at compile time. The metafunctions are declared as consteval. consteval creates a so-called immediate function. Each invocation of an immediate function creates a compile-time constant. To say it more directly. A consteval (immediate) function is executed at compile-time. Read more about consteval and constinit in my previous post: Two [&hellip;]<\/p>\n","protected":false},"author":21,"featured_media":10083,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[559],"tags":[560],"class_list":["post-10109","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c26-blog","tag-reflection"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/10109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=10109"}],"version-history":[{"count":19,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/10109\/revisions"}],"predecessor-version":[{"id":10145,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/10109\/revisions\/10145"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/10083"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=10109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=10109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=10109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}