Syntax for Reflection

submited by
Style Pass
2024-11-24 18:30:03

[P1240R2] originally proposed ^ as the reflection operator, which was also what [P2996R5] proposed and what both existing implementations (EDG and Clang) used. We’ve grown to really like the syntax: it’s terse and stands out visually.

Unfortunately, it turns out that ^ is not a viable choice for reflection for C++26, due to the collision with the block extension used by Clang and commonly used in Objective-C++.

This gets worse with the [P3294R1] usage of ^{ ... } as a token sequence. This sequence is completely ambiguous:

The original reflection design did use a keyword — reflexpr(e). But that is far too verbose, which is why the design had changed to ^ to begin with. We would strongly prefer not to go back down that road.

There are not too many single character options available to us, presuming we want to stick with the characters that are easy to type and not just start perusing the available Unicode characters (↑ is available after all). It also makes life much easier if we do not need to add new basic source characters (which a character like ↑ would require).

Leave a Comment