On Tuesday, 12 June 2012 at 13:05:26 UTC, bearophile wrote:
Era Scarecrow:

struct defs {
 mixin(bitfields_D!(
   bitfields!( //borrowed from std.bitmanip
     bool, "b", 1,
     uint, "i", 3,
     short, "s", 4),
   "i=2",
   "s=5"));
}

Are you able to support a syntax like:

struct defs {
 mixin(bitfields!(
     bool, "b", 1,
     uint, "i=2", 3,
     short, "s=5", 4));
}

That does look cleaner and better IMO. At this second I'm not sure. I was trying not to interfere with the original bitfield generator. I'm not as competent with templates as I'd like to be so having it go through and separate the data out seems a lot more difficult than simply replacing the end of the string as I currently have it.

The bitfields as it is creates enums (min/max values), the get, the set, and then at the end has a 'private xxx valname;'. My little function is just a wrapper that builds on it by making the calculations as specified and then modifying the very end of the bitfields string with the answer, in my example that was '84'.

I can try and make it as you have it, but I'm not sure how much harder that will be compared to what it is now; would probably end up as 'private xxx valname = (2<<1) | (5<<4);, which makes sense without adding too much complexity.. unless you go negative numbers, then you have to add a mask... Hmmm.... 'private xxx valname = ((2 & 7) << 1) | ((5 & 15) << 4);'

Reply via email to