我有一个包装器,可以多次调用模板函数:
template <std::uint16_t N, typename F, typename ... Args>
inline typename std::result_of<F && (Args &&...)>::type retry_n(F && f, Args&& ... ax)
{
for (auto i = 0; i < N; ++i)
{
try
{
return std::forward<F>(f)(std::forward<Args>(ax)...);
}
catch (const some_except &e){ /*ignore exception for a while*/ }
}
throw;//re-raise
}
在我传递默认参数函数之前,所有东西都正常工作:
int f(int a, int b, int c = 5);
....
retry_n<10>(f, 1, 2); // error C2198: 'bla-bla' : too few arguments for call
如何允许默认参数在不显式指定的情况下使用?
retry_fn<10>([](auto...x){return f(x...);}, 1, 2)
- Johannes Schaub - litb