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 import std.stdio;
4 assert( eq( a, [2.2, 3.3] ) );
5 a[0] = 10;
6 assert( eq( buf, [1.1, 10, 3.3, 4.4, 5.5] ) );
ubyte[] buf = [ 1, 2, 3, 4 ];
auto a = getTypedArray!void( 4, cast(void*)buf );
assert( eq( 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 assert( eq( fnc( tt ), cast(ubyte[])[0,1,3] ) );