Код: Выделить всё
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;
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... reating-an