How to get the "this" ptr of a lambda inside the lambda?

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 19 10:24:44 PDT 2016


On 7/19/16 1:03 PM, Rufus Smith wrote:
> On Tuesday, 19 July 2016 at 16:58:12 UTC, Steven Schveighoffer wrote:
>> On 7/19/16 12:52 PM, Rufus Smith wrote:
>>> On Tuesday, 19 July 2016 at 15:58:49 UTC, Steven Schveighoffer wrote:
>>>> [...]
>>>
>>> Yes, but then this = null. I matters not for my use case.
>>
>> 'this' is not null in either case. There is no 'this'.
>>
>
> Please stop saying that:
>
> https://en.wikipedia.org/wiki/This_(computer_programming)
>
> this is more general than you think.

The compiler knows about the context pointer, your delegate has no name 
for it. And in a lambda that does not need one, there is no context 
pointer, it's not a pointer that's set to null.

I fully understand what you're looking for. In D, 'this' means the 
object/struct that a method is being called with. If you don't have an 
object delegate, then you don't have a 'this' reference (and by that I 
mean a named parameter to the member function called 'this' or any other 
name).

-Steve


More information about the Digitalmars-d-learn mailing list