-1

I am trying to understand what this declaration means. is it a function or a variable declaration? When I try to compile it in c or c++, it doesn't compile. However I found this code as part of a optimized solution to a question I was trying to solve, that is why I'm trying to figure it out.

int any = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    return 0;
}();
Vivian_S.O.
  • 147
  • 1
  • 2

1 Answers1

6

It is an immediately invoked lambda expression:

[] is an empty capture list;

() is an empty argument list;

{...} is a lambda body, that should return something that is convertible to an int, because it needs to be assigned to any.

Everything above defines a lambda.

() is a (function) call to that lambda with an empty argument list.

Lambda expressions are available since C++11, so maybe your compiler is using an outdated standard.

Dev Null
  • 4,046
  • 1
  • 19
  • 40