I've been thinking for hours about how to expand the template parameter pack for generating a 2D array, but haven't come up with anything. Maybe one of you can guess? So far, it looks impossible to me.
The result should be as follows:
#include <utility>
int Values[3][3]{ };
void Generate()
{
int result[3][3]
{
{ Values[0][0] + 1, Values[0][1] + 1, Values[0][2] + 1 },
{ Values[1][0] + 1, Values[1][1] + 1, Values[1][2] + 1 },
{ Values[2][0] + 1, Values[2][1] + 1, Values[2][2] + 1 }
};
}
int main()
{
}
Let's try to do it with a template:
One of my bad tries:
#include <utility>
int Values[3][3]{ };
template<std::size_t... Indices1, std::size_t... Indices2>
void Generate(std::index_sequence<Indices1...>, std::index_sequence<Indices2...>)
{
int result[3][3]
{
(Indices1, { (Values[Indices1][Indices2] + 1)... })... // ERROR
};
}
int main()
{
Generate(std::make_index_sequence<3>{ }, std::make_index_sequence<3>{ });
}
There were more tries, but I'm ashamed to even show them.
This can be solved by using std::array, or by declaring an empty array and filling it with loops, etc. Please don't write such answers. In this case, I'm wondering if it's possible to do this with standard arrays or not.