getTypedArray

getTypedArray
pure nothrow
(
T
X
)
(
size_t sz
,
X* addr
)

Examples

1 float[] buf = [ 1.1f, 2.2, 3.3, 4.4, 5.5 ];
2 auto a = getTypedArray!float( 2, cast(void*)(buf.ptr + 1) );
3 assertEq( a, [2.2, 3.3] );
4 a[0] = 10;
5 a[1] = 12;
6 assertEq( buf, [1.1, 10, 12, 4.4, 5.5] );
ubyte[] buf = [ 1, 2, 3, 4 ];
auto a = getTypedArray!void( 4, cast(void*)buf );
assertEq( cast(ubyte[])a, buf );
1 static struct TT { ubyte val; }
2 
3 ubyte[] fnc( in TT[] data ) pure
4 { return getTypedArray!ubyte( data.length, data.ptr ).arr.dup; }
5 
6 auto tt = [ TT(0), TT(1), TT(3) ];
7 assertEq( fnc( tt ), cast(ubyte[])[0,1,3] );

Meta