   Vector to hold 2d int Array
  Hi, i am currently writing a game Ai for which i am generating moves and storing then in a dynamic structure,thus the choice of vector. Initially when i started out ,1D looked great, but after changes  i have decided to go with 2D representation. Creating a vector which just holds ints is a breeze vector <int> move_list;but since the approach has changed , i would like this to store a 2D integer array.i would like to know if there is a support for the same by the library or i need to encapsulate the moves in a structure , create a vector of that and then  parse the values from it.Cheers![Edited by - Nokturnal on December 16, 2005 5:13:21 PM]
  Just as a quick note, you could always just use a vector of vectors to emulate the 2D storage. I don't know about performance of this but I don't see it being a bad thing. Just use the original vector for either your x or y axis and then the element vectors are the other axis.Something like this:vector < vector <int> > my_variable;   ;  Thanks spanky that just might do the trick! I did find out another way to acomplish this :) , but out of curiosity , is what i said above possible ?Cheers!   ;  you could use Boost Multi-array.   ;  Boost::multi_array is probably the best standard option.If you really want to do things yourself, you should read this (and the next few sections). (Actually, beginning programmers would do well to read the whole C++ FAQ Lite :) )   ;  WOW!! Boost is a very sweet option, not that i dont want to get tangled with pointers , right now the priority is to get it working, Thanks :)   ;  From what I know, other than a vector<vector> approach (or some other nested container) or a [][] array, there isn't any built in support for it. You could use a single [] array for the job. You could do something like:gridSize = width * height;elements = new int[gridSize];and then to access something at a given x,y location, you would access it like such:elements[x + y*width];which of course can be wrapped in a function with some bounds checking.The reason you do the y*width is because each row is width elements wide. If you want to skip the first line (where the first line is 0 and the line you want access to is y=1) that's 'width' elements you skip. This will "bump" you down the rows so you can move across the given row.This is a simple solution (like the nested vector) using the features of the language. I'm not familiar with Boost myself (I've wanted to for a bit) but I've heard good things about it as well so it might be worth checking out.ShawnPS - I make no guarantee's about anything I say since I said I would start participating in hopes that my talking will further enforce what I do and do not know about. If I make a mistake, someone will hopefully kick my butt and educate me as to the correct response.   