Skip to content
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

how to expose types that are mostly just a wrapper around a collection #1643

Open
rajkosto opened this issue Mar 7, 2025 · 4 comments
Open

Comments

@rajkosto
Copy link

rajkosto commented Mar 7, 2025

i have some types that are just a wrapper around vector, map, etc
i thought just passing through cbegin/cend/begin/end/at/operator[] key_type and value_type would be enough but it doesn't seem to be
the internal collection member is private so i can't just passthrough that one via a lambda

@rajkosto
Copy link
Author

rajkosto commented Mar 8, 2025

im now trying to get unknown_read/unknown_write to just read/dump values from the "self" object but lambdas arent supported for those, only member function and object pointers...

@stephenberry
Copy link
Owner

What kind of wrapper is this? Consider how the wrapper's purpose should be seen in JSON. For example, std::optional is a wrapper that provides a null state.

Lambdas are allowed for self and for glz::custom, so there's probably just a misunderstanding.

Can you provide a simple code example of what your wrapper is like and what its purpose is? Take a look at glz::custom as well, where you can register lambdas for decode/encode.

@rajkosto
Copy link
Author

rajkosto commented Mar 10, 2025

I actually tried just exposing the inside vector but I kept getting strange errors I couldn't fix like mangled_name not defined (which I couldn't fix even by adding "name" to meta for the inner key/collection type, I think it's because those types were templates ?)
And how would one use custom to have a key/value style output when the collection is an array or vector instead of a map?

@stephenberry
Copy link
Owner

mangled_name not being defined could come from your type not being reflectable (aggregate initializable). It is hard to say without any code or error output.

Use array() rather than object() in your glz::meta to deal with a collection that should be an array instead of a map (object).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants