【发布时间】:2017-08-09 02:59:33
【问题描述】:
我有调用模板函数 N 次的包装器:
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) -
@ᐅJohannesSchaub-litbᐊ 是的,很明显的解决方法