-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for expressions with template arguments. #5
Comments
Hi @cra2801, I think I see what you're proposing. It'd be a cool enhancement, it will add a lot of complexity to the expression decomposer but I think it could work. I will try to play around with it when I get the chance! |
Supporting this would involve further complicating an already intricate expression decomposition system and I'm concerned about possible impact on build times. Possibly the sort of thing that would make sense to optionally enable/disable, but that'd probably involve maintaining two expression decomposition systems. I'm going to mark this as a backlog enhancement for now. |
You cna draft a small macro to take any token like // Remove parens around macro token if any are present
#define TTS_REMOVE_PARENS(x) TTS_EVAL((TTS_REMOVE_PARENS_I x), x)
#define TTS_REMOVE_PARENS_I(...) 1, 1
#define TTS_APPLY(macro, args) TTS_APPLY_I(macro, args)
#define TTS_APPLY_I(macro, args) macro args
#define TTS_EVAL_I(test, x) TTS_MAYBE_STRIP_PARENS(TTS_TEST_ARITY test, x)
#define TTS_EVAL(test, x) TTS_EVAL_I(test, x)
#define TTS_TEST_ARITY(...) TTS_APPLY(TTS_TEST_ARITY_I, (__VA_ARGS__, 2, 1))
#define TTS_TEST_ARITY_I(a, b, c, ...) c
#define TTS_MAYBE_STRIP_PARENS(cond, x) TTS_MAYBE_STRIP_PARENS_I(cond, x)
#define TTS_MAYBE_STRIP_PARENS_I(cond, x) TTS_CAT(TTS_MAYBE_STRIP_PARENS_, cond)(x)
#define TTS_MAYBE_STRIP_PARENS_1(x) x
#define TTS_MAYBE_STRIP_PARENS_2(x) TTS_APPLY(TTS_MAYBE_STRIP_PARENS_2_I, x)
#define TTS_MAYBE_STRIP_PARENS_2_I(...) __VA_ARGS__ Thus you can ask people to put () in their expression and pass the macro argument through TTS_REMOVE_PARENS. |
Currently, the following code fails to compile:
This code can be seen in action on compiler explorer.
This is due to
foo<3,4>()
being seen as two arguments when passed to a macro, specificallyfoo<3
and4>()
. This can be worked around with an extra set of parenthesis. Working around this in the library would be difficult, but should be possible. Decomposition would need to overloadoperator,
to handle the error message string, and additional diagnostic variables. The top level macros would then consume a single variadic argument pack.The text was updated successfully, but these errors were encountered: