dmd.root.array
Dynamic array implementation.
License
Source: root/array.d
Documentation: https://dlang.org/phobos/dmd_root_array.html
-
Declaration
pure nothrow @nogc @property inout(T)[]peekSlice(T)(inout(Array!T)*array);Exposes the given root Array as a standard D
array.Parameters
inout(Array!T)*arraythe
arrayto expose.Return Value
The given
arrayexposed to a standard Darray. -
Declaration
pure nothrow voidsplit(T)(ref Array!Tarray, size_tindex, size_tlength);Splits the
arrayat and expands it to make room for elements by shifting everything past to the right.Parameters
Array!Tarraythe
arraytosplit.size_tindexthe
indextosplitthearrayfrom.size_tlengththe number of elements to make room for starting at .
-
Declaration
pure nothrow @nogc @safe T[]reverse(T)(T[]a);Reverse an array in-place.
Parameters
T[]aarray
Return Value
reversed
a[] -
Declaration
voideach(alias callable, T)(ref Array!Tarray) if (is(ReturnType!(typeof((T t) => callable(t))) == void));Iterates the given
arrayand calls the given callable foreachelement.Discussion
Use this instead of
foreachwhen thearraymay expand during iteration.Parameters
callablethe callable to call for
eachelementArray!Tarraythe
arrayto iterateSee Also
Examples
static immutable expected = [2, 3, 4, 5]; Array!int array; foreach (e ; expected) array.push(e); int[] result; array.each!((e) { result ~= e; }); assert(result == expected);
-
Declaration
inteach(alias callable, T)(ref Array!Tarray) if (is(ReturnType!(typeof((T t) => callable(t))) == int));Iterates the given
arrayand calls the given callable foreachelement.Discussion
If
callablereturns!= 0, it will stop the iteration and return that value, otherwise it will return 0.
Use this instead offoreachwhen thearraymay expand during iteration.Parameters
callablethe callable to call for
eachelementArray!Tarraythe
arrayto iterateReturn Value
the last value returned by
callableSee Also
Examples
Array!int array; foreach (e ; [2, 3, 4, 5]) array.push(e); int[] result; const returnValue = array.each!((e) { result ~= e; if (e == 3) return 8; return 0; }); assert(result == [2, 3]); assert(returnValue == 8);
-
Declaration
T[n]staticArray(T, size_t n)(auto ref T[n]array);Return Value
A static
arrayconstructed from.arrayExamples
enum a = [0, 1].staticArray; static assert(is(typeof(a) == int[2])); static assert(a == [0, 1]);
-
Declaration
boolequal(Range1, Range2)(Range1range1, Range2range2);Return Value
trueif the two given ranges areequalExamples
enum a = [ 1, 2, 4, 3 ].staticArray; static assert(!equal(a[], a[1..$])); static assert(equal(a[], a[])); // different types enum b = [ 1.0, 2, 4, 3].staticArray; static assert(!equal(a[], b[1..$])); static assert(equal(a[], b[]));
-
Declaration
autofilter(alias predicate, Range)(Rangerange) if (isInputRange!(Unqual!Range) && isPredicateOf!(predicate, ElementType!Range));Lazily filters the given
rangebased on the given predicate.Return Value
a
rangecontaining only elements for which the predicate returnstrueExamples
enum a = [1, 2, 3, 4].staticArray; enum result = a[].filter!(e => e > 2); enum expected = [3, 4].staticArray; static assert(result.equal(expected[]));
-
Declaration
automap(alias callable, Range)(Rangerange) if (isInputRange!(Unqual!Range) && isCallableWith!(callable, ElementType!Range));Lazily iterates the given
rangeand calls the given callable for each element.Return Value
a
rangecontaining the result of each call tocallableExamples
enum a = [1, 2, 3, 4].staticArray; enum expected = [2, 4, 6, 8].staticArray; enum result = a[].map!(e => e * 2); static assert(result.equal(expected[]));
-
Declaration
autowalkLength(Range)(Rangerange) if (isInputRange!Range);Return Value
the length of the given
range.Examples
enum a = [1, 2, 3, 4].staticArray; static assert(a[].walkLength == 4); enum c = a[].filter!(e => e > 2); static assert(c.walkLength == 2);
-
Declaration
templateElementType(R)Evaluates to the element type of
R. -
Declaration
enum autoisInputRange(R);Evaluates to
trueif the given type satisfy the input range interface. -
Declaration
enum autoisPredicateOf(alias func, T);Evaluates to
trueiffunccan be called with a value ofTand returns a value that is convertible tobool. -
Declaration
enum autoisCallableWith(alias func, T);Evaluates to
trueiffuncbe called withl a value ofT.