私は、C++ 14バリデーションテンプレートを使用してコンパイル時ルックアップテーブルを作成したいと思います。 私はそこだ瞬間: C++ 14コンパイル時std :: array with variadic templates
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()
に立ち往生しています。私は何とかインデックスをgetRow()
に渡してテンプレートパラメータとして渡す必要があります。
これはstd::integer_sequence
とテンプレートパラメータパックの拡張を使用して達成可能ですか、それとも自分で再帰を実装する必要がありますか?
(getRow()
が簡略化されている - 。値の種類は、実際にテンプレートの種類から来ているIndex * Index
は単なるプレースホルダである私は、パラメータパックの拡張を使用してgetRow()
を呼び出す方法の方法を知っておく必要があります。。)
「インデックス」とは何ですか?行番号? – Arunmu
はい、インデックスは行番号です。現在0から4まで動いています。 – Wum