about destroy and delete.

Marco Leise via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 20 13:49:58 PDT 2016


The semantics of `delete` from C++ are pretty clear. It is
meant for dynamically allocated memory. destroy(…) however is
a generic tool that brings the thing you pass in back to an
initial state. For pointers, null is assigned, for structs and
classes (which are not pointers but references) the dtor is
called.
Making it do the same thing for an argument of struct type T
and T* should not be done lightly. It will break generic
code, where the location that calls destroy(…) does not own
the pointed-to struct.

-- 
Marco



More information about the Digitalmars-d mailing list