If your arrays will always have the same length (6 in your example), then you could use std::array instead of QVector:
#include <array>
typedef std::array<int, 6> MyArray;
QList<MyArray> l;
l.push_back(MyArray{0, 1, 2, 3, 4, 5});
#include <array>
typedef std::array<int, 6> MyArray;
QList<MyArray> l;
l.push_back(MyArray{0, 1, 2, 3, 4, 5});
To copy to clipboard, switch view to plain text mode
This is C++11, but if you use an older version you can define your own MyArray by wrapping a plain C array in a class. std::array has the following advantages over QVector:
- the fixed length (6) of all the arrays is enforced by typing;
- std::array is more memory-efficient, because it does allocate extra storage in case the array grows, like QVector does;
- there is no extra indirection (although QVector could implement a small array optimization).
Bookmarks