want to add `pointers to data members -> index`
- 主要言語
- C++
- スター
- 1.5k
- フォーク
- 176
- 平均マージ
- 5日 21時間
- マージ済み PR(30日)
- 1
説明
```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));
```
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
評価
この issue はまだ評価されていません。