Calls `this(this)` extra with delegate stuff in the code
Basile B. via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jan 21 19:50:09 PST 2017
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 {
> 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
Same mood. I'm quite astonished to see that something like that
still can be discovered, years after the language creation.
More information about the Digitalmars-d-learn
mailing list