C++ Logo


Advanced search

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

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Sun, 16 Apr 2023 12:27:03 +0200
Probably ;-) What I mean is, calling the lambda by patching executable code can be replaced by 1. serializing/deserializing the lambda object 2. potentially creating a bind to call the lambda   So the idea should not focus on calling lambdas specifically, but on serializing/deserializing C++ objects or generically calling member functions instead. There is nothing special about lambda functions in that regard as far as I can see.   For both of those there exists a lot of approaches (which can be further improved perhaps) and the use cases are much wider.   -----Ursprüngliche Nachricht----- Von:Giuseppe D‘Angelo via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Fr 14.04.2023 17:50 Betreff:Re: [std-proposals] Function Pointer from Lambda with Captures Anlage:untitled An:std-proposals_at_[hidden]; CC:Giuseppe D‘Angelo <giuseppe.dangelo_at_[hidden]>; 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 -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2023-04-16 10:27:05