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.
							
						Module std.array
Functions and types that manipulate built-in arrays and associative arrays.
This module provides all kinds of functions to create, manipulate or convert arrays:
| Function Name | Description | 
|---|---|
| array | Returns a copy of the input in a newly allocated dynamic array. | 
| appender | Returns a new AppenderorRefAppenderinitialized with a given array. | 
| assocArray | Returns a newly allocated associative array from a range of key/value tuples. | 
| byPair | Construct a range iterating over an associative array by key/value tuples. | 
| insertInPlace | Inserts into an existing array at a given position. | 
| join | Concatenates a range of ranges into one array. | 
| minimallyInitializedArray | Returns a new array of type T. | 
| replace | Returns a new array with all occurrences of a certain subrange replaced. | 
| replaceFirst | Returns a new array with the first occurrence of a certain subrange replaced. | 
| replaceInPlace | Replaces all occurrences of a certain subrange and puts the result into a given array. | 
| replaceInto | Replaces all occurrences of a certain subrange and puts the result into an output range. | 
| replaceLast | Returns a new array with the last occurrence of a certain subrange replaced. | 
| replaceSlice | Returns a new array with a given slice replaced. | 
| replicate | Creates a new array out of several copies of an input array or range. | 
| sameHead | Checks if the initial segments of two arrays refer to the same place in memory. | 
| sameTail | Checks if the final segments of two arrays refer to the same place in memory. | 
| split | Eagerly split a range or string into an array. | 
| uninitializedArray | Returns a new array of type Twithout initializing its elements. | 
Functions
| Name | Description | 
|---|---|
| 
									appender()
								 | Convenience function that returns an Appenderinstance,
    optionally initialized witharray. | 
| 
									appender(arrayPtr)
								 | Convenience function that returns a RefAppenderinstance initialized
    witharrayPtr. Don't use null for the array pointer, use the other
    version ofappenderinstead. | 
| 
									array(r)
								 | Allocates an array and initializes it with copies of the elements
 of range r. | 
| 
									array(str)
								 | Convert a narrow string to an array type that fully supports random access.
This is handled as a special case and always returns an array of dchar | 
| 
									assocArray(r)
								 | Returns a newly allocated associative array from a range of key/value tuples. | 
| 
									byPair(aa)
								 | Construct a range iterating over an associative array by key/value tuples. | 
| 
									insertInPlace(array, pos, stuff)
								 | Inserts stuff(which must be an input range or any number of
    implicitly convertible items) inarrayat positionpos. | 
| 
									join(ror, sep)
								 | Eagerly concatenates all of the ranges in rortogether (with the GC)
   into one array usingsepas the separator if present. | 
| 
									minimallyInitializedArray(sizes)
								 | Returns a new array of type Tallocated on the garbage collected heap. | 
| 
									overlap(a, b)
								 | Returns the overlapping portion, if any, of two arrays. Unlike equal,overlaponly compares the pointers and lengths in the
ranges, not the values referred by them. Ifr1andr2have an
overlapping slice, returns that slice. Otherwise, returns the null
slice. | 
| 
									replace(subject, from, to)
								 | Replace occurrences of fromwithtoinsubjectin a new array. | 
| 
									replace(subject, from, to, stuff)
								 | Replaces elements from arraywith indices ranging fromfrom(inclusive) toto(exclusive) with the rangestuff. | 
| 
									replaceFirst(subject, from, to)
								 | Replaces the first occurrence of fromwithtoinsubject. | 
| 
									replaceInPlace(array, from, to, stuff)
								 | Replaces elements from arraywith indices ranging fromfrom(inclusive) toto(exclusive) with the rangestuff. Expands or
    shrinks the array as needed. | 
| 
									replaceInto(sink, subject, from, to)
								 | Replace occurrences of fromwithtoinsubjectand output the result intosink. | 
| 
									replaceLast(subject, from, to)
								 | Replaces the last occurrence of fromwithtoinsubject. | 
| 
									replaceSlice(s, slice, replacement)
								 | Creates a new array such that the items in sliceare replaced with the
    items inreplacement.sliceandreplacementdo not need to be the
    same length. The result will grow or shrink based on the items given. | 
| 
									replicate(s, n)
								 | |
| 
									sameHead(lhs, rhs)
								 | Returns whether the fronts oflhsandrhsboth refer to the
    same place in memory, making one of the arrays a slice of the other which
    starts at index0. | 
| 
									sameTail(lhs, rhs)
								 | Returns whether the backs oflhsandrhsboth refer to the
    same place in memory, making one of the arrays a slice of the other which
    end at index$. | 
| 
									split(s)
								 | Eagerly splits rangeinto an array, usingsepas the delimiter. | 
| 
									staticArray(a)
								 | Constructs a static array from a.
The type of elements can be specified implicitly so that[1, 2]results inint[2],
or explicitly, e.g.[1, 2]returnsfloat[2].
Whenais a range whose length is not known at compile time, the number of elements must be
given as template argument (e.g.myrange).
Size and type can be combined, if the source range elements are implicitly
convertible to the requested element type (eg:2).
When the rangeais known at compile time, it can also be specified as a
template argument to avoid having to specify the number of elements
(e.g.:staticArray!(2orstaticArray!(double, 2). | 
| 
									uninitializedArray(sizes)
								 | Returns a new array of type Tallocated on the garbage collected heap
without initializing its elements. This can be a useful optimization if every
element will be immediately initialized.Tmay be a multidimensional
array. In this case sizes may be specified for any number of dimensions from 0
to the number inT. | 
Structs
| Name | Description | 
|---|---|
| 
									Appender
								 | Implements an output range that appends data to an array. This is
recommended over array ~= datawhen appending many elements because it is more
efficient.Appendermaintains its own array metadata locally, so it can avoid
global locking for each append wherecapacityis non-zero. | 
| 
									RefAppender
								 | A version of Appenderthat 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. | 
Authors
License
					Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.