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?
A little painful, but it works.
FWIW, if the syntax for the argument allows
()s, you don’t need the substitution, e.g.,will work for a single argument macro but that doesn’t work in all cases (including yours).