"Value class instance" pattern?

Benjamin Thaut code at benjamin-thaut.de
Sun Jul 14 02:39:03 PDT 2013


Am 13.07.2013 18:49, schrieb bearophile:
> Benjamin Thaut:
>
>> Yes the assignment in this(DefaultCtor) is needed, because the
>> construction process of a D object is defined as:
>
> OK.
>
>
>> The debugging values are needed because most debuggers won't be able
>> to evaluate properties while debugging.
>
> OK.
>
>
> Is that ClassCompose destructor enough (with something added for the
> debug build)?
>
>      ~this() {
>          if (!isDestructed) {
>              _instance.destroy;
>              isDestructed = true;
>          }
>      }

Thats enough for the debug build.

>
> Trying to use ClassCompose in my code I have had some problems caused by
> const classes and ClassCompose dtor. Maybe such dtor (and isDestructed)
> can be versioned out for composed-in classes that only contain values...
>

Can you give an example for that?

>
>
>> Yes this looks pretty similar to scoped in phobos but I always thought
>> that scoped was inteded for objects to be placed on the stack instead
>> of inside other objects.
>
> Right. I think Scoped can't be used for class composition.
> But isn't such ClassCompose enough for both purposes? Or is it better to
> have in Phobos both Scoped and something similar to ClassCompose?
>
>
>> Thats also why scoped does some additional alignment which is
>> garantueed when you do it within a class.
>
> Maybe such alignment can be added to the ClassCompose too.
>

But that would be a uneccessary overhead. Just adding a align(4) or 
align(16) like suggested below would be sufficient.

Kind Regards
Benjamin Thaut



More information about the Digitalmars-d mailing list