I was working on a contest problem, where I had to initialize a vector in the following way:
vector<pair<int,int>> moves({{i,j}, {i,-j}, {-i,j}, {-i,-j},
{j,i}, {j,-i}, {-j,i}, {-j,-i}});
Although I know that this is not the best way and am aware of a number of different ways to accomplish this with minimal effort, I wonder if there is a way the C++ macros allow me to simply copy-paste the first four elements of the above vector to achieve the same in the following way:
vector<pair<int,int>> moves({{i,j}, {i,-j}, {-i,j}, {-i,-j},
#define i j
#define j i
{i,j}, {i,-j}, {-i,j}, {-i,-j}
#undef i
#undef j
});
The above code obviously does not work because of circular referencing of the variables.
P.S. : Although Matteo Italia's answer is absolutely correct in the above context, I am more interested in knowing whether swapping occurences of variables using macros is possible in C++ or not and how, if possible?