You can't.
Generic lambda and std::function
are completely different things.
You can rougly see an auto(auto)
lambda as a not-template class with a template operator()
.
Something as
struct myUnnamedLambdaStruct
{
// ...
template <typename T>
auto operator() (T t) const
{ /* .... */ };
};
Where std::function()
is the contrary: it's a (specialization of a) template class with a not-template operator()
template <typename>
class function;
template <typename RetType, typename ... ArgTypes>
class function<RetType(ArgTypes...)>
{
// a lot of other members/methods
public:
RetType operator() (ArgTypes ... args) const
{ /* .... */ }
};
So a generic lambda object doesn't contain a single operator()
but a set of operator()
where a std::function
object contain a single operator()
.
You can "save" a generic lambda in a std::function
but only fixing, one time for all, the RetType
and the ArgTypes...
. That is: selecting a single operator()
, in the available set of operator()
s, and forgetting all the others.