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)*
array
the
array
to expose.Return Value
The given
array
exposed to a standard Darray
. -
Declaration
pure nothrow void
split
(T)(ref Array!Tarray
, size_tindex
, size_tlength
);Splits the
array
at and expands it to make room for elements by shifting everything past to the right.Parameters
Array!T
array
the
array
tosplit
.size_t
index
the
index
tosplit
thearray
from.size_t
length
the 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[]
a
array
Return Value
reversed
a
[] -
Declaration
void
each
(alias callable, T)(ref Array!Tarray
) if (is(ReturnType!(typeof((T t) => callable(t))) == void));Iterates the given
array
and calls the given callable foreach
element.Discussion
Use this instead of
foreach
when thearray
may expand during iteration.Parameters
callable
the callable to call for
each
elementArray!T
array
the
array
to 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
int
each
(alias callable, T)(ref Array!Tarray
) if (is(ReturnType!(typeof((T t) => callable(t))) == int));Iterates the given
array
and calls the given callable foreach
element.Discussion
If
callable
returns!= 0
, it will stop the iteration and return that value, otherwise it will return 0.
Use this instead offoreach
when thearray
may expand during iteration.Parameters
callable
the callable to call for
each
elementArray!T
array
the
array
to iterateReturn Value
the last value returned by
callable
See 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
array
constructed from
.array
Examples
enum a = [0, 1].staticArray; static assert(is(typeof(a) == int[2])); static assert(a == [0, 1]);
-
Declaration
bool
equal
(Range1, Range2)(Range1range1
, Range2range2
);Return Value
true
if the two given ranges areequal
Examples
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
auto
filter
(alias predicate, Range)(Rangerange
) if (isInputRange!(Unqual!Range) && isPredicateOf!(predicate, ElementType!Range));Lazily filters the given
range
based on the given predicate.Return Value
a
range
containing only elements for which the predicate returnstrue
Examples
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
auto
map
(alias callable, Range)(Rangerange
) if (isInputRange!(Unqual!Range) && isCallableWith!(callable, ElementType!Range));Lazily iterates the given
range
and calls the given callable for each element.Return Value
a
range
containing the result of each call tocallable
Examples
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
auto
walkLength
(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
template
ElementType
(R)Evaluates to the element type of
R
. -
Declaration
enum auto
isInputRange
(R);Evaluates to
true
if the given type satisfy the input range interface. -
Declaration
enum auto
isPredicateOf
(alias func, T);Evaluates to
true
iffunc
can be called with a value ofT
and returns a value that is convertible tobool
. -
Declaration
enum auto
isCallableWith
(alias func, T);Evaluates to
true
iffunc
be called withl a value ofT
.