Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[expr.prim.lambda] 8.1.5/4 Add capture to the j variant to make the example to be compiled #1749

Closed
wants to merge 1 commit into from

Conversation

anatoly-spb
Copy link

@anatoly-spb anatoly-spb commented Sep 15, 2017

Here is a small fix to make the 8.1.5.4 example to be compiled.

@cpplearner
Copy link
Contributor

See #609

@tkoeppe
Copy link
Contributor

tkoeppe commented Sep 15, 2017

@cpplearner: Thanks for the reference.

Closing, since there is nothing wrong with the example.

@tkoeppe tkoeppe closed this Sep 15, 2017
@berkus
Copy link

berkus commented Sep 15, 2017

Since you got two reports on this where people think the capture is erroneously missing - it makes sense to add a comment to this snippet explaining the expected j scope.

wdyt?

@tkoeppe
Copy link
Contributor

tkoeppe commented Sep 15, 2017

The standard is not a tutorial?

@zygoloid: what do you think?

@jensmaurer jensmaurer changed the title 8.1.5.4 Add capture to the j variant to make the example to be compiled [expr.prim.lambda] 8.1.5/4 Add capture to the j variant to make the example to be compiled Sep 15, 2017
@timsong-cpp
Copy link
Contributor

[expr.prim.lambda]'s examples are all over the place w/r/t scope. Many are scope-neutral, so to speak, but we do have stuff like this that only works at block scope, stuff like the one at issue here that only works at namespace scope, and then stuff like this that actually needs to be split up and put into two different scopes to compile. Meanwhile, we also have examples like this that introduces a function solely to get a block scope so that captures can be used. It might not be a bad idea to come up with some rule on scopes for examples and apply it uniformly.

In this particular case, I would argue that the example could use some improvement; there's no explicit marker that the declarations are at namespace scope, and I'd wager that local lambdas arise more frequently than global ones, so the "missing capture" gets distracting because it resembles a common programming error with local lambdas. But I dislike an explicit comment too, as that also distracts from the point of the example, which has nothing to do with scope or captures.

How about just adding a static before int j;?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants