【发布时间】:2017-12-29 13:05:35
【问题描述】:
所以我正在做一些功课,我必须在 C++11 中编写自己的编译时整数序列并为其编写一些函数(打印、连接、排序等),但我有有点麻烦我将如何去写这些东西。
template<typename T, typename Comp = std::less<int>>
struct Facility{
template<T ... Nums>
struct List{
struct Element<T ... nums>{};
template<unsigned num, T val, T ... rest>
struct Element{
unsigned index = num;
T value = val;
Element<index-1, rest...> others;
};
template<unsigned num, T val, T ... rest>
struct Element<0, val>{
unsigned index = 0;
T value = val;
};
static constexpr Element<sizeof...(Nums)-1,Nums...> elem = {};
static void Print()
{
// Prints out the list
}
};
};
using IntList = typename Facility<int>::List<intlist...>;
int main()
{
using List1 = IntList<1, 2, 3>;
List1::print()
}
我只是想知道我是否走在正确的轨道上,这样我就不会陷入死胡同。我对List 中的static print() 和static constexpr 成员不是100% 确定的,尽管我想不出任何其他方法来使它工作。
【问题讨论】:
标签: c++ c++11 sequence variadic-templates variadic