Do all versions of GCC C++ standard library on 64-bit Ubuntu implement this bitset and vector bool specialization with bit packing?
I have a special bit data structure that I want to ensure is as space efficient as possible (up to padding for alignment). It needs to hold up to 2^20 bits. I'm considering implementing it manually on uint64 words with bit operations.
Do all versions of GCC C++ standard library on 64-bit Ubuntu implement this bitset and vector bool specialization with bit packing?
I have a special bit data structure that I want to ensure is as space efficient as possible (up to padding for alignment). It needs to hold up to 2^20 bits. I'm considering implementing it manually on uint64 words with bit operations.
Share Improve this question edited Feb 2 at 5:57 qwr asked Feb 1 at 17:53 qwrqwr 11k6 gold badges70 silver badges115 bronze badges 2 |1 Answer
Reset to default 0The standard says:
There is no requirement that the data be stored as a contiguous allocation of
bool
values. A space-optimized representation of bits is recommended instead.
Although that's only a recommendation, it's natural to use similar representations for both std::vector<bool>
and std::bitset
.
With std::bitset
, you could use static_assert()
with sizeof
to help ensure the size is minimal; that's more difficult with std::vector<bool>
.
std::bitset
, I'd be extremely surprised if it has ever not been the case. – Nate Eldredge Commented Feb 2 at 5:10