On 2010-02-14 13:17:44 -0500, Andrei Alexandrescu
<seewebsiteforem...@erdani.org> said:
Currently new is baroque to the extreme. Should we eliminate the
class-specific allocators in favor of a simple scheme for placement
new? All that's really needed is to construct an object of a given type
at a given address. All of the syntactic mess around it is unnecessary.
I think class-specific new and delete are not a useful feature.
Second, the whole new anonymous class thing is for Java's sake. Do you
think we need to keep all that?
I suggest the following syntaxes for a type T, an integral length, an
initializerlist a la "e1, e2, e3, ..." that could be empty, and an addr
convertible to void*:
new T[length]
new T(initializerlist)
new(addr) T[length]
new(addr) T(initializerlist)
and call it a day.
Hum, what's the syntax for placement delete?
While I welcome a real placement-new syntax, I'm not sure adding it
justifies any of the other changes you're proposing. Placement-new can
be see as just another allocator taking a pointer as an argument and
returning that same pointer as the address to use for whatever you're
initializing.
So why remove custom allocators? Those can be useful to catch all
allocations of a specific class in an existing code base and improve it
for some specific needs without having to change code everywhere. I'd
rather see that better generalized (we talked about making 'new' a
template earlier).
Also, why remove anonymous classes? They're just a shortcut syntax for:
void func() {
class Anonymous {
...
}
auto a = new Anonymous;
...
}
I don't really see what's the problem in allowing this:
void func() {
auto a = new class {
...
}
...
}
--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/