Код: Выделить всё
#include
#include
#include
#include
#include
template
struct BitfieldBits
{
constexpr static inline uint64_t num_bits = N;
};
struct DepthMode : BitfieldBits
{
};
struct UseCulling : BitfieldBits
{
};
struct VertexShaderID : BitfieldBits
{
};
template
struct MyBitfield
{
uint64_t bitfield;
/* HERE, IS THERE A WAY TO HOLD THE TYPES BUT WITHOUT THE ACTUAL OBJECTS */
constexpr static inline std::tuple tuple{};
constexpr static inline std::array bit_shift_offsets = []() consteval
{
std::array arr;
auto lambda = [&] (const auto& self) consteval
{
if constexpr (idx >= sizeof ... (T))
return;
else
{// SO I CAN ACCESS IT HERE THROUGH A 'TYPE' std::get(tuple)::num_bits
arr[idx] = offset;
self.template operator() (self);
}
};
lambda.template operator() (lambda);
return arr;
}();
};
int main(int argc, char* argv[])
{
MyBitfield my_bitfield;
constexpr auto offset = my_bitfield.bit_shift_offsets[2];
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... -tuple-mem