C ++ 5 dimensional vector?

I am trying to make a 5-dimensional vector, and I cannot get it to work. I know if I need to write a three-dimensional vector, I could write it as follows: vector< vector< vector<string> > > block(27, vector< vector<string> > (27, vector<string>(27)));

Then I call it: block[x][y][z] = "hello";

I wrote a 5-dimensional vector as follows, and this gives me an error. vector< vector< vector< vector< vector<string> > > > > block(27, vector< vector< vector< vector<string> > > >(27, vector< vector< vector<string> > >(27, vector< vector<string> >(27, vector<string>(27)))));

Could you tell me how to write a 5-dimensional vector correctly? Many thanks.

+3
source share
3 answers

But you have to stop and think if the dictionary will work better. If the data is sparse, you will save a lot of memory. Create a key using 5 dimensions and create only those members that you need.

+3
source

5- , .

vector< vector< vector< vector< vector > > > > 
                                     ^^
                                     Here. What is the base vector a vector off?

typedef, :

typedef std::vector<std::string>     Dim1;
typedef std::vector<Dim1>            Dim2;
typedef std::vector<Dim2>            Dim3;
typedef std::vector<Dim3>            Dim4;
typedef std::vector<Dim4>            Dim5;

Dim5 block(27, Dim4(27, Dim3(27, Dim2(27, Dim1(27)))));
+6

Boost .

http://www.boost.org/doc/libs/1_43_0/libs/multi_array/doc/user.html

"Boost MultiArray - N- , ( N- std::vector > ). , , ++-. , , , ( ).

+6

Source: https://habr.com/ru/post/1757440/


All Articles