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

[stmt.if] Add an example for the value-dependence of the condition after instantiation #6626

Open
frederick-vs-ja opened this issue Oct 15, 2023 · 3 comments

Comments

@frederick-vs-ja
Copy link
Contributor

It seems that the rule "if the condition is not value-dependent after its instantiation" mainly affects implicit lambda captures of generic lambdas.

If I understand correctly, the intent is that the condition may still remain value-dependent when determining implicit lambda captures but won't be value-dependent after the instantiation of the lambda body. Should we add a proper example explaining this?

CC-ing @jensmaurer @zygoloid

@jensmaurer
Copy link
Member

The rule is from P0292R2.

@jensmaurer
Copy link
Member

Here's an example, adjusted from the discussions on P0292R2 in Oulu. Would you like to see this in the standard?

template<class T>
int f(T x) {
  int v = 10;
  auto lam = [&] (auto a) {
    if constexpr (sizeof(T) > 1)
       ++v;
  };
  lam(5);
  return 0;
}
int v = f('a');   // "v" is not captured

@frederick-vs-ja
Copy link
Contributor Author

frederick-vs-ja commented Oct 19, 2023

Here's an example, adjusted from the discussions on P0292R2 in Oulu. Would you like to see this in the standard?

template<class T>
int f(T x) {
  int v = 10;
  auto lam = [&] (auto a) {
    if constexpr (sizeof(T) > 1)
       ++v;
  };
  lam(5);
  return 0;
}
int v = f('a');   // "v" is not captured

I guess it might be better to have two examples, one doesn't captures the outer variable like this, and the other captures it because the condition in if constexpr depends on the type of the generic lambda parameter.

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

No branches or pull requests

2 participants