Consistency, Templates, Constructors, and D3

F i L witte2008 at gmail.com
Mon Aug 27 09:15:42 PDT 2012


F i L wrote:
> foobar wrote:
>> I'd expect something like:
>>
>> [ ... ]
>
> Ya, you could always have the Array constructor pass on 
> construction Parameters as well, and I think your examples make 
> sense.

On a side note, you could always invoke Arrays, Dynamic Arrays 
(Lists), and Associative Arrays (Maps) by name (like every other 
object), and use the '[...]' syntax for initializing the size:

     auto a = Array(Point(int))[5].new(1, 2); // static
     auto l = List(Point(int))[5].new(1, 2); // dynamic
     auto m = Map(Point(int), string)[
                  'one',
                  'two',
                  'three',
                  'four',
                  'five'
              ].new(1, 2)

     // shorthands:
     auto a = [0, 1, 2]; // Array(int)[3]
     auto l = [][0, 1, 2]; // List(int)[3]
     auto m = ['z':0, 'o':1, 't':2];
         // Map(int, string)['z', 'o', 't']

this would have the added benefit of being consistent with 
std.containers types, but only the three default one would have 
shorthands:

     import std.containers;

     auto l = List(int)[5];     // object.d
     auto sl = SLinked(int)[5]; // std.containers.d
     auto dl = DLinked(int)[5]; // std.containers.d

IDK though, just a thought.


More information about the Digitalmars-d mailing list