boostorg / boostorg/pfr

Accessing addresses to members

Open
#184 6 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
C++
Stars
1.5k
Forks
176
Avg merge
5d 21h
Merged PRs (30d)
1

Description

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

```cpp
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:

```cpp
auto cls = py::class_< MyStruct >(module, "MyStruct");
boost::pfr::for_each_member_address_with_name([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!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.