31#ifndef FENNEC_CONTAINERS_BITFIELD_H
32#define FENNEC_CONTAINERS_BITFIELD_H
46 static constexpr size_t bits = N;
47 static constexpr size_t bytes = (N + 7) / 8;
54 explicit constexpr bitfield(
const bool (&arr)[N])
56 for (
size_t i = 0; i < arr; ++i) {
57 this->store(i, arr[i]);
62 explicit constexpr bitfield(
const size_t (&arr)[I])
64 for (
size_t i : arr) {
69 template<
typename...ArgsT>
72 (this->store(fennec::forward<ArgsT>(args),
true), ...);
75 template<
typename...ArgsT>
requires((is_bool_v<ArgsT> or is_convertible_v<ArgsT, bool>) and ...)
79 (this->store(i++, fennec::forward<ArgsT>(args)), ...);
95 bool test(
size_t i)
const {
96 assertd(i < bits,
"Index out of Bounds!");
99 return _bytes[b] & (1 << o);
103 assertd(i < bits,
"Index out of Bounds!");
106 _bytes[b] |= (1 << o);
109 void clear(
size_t i) {
110 assertd(i < bits,
"Index out of Bounds!");
113 _bytes[b] &= ~(1 << o);
116 void toggle(
size_t i) {
117 assertd(i < bits,
"Index out of Bounds!");
120 _bytes[b] ^= (1 << o);
123 void store(
size_t i,
bool v) {
124 assertd(i < bits,
"Index out of Bounds!");
127 (_bytes[b] &= ~((1 << o))) |= ((v << o));
141 ((_bytes[I] = ~_bytes[I]), ...);
A header containing the definition for a static/stack allocated array.
Data Structure that defines a compile-time allocated array.
Definition array.h:64
Bitfield Container with basic Bit Ops.
Definition bitfield.h:45
wrapper for sets of elements
Definition set.h:68