Reputation: 13
I dont understand what the following code is doing
auto sgn = [&](int x)
{
if (x > 0) return 1;
else return -1;
};
What is the role of ampersand here? Is it a pointer? And is this block a structure or something like that?
I came across this block of code in codeforces round 636 division 3 editorial.
Upvotes: 0
Views: 95
Reputation: 31465
The &
here means that the lambda captures all variables by reference.
The lambda returns 1
or -1
depending on the value of the argument x
, so the capture really doesn't actually matter here.
Upvotes: 5