bitfields - Default values?

Era Scarecrow rtcvb32 at yahoo.com
Tue Jun 12 04:05:56 PDT 2012


On Tuesday, 5 June 2012 at 00:17:08 UTC, bearophile wrote:
> Era Scarecrow:
>> The documentation for bitfields doesn't go into detail if you 
>> can put any default values into it. Can you?
>
> I think you can't. See:
> http://d.puremagic.com/issues/show_bug.cgi?id=4425
>
> Bye,
> bearophile

  K, I think I have a fix for this done. Now if I bother to get 
GitHub to work with me at all...

  Here's a sample, thoughts of naming or other changes before I 
try and add this back in? (I'm not the best with naming things)


//T is a array of strings of name=value.
//returns a replacement string from bitfields with the defaults 
in place
string bitfields_D(string bitf, T...)();


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

defs s;

assert(!s.b);
assert(s.i == 2);
assert(s.s == 5);


More information about the Digitalmars-d-learn mailing list