C++ Logo


Advanced search

Subject: Re: Idea: lambda capture list as ad-hoc structure or named members tuple
From: Michael Hava (mfh_at_[hidden])
Date: 2020-01-24 07:47:12

Purely personal opinion: the last thing C++ (ATM) needs is yet another special syntax with limited applicability...

I'd rather restart the discussion on lifting the restriction on local templates... (aka. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1988r0.html)

From: Std-Discussion <std-discussion-bounces_at_[hidden]> On Behalf Of Raymund Hofmann via Std-Discussion
Sent: Friday, January 24, 2020 7:23 AM
To: std-discussion_at_[hidden]
Cc: Raymund Hofmann <hofmannraymund_at_[hidden]>
Subject: [std-discussion] Idea: lambda capture list as ad-hoc structure or named members tuple


So why not have something like a capture list of a lambda with outside access of its named auto typed members?

A kind of structured binding with initializing expressions for each member?

auto f()
auto adhocstruct=[m=expression_m, n=expression_n];


return adhocstruct;

auto sometransform()
return [result=expression, tolerance=expression, moved=std::move(movedfrom)];

decltype(sometransform()) sometransformresultvalue;

Using tuples for that has a major drawback of not being able to give descriptive names for members.
Using predefined structs has three major drawbacks: more typing/code (DRY), less locality and no auto member type deduction.

STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups