Consider a simple macro:
#define ECHO(x) x
ECHO(foo(1, 2))
This produces the exact output we expect:
foo(1, 2)
The above example works because the parenthesis adjacent to the function call are recognized by the preprocessor.
Now consider what happens if I use a template instead of a function call:
ECHO(template<int, bool>)
This causes an error because the preprocessor interprets the template<int
and the bool>
as two separate arguments to the macro. The preprocessor doesn't recognize <>
for scope!
Is there anyway to use a template like this in a macro?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…