On 11/24/2010 07:06 AM, Jonathan M Davis wrote:
On Tuesday 23 November 2010 20:43:34 dsimcha wrote:
I was browsing through druntime's lifetime.d for an unrelated reason and I
noticed that, when an array is copied for the purpose of appending to it,
the postblits are not called on the new array if it is an array of
structs.  Is there something I'm missing, or is this a bug that somehow
noone has noticed up to this point?

Well, if it's copied for the purpose of appending, the elements need to be
moved, not copied, don't they? And if they're moved, there's no need to call the
postblit constructor.

The appended elements would need to be postblitted. Also, the original elements would need to be postblitted in case the append triggers a reallocation. They cannot be simply moved because there may be slices pointing to the original array.

Anyway, in the general case we cannot store structs with dtors/postblits in dynamic arrays (append requires GC and GC cannot destroy structs), which means you will have to use a special container for that purpose.


- Jonathan M Davis

Reply via email to