The OpenD Programming Language

RefAppender

A version of Appender that can update an array in-place. It forwards all calls to an underlying appender implementation. Any calls made to the appender also update the pointer to the original array passed in.

Tip: Use the arrayPtr overload of appender for construction with type-inference.

Constructors

this
this(A* arr)

Constructs a RefAppender with a given array reference. This does not copy the data. If the array has a larger capacity as determined by arr.capacity, it will be used by the appender.

Members

Functions

opDispatch
void opDispatch(Args args)

Wraps remaining Appender methods such as put.

opOpAssign
void opOpAssign(U rhs)

Appends rhs to the managed array.

Properties

capacity
size_t capacity [@property getter]

Returns the capacity of the array (the maximum number of elements the managed array can accommodate before triggering a reallocation). If any appending will reallocate, capacity returns 0.

opSlice
inout(ElementEncodingType!A)[] opSlice [@property getter]

Parameters

A

The array type to simulate

Examples

int[] a = [1, 2];
auto app2 = appender(&a);
assert(app2[] == [1, 2]);
assert(a == [1, 2]);
app2 ~= 3;
app2 ~= [4, 5, 6];
assert(app2[] == [1, 2, 3, 4, 5, 6]);
assert(a == [1, 2, 3, 4, 5, 6]);

app2.reserve(5);
assert(app2.capacity >= 5);

Meta