PP: Support operator creation with token pasting.

This commit is contained in:
John Kessenich
2016-12-21 12:32:56 -07:00
parent 0c4b7c931a
commit 224b1f733b
4 changed files with 118 additions and 8 deletions

View File

@@ -50,3 +50,21 @@ float simplePaste(ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF01234567
// non-identifiers
int a = simplePaste(11,12);
// operators
#define MAKE_OP(L, R) L ## R
const int aop = 10;
const int bop = 4;
int cop = aop MAKE_OP(<, <) bop;
bool dop = aop MAKE_OP(!,=) bop;
#define MAKE_OP3(L, M, R) L ## M ## R
void foo()
{
int e = 16;
e MAKE_OP3(>,>,=) 2;
// recovery from bad op
bool f = e MAKE_OP(>,!) 5;
}