C++26 introduces static reflection, and this tutorial demonstrates how to build a universal printer/formatter using it. Starting with the lift operator (^^) to enter the reflection domain and the splice operator ([: :]) to return to the code domain, the guide walks through querying struct members via nonstatic_data_members_of(), handling access contexts (public vs private), and implementing a custom std::formatter. The tutorial progressively covers inheritance (bases_of()), unnamed types (has_identifier()), and enum formatting (enumerators_of()), culminating in a complete UniversalFormatter that can print any struct's members — including private ones and base class fields — by name and value.
Table of contents
Our missionThe Lift operatorThe members of a structDifferent types of access_contextCustom formatterInheritanceThere’s more, to be completeEnumerationRecap69 Impressions