TheNitesWhoSay / RareCpp

Creating a simpler, more intuitive means of C++ reflection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Field Limits

TheNitesWhoSay opened this issue · comments

With the current version you're limited to 20 reflected fields, should be expanded as much as possible.

It seems that COUNT_ARGUMENTS and FOR_EACH can both be expanded to take 125 varadic arguments.

The triplets (e.g. "int, size, false", shortened"B(int, size)") should be cut out. We can do a template B<int> easy enough, reducing the arguments to a pair (e.g. "B<int>, size"), then the field name "size" can be brought in together if we wrap B in parenthesis and place "size" after it (e.g. "(B<int>) size"), when things are in the form "(LHS) RHS" (Left Hand Side/Right Hand Side) - which I'll call a partially parameterized argument - the LHS and RHS are extractable with some macro trickery...

To get RHS:
#define BLANK(...)
#define GET_RHS(x) BLANK x

1.) GET_RHS((lhs) rhs) -- call GET_RHS with "(lhs) rhs"
2.) BLANK (lhs) rhs-- GET_RHS expands, lhs is now being interpreted as an argument to the macro "BLANK"
3.) rhs -- BLANK (lhs) expands (expands into nothing), so rhs is all that's left

To get LHS:
#define GET_FIRST(x, y) x
#define WRAP(x) (x),
#define EXPAND(x) x
#define GET_LHS(x) GET_FIRST(EXPAND WRAP x)

1.) GET_LHS((lhs) rhs) -- call GET_LHS with "(lhs) rhs"
2.) GET_FIRST(EXPAND WRAP (lhs) rhs) -- GET_LHS expands, lhs is now being interpreted as an argument to the macro "WRAP"
3.) GET_FIRST(EXPAND (lhs), rhs) -- WRAP(lhs) expands, lhs is now being interpreted as an argument to the macro "EXPAND"
4.) GET_FIRST(lhs, rhs) -- EXPAND(lhs) expands, lhs and rhs are now two arguments to the macro "GET_FIRST"
5.) lhs -- GET_FIRST expands, it gives back the first argument passed to it: lhs

When I set this all up in a new REFLECT macro, it appears you can only provide 123 fields, providing 124 results in it throwing C1009: compiler limit: macros nested too deeply, though the largest structure I've ever used (a large, flat data file) has 59 fields so 123 is more than enough.

With the in-process refactor this has been expanded to 125 fields f31b851