我希望使用C++14可变模板构建一个编译时查找表。
目前我的进展如下:
我希望将表格放在
使用
(
static const unsigned kCount = 5;
template<unsigned Index>
constexpr auto getRow(void)
{
return std::array<unsigned, 2> { Index, Index * Index };
}
template<unsigned... Indices>
constexpr auto generateTable(std::index_sequence<Indices...>)
{
return std::array<std::array<unsigned, 2>, sizeof...(Indices)>
{
// This is were I'm stuck. How to build a std::array using Indices as template parameter in getRow()?
};
}
constexpr auto generate(void)
{
return generateTable(std::make_index_sequence<kCount>{});
}
我希望将表格放在
std::array
中。每一行由一个具有2列的std::array
组成。 我卡在了generateTable()
中,在这里我需要以某种方式将我的 Indices 作为模板参数传递给getRow()
。使用
std::integer_sequence
和模板参数包展开来实现这一点是否可行,还是我需要自己实现递归?(
getRow()
已简化-值类型实际上来自模板类型。Index * Index
只是一个占位符。我需要知道如何使用参数包展开调用getRow()
的方法。)
Index
?行号吗? - Arunmu