is it possible to implement a macro that swaps a trailing parenthesized expression?

51 Views Asked by At

Is something like the following possible with c/c++ preprocessor?

#define SWAP(...) ???

SWAP(1,2,3)(4,5)

// will expand to

{ 4,5 , 1,2,3 }

Any use of Boost.Preprocessor and/or variable argument macros is legit.

If this is not possible, why not?

Please note: The trailing parenthesis is an important part of this question. Obviously, an alternative such as SWAP( (1,2,3) (4,5) ) can be made to work trivially (e.g. https://godbolt.org/z/97EqxK)

PS: A non-swapping version looks like this https://godbolt.org/z/u9kby3

0

There are 0 best solutions below