eliminate new operator paraphernalia
Lars T. Kyllingstad
public at kyllingen.NOSPAMnet
Mon Feb 15 23:03:46 PST 2010
Steven Schveighoffer wrote:
> On Sun, 14 Feb 2010 13:17:44 -0500, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>
>> 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.
>>
>> What do you think?
>
> Except for anonymous classes, that works for me. I don't think I've
> ever used class-specific allocators, and except for slightly ugly
> syntax, you can cover custom allocators with your new syntax.
>
> One thing however, let's look at how the syntax will change:
>
> auto t = new T(x, y, z);
>
> ...
>
> auto t = new(customAlloc(???)) T(x, y, z);
>
> Whatever you do for ??? to get the allocation size of T needs to be
> easy. I think right now, it is not a simple property of the class name,
> I think it should be, to make this as painless as possible. Even with
> that, unfortunately, you must repeat the type, which may be significant
> if the typename is long or complex.
__traits(classInstanceSize, T)
...I think.
-Lars
More information about the Digitalmars-d
mailing list