clear()
Vladimir Panteleev
thecybershadow at gmail.com
Fri Oct 9 12:45:07 PDT 2009
On Fri, 09 Oct 2009 22:01:30 +0300, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> Andrei Alexandrescu wrote:
>> Jacob Carlborg wrote:
>>> On 10/9/09 18:40, Andrei Alexandrescu wrote:
>>>> I'm talking with Sean and Walter about taking the first step towards
>>>> eliminating delete: defining function clear() that clears the state of
>>>> an object. Let me know of what you think.
>>>>
>>>> One problem I encountered is that I can't distinguish between a
>>>> default
>>>> constructor that doesn't need to exist, and one that was disabled
>>>> because of other constructors. Consider:
>>>>
>>>> class A {}
>>>> class B { this(int) {} }
>>>>
>>>> You can evaluate "new A" but not "new B". So it's legit to create
>>>> objects of type A all default-initialized. But the pointer to
>>>> constructor stored in A.classinfo is null, same as B.
>>>>
>>>> Any ideas?
>>>>
>>>>
>>>> Andrei
>>>
>>> How about this:
>>>
>>> static if (is(typeof({
>>> auto t = new T;
>>> })))
>> I'm in awe. Thanks, Jacob!!!
>> Andrei
>
> Oh, wait, that doesn't work:
>
> class A {}
> class B : A { this(int) {} }
>
> A a = new B;
> clear(a); // oops
From what I understand, if you need to be able to look at derived classes,
then this information can only be stored in the ClassInfo - but, as you
have already pointed out, defaultConstructor is only set for explicit
constructors. Therefore you'll need some kind of new flag, which indicates
whether the class only has non-default constructors.
P.S. I hope that by "eliminating delete" you mean obsoleting it, and not
actually taking it out of the language :)
--
Best regards,
Vladimir mailto:thecybershadow at gmail.com
More information about the Digitalmars-d
mailing list