View source code
Display the source code in std/array.d from which this page was generated on
github.
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.
Page wiki
View or edit the community-maintained wiki page associated with this page.
std.array.appender
- multiple declarations
- Function appender
- Function appender
- Struct Appender
Function appender
Convenience function that returns a RefAppender
!Aobject
initialized
with
. Don't use null for the array
pointer, use the other
version of array
instead.
appender
Prototype
RefAppender!(E[]) appender(A, E)( A array );
Function appender
Convenience function that returns an Appender
!Aobject
initialized
with
.
array
Prototypes
Appender!A appender(A)() if (isDynamicArray!A); Appender!(E[]) appender(A, E)( A array );
Struct Appender
Implements an output range that appends data
to an array
. This is
recommended over a ~=
when appending many elements because it is more
efficient.
data
Constructors
Name | Description |
---|---|
this
|
Construct an appender with a given array . Note that 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 . After initializing an appender on an array ,
appending to the original array will reallocate.
|
Properties
Name | Type | Description |
---|---|---|
capacity
[get]
|
size_t |
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, returns 0 .
|
data
[get]
|
inout(T)[] |
Returns the managed array .
|
Methods
Name | Description |
---|---|
reserve
|
Reserve at least newCapacity elements for appending. Note that more elements
may be reserved than requested. If newCapacity <= capacity , then nothing is
done.
|
Templates
Name | Description |
---|---|
opOpAssign
|
Appends one item to the managed array .
|
opOpAssign
|
Appends an entire range to the managed array .
|
put
|
Appends one item to the managed array .
|
put
|
Appends an entire range to the managed array .
|
Example
auto app = appender!string(); string b = "abcdefg"; foreach (char c; b) app.put(c); assert(app.data == "abcdefg"); int[] a = [ 1, 2 ]; auto app2 = appender(a); app2.put(3); app2.put([ 4, 5, 6 ]); assert(app2.data == [ 1, 2, 3, 4, 5, 6 ]);
Authors
Andrei Alexandrescu and Jonathan M Davis