Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. COAlthough what you say is true, you could make exactly the same mistake if you wrote a for loop, and did int xl = *iterator; sum += x1;. Nobody's demanding explicit capture in that situation. In cases where the lifetime of the lambda is confined to the local scope, I think that implicit capture is no more (nor less) dangerous than the fact that simple braces inherit the surrounding automatic scope. It's when the lambda is going to live on that I think you want to be explicit what's captured (and deduce that what is not captured can safely die at end of lexical scope).
      singulars
    2. COIt is not important that the error can exist in other constructs. This is an additional advantage of lambda's, in that you can reduce the visibility of names more than is possible for a "for loop". There are many ways that name hiding/visibility can result in subtle errors. One goal of a coding standard is to reduce the cases that can cause a problem and you'll find several rules regarding name hiding and reduction of name visibility in standards such as JSF++, MISRA C/C++. I can see this being another.
      singulars
    3. COBut it doesn't actually reduce the visibility compared with the equivalent functor, it just prevents it being extended. That's not an advantage, it's mitigation. So on this point I think lambdas are (very slightly) worse than functors, in that if you think default capture is bad, you now have to ban it and police the ban. But yes, perhaps better than structured programming.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload