View source code
Display the source code in std/array.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Struct std.array.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.

struct RefAppender(A)
  
if (isDynamicArray!A);

Constructors

NameDescription
this (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.

Properties

NameTypeDescription
capacity[get] size_tReturns 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[get] inout(ElementEncodingType!A)[]

Methods

NameDescription
opDispatch (args) Wraps remaining Appender methods such as put.
opOpAssign (rhs) Appends rhs to the managed array.

Tip

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

Parameters

NameDescription
A The array type to simulate

Example

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

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

Authors

Andrei Alexandrescu and Jonathan M Davis

License

Boost License 1.0.