API

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Tue May 6 06:21:33 PDT 2014


On Mon, 05 May 2014 20:10:35 -0400, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> 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));
>
> 2. Follow the [ literal ] convention:
>
> auto a = allok.make!(int[])(42);
> assert(a.length == 1);
> assert(a[0] == 42);

case 1. allok.arrayOf!int(42);

Yes, I know I got rid of the array type as the template parameter, but I  
don't think we want to duplicate the problem of not being able to allocate  
arrays on the heap that we have with 'new'.

case 2. allok.array(42); // Use IFTI

This mirrors std.array.array

In fact, 2 really should be in std.array:

array(Allocator, T...)(Allocator allok, T t) if (isAllocator!Allocator)

-Steve


More information about the Digitalmars-d mailing list