Auto and empty array
Daniel Kozak via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jun 30 01:27:11 PDT 2014
V Mon, 30 Jun 2014 05:39:36 +0000
Igor via Digitalmars-d <digitalmars-d at puremagic.com> napsáno:
> In case I want to create a new array with size I know, it's very
> convenient to use auto:
> auto a = new int[](13);
> But if I want to create a new, empty array? Then using auto is
> not convenient and I have:
> auto a = new int[](0);
> It seems a bit bloated, compared to int[] a = []. I like using
> auto because of uniform syntax and other reasons. Is there any
> concise way to create a new empty array with auto?
import std.stdio;
void main(string[] args)
{
auto a = new int[13];
auto b = new int[0];
writeln(a.length);
writeln(b.length);
stdin.readln;
}
More information about the Digitalmars-d
mailing list