From fa318825ef0404816728f733484caa1bc23afa53 Mon Sep 17 00:00:00 2001 From: hovertank3d Date: Fri, 14 Nov 2025 20:05:59 +0100 Subject: george droid --- include/util/bitset.hpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'include/util/bitset.hpp') diff --git a/include/util/bitset.hpp b/include/util/bitset.hpp index de5bd49..cd1dbd0 100644 --- a/include/util/bitset.hpp +++ b/include/util/bitset.hpp @@ -3,6 +3,7 @@ #include #include #include +#include constexpr int bits_ceil(int bits) { @@ -50,4 +51,48 @@ public: assert(i < flags); return bit_ref(*this, i / 8, (1 << (i % 8))); } +}; + +// FIXME: ?? +template <> +struct bitset<0> : std::vector { + using container_type = std::vector; + +private: + struct bit_ref { + bitset<0>& a; + int referenced_byte; + uint8_t referenced_bit_mask; + + bool operator=(bool b) + { + if (b) + a.at(referenced_byte) |= referenced_bit_mask; + else + a.at(referenced_byte) &= ~referenced_bit_mask; + return b; + } + + constexpr operator bool() const + { + return (a.at(referenced_byte) & referenced_bit_mask) > 0; + } + }; + +public: + template + constexpr bool operator[](T idx) const + { + unsigned int i = (unsigned int)(idx); + assert(i < container_type::size()); + return (container_type::at(i / 8) & (1 << (i % 8))) > 0; + } + + template + bit_ref operator[](T idx) + { + unsigned int i = (unsigned int)(idx); + assert(i < container_type::size()); + return bit_ref(*this, i / 8, (1 << (i % 8))); + } }; \ No newline at end of file -- cgit v1.2.3