add array/string casts
This commit is contained in:
parent
c7f77523c4
commit
421f903cff
21
util.d
21
util.d
@ -13,6 +13,21 @@ import std.string;
|
|||||||
import core.stdc.string : memset;
|
import core.stdc.string : memset;
|
||||||
import core.simd;
|
import core.simd;
|
||||||
|
|
||||||
|
T[]
|
||||||
|
CastStr(T)(string str)
|
||||||
|
{
|
||||||
|
T[] arr = (cast(T*)str.ptr)[0 .. str.length];
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
T[]
|
||||||
|
CastArr(T, U)(U[] input_array)
|
||||||
|
{
|
||||||
|
static assert(T.sizeof == U.sizeof);
|
||||||
|
T[] output_array = (cast(T*)input_array.ptr)[0 .. input_array.length];
|
||||||
|
return output_array;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Logf(Args...)(string fmt, Args args)
|
Logf(Args...)(string fmt, Args args)
|
||||||
{
|
{
|
||||||
@ -1017,4 +1032,10 @@ unittest
|
|||||||
|
|
||||||
assert(stack.top == &nil);
|
assert(stack.top == &nil);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{ // Casts
|
||||||
|
u8[] arr = CastStr!(u8)("Test");
|
||||||
|
char[] char_arr = ['a', 'b'];
|
||||||
|
arr = CastArr!(u8)(char_arr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user