سؤال

I'm new to lambdas and I'm having a hard time understanding how the following lambda expression's parameter list works.

The code is part of a facebook authentication method:

---------------- begin snippet ------------------

auto webAuthenticationOperation = WebAuthenticationBroker::AuthenticateAsync(WebAuthenticationOptions::Default, startURI, endURI);

webAuthenticationOperation->Completed = ref new AsyncOperationCompletedHandler<WebAuthenticationResult^>([output, facebookOutput, facebookToken](IAsyncOperation<WebAuthenticationResult^>^ thisOperation)
{
    if (thisOperation->ErrorCode.Value == 0)

----------------some other stuff ---------------

Specifically, I don't know how thisOperation actually refers to the WebAuthenticationResult that's currently being handled.

I read the block as:

1.) start an async authentication

2.) when the authentication is complete, run a function defined by the lambda


But the lambda function needs to know about THIS particular authentication operation (I'm assuming there's some kind of result that's returned to us when its complete). Based on the lambda's parameter list, it looks like we've just declared a pointer to a web authentication result without actually pointing it at anything.

How is it that thisOperation ends up referencing the correct object?

هل كانت مفيدة؟

المحلول

thisOperation is a lambda parameter. Its value is provided as an argument to the lambda expression when it is invoked.

When the webAuthenticationOperation's Completed event is raised, your lambda expression is called with the result of the webAuthenticationOperation as its argument.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top