For writing/reading files, I do some low-level/binary manipulation with tuples and vectors.
When I do std::vector<bool> v(8) or std::tuple<bool, bool, bool, bool, bool, bool...>, do I have the guarantee that the boolean are not concatenated ? (and consequently the vector and the tuples weights at least n bytes (where n is the number of booleans).
For writing/reading files, I do some low-level/binary manipulation with tuples and vectors. When I
Share
It is implementation-defined whether
std::vector<bool>is bit-packed. Its interface doesn’t provide any way to directly access the bool values, thus trying to access the underlying array directly, you will certainly get burnt at some point.std::tupleis a generalization ofstd::pair. Thusstd::tuple<bool, bool, bool>is equivalent tostruct SomeStruct { bool a, b, c; };, in other words, bool values won’t be bit-packed.