VoidBufferAsArrayOf

Struct template which wraps a void[] with an API allowing it to be safely used as an array of another type.

Members

Functions

array
T[] array()
length
size_t length()
length
void length(size_t len)

Sets the length of the array.

opOpAssign
T[] opOpAssign(T[] arr)

Appends an array of elements.

opOpAssign
T[] opOpAssign(T element)

Appends an element.

Parameters

T

element type of array which the API mimics

Examples

// Backing array.
void[] backing;

// Wrap the backing array for use as an S[].
struct S
{
    ubyte b;
    hash_t h;
}

auto s_array = VoidBufferAsArrayOf!(S)(&backing);

// Append some elements.
s_array ~= S();
s_array ~= [S(), S(), S()];

// Resize the array.
s_array.length = 2;

// Iterate over the elements.
foreach ( e; s_array.array() ) { }

Meta