Calls `this(this)` extra with delegate stuff in the code

2017-01-21 Thread Joel via Digitalmars-d-learn
Compile this and see, (it's crazy!): import std.stdio; struct Widget { private int[] array; this(uint length) { array = new int[length]; } this(this) { writeln( "this(this) called" ); array = array.dup; }

Re: Calls `this(this)` extra with delegate stuff in the code

2017-01-21 Thread Ali Çehreli via Digitalmars-d-learn
Simplified: import std.stdio; struct Widget { private int[] array; this(uint length) { array = new int[length]; writefln("ctor called : %s", array.ptr); } this(this) { writef( "this(this) called: %s", array.ptr ); array = array.dup; wr

Re: Calls `this(this)` extra with delegate stuff in the code

2017-01-21 Thread Ali Çehreli via Digitalmars-d-learn
On 01/21/2017 03:19 PM, Ali Çehreli wrote: this(this) { TIL! Change the signature and it works without copies: this(const(this)) { // ... } How did I miss this for so long? Ali

Re: Calls `this(this)` extra with delegate stuff in the code

2017-01-21 Thread Ali Çehreli via Digitalmars-d-learn
On 01/21/2017 03:36 PM, Ali Çehreli wrote: > Change the signature and it works without copies: > > this(const(this)) { > // ... > } Ugh... :( It's not a post-blit. Then what is it? Ali

Re: Calls `this(this)` extra with delegate stuff in the code

2017-01-21 Thread Basile B. via Digitalmars-d-learn
On Sunday, 22 January 2017 at 00:31:38 UTC, Ali Çehreli wrote: On 01/21/2017 03:36 PM, Ali Çehreli wrote: > Change the signature and it works without copies: > > this(const(this)) { > // ... > } Ugh... :( It's not a post-blit. Then what is it? Ali This is a __ctor that takes

Re: Calls `this(this)` extra with delegate stuff in the code

2017-01-21 Thread Ali Çehreli via Digitalmars-d-learn
On 01/21/2017 07:22 PM, Basile B. wrote: On Sunday, 22 January 2017 at 00:31:38 UTC, Ali Çehreli wrote: On 01/21/2017 03:36 PM, Ali Çehreli wrote: > Change the signature and it works without copies: > > this(const(this)) { > // ... > } Ugh... :( It's not a post-blit. Then what

Re: Calls `this(this)` extra with delegate stuff in the code

2017-01-21 Thread Basile B. via Digitalmars-d-learn
On Sunday, 22 January 2017 at 03:42:21 UTC, Ali Çehreli wrote: On 01/21/2017 07:22 PM, Basile B. wrote: [...] Wow! Thanks. I know about 'alias this' but this (pun!) is new to me. TIL indeed and WAT (four exclamation marks is right in this case. :o) ) import std.stdio; struct S {