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 arrayarrayappender
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 appenderwith a givenarray.  Note that this does not copy thedata.  If thearrayhas a largercapacityas determined by arr.capacity,
 it will be used by theappender.  After initializing anappenderon anarray,
 appending to the originalarraywill reallocate. | 
Properties
| Name | Type | Description | 
|---|---|---|
| capacity[get] | size_t | Returns the capacityof thearray(the maximum number of elements the
 managedarraycan accommodate before triggering a reallocation).  If any
 appending will reallocate,returns0. | 
| data[get] | inout(T)[] | Returns the managed array. | 
Methods
| Name | Description | 
|---|---|
| reserve | Reserve at least newCapacityelements for appending.  Note that more elements
 may be reserved than requested.  IfnewCapacity<=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