I am trying to write a function funcso that the compiler can output a template argument, it works when I go in std::function, but it does not work with lambdas:
template<typename TResult>
TResult func(std::function<TResult()> f)
{
return TResult();
}
int main()
{
int result = func([]() {
return 100;
});
std::function<int()> testFunc = []() {
return 100;
};
int result2 = func(testFunc);
return 0;
}
Is it possible to infer a template argument for lambda so that this string compiles? Instead of writing, func<int>([](){ return 100; });I want to writefunc([](){ return 100; });
source
share