Why are the following valid C++ expressions? These aren't lambdas
[]{}(); {}[]{}; Can someone explain them to me?
The first is a lambda with no parameter list and a subsequent call. []{} is equivalent to [](){} so the whole line is equivalent to
[](){}(); The second is a pair of braces, which introduce and then immediately close a scope, followed by an unused lambda definition with no parameter list:
{ // empty scope } []{}; // lambda You can refer to http://en.cppreference.com/w/cpp/language/lambda for the variations on lambda definition syntax.
This one is a lambda call
[]{}(); it is equivalent to
[](){}(); The second is an empty scope, followed by a (unused) lambda.
Parens are optional for lambda without parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With