Answer the question
In order to leave comments, you need to log in
Is it possible to return lambdas?
auto GetLambda() {
return []( const int &x ) { return x*x ; } ;
}
auto lambda = [] ( const int &x ) { return x*x ; } ;
int ( * const fn ) (const int &) = [] ( const int &x ) { return x*x ; } ;
Answer the question
In order to leave comments, you need to log in
Doing this is normal?Quite
And what is returned in this case, a pointer to the function or the function itself?functional object. Lambda is not a function , it can be cast to a function pointer in some cases.
If a pointer is returned, where is the function itself stored, on the heap or on the stack?The "function" of the lambda is stored in the same place as the rest of the code. On the fly, nothing is collected and compiled. A lambda is syntactic sugar for declaring a class with an overloaded function call operator.
And one more question on the same topic:lambda has a unique type. It's not a function (but can be cast to in this case).
This is an abbreviated notation like this:
Or something else?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question