Here is some C++ code I\'m playing around with:
#include
#include
#define IN ,
#define FOREACH(x,y) for(unsigned int i=0;i&l
Others have already explained why it doesn't compile as is.
In order to make it work you have to give that IN
a chance to turn into a comma. For that you can introduce an extra level of "indirection" in your macro definition
#define IN ,
#define FOREACH_(x,y) for(unsigned int i=0;i
In this case you'll have to use some substitute for comma (like your IN
) and can no longer specify comma explicitly. I.e. now this
FOREACH(int item IN ints)
cout << item;
ENDFOREACH
compiles fine, while
FOREACH(int item, ints)
cout << item;
ENDFOREACH
does not.