Skip to content

Mapping between members of the struct and it's json counterpart #1397

Answered by stephenberry
DragosPetri asked this question in Q&A
Discussion options

You must be logged in to vote

Currently no, this mode of reflection is quite tricky to implement until C++26. You can call glz::reflect<my_struct>::keys[0] which will return "i", but this requires you to know the index of i.

You could probably hack a solution that works for standard layout types that have known packed behavior (e.g. equal sized elements) by computing the distance between the pointer to the object instance and the pointer to the reference, but this would have to be very specialized. This would give you the index to use in the code above.

It essentially comes down to reflection working through structured bindings, which are converted to tuples and thus are only accessed by index. There is the possibilit…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@DragosPetri
Comment options

Answer selected by DragosPetri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants