API

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Tue May 6 13:14:49 PDT 2014


On Tue, 06 May 2014 15:32:23 -0400, Dmitry Olshansky  
<dmitry.olsh at gmail.com> wrote:

> 06-May-2014 04:10, Andrei Alexandrescu пишет:
>> So I'm looking at creation functions and in particular creation
>> functions for arrays.
>>
>> 1. Follow the new int[n] convention:
>>
>> auto a = allok.make!(int[])(42);
>> assert(a.length == 42);
>> assert(a.equal(repeat(0, 42));
>
> Have this primitive to keep it simple.
> (i.e. make => pass args to "ctor")
> Especially in the case of int[][][] and such.

I agree with the spirit of your idea, but not the implementation.

make!T(args) should build an instance of that type on the heap, and then  
call it's constructor.

In the case of T == int[], it should mean put an int[] on the heap, not  
allocate a block, and give me an int[] reference to it.

Array is a special case IMO, and deserves its own primitive.

-Steve


More information about the Digitalmars-d mailing list