最後のパラメータではない場合、バリアブルテンプレート関数でパラメータパックがどのように機能するかを理解しようとしています。私のサンプルコードで私の呼び出しのいくつかがうまくいかない理由は分かりません。質問はコメントに記載されています。彼らは動作するか、私は何かを理解していないか、またはVS2015アップデート3のコンパイラはまだそれらをサポートしていませんか?関数テンプレートでは、パラメータパックの種類は、それが中にいた場合にのみ推定することができ、ので最後のパラメータパックコンパイルエラー
template <typename T>
double sum(T t) {
return t;
}
template <typename T, typename... Rest>
double sum(Rest... rest, T t) {
return t + sum(rest...);
}
template <typename T>
double sum2(T t) {
return t;
}
template <typename T, typename... Rest>
double sum2(T t, Rest... rest) {
return t + sum2(rest...);
}
template<typename... Args>
void func(Args..., int = 0)
{}
void func()
{
func<int, int, int>(1, 1, 1);
func(1, 1, 1); // why doesn't this compile?
sum(1, 1); // why doesn't this compile?
sum<int, int>(1, 1);
sum<int, int, int>(1, 1, 1); // why doesn't this compile while func<int, int, int>(1, 1, 1) does?
// why are these compile? I only changed the order of the parameters compared to sum()
sum2(1);
sum2(1, 1);
sum2(1, 1, 1);
}