当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - Single type compile time list: concat with clang

问题描述:

I'm using a "fixed type compile-time list" for a project of mine. Recently I tested this project for compatibility with different compilers and I noticed the clang (3.8) can't compile my implementation.

This error appeared:

error: expected expression return

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

^

The following part is extracted from my implementation of the compile time list:

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();

}

};

Additional there are two spezialisation for TNum=1 and TNum=0 that are missing in this example. I can add them if needed

I hope you can help my find the error that creates this problem

Edit:

Thanks Jarod42 for the answer. With his help i found this: Where and why do I have to put the "template" and "typename" keywords? That exlains things further.

网友答案:

template is missing in rhs.get<Ints2>():

it should be

rhs.template get<Ints2>()

Demo

分享给朋友:
您可能感兴趣的文章:
随机阅读: