-
-
Notifications
You must be signed in to change notification settings - Fork 258
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
Add support for simple structs? #6
Comments
You can use magic_get (https://www.youtube.com/watch?v=abdeAew3gmQ). Requires C++14. |
If there is a small subset of the code that we could include in dbg(c); // CustomDatatype{42, "hello"} (which would already be great). |
There's also cista, which uses another approach for simple type reflection (see to_tuple.h for example). |
Thank you for the reference! Unfortunately, it seems to rely on C++17 functionality, but I would really like |
Would it be good enough if For C++11, I think it's possible to define a macro so
based on this technique but it's tricky. |
Agreed. If the concerns above (license, code size) can be clarified, I'd be willing to accept this addition. |
@sharkdp Here is a proposal to incorporate this feature. This is a working example that I came up with based on the above discussions and some snippets from here. Sample driver codestruct MetaData {
std::string name;
int64_t id;
};
struct Entity3D {
int32_t x, y, z;
MetaData meta;
};
DBG_REGISTER_STRUCT(MetaData, name, id)
DBG_REGISTER_STRUCT(Entity3D, x, y, z, meta)
int32_t main() {
Entity3D e = {3, 2, 1, {"dummy_name", 98765}};
dbg(e); // [main.cc:34 (main)] e = {'x': 3, 'y': 2, 'z': 1, 'meta': {'name': "dummy_name", 'id': 98765}} (Entity3D)
} If this is satisfactory I'll be glad to open a PR! |
Thank you. If we add support for this, then I would definitely look for a solution which does not require any additional macro calls like |
It would be cool to somehow add support for simple
struct
s/class
es likeWe would somehow have to iterate over all members... without modifying to original struct definition. Not sure if this is possible in C++ (without reflection).
The text was updated successfully, but these errors were encountered: