Default argument for a functor in a templated parameter
From C++11 you can already do that:
template <typename Functor = int(int)>
int run_new(int x, Functor func = [](int a){ return a+1; })
{
return func(x);
}
Just add an overload for this.
template <typename Functor>
int run_new(int x, Functor func)
{
return func(x);
}
int run_new(int x)
{
return run_new(x, [](int a){ return a+1; });
}
Allows you to get around not beening able to have a lambda expression as a default function argument.