Discussion on static reflection syntax in C++

Paul Backus snarwin at gmail.com
Tue Feb 23 16:10:26 UTC 2021

On Tuesday, 23 February 2021 at 15:49:14 UTC, Stefan Koch wrote:
> 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__.

My gut feeling is that it would not be too difficult to 
understand in practice, but yes, it would require special-casing.

> 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.

Actually, now that I think of it, wouldn't the existing CTFE 
semantics prevent you from doing this anyway?

enum __struct s = someTypeFunction();
auto modify(ref __struct s) { ... }
enum result = modify(s); // Error: can't modify rvalue

Or if you tried to do it inside a type function:

auto someTypeFunction(...) {
     __struct s = ...;
     alias Before = mixin(s); // Error: can't read `s` at compile 

More information about the Digitalmars-d mailing list