I would like to generalize bitwise operators in C ++ without thinking that the underlying structure is an array.
As an instance ... if I want to represent 86 bits, I would use a structure / structure class, for example:
typedef struct { uint64_t x[1]; uint16_t y[1]; uint8_t z[1]; } sampleStruct;
Instead, if I wanted to allocate 160 bits, I would use a structure such as:
typedef struct { uint64_t x[2]; uint32_t y[1]; } sampleStruct;
I think that a trivial but not optimal storage solution would be to assume that all the pieces are homogeneous and give off a minimum of those st it covers the size that I realize, however, even with regard to exercises, I prefer the way I showed.
It seems to me that I should use metaprogramming to solve the problem, so I should correctly identify
template <int I> typedef sampleStruct {
However, I am not a great expert in metaprogramming C ++ templates, so I would like to understand what would be the best way to implement a different type of struct var I. I know how to choose the best "cover" for my length would be something like this:
N64 = I/64; RemN = I%64; if(0 < RemN <= 8) { add uint8_t var; } else if (8 < RemN <= 16) { add uint16_t var; } else if (16 < RemN <= 24) { add uint16_t var; add uint8_t var; } else {
What can I do to achieve what I want to do?
I also assume that the correct arrays will achieve slightly better performance compared to another possible implementation.
Hoping this is clear enough ... (Assume C ++ 11 or later).