[OT] Generative C++

Stefan Koch via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 28 15:33:05 PDT 2017


On Friday, 28 July 2017 at 22:12:32 UTC, Kagamin wrote:
> On Friday, 28 July 2017 at 15:41:28 UTC, 12345swordy wrote:
>> ... That's not what I consider to be "simple" (Hard to read 
>> IMO).
>
> struct DblRep
> {
>   mixin(bitfieldString([
>     BitFieldDesc(Type.Ulong, "fraction", 23),
>     BitFieldDesc(Type.Ushort, "exponent", 8),
>     BitFieldDesc(Type.Bool, "sign", 1)
>   ]));
> }
>
> With macros would look like
>
> struct DblRep
> {
>   @BitFields
>   struct
>   {
>     @23 ulong fraction;
>     @8 ushort exponent;
>     @1 bool sign;
>   }
> }

The great thing about string-mixins is that you can explain 
easily and they have an understandable representation which you 
can dump out easily.

Whereas with AST macros you need to understand the macro and can 
not as easily dump the output.



More information about the Digitalmars-d mailing list