Skip to content

Commit 727e9d7

Browse files
committed
Add Array.putAsBytes
1 parent 04df0e2 commit 727e9d7

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

source/vox/lib/mem/array.d

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,22 @@ struct Array(T)
7878
return this[_length-howMany.._length];
7979
}
8080

81-
void put(ref VoxAllocator allocator, T[] items...)
81+
void put(ref VoxAllocator allocator, const(T)[] items...)
8282
{
8383
if (_length + items.length > _capacity) extend(allocator, cast(uint)items.length);
8484

8585
_length += items.length;
86-
this[_length-items.length..$][] = items;
86+
this[_length-items.length..$][] = cast(T[])items;
87+
}
88+
89+
static if (is(T == ubyte))
90+
{
91+
void putAsBytes(V)(ref VoxAllocator allocator, auto ref V value)
92+
if (!is(immutable(V) == immutable(I)[], I))
93+
{
94+
ubyte[] ptr = voidPut(allocator, V.sizeof);
95+
ptr[] = *cast(ubyte[V.sizeof]*)&value;
96+
}
8797
}
8898

8999
void putFront(ref VoxAllocator allocator, T item)

0 commit comments

Comments
 (0)