On Wednesday, 22 April 2015 at 11:28:44 UTC, Daniel Kozak wrote:
static struct S
{
     immutable FLAG_ON = 1;
     immutable FLAG_GPRS = 2;
     immutable FLAG_HIDDEN = 4;
     ubyte flags;
     ubyte value;

     bool isFlagSet(int flag)
     {
         return flags && flag == flag;
     }
}

void main(string[ ] args)
{
     auto someData = [0x01, 0x10, 0x02, 0x16, 0x04, 0x08];
     auto countS = someData.length / S.sizeof;

     S[] sArray = (cast(S*)someData.ptr)[0 .. countS];
     assert(sArray.length == 3);
}

Reply via email to