I am wondering if there is a way to initialize a vector using an enumeration. Enumeration is necessary because I create a vector of objects (the same class, Chess_piece, but of a different type). I want to have access to an element without a lot of tests ( if (this is white pawn 8)... ). Enumeration can be used to drill down the shapes in the beautiful way vec(W_PAWN8)... Anyway, when I create a vector, I do something like this (pseudo code)
//generate enum of pieces enum pieceList{ ... } pieceEnum; vector<int> pieceIter = {W_PAWN1,W_PAWN2,...}; //equal to {1,2,...} //board index goes from lower left to upper right vector<int> boardIdx = {8,9,10,11,12,13,14,15,16,1...}; vector<Piece*> pieceVec; for (int i=0; i<32; i++) pieceVec.pushback( new Piece( boardIdx(i), pieceIter(i) ) );
However, now I actually write the same thing 2 times. And when I create the listing and pieceIter . For this program, I can live with it, but I may have the same problem more than once.
That's why I wonder if something like vector<int> pieceIter {pieceEnum}; in c ++? Of course, the code snippet in the previous sentence is not valid, but I think it hints at my problem, use all the variables in the enumeration and initialize the vector in a simple way?
If not, is it possible to use some "range initialization" for a vector, for example, in matlabl. Sort of:
vector<int> vec {1:32};
But with C ++ syntax?