Wum*_*Wum 3 c++ variadic-templates c++11 stdarray c++14
我想使用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.每行包含std::array2列.我被困在generateTable()我需要以某种方式将我的指数传递getRow()给模板参数的地方.
这是可以实现的使用std::integer_sequence和模板参数包扩展还是我需要自己实现递归?
(getRow()简化 - 值类型实际上来自模板类型.Index * Index只是一个占位符.我需要知道如何getRow()使用参数包扩展调用.)
看起来你几乎就在那里.只需依靠参数包扩展:
return std::array<std::array<unsigned, 2>, sizeof...(Indices)>
{
   getRow<Indices>()...
};
该getRow<Indices>()...行将扩展到:
getRow<0>(), getRow<1>(), ..... , getRow<sizeof...(Indices)-1>()