Top 5
Denis Koroskin
2korden at gmail.com
Fri Oct 10 12:28:36 PDT 2008
On Fri, 10 Oct 2008 23:23:28 +0400, Benji Smith <dlanguage at benjismith.net>
wrote:
> Jarrett Billingsley wrote:
>> On Fri, Oct 10, 2008 at 11:54 AM, Benji Smith
>> <dlanguage at benjismith.net> wrote:
>>
>>>> new T[x] is a brain-dead syntax that I wish Walter hadn't imported in
>>>> the
>>>> first place.
>>> Really? I think it's very valuable.
>>>
>>> The "new T[x]" syntax lets you construct an array as an RValue.
>>> Without that
>>> syntax, you have to declare an array before using it.
>> No, what he's getting at is that "new T[x]" does not mean "allocate a
>> statically-sized array", it means "allocate a dynamically-sized
>> array". "new T" for any T should mean "allocate a T", not "allocate
>> something that's kind of close to a T."
>
> As long as T[3] and T[5] and T[] are considered different types, I agree
> with that sentiment.
>
> But then again, I think array semantics would make a lot more sense if
> all arrays were of type T[], regardless of their size, their location
> (stack vs heap), and whether they're static or dynamic.
>
> --benji
No prob, get a static, dynamic array, Vector, Appender, whatever and get a
slice out of them:
T[] t;
T[3] t3;
t = t3[];
T[4] t4;
t = t4[];
auto a = new Array!(T);
t = a.all; // I would prefer a[] here :)
etc.
More information about the Digitalmars-d
mailing list