Sean Kelly wrote:
== Quote from Andrei Alexandrescu (seewebsiteforem...@erdani.org)'s article
Georg Wrede wrote:
Andrei Alexandrescu wrote:
Don wrote:
Andrei Alexandrescu wrote:
new is a really bad construct. I'm very unhappy that D inherited it.
Care to elaborate?
I just did in the PS :o). New is not uniform: you can't use it easily
to allocate a pointer to a dynamic array, or even a fixed-size array.
Why? Because new is syntactically ill-conceived. It also allocates two
keywords for no good reason.
new should disappear and delete should be an unsafe function.
Have I missed a discussion on what to have instead of new?
Nothing.
auto a = T(args);
should create a T, whether T is a class, array, struct, what have you.
This "new" business is lame, lame, lame.
So it's back to malloc when we want to dynamically allocate a struct,
or does calling the ctor this way always perform dynamic allocation?
To dynamically allocate a struct, the stdlib should provide a function
e.g. create!T or allocate!T.
struct S { int x; }
auto s = S(42); // stack
auto ps = allocate!S(42);
Andrei