Template Class BitArray
Defined in File binary.h
Class Documentation
-
template<std::size_t Bits>
class BitArray Fixed-size packed bit array.
Storage uses the smallest fixed-width integer that can hold the requested bits without exceeding the platform’s native word size. Larger arrays are split across native words.
Bit zero is the least-significant bit. Mutable indexing returns a proxy so individual bits can be assigned as though they were ordinary booleans. words() exposes the same packed storage as a contiguous word array. Indices must be below Bits; assertions are not checked release-mode errors. Spans/proxies borrow this array. Access is unsynchronized, including writes to different bits in one word; whole-word access can modify unused high bits. Native storage/byte order is not a portable serialized representation.
See also
- Template Parameters:
Bits – Positive logical bit count, enforced by static_assert; starts with all bits zero.
Public Types
Public Functions
-
Reference operator[](std::size_t index) noexcept
Borrows a writable bit proxy; indexing performs no allocation.
See also
- Parameters:
index – Zero-based bit index, strictly below Bits; asserted, not a checked release error.
- Returns:
Proxy borrowing this array’s backing word. Assignment from bool writes that bit; assignment from another proxy copies its current bit value, not its binding. Explicit bool conversion samples the bit. Keep this array alive through proxy use; copied/moved arrays have separate storage and do not retarget existing proxies. Writes, including different bits sharing a word, require caller synchronization.
-
bool operator[](std::size_t index) const noexcept
Reads one bit as an independent bool value.
- Parameters:
index – Zero-based bit index below Bits; violations are assertion-only.
- Returns:
Current bit value; no pointer/proxy or synchronization is retained.
-
std::span<word_type, word_count> words() noexcept
Borrows contiguous mutable backing words in least-significant-bit index order.
- Returns:
Fixed-extent word span borrowing this array. It does not mask unused high bits. Caller mutations and synchronization operate on whole words; this is native storage, not a portable byte serialization. Keep the owning array alive through use.
-
std::span<const word_type, word_count> words() const noexcept
Borrows a read-only span of contiguous native backing words.
- Returns:
Fixed-extent view valid while this array lives, including any unused high bits. It is a live view, not a snapshot; reads must not race mutation of the same words.