2016-12-02 38 views
0

我爲我的一個項目使用了「固定類型編譯時間列表」。最近我測試了這個項目與不同編譯器的兼容性,我注意到clang(3.8)不能編譯我的實現。 這個錯誤出現了:單一類型的編譯時間列表:concat和clang

error: expected expression return 

List<T, sizeof...(Ints1) + sizeof...(Ints2)>(this->get<Ints1>()..., rhs.get<Ints2>()...);               
                       ^

下面的部分是從我執行編譯時列表中提取:

template<class T, size_t TNum> 
class List; 

template<class T, size_t TNum> 
class List: public List<T, TNum - 1> 
{ 
protected: 
    T data; 
    template<size_t ... Ints1, size_t ... Ints2> 
    constexpr List<T, sizeof...(Ints1) + sizeof...(Ints2)> _concat(const List<T, sizeof...(Ints2)> rhs, std::index_sequence<Ints1...>, std::index_sequence<Ints2...>) const 
    { 
     return List<T, sizeof...(Ints1) + sizeof...(Ints2)>(this->get<Ints1>()..., rhs.get<Ints2>()...); 
    } 

    template<class ... TArgs> 
    constexpr List(T d, TArgs&& ... arg) 
     : List<T, TNum - 1>(std::forward<TArgs>(arg)...), data(d) 
    { 
     static_assert(TNum != sizeof...(TArgs), "Number of arguements and list size does not match!"); 
    }   

    template<size_t TNum2, typename Indices1 = std::make_index_sequence<TNum>, typename Indices2 = std::make_index_sequence<TNum2>> 
    constexpr List<T, TNum + TNum2> concat(const List<T, TNum2>& rhs) const 
    { 
     return this->_concat(rhs, Indices1(), Indices2()); 
    } 

    template<size_t TI> 
    constexpr T get() const 
    { 
     static_assert(TI < TNum, "Element out of valid range!"); 
     static_assert(TI >= 0, "Element out of valid range!"); 
     return static_cast<List<T, TNum - TI> >(*this).get(); 
    } 
}; 

附加有兩個spezialisation爲TNum = 1和TNum = 0是在失蹤這個例子。如果需要的話

我可以加入他們,我希望你能幫助我找到產生這個問題的錯誤

編輯: 感謝Jarod42的答案。在他的幫助下,我發現了這個:Where and why do I have to put the "template" and "typename" keywords?這使事情更進一步。

+2

你可能之前'在編譯器指定的地方GET'缺少模板關鍵字... –

回答

2

template中缺少rhs.get<Ints2>()

應該

rhs.template get<Ints2>() 

Demo

+0

THX ,這工作正常。不知道爲什麼VC++和gcc沒有這個問題。 – Matyro