ubyte [] toByteArray (T) (T t) {
return (cast(ubyte *)&t)[0..T.sizeof].dup
}
> Is there a reason for this explicit cast not to work automatically? (I
> know that templates can alleviate this)
>
> E.g.
>
> struct Foo
> {
> int a;
> float b;
> }
Foo f;
auto b = toByteArray!(Foo)(f); // Yay!
Hope that helps. :P
>
> --
> Luís