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 is it?
Ali
This is a __ctor that takes another instance as param. The param name is
not specified, i.e
struct Foo
{
this(const(this)){}
}
is the same as
struct Foo
{
this(const(this) param){}
}
since __PRETTY__FUNCTION__ in the function returns
"Foo Foo.this(const(Foo) _param_0) ref"
That's strange.
Isn't it mentioned somewhere in the specification that within a function
declaration, "this" resolves to the type of the current aggregate ?
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 {
void foo(this a = () {
static assert(is(this)); // 'this' is a type
return S();
}()) {
static assert(is(typeof(this))); // 'this' is an expression
writeln("foo called for ", this);
}
// WAT!!!!
}
void main() {
auto s = S();
s.foo(s);
}
Ali