Templates and stringof...

Era Scarecrow rtcvb32 at yahoo.com
Fri Aug 3 23:00:50 PDT 2012


On Saturday, 4 August 2012 at 03:07:21 UTC, Era Scarecrow wrote:
> Then doesn't it seem like we're missing a potentially important 
> piece of the puzzle for mixins and templates? very likely my 
> modified template will include you including the same variable 
> twice, but if someone gets lazy then it may not work.

  Well I have a working work-around that I need to test further, 
however it does the job; Although for other applications it may 
fail miserably on, and has very limited application.

template bitfieldsOn(string storeName, T...) {
   enum bitfieldsOn = "mixin(bitfieldsOn_b!(\"" ~ storeName ~ 
"\"," ~ storeName ~ TupleToString!(T) ~ "));";
}

template TupleToString(T...) {
   static if (T.length)
     enum TupleToString = "," ~ T[0].stringof ~ TupleToString!(T[1 
.. $]);
   else
     enum TupleToString = "";
}

so this makes...
   mixin(bitfieldsOn!("bits",
     ulong, "back",  32,
     ulong, "", 32));

and becomes:
   mixin(bitfieldsOn_b!("bits",bits,ulong,"back",32,ulong,"",32));



More information about the Digitalmars-d mailing list