Discussion on static reflection syntax in C++

Stefan Koch uplink.coder at googlemail.com
Tue Feb 23 15:49:14 UTC 2021

On Tuesday, 23 February 2021 at 15:35:43 UTC, Paul Backus wrote:
> On Tuesday, 23 February 2021 at 14:14:13 UTC, Stefan Koch wrote:
>> On Monday, 22 February 2021 at 23:44:45 UTC, Paul Backus wrote:
> I haven't fully thought this through, but would it be possible 
> to overload `mixin` to do this? E.g.,
>     import core.ast: Struct, Type;
>     // some type function
>     Struct pair(Type t) { ... }
>     alias PairOfInts = mixin(pair(int));
> Conceptually, `mixin` already means "take this stuff and inject 
> it into the current scope," and grammatically it's allowed to 
> appear as both an expression and a type.

Yes it would be possible to reuse mixin, but iirc mixins convert 
non-string expressions to string which would introduce ambiguity, 
if I special case it __struct, or __type__.

>> At which point any modification of the __struct* is an error 
>> and will abort compilation.
> If __struct is only the "user-space" representation, and not 
> the real AST node, I don't see why this is necessary, since 
> modifying the __struct after mixing it in wouldn't have any 
> affect on the actual AST.
The restriction is imposed to avoid confusing situations, due to 
the closeness of the mapping to real compiler entities you cannot 
finalize the same struct* twice and such things.
Modifying a __struct after it has been finalized or 'mixed-in' is 
either useless or a bug.

More information about the Digitalmars-d mailing list