D's Destructors are What Scott Meyers Warned Us About
Steven Schveighoffer
schveiguy at yahoo.com
Thu May 24 09:34:08 UTC 2018
On 5/23/18 9:38 PM, Mike Franklin wrote:
> On Wednesday, 23 May 2018 at 13:12:57 UTC, Steven Schveighoffer wrote:
>
>> Hm.. that should be fixed. I don't see why we can't just do = T.init,
>> we should at least be optimizing to this for small enough structs.
>
> The problem I ran into with this is that if you use T.init directly you
> end up making copies (postblit) and then needing to destruct those
> copies since they are temporary. That's why I had to lower it to
> simpler byte array primitive.
This is the fool-proof way, but this is a template function! We can
deduce whether doing the T.init copy is going to call a postblit or
destructor.
-Steve
More information about the Digitalmars-d
mailing list