"Value class instance" pattern?

Artur Skawina art.08.09 at gmail.com
Sun Jul 14 10:41:24 PDT 2013


On 07/14/13 18:59, Dicebot wrote:
> Ugh, rly? As far as I understand spec it should work like this:
> 
> T x; // sets x to T.init
> T x = void; // don't initialize x at all, leave garbage

"void-initialization of aggregate fields does *not* actually disable
initialization":

   struct S {
      T x = void;
   }

   S s; // Copies S.init -> s; including s.x.

The initialization of s.x is *not* skipped.
When T==ubyte[100_000] etc adding the '=void' initializer can
make things /worse/ (blit instead of bzero).

> What hole in .init are you referring to?

See above - handling this properly means treating every `void`
initialized field as a hole. Also, '=void' alone should not
result in copying of T.init when it is just a zero-filled
chunk.

artur


More information about the Digitalmars-d mailing list