i am using c++11 variadic template, however the compiler complains template instantiation depth excedds maximun of 900, the code looks like:
template<typename F1, typename F2>
composed<F1, F2> compose(F1 f1, F2 f2) {
return composed<F1, F2>(f1, f2);
}
template<typename F1, typename F2, typename... Fs>
auto compose(F1 f1, F2 f2, Fs... fs) ->decltype(compose(compose(f1, f2), fs...)) {
return compose(compose(f1, f2), fs...);
}
i am using this template like:
auto composed_func = compose(f1, f2, f3, f4);
but if i change the variadic template defination to:
template<typename F1, typename F2, typename F3, typename... Fs>
auto compose(F1 f1, F2 f2, F3 f3, Fs... fs) ->decltype(compose(compose(f1, f2), f3, fs...)) {
return compose(compose(f1, f2), f3, fs...);
}
it will work OK. i am not clear why this happened. it seems to me that the upper usage also looks valid since it still recursively reduce the args to call compose.
Aucun commentaire:
Enregistrer un commentaire