Is there a way to slice non-array type in @safe?

Stefanos Baziotis sdi1600105 at di.uoa.gr
Thu Jul 11 16:31:58 UTC 2019


I searched the forum but did not find something.

I want to do this:

int foo(T)(ref T s1, ref T s2)
{
     const byte[] s1b = (cast(const(byte)*)&s1)[0 .. T.sizeof];
     const byte[] s2b = (cast(const(byte)*)&s2)[0 .. T.sizeof];
}

Which is to create a byte array from the bytes of the value 
given, no matter
the type. The above works, but it's not @safe.

Thanks,
Stefanos


More information about the Digitalmars-d-learn mailing list