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 && !isAutodecodableString!Range && !isInfinite!Range);
ForeachType!(PointerTarget!Range)[] array(Range)
(
Range r
)
if (isPointer!Range && isIterable!(PointerTarget!Range) && !isAutodecodableString!Range && !isInfinite!Range);
Narrow strings are handled as follows: - If autodecoding is turned on (default), then they are handled as a separate overload. - If autodecoding is turned off, then this is equivalent to duplicating the array.
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 autodecoding string to an array type that fully supports
random access. This is handled as a special case and always returns an array
of dchar
CopyTypeQualifiers!(ElementType!String,dchar)[] array(String)
(
scope String str
)
if (isAutodecodableString!String);
NOTE
This function is never used when autodecoding is turned off.
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;
import std .traits : isAutodecodableString;
// note that if autodecoding is turned off, `array` will not transcode these.
static if (isAutodecodableString!string)
writeln("Hello D" .array); // "Hello D"d
else
writeln("Hello D" .array); // "Hello D"
static if (isAutodecodableString!wstring)
writeln("Hello D"w .array); // "Hello D"d
else
writeln("Hello D"w .array); // "Hello D"w
static assert(isRandomAccessRange!dstring == true);
Authors
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.