Conference | Live Schedule | Talks | Get your ticket | Slides | Set your timezone
C++26 static reflection: All you need is annotations

Dawid Zalewski
On Day 1 at 17:15 (CET/Berlin) in Track A [Saphir Room and online]
Static reflection that shipped with C++26 is primarily a compile-time introspection powerhouse. Luckily, next to inspection, we also got two features that together allow us to use reflection for compile-time code injection. The first is the ability to define arbitrary aggregates with std::meta::define_aggregate. The second is annotations, an amazingly flexible tool for attaching metadata to our code. When combined, they finally make it possible to bring user-friendly features like Rust's #[derive(Debug)] to C++.
In this talk, we will explore the basic building blocks of this approach. Starting with the reflection primitives, we will go through implementing various small yet useful utilities, like a universal structured bindings enabler for any class type or generating secure views of sensitive data with compile-time, annotation-based access control. Finally, we will demonstrate a generic builder that not only can create instances of any aggregate type, but also fully validates all the fields at the runtime with checks attached as annotations to the original type.
Please login to comment