私はテンプレート関数N回を呼び出すラッパーありますC++ 11個の可変長引数
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>([](オート... x)は、それを使用してファンクタに{戻りF(Xを...);} 1、2) ' –
@ᐅJohannesSchaub-litbᐊはいこれは明確な回避策です。 – Dewfy