After seeing the benefits of std::array I was trying to create a class that supports multiple dimensions.
My initial experiments used nested std::array. I chose not to use this method partly for the ugly way to write the type.
ie: std::array<std::array<std::array<...>, >, >
The new class is mostly working except for initialization. I haven't decided whether its best to use inheritance or containment. The choice may depend on whether I can get initialization working.
How can I get either of the last two lines of this to compile:
// multi-dimensional array based on std::array
#include <array>
template <class T, int s, int... r>
class arraynd_a : public std::array<arraynd_a<T, r...>, s>
{
public:
};
template <class T, int s>
class arraynd_a<T, s> : public std::array<T, s>
{
public:
};
template <class T, int s, int... r>
class arraynd_b
{
public:
std::array<arraynd_b<T, r...>, s> arr;
};
template <class T, int s>
class arraynd_b<T, s>
{
public:
std::array<T, s> arr;
};
void test()
{
constexpr std::array<std::array<int, 2>, 3> a1 = { { { 0, 1 }, { 1, 0 }, { 2, 4 } } };
/*constexpr*/ arraynd_a<int, 3, 2> a2a;
/*constexpr*/ arraynd_b<int, 3, 2> a2b;
#if 0
/*constexpr*/ arraynd_a<int, 3, 2> a3a = { { { 0, 1 }, { 1, 0 }, { 2, 4 } } };
#endif
#if 0
/*constexpr*/ arraynd_b<int, 3, 2> a3b = { { { 0, 1 }, { 1, 0 }, { 2, 4 } } };
#endif
}