C++14 Reflections Without Macros, Markup nor External Tooling..
summary
A compile-time reflection technique for C++14 uses aggregate initialization probing plus variadic templates, constexpr, SFINAE, decltype and an implicit conversion operator to count fields and implicit conversion to capture field types, producing a std::tuple-like type map at compile time. It handles nested PODs (by flattening), const/volatile and multi-level pointers (encoding pointer bits into type IDs), and enums (by using their underlying type), and ships as apolukhin/magic_get (now pfr) on GitHub. It works and compiles fast (binary-search field detection); limitations include flattening, some loss of enum identity, and a reinterpret_cast workaround in C++14 that C++17 structured bindings can remove.
AI-written summary · about
chapters (31)
- 0:00Introduction to reflection
- 1:06How magic_get works
- 3:15Counting fields in structures
- 7:36Detecting fields count implementation
- 10:04Extracting field types
- 12:59Encoding fundamental types
- 15:29Extracting field information
- 17:36Accessing fields by index
- 18:41Handling pointer types
- 21:36Encoding pointer types
- 23:21Handling nested structures
- 25:52Copying type identifiers
- 29:52Examples and use cases
- 31:19Comparison operators
- 32:41Serialization benefits
- 34:28Compile time performance
- 35:55Practical examples
- 37:44Flat tie function
- 38:47Fixing constexpr issues
- 39:50C++17 structured binding
- 41:37Conclusion and thanks
- 43:03Q&A: C++11 compatibility
- 44:06Q&A: Aggregate initialization
- 45:11Q&A: Reinterpret cast alternatives
- 46:39Q&A: Flattening limitations
- 48:30Q&A: Future of reflection
- 48:53Q&A: C++11 implementation details
- 49:58Q&A: Russian accent appreciation
- 50:20Q&A: Bit fields support
- 51:27Q&A: Nested structure layout
- 54:06Q&A: Function argument reflection
related talks
01h 01mReflection
01h 27mC++ Reflection - Back on Track
01h 37mReflection: Compile-Time Introspection of C++
36mCompile-time reflection, Serialization and ORM
01h 03mC++ Reflection: Back on Track
01h 08mReflections: Compile-time Introspection of Source Code
05mLightning Talk: Static Reflection on the Budget in C++23
01h 08mKeynote: Reflection in C++26 - Welcome to v0.1 of the meta::[[verse]]!
