You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was thinking about using boost::pfr to automate this, but I don't think there is currently any way, since boost::pfr doesn't have an interface to access member addresses i.e. something like this:
auto cls = py::class_< MyStruct >(module, "MyStruct");
boost::pfr::for_each_member_address_with_name<MyStruct>([cls](std::string_view name, auto address) {
cls.def_readonly(name, address);
});
Is there any interest in having such interface? And if so - I think I can make a PR. If you could give me some hints on possible implementation - that would be greatly appreciated.
As far as I understand, in the code above there is no point at which we have pointer of type Us Ts::*.
This reinterpret_cast<void*>(&(pfr::get<meta>(mystruct))); is indeed the memory address, but I don't know of any way to make a hop from memory address to a pointer-to-member.
Activity
apolukhin commentedon Oct 17, 2024
Looks quite interesting. Please provide a PR.
very-cool-name commentedon Oct 29, 2024
Gave it some thought and I don't really know how to implement it. Structured bindings won't help here, since essentially:
If you are aware of maybe compiler specific tricks that can let me do that - please help me.
hansalemaos commentedon Nov 7, 2024
Maybe something like this? Probably not the safest version, but it works :)
very-cool-name commentedon Nov 7, 2024
As far as I understand, in the code above there is no point at which we have pointer of type
Us Ts::*.This
reinterpret_cast<void*>(&(pfr::get<meta>(mystruct)));is indeed the memory address, but I don't know of any way to make a hop from memory address to a pointer-to-member.hansalemaos commentedon Nov 7, 2024
Got it, I thought your main concern was getting the memory address of each member.
mnemolyst commentedon Jul 3, 2026
I just opened #237 , which can be used like this: