Practical Reflection With C++26 - Barry Revzin - CppCon 2025
[HPP] Katie LedeckyFebruary 18, 20261h 7min
28 connections·40 entities in this video→C++26 Reflection Overview
- 💡 The adoption of Reflection for C++26 significantly expands what's possible in C++ programming.
- 🎯 This talk demonstrates reflection by implementing a Struct-of-Arrays (SOA) vector for arbitrary aggregate types.
- 🔑 The primary goal of reflection is to enable the creation of easy-to-use libraries, such as an SOA vector that "just works" without complex user code.
Core Reflection Mechanisms
- 🛠️ C++26 reflection provides a narrow code generation mechanism to populate incomplete types with specific non-static data members.
- 🚀 This is achieved using a
constevalblock and callingdefine_aggregatewith a reflection representing the incomplete type. - 🧠 The
substituteandextractpattern is crucial for working with templates and their values, allowing for template instantiation and value retrieval at compile time.
Building the SOA Vector
- ✅ An SOA vector requires the type
Tto be an aggregate, have independently destructible members, and ideally no base classes. - 📝 Type traits can now be written as regular functions (e.g.,
is_aggregate_type) instead of only templates, simplifying constraint checks. - ⚡ Implementing
push_backinvolves iterating over members using structured bindings and new C++26 features like expansion statements andviews::indices. - 🧩 The
define_static_arrayfunction promotes a range to static storage, returning a span, which is useful for compile-time array creation.
Enhancing Functionality with Annotations
- ✨ Annotations (e.g.,
derived_debug,format_as) are a new C++26 feature allowing users to attach metadata to types. - 🔍 These annotations can drive custom behaviors, such as automatic formatting for debugging purposes, by specializing formatters.
- 💬 The
has_annotationfunction checks for specific annotations, andidentifier_ofvs.display_string_ofhandle different naming contexts. - ⚠️ Compile-time exceptions using
meta_exceptioncan provide user-friendly error messages during code generation.
Future of C++ with Reflection
- 📈 Reflection opens up possibilities for creating highly generic and powerful libraries that were previously impossible or overly complex.
- 💡 It blurs the distinction between language features and library features, potentially allowing more features to start as libraries for broader experimentation.
- 🚀 Examples like the
withfunction, which selects members based on parameter names, demonstrate how reflection enables more intuitive and less verbose APIs.
Knowledge graph40 entities · 28 connections
How they connect
An interactive map of every person, idea, and reference from this conversation. Hover to trace connections, click to explore.
Hover · drag to explore
40 entities
Chapters17 moments
Key Moments
Transcript252 segments
Full Transcript
Topics17 themes
What’s Discussed
C++26ReflectionStruct-of-Arrays (SOA)SOA vectorAggregate typesdefine_aggregateconstevalsubstitute and extractType traitsStructured bindingsExpansion statementsdefine_static_arrayAnnotationsCompile-time exceptionsformatterMeta-programmingCode generation
Smart Objects40 · 28 links
People· 3
Concepts· 25
Products· 10
Company· 1
Event· 1