I had this lambda somewhere in my code:
[](bool a, bool=true){ return !a;} }
and GCC 4.6 "complained" with this warning:
warning: default argument specified for lambda parameter [-pedantic]
Which is mightily unhelpful when you don't know why this is "bad". I consulted the FDIS n3290 and didn't find anything in 5.1.2 Lambda Expressions
with regards to default arguments and a lambda.
UPDATE: I filed a bug report here.
UPDATE2: OK, from now on I'm using -pedantic-errors
. -pedantic
only emits warnings, not errors.
Solution: If variable <variable_name> or function <function_name> is not used, it can be removed. If it is only used sometimes, you can use __attribute__((unused)) . This attribute suppresses these warnings.
A stateless lambda is a lambda that captures nothing from its environment. Or to put it the other way around. A stateless lambda is a lambda, where the initial brackets [] in the lambda definition are empty. For example, the lambda expression auto add = [ ](int a, int b) { return a + b; }; is stateless.
Capture clause A lambda can introduce new variables in its body (in C++14), and it can also access, or capture, variables from the surrounding scope. A lambda begins with the capture clause. It specifies which variables are captured, and whether the capture is by value or by reference.
Much like functions can change the value of arguments passed by reference, we can also capture variables by reference to allow our lambda to affect the value of the argument. To capture a variable by reference, we prepend an ampersand ( & ) to the variable name in the capture.
Section 5.1.2 paragraph 5 specifically says that you can not have default values for the parameters.
Default arguments (8.3.6) shall not be specified in the parameter-declaration-clause of a lambda-declarator.
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