Andrei Alexandrescu wrote:
I'm having a hard time justifying that you use
new X(args)
to create a class object, and
X(args)
to create a struct object. I wrote this:
============
The syntactic difference between the expression creating a @struct@
object---Test(@\meta{args}@)@---and the expression creating a @class@
object---\cc{new Test(}\meta{args}@)@---may be jarring at first. \dee
could have dropped the @new@ keyword entirely, but that @new@ reminds
the programmer that an object allocation (i.e., nontrivial work) takes
place.
===============
I'm unhappy about that explanation because the distinction is indeed
very weak. The constructor of a struct could also do unbounded amounts
of work, so what gives?
I hereby suggest we get rid of new for class object creation. What do
you guys think?
Andrei
What would become the equivalent of, for example:
new uint[][][](4, 3, 8)
I can live with having to define API's for custom allocation strategies of classes and
structures, rather than being able to hijack a language expression (the way one can with
'new'/'delete'), but what about the non-class new'ables?
However, if we really must toss the 'new' keyword out the window, I reiterate my support
for a 'T new(T,A...)(A a)' in the runtime.
-- Chris Nicholson-Sauls