eliminate new operator paraphernalia
Michel Fortin
michel.fortin at michelf.com
Sun Feb 14 14:28:02 PST 2010
On 2010-02-14 17:21:51 -0500, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> said:
> Michel Fortin wrote:
>> On 2010-02-14 15:41:30 -0500, Andrei Alexandrescu
>> <SeeWebsiteForEmail at erdani.org> said:
>>
>>> Michel Fortin wrote:
>>>>
>>>> Hum, what's the syntax for placement delete?
>>>
>>> There is no need for placement delete. There will be a function clear()
>>> in object.d that only calls the destructor. (That is needed
>>> regardless.) You can carry deallocation with your own API functions.
>>
>> What's the point in wasting a function name only to call the
>> destructor? Why not just allow "object.~this()"?
>
> You might want to clear an int etc. for which it's unclear whether the
> above should work.
>
>> Also, if you really want to put an object back in it's initial state,
>> you could call both the destructor and the constructor. Anything else
>> is going to break the object's invariant. I think it's best to leave
>> breaking the object's invariants to a special syntax, hence
>> "object.~this()".
>
> Yah, clear destroys and then fills with .init.
...and call the default constructor for classes (and is not callable if
there is no default constructor). If you don't call a constructor for a
class, invariants can't hold.
Ok. That's fine for clear() then, but it's not the same thing as just
calling the destructor. There should be a way to just call the
destructor prior deallocation.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list