C++ Logo

std-proposals

Advanced search

Abbreviated Lambdas with structured bindings

From: Cleiton Santoia <cleitonsantoia_at_[hidden]>
Date: Tue, 7 Sep 2021 20:09:36 -0300
I'm reading p2425r0
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2425r0.html> 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(); };


BR

Cleiton

Received on 2021-09-07 18:09:50