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

NOTE: This function is never used when autodecoding is turned off.

  1. ForeachType!Range[] array(Range r)
  2. ForeachType!(PointerTarget!Range)[] array(Range r)
  3. CopyTypeQualifiers!(ElementType!String, dchar)[] array(String str)
    array
    (
    String
    )
    (
    scope String str
    )

Parameters

str String

isNarrowString to be converted to an array of dchar

Return Value

Type: CopyTypeQualifiers!(ElementType!String, dchar)[]

a dchar[], const(dchar)[], or immutable(dchar)[] depending on the constness of the input.

Examples

1 import std.range.primitives : isRandomAccessRange;
2 import std.traits : isAutodecodableString;
3 
4 // note that if autodecoding is turned off, `array` will not transcode these.
5 static if (isAutodecodableString!string)
6     assert("Hello D".array == "Hello D"d);
7 else
8     assert("Hello D".array == "Hello D");
9 
10 static if (isAutodecodableString!wstring)
11     assert("Hello D"w.array == "Hello D"d);
12 else
13     assert("Hello D"w.array == "Hello D"w);
14 
15 static assert(isRandomAccessRange!dstring == true);

Meta

Suggestion Box / Bug Report