C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Function Pointer from Lambda with Captures

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Fri, 14 Apr 2023 17:49:54 +0200
Hi,

Il 14/04/23 17:28, Sebastian Wittmeier via Std-Proposals ha scritto:
> Wouldn't it be nice, if C++ lambdas were of class type, storing the
> captures in its member variables, and calling the lambda would call its
> () operator?
>
> Something like
>
> |int x = 4; ||struct { int& b; void operator()(int a) { return a + b + 1; } } lambda1
> = { x }; x = 15; std::cout << lambda1(2) << std::endl; // prints out 18 |


Was there a <satire> tag missing? Because that's precisely what a lambda
is, an instance of a closure type.

https://eel.is/c++draft/expr.prim.lambda.closure

My 2 c,
-- 
Giuseppe D'Angelo

Received on 2023-04-14 15:49:57