3 ms·
C++ has `std::bitset` for when the length is known ahead of time [0]. Otherwise, `std::vector<bool>` _may_ be specialized to occupy one bit per element [1]. [
by dgunay 5y ago
C++ has `std::bitset` for when the length is known ahead of time [0].
Otherwise, `std::vector<bool>` _may_ be specialized to occupy one bit per element [1].
[0]: https://en.cppreference.com/w/cpp/utility/bitset https://en.cppreference.com/w/cpp/utility/bitset
[1]: https://en.cppreference.com/w/cpp/container/vector_bool https://en.cppreference.com/w/cpp/container/vector_bool
- wruza 5y agoBoth (and boost’s version too) can only address/assign one bit at a time, so it introduces the mirrored problem: how do you splice an n-bit integer into it without fiddling? Of course one can always abstract ops from my snippet away into some library, like setbits(ptr, offset, len, value), that’d be still valid, no need for fancy overloads even. But when batteries aren’t included, nobody cares enough to buy them separately. We know that from the situation with C strings.