Empty array and AA literals

JR zorael at gmail.com
Wed Apr 9 10:33:28 PDT 2014


On Wednesday, 9 April 2014 at 16:46:00 UTC, monarch_dodra wrote:
> I *think* there was some miscommunication here:
> auto arr = new int[](99);
>
> Is perfectly valid, and the recommended way to do it (provided 
> you know how much you want to allocate when constructing).

Looks like it. :)

The flow of conversation reads to me like so:

1. "There's no need to new or create a dynamic array"
2. "But newing allows for setting the length immediately though. 
<example>. Does doing it in two steps (declaring, then setting 
length) allocate twice?"
3. "No, [doing it in two steps] is perfectly valid (and 
recommended), [with valid meaning you're not double-allocating 
for no reason]"
4. "I see, but if [doing it in two steps] is recommended and 
there's no need to new, you'll have to agree that newing is still 
alluring etc etc"


>> My main pet peeve remains array literals being dynamic.
>
> What do you mean? Perhaps you meant you wanted to allocate a 
> static array on the heap? EG, "int[99]* p = new ???;"
>
> Otherwise, I don't really understand the statement.

Different topic, but I mean !is(typeof([1, 2, 3]) == int[3]). 
Nothing that can't be danced around, yet a peeve nonetheless.


More information about the Digitalmars-d-learn mailing list