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.
std.array.array
- multiple declarations
Function array
Allocates an array and initializes it with copies of the elements
of range r
.
ForeachType!Range[] array(Range)
(
Range r
)
if (isIterable!Range && !isNarrowString!Range && !isInfinite!Range);
ForeachType!(PointerTarget!Range)[] array(Range)
(
Range r
)
if (isPointer!Range && isIterable!(PointerTarget!Range) && !isNarrowString!Range && !isInfinite!Range);
Narrow strings are handled as a special case in an overload.
Parameters
Name | Description |
---|---|
r | range (or aggregate with opApply function) whose elements are copied into the allocated array |
Returns
allocated and initialized array
Example
auto a = array([1, 2, 3, 4, 5][]);
writeln(a); // [1, 2, 3, 4, 5]
Function array
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
Parameters
Name | Description |
---|---|
str | isNarrowString to be converted to an array of dchar |
Returns
a dchar[]
, const(dchar)[]
, or immutable(dchar)[]
depending on the constness of
the input.
Example
import std .range .primitives : isRandomAccessRange;
writeln("Hello D" .array); // "Hello D"d
static assert(isRandomAccessRange!string == false);
writeln("Hello D"w .array); // "Hello D"d
static assert(isRandomAccessRange!dstring == true);
Authors
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.