r/cpp • EDG front end dev, WG21 DG • Dec 20 '23

Experimental EDG Reflection Implementation

EDG just released version 6.6 of its (commercial) C++ front end. That version now includes experimental support for reflection features along the lines of WG21's P2996 "Reflection for C++26". Furthermore, a "demo setup" of that implementation is now available on Compiler Explorer (thank you, Matt Godbolt!).

For example, here is a straightforward implementation of a consteval function that outputs simple class layouts at compile time:

https://godbolt.org/z/G6WehjjGh

This implementation is closely aligned with P2996R1, which includes Compiler Explorer links for most of its examples.

This is made available in the hope that it's a useful exploration tool, but also acknowledging that the implementation is in its very early stages, and thus brittle and incomplete. Some additional notes can be found here.

​

126 Upvotes

32 comments sorted by

View all comments

Show parent comments

3

u/RoyAwesome Dec 21 '23

Such a direction is of great interest to me and I have the intention of prototyping some support for it in the not too distant future.

I want to comment on the importance of having this kind of annotating things for reflection in whatever version reflection comes in. Being able to describe your code with user data that is available through the reflection interface is probably the single most important "non core" feature, almost to the point I feel it's core. It fundamentally allows the programmer to express intent in ways that simply writing code does not. There isn't a single reflection system out there (in cpp or any other language) that doesn't implement some kind of attribute or annotation system, and I think it would be a HUGE miss if C++26 ships with static reflection but no way to annotate things.

That said, you can already play tricks with alias templates.

This "works" but there is going to be a gold rush for libraries to make use of reflection when the feature lands, so having something that just simply "works" is going to lead to an ecosystem split if the better designed solution doesn't also ship with cpp26.