want to add `pointers to data members -> index`
- Dominant language
- C++
- Stars
- 1.5k
- Forks
- 176
- Avg merge
- 5d 21h
- Merged PRs (30d)
- 1
Description
```C++
template
struct DelayConstruct {
static inline T value{}; // construct in runtime.
};
template
constexpr std::size_t get_index(M T::*mem_ptr) {
auto &t = DelayConstruct::value;
return
std::apply([&](auto&...e) {
int idx = 0;
std::array list = { (void*)&e ... };
for (auto b : list) {
if (b == &(t.*mem_ptr))
return idx;
idx += 1;
}
return 42;
}, structure_tie(t));
}
```
```C++
//example1
struct S {
std::string x;
std::vector y;
std::string z;
};
static_assert(boost::pfr::get_index(&S::x) == 0);
static_assert(boost::pfr::get_index(&S::y) == 1);
static_assert(boost::pfr::get_index(&S::z) == 2);
```
```C++
//example2
struct S {
static constexpr auto names = std::make_tuple("x","y","z");
std::string x;
std::vector y;
std::string z;
};
assert(std::string_view{"x"} == std::get(S::names));
assert(std::string_view{"y"} == std::get(S::names));
assert(std::string_view{"z"} == std::get(S::names));
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the existing Boost.PFR implementation and tests, then compare the requested behavior with the two C++ examples in this issue. Done means the requested get_index operation supports each listed pointer-to-data-member and the examples are covered by compile-time or runtime tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100