BitArray is a tiny header-only library for implementing a generic bit array that works with multiple integer types such as char, (u)int8_t, (u)int16_t, (u)int32_t etc.
Each element of the provided integer type (type) comprises a block in an array, containing sizeof(type) * __CHAR_BIT__ bits within it.
BitArray<std::uint8_t> arr{17};
for (int i = 0; i < arr.size(); i++) {
arr.set(i);
for (bool bit : arr) {
std::cout << bit;
}
std::cout << '\n';
arr.clear(i);
}set- Sets the bit at an (unchecked) indexclear- Clears the bit at an (unchecked) indexset_all- Sets all the bits in the arrayclear_all- Clears all the bits in an array
accessible- Checks if the provided index is within boundsat- Checked indexing, throwsstd::range_erroron out of rangeoperator[]- Unchecked indexingsize- Returns the number of bits stored in the array
begin/end- Non-const bi-directional forward iterator methodscbegin/cend- Const bi-directional forward iterator methodsrbegin/rend- Non-const bi-directional reverse iterator methodscrbegin/crend- Const bi-directional reverse iterator methods
BitArray does not support random access iterators. It is also not possible to
mutate the bit array through the iterators.
The documentation for this project is hosted at readthedocs
This project uses the MIT license.