To create a dynamic arrays the following first example is ok, but the second fails, maybe the second method should compile? Also, the documentation does not mention the "abc"[] method to create a dynamic array.
Example
-------
auto str1 = "abc"[]; // OK
auto str2 = ['a', 'b', 'c'][]; // Error, invalid syntax?
Comment #1 by gide — 2008-10-25T05:48:38Z
The following example now compiles in DMD v2.020, but it wasn't mentioned in the changelog, but the docs don't mention "abc"[] as a method of creating dynamic arrays.
test.d
------
import std.stdio;
void main() {
auto str1 = "abc"[]; // OK
auto str2 = ['a', 'b', 'c'][];
writefln(typeof(str1).stringof);
writefln(typeof(str2).stringof);
}
Output
------
invariant(char)[]
char[]
Comment #2 by yebblies — 2011-06-10T05:40:00Z
This now works as array literals are dynamic arrays.