Программы на C++. Форум разработчиков
-
Anonymous
Преобразование указателя в член для члена индекса с использованием boost.pfr без создания объекта
Сообщение
Anonymous »
Рассмотрим следующую структуру: < /p>
Код: Выделить всё
struct Particle
{
float scale;
float opacity;
float rotation;
};
< /code>
Я хочу, чтобы следующее компилировало: < /p>
static_assert(indexOf() == 0);
static_assert(indexOf() == 1);
static_assert(indexOf() == 2);
< /code>
Мне удалось реализовать рабочую версию с помощью boost.pfr: < /p>
template
consteval int indexOf()
{
using ClassType = typename PMTraits::ClassType;
constexpr ClassType obj{};
std::size_t result = -1;
[&](std::index_sequence)
{
(...,
(
( static_cast(&(boost::pfr::get(obj)))
== static_cast(&(obj.*PM)) )
? (result = Is) : 0
)
);
}(std::make_index_sequence{});
return result;
}
Но я недоволен тем фактом, что мне нужно создать объект типа classtype , чтобы сделать Obj.*PM работа>
Подробнее здесь:
https://stackoverflow.com/questions/797 ... reating-an
1757138706
Anonymous
Рассмотрим следующую структуру: < /p>
[code]struct Particle
{
float scale;
float opacity;
float rotation;
};
< /code>
Я хочу, чтобы следующее компилировало: < /p>
static_assert(indexOf() == 0);
static_assert(indexOf() == 1);
static_assert(indexOf() == 2);
< /code>
Мне удалось реализовать рабочую версию с помощью boost.pfr: < /p>
template
consteval int indexOf()
{
using ClassType = typename PMTraits::ClassType;
constexpr ClassType obj{};
std::size_t result = -1;
[&](std::index_sequence)
{
(...,
(
( static_cast(&(boost::pfr::get(obj)))
== static_cast(&(obj.*PM)) )
? (result = Is) : 0
)
);
}(std::make_index_sequence{});
return result;
}
[/code]
Но я недоволен тем фактом, что мне нужно создать объект типа classtype , чтобы сделать Obj.*PM работа>
Подробнее здесь: [url]https://stackoverflow.com/questions/79757242/converting-pointer-to-member-to-member-index-using-boost-pfr-without-creating-an[/url]