Just wrap your array in a struct. The downside is that you have to use double braces for initialization, but now you can use array assignment:
Code:
---
|
``` template <class T, size_t N>
|
struct Array {
|
T data[N];
|
T &operator[](size_t index) { return data[index]; }
const T &operator[](size_t index) const { return data[index]; }
T *begincolor=#000000[/color] { return &data[0]; }
const T *begincolor=#000000[/color] const { return &data[0]; }
T *endcolor=#000000[/color] { return &data[N]; }
const T *endcolor=#000000[/color] const { return &data[N]; }
};
Array<Array<Array<byte, 2>, 4>, 2> matrix = {{
{{
{ 1, 1 }, { 4, 4 }, { 10, 10 }, { 13, 13 }
}},
{{
{ 3, 3 }, { 6, 6 }, { 13, 13 },
}},
}};
```
|
template <class T, size_t N>
struct Array {
T data[N];
T &operator[](size_t index) { return data[index]; }
const T &operator[](size_t index) const { return data[index]; }
T *begin() { return &data[0]; }
const T *begin() const { return &data[0]; }
T *end() { return &data[N]; }
const T *end() const { return &data[N]; }
};
Array<Array<Array<byte, 2>, 4>, 2> matrix = {{
{{
{ 1, 1 }, { 4, 4 }, { 10, 10 }, { 13, 13 }
}},
{{
{ 3, 3 }, { 6, 6 }, { 13, 13 },
}},
}};
template <class T> void print(Print &p, const T &value, const uint8_t indent = 0) {
for (uint8_t i = 0; i < indent; i++)
p.print(' ');
p.println(value);
}
template <class T, size_t N> void print(Print &p, const Array<T, N> &array, const uint8_t indent = 0) {
for (uint8_t i = 0; i < indent; i++)
p.print(' ');
p.println('{');
for (const T &el : array)
print(p, el, indent + 2);
for (uint8_t i = 0; i < indent; i++)
p.print(' ');
p.println('}');
}
void setup() {
Serial.begin(115200);
while(!Serial);
print(Serial, matrix);
matrix = {{
{{
{ 2, 2 }, { 3, 3 }, { 4, 4 }, { 5, 5 }
}},
{{
{ 6, 6 }, { 7, 7 }, { 8, 8 }, { 9, 9 }
}},
}};
print(Serial, matrix);
}
void loop() {}
However, I think that it would be better to rethink the architecture of your program, as this approach seems very error-prone.
Pieter