Bypassing the postblit?

monarch_dodra monarchdodra at
Mon Dec 30 14:34:30 PST 2013

On Monday, 30 December 2013 at 16:18:22 UTC, Maxim Fomin wrote:
> On Sunday, 29 December 2013 at 19:26:09 UTC, monarch_dodra 
> wrote:
>> Nope. What you are asking for is basically a default 
>> constructor, which D does not provide. Workarounds include the 
>> "static opCall" pattern, as well as the "function builder" 
>> pattern (eg: "MyStruct myStruct(Args args)")
> Actually it does provide, but does not allow to override it. 
> When you define postblit, dmd generates default constructor 
> like this:
> struct S
> {
>    int data[];
>    this(this) { data = data.dup; }
>    void __cpctor(const ref S s) const
>    {
>       this = s;
>       s.__postblit();
>    }
> }
> The only way to override it is currently is to make your 
> function, drop original symbol from binary file and link the 
> program.
> I think it could work like opAssign - provide default version 
> but allow to place yours. In such case it would be possible to 
> alter original struct object but it would lead to conflict if 
> original object is const or immutable qualified.

Hum... The original question was "Any possibility of *preblit* 
kind functionality?". I meant "default constructor" in the C++ 
sense: A constructor that gets called with no arguments. That 
does not exist in D.

I did not know dmd generated an actual symbol for CC though. 
Interesting to know.

More information about the Digitalmars-d mailing list