Let's say I have a struct using bit-fields like that :
struct SomeData
{
char someChar:5;
char someSmallerChar:3;
}
The size of the content of one SomeData should be one char long instead of two, thanks to bitfields.
Now if I want to organize my data this way...
class SomeDataContainer
{
std::vector<char> someChar;
std::vector<char> someSmallerChar;
}
... I lose the benefit I had with the bit-fields regarding space efficiency. The size of the equivalent container is now twice the original one.
Is there a way to create a vector of char:5 and char:3 or something similar to it to get the same benefits while having the data in this vector format (contiguous in memory) ?
someChar's to be contiguous andstd::vector<SomeData>would putsomeSmallerChar's in the middle.std::vector<bool>which has bit-level granularity (andstd::bitsetwith a compile-time length). The next higher granularity provided by the standard library isstd::vector<char>(or similar). You could write your own container that allows granularity at the level you need.std::vector<bool>disaster is solely because it is a specialization, and not a completely different container