I'm reading
p2425r0 and notice that the lambda declaration
[ captures ] ( params ) lambda-specifiers requires(optional) { body }
|
in "(params)" part we may include a structured binding syntax but with implicit "auto"
cv-auto ref-qualifier(optional) [
identifier-list ]
This could help solve the "Arbitrary lookahead parsing" problem ?
Sample 1 -----------------------
[][a,b] { return a * b; } // becomes:
[](auto a, auto b) { return a * b ; }
Sample 2 -----------------------
[] const&& [a, b] { return a; } // becomes:
[](const auto&& a, const auto&& b) { return a; }
Sample 3 -----------------------
[]&[p] p.foo();
[](auto& p) noexcept(noexcept(p.foo())) -> decltype(( p.foo() )) { return p.foo(); };
Your proposal doesn't have anything to do with structured binding, though. Normally (since C++17), when we see `[a, b]`, it means "we're structured-binding to some structure that is going to be destructured here." This does have applications to function parameters, but the application would be, like,
auto magnitude(auto [x, y]) {
return sqrt(x*x + y*y);
}
auto coord = std::pair(3, 4);
auto five = magnitude(coord);
This is not C++20, but it's a fairly obvious notion that has definitely been talked about informally, as well as having users ask about it:
So reusing any part of "structured binding" syntax, anywhere in this general vicinity, for any purpose other than structured binding, is a bad idea IMO.
–Arthur