I need to exclude double instantiation, therefore I need to exclude the same types from the sequence of types.
#define ENTITY_SEQ (A)(B)(C)(A)(C)
||
\/
#define UNIQUE_ENTITY_SEQ (A)(B)(C)
I want to process it using a boost preprocessor. Is it possible to do that?
There is, to my knowledge, no way to check the equality of two unknown identifiers. But, if you know the list of identifiers ahead of time, then it is certainly is possible.
I had some time to implement the trivial
O(n^2)algorithm today, although you could probably do better. I hope the order isn't important to you, because I decided against trying to keep it.The basic idea is to transform the sequence (
(1)(2)(3)) into a terminated guide (1)2)3)0end)), which allows for iteration with a context. This context is used inDEDUPE1(seq,x)to remove all occurrences ofxinseqand appendxto the end ofseqafterwards.DEDUPE(seq)usesseqitself as the context and iterates through all elements ofseq, and updates the iteration context withDEDUPE1(seq,x).The above works for sequences of any size, but it is implementation defined if this type of sequence iteration works. Luckily, essentially all preprocessors support it.
Update: Here is a
O(n)version, that is shorter, but requires more code for each extra supported identifier:Edit: I updated the
CHECKmacro, because I realized that I've been using a less ideal implementation.