convert ubyte[k..k + 1] to int
Roman D. Boiko
rb at d-coding.com
Thu May 17 01:15:27 PDT 2012
On Thursday, 17 May 2012 at 07:07:58 UTC, Roman D. Boiko wrote:
> And what about the following code:
>
> // This implementation is optimized for speed via swapping
> endianness in-place
> pure immutable(C)[] fixEndian(C, Endian blobEndian =
> endian)(ubyte[] blob) if(is(CharTypeOf!C))
> {
> import std.bitmanip, std.system;
> auto data = cast(C[]) blob;
> static if(blobEndian != endian)
> {
> static assert(!is(typeof(C) == char)); // UTF-8 doesn't
> have endianness
> foreach(ref ch; data) ch = swapEndian(ch);
> }
> return cast(immutable) data;
> }
I mean, is it safe (assuming that we are allowed to mutate blob,
and its length is a multiple of C.sizeof)?
I do casting from ubyte[] to C[].
More information about the Digitalmars-d-learn
mailing list