I'm making a 2D board game and to desing the board layout and record tokens, I
use a vector of vectors, which gives me the following, unatural, board layout:
(0,0) (0,1) (0,2) (0,3)
(1,0) (1,1) (1,2) (1,3)
(2,0) (2,1) (2,2) (2,3)
(3,0) (3,1) (3,2) (3,3)
|
The layout I would like to have is the following:
(3,0) (3,1) (3,2) (3,3)
(2,0) (2,1) (2,2) (2,3)
(1,0) (1,1) (1,2) (1,3)
(0,0) (0,1) (0,2) (0,3)
^
|
|
Rows in reverse order...
|
which seems more natural to me in terms of use and readability.
In other words, I would like a vector whose behaviour is "reversed". For example,
I would like to be able to do:
1 2 3 4
|
reverse_vector a {1, 2, 3, 4};
cout << a[0]; // prints 4
cout << a[3]; // prints 1
|
and "begin" and "end" for iterators are reversed also.
I though about overloading the containing "row" vecor operator[] to give me the
wanted result, but then realized that there were a lot of other methods and
stuff to be overloaded in order to do this, which is starting to make me beleive
there should be a simpler way.
I try googling, but found nothing so far. Do you know of any?
Should I write one from scratch?
Thanks!