我为我的一个项目使用了“固定类型编译时间列表”。最近我测试了这个项目与不同编译器的兼容性,我注意到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?这使事情更进一步。
你可能之前'在编译器指定的地方GET'缺少模板关键字... –