Mam otoki, który wywołuje funkcji szablonu razy N:C++ 11 o zmiennej liczbie argumentów args z domyślnej wartości argumentów funkcji
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
}
wszystko działa w porządku, dopóki nie przejdzie funkcję z argumentem domyślnym:
int f(int a, int b, int c = 5);
....
retry_n<10>(f, 1, 2); // error C2198: 'bla-bla' : too few arguments for call
Jak aby zezwolić na użycie domyślnego argumentu bez jawnej specyfikacji?
'retry_fn <10> ([] (auto ... x) {powrotu f (x, ...);} 1, 2) ' –
@ ᐅ JohannesSchaub-litb ᐊ tak, jest jasne, obejście problemu – Dewfy