Given a lambda with a lambda-capture, the type of the explicit object parameter, if any, of the lambda's function call operator (possibly instantiated from a function call operator template) shall be either:
* the closure type,
* a class type derived from the closure type, or
* a reference to a possibly cv-qualified such type.
[Example 2:
struct C {
template
C(T);
};
void func(int i) {
int x = [=](this auto&&) { return i; }(); // OK
int y = [=](this C) { return i; }(); // error
int z = [](this C) { return 42; }(); // OK
}
-- end example]
Question: Why is there such restriction for lambda with capture only? Are there any implementation issues?
0 comments:
Post a Comment
Thanks