I have functions like:
template <typename T>
Result<T> run(std::function<T()> f);
and with various templated parameters. Like:
template <typename T, typename P>
Result<T> run(std::function<T(P)> f):
There are several layers of these that call each other and add features like retry. Rather than write a version of those for every instance, those look like:
template <typename F>
auto runWithRetry(F f);
The problems start when I pass a lambda to one of these. When I call run
directly I can specify the template parameters and then the lambda gets converted to a std::function. I don't want to specify the template parameters manually, but it works.
When calling the wrappers, it gets more complicated since I'd have to manually specify an std::function template parameter. Otherwise, the lambda arrives at run
and doesn't match because it's not a std::function and, as I understand now, conversion happens later.
I'd like the whole thing to work without manually specifying any template parameters. I'd like the types to be deduced.
How can I create something like that? Or, what's the right way for a function template to specify a callable parameter?
I'm using C++20.