C++ Logo


Advanced search

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

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Fri, 14 Apr 2023 17:28:49 +0200
Hi Frederick,   in a C++ way, compare (equate) calling a lambda with calling a member function. You have the pointer to the object and the pointer to the member function itself.   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   -----Ursprüngliche Nachricht----- Von:Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Fr 14.04.2023 15:19 Betreff:[std-proposals] Function Pointer from Lambda with Captures An:std-proposals <std-proposals_at_[hidden]>; To invoke a capture lambda, we need two pieces of data:  Datum A: The address of the lambda object  Datum B: The address of the 'operator()' member function Datum A is a pointer into data memory. Datum B is a pointer into code memory.  

Received on 2023-04-14 15:28:51