I\'m writing some code against a C++ API that takes vectors of vectors of vectors, and it\'s getting tedious to write code like the following all over the place:
<
In C++0x you will be able to use your desired syntax:
vector > > vvvs =
{ { {"x","y", ... }, ... }, ... };
But in today's C++ you are limited to using boost.assign which lets you do:
vector vs1;
vs1 += "x", "y", ...;
vector vs2;
...
vector > vvs1;
vvs1 += vs1, vs2, ...;
vector > vvs2;
...
vector > > vvvs;
vvvs += vvs1, vvs2, ...;
... or using Qt's containers which let you do it in one go:
QVector > > vvvs =
QVector > >() << (
QVector >() << (
QVector() << "x", "y", ...) <<
... ) <<
...
;
The other semi-sane option, at least for flat vectors, is to construct from an array:
string a[] = { "x", "y", "z" };
vector vec(a, a + 3);