0
我試圖編譯GCC 5.4以下的C++代碼14(online example):GCC5:嵌套變量模板不是函數模板?
template<typename T>
struct traits {
template<typename X>
static constexpr bool vect = true;
};
template<typename T1, typename T2>
constexpr bool all_vect = traits<T1>::template vect<T2>;
bool something() {
return all_vect<void, double>;
}
,但我得到了以下錯誤:
<source>: In instantiation of 'constexpr const bool all_vect<void, double>':
<source>:11:12: required from here
<source>:8:16: error: 'template<class X> constexpr const bool traits<void>::vect<X>' is not a function template
constexpr bool all_vect = traits<T1>::template vect<T2>;
^
<source>:8:16: error: 'vect<T2>' is not a member of 'traits<void>'
Compiler exited with result code 1
雖然我在GCC沒有問題6.1或更多或在3.9以上。但是我嘗試過的所有GCC5版本都是一樣的。
我不明白爲什麼?通常,GCC5應該是C++ 14功能完備的。
在GCC5中仍然使用變量模板的問題有一個簡單的解決方法嗎?我寧願不回去使用簡單的特徵,因爲我將所有特徵轉換爲使用可變模板。
謝謝回答。我實際上正在尋找一個更簡單的解決方法,仍然使用變量模板。我寧願不回去使用簡單的特徵,因爲我將所有特徵轉換爲使用可變模板。 –
@BaptisteWicht它看起來像你唯一的選擇是編譯器的一個新版本,修正了錯誤或回到舊的特徵,或者你可以使用constexpr函數。 – bolov