How to get the "this" ptr of a lambda inside the lambda?
Rufus Smith via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 19 09:52:51 PDT 2016
On Tuesday, 19 July 2016 at 15:58:49 UTC, Steven Schveighoffer
wrote:
> On 7/19/16 11:25 AM, Rufus Smith wrote:
>>[...]
>
> I think what Mike may be alluding to is that there is no name
> for the stack frame pointer you can use. There is no 'this'
> pointer that you can get at (even though it can be passed).
>
> Also note that lambdas are not necessarily delegates, they
> could be straight function pointers if they don't need a
> context:
>
> void main()
> {
> int a;
> pragma(msg, typeof((int b) => b * 2)); // int function(int
> b) pure nothrow @nogc @safe
> pragma(msg, typeof(() => a * 2)); // int delegate() pure
> nothrow @nogc @safe
> }
>
Yes, but then this = null. I matters not for my use case.
> A question to ask is, why do you need it?
Magic my friend! Magic!!!
More information about the Digitalmars-d-learn
mailing list