I am trying to use Boost.Preprocessor to do some compile-time work. I want to index a table using values that are computed in other macros. When I try I get the following error: "concatenation with '(' in macro 'BOOST_PP_BOOL_I' does not create a valid token."
This is the simplest code that produces the issue.
#define MY_TABLE (0, (1, BOOST_PP_NIL))
#define MY_INDEX_FUNCTION(x) (x)
void func() {
int y = BOOST_PP_LIST_AT(MY_TABLE, MY_INDEX_FUNCTION(0));
}
It is pretty easy to determine that removing the parens in MY_INDEX_FUNCTION resolves the issue in this case. My actual code uses a much more complex function to calculate the table index in a much larger table.
Is there something that I can do or change that would fix this such that the parens and more complex macros don't cause problems?
The second parameter of
BOOST_PP_LIST_ATtakes an index/integer. It works with tricky preprocessor hacks under the hood. The parameter(expanded) should be exactly an integer-literal, not an integer inside parenthesis. TheMY_INDEX_FUNCTIONshould be changed, so that the parameter passed to theBOOST_PP_LIST_ATis literally an integer-literal:The macro does not work with arithmetic expressions, this will not work:
But you can do this with
This macro definitions can be created by a (python-)script