Umm, sounds nice. If you want to store a long into buffer, you can cast the desired position as long* and assign the value. The following is adapted from std.outbuffer, that is another option.<div><div><br></div><div><div>
<font face="'courier new', monospace"> ubyte buffer[];</font></div><div><font face="'courier new', monospace"> size_t offset;</font></div><div><font face="'courier new', monospace"> </font></div>
<div><font face="'courier new', monospace"> ulong a = 1;</font></div><div><font face="'courier new', monospace"> byte b = 2;</font></div><div><font face="'courier new', monospace"> </font></div>
<div><font face="'courier new', monospace"> // allocate space for ulong e byte</font></div><div><font face="'courier new', monospace"> buffer.length = a.sizeof + b.sizeof;</font></div><div><font face="'courier new', monospace"> </font></div>
<div><span style="font-family:'courier new',monospace"> *cast(ulong *)&buffer[offset] = a; // store value</span></div><div><font face="'courier new', monospace"> offset += a.sizeof; // increment offset</font></div>
<div><font face="'courier new', monospace"> </font></div><div><font face="'courier new', monospace"> *cast(byte *)&buffer[offset] = b;</font></div><div><font face="'courier new', monospace"> offset += b.sizeof;</font></div>
<div><br></div><div><br></div>Pedro Lacerda<br><br>
<br><br><div class="gmail_quote">2012/2/8 Era Scarecrow <span dir="ltr"><<a href="mailto:rtcvb32@yahoo.com">rtcvb32@yahoo.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Tuesday, 7 February 2012 at 17:51:42 UTC, Pedro Lacerda wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
You can roll your own tagged union instead. The S struct can store long and<br>
byte[], S.ptr is a pointer to the data.<br>
</blockquote>
<br>
<br></div>
Yep, a bit like my code, except with switch cases covering all major types; That and trying to do comparison and setting functions, which seems a bit much. Testing it using templates and testing all the types seems like a nightmare. I've decided I need to pass it a ubyte array so I could do bounds checking before binding the memory to the union. One fewer things to worry about.<br>
<br>
Let's see... not that I expect you to use this, but I sorta have this as my enum set for types.<br>
<br>
<br>
enum ValueType {<br>
raw = 0x00000000, ///default upon unknown<br>
mask_types = 0xfff00000, ///Upper 4k defines general types, or 12 flag types<br>
mask_size = 0x000fffff, ///lower gives 1Million for size.<br>
<br>
i_types = 0x00100000, ///integars types<br>
i_8 = i_types + byte.sizeof,<br>
i_16 = i_types + short.sizeof,<br>
i_32 = i_types + int.sizeof,<br>
i_64 = i_types + long.sizeof,<br>
<br>
u_types = 0x00200000, ///unsigned numbers<br>
u_8 = u_types + ubyte.sizeof,<br>
u_16 = u_types + ushort.sizeof,<br>
u_32 = u_types + uint.sizeof,<br>
u_64 = u_types + ulong.sizeof,<br>
<br>
floating_types = 0x00400000,<br>
float_32 = floating_types + float.sizeof, fl = float_32,<br>
double_64 = floating_types + double.sizeof, doub = double_64, <br>
<br>
flags_types = 0x00800000,<br>
flags_8 = flags_types + ubyte.sizeof,<br>
flags_16 = flags_types + ushort.sizeof,<br>
flags_32 = flags_types + uint.sizeof,<br>
flags_64 = flags_types + ulong.sizeof,<br>
<br>
ranged_types = 0x01000000,<br>
ranged_8 = ranged_types + ubyte.sizeof,<br>
ranged_16 = ranged_types + ushort.sizeof,<br>
ranged_32 = ranged_types + uint.sizeof,<br>
ranged_64 = ranged_types + ulong.sizeof,<br>
<br>
voidp = 0x02000000, pointer_types = voidp, ///pointers<br>
i_8p, u_8p,<br>
i_16p, u_16p,<br>
i_32p, u_32p,<br>
i_64p, u_64p,<br>
float_32p, double_64p,<br>
<br>
var_str = 0x04000000,<br>
fixed_str = 0x08000000,<br>
var_ustr = 0x10000000,<br>
fixed_ustr = 0x20000000<br>
}<br>
</blockquote></div><br></div></div>