考慮代碼:是否合法,以部分地專門與來自外部類的可變參數模板ARGS可變參數模板內部類
#include <iostream>
template <class... Ts>
struct outer {
template <class... ITs>
struct inner {
static constexpr bool value = false;
};
template <class... ITs>
struct inner<Ts..., ITs...> {
static constexpr bool value = true;
};
};
int main() {
std::cout << outer<int, float, double>::inner<int, float, double, int>::value << std::endl;
}
代碼編譯與鐺++但不與克++,它產生一個錯誤:
temp3.cc:11:11: error: parameter pack argument ‘Ts ...’ must be at the end of the template argument list
struct inner<Ts..., ITs...> { ^
由於我已經建立here內部類的部分專業化應該是合法的。
編輯: 出於完整性很值得補充說,鐺上面的代碼警告說,他可能會與推斷它的參數還沒有這樣做沒有任何問題一個問題...
我完全不知道規則,但是當我得到一個依賴類型的錯誤時,在它有時幫助之前添加'typename'或'template'。試試'struct inner
Dani
添加'typename'後我得到'temp3.cc:11:39:錯誤:模板參數1無效' –
請注意,請求的場景仍然可以通過一些額外的模板元編程實現... http:///coliru.stacked-crooked.com/a/0c6c643c8ff5809e(是的,我知道這不是問題,但實施它的挑戰是不可避免的...)。 –