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

Accessing addresses to members #184

Open
very-cool-name opened this issue Sep 16, 2024 · 0 comments
Open

Accessing addresses to members #184

very-cool-name opened this issue Sep 16, 2024 · 0 comments

Comments

@very-cool-name
Copy link

Hey, I have some pybinded structs, that have a lot of repeating boilerplate:

struct MyStruct {
  int x;
  char c;
};

py::class_< MyStruct >(module, "MyStruct")
  .def_readonly("x", &MyStruct::x)
  .def_readonly("c", &MyStruct::c);

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.

Thanks!

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

1 participant