diff options
Diffstat (limited to 'chilbert/Operations.hpp')
-rw-r--r-- | chilbert/Operations.hpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/chilbert/Operations.hpp b/chilbert/Operations.hpp index 578daaf..06a06fa 100644 --- a/chilbert/Operations.hpp +++ b/chilbert/Operations.hpp @@ -52,6 +52,16 @@ testBit(const T& field, const BitsetIndex<T> index) return field.test(index); } +/// Set the `index`th bit in `field` +template <typename T> +void +setBit(T& field, const IntegralIndex<T> index) +{ + assert(size_t(index) < sizeof(field) * CHAR_BIT); + field |= ((T)1 << index); + assert(testBit(field, index)); +} + /// Set the `index`th bit in `field` to `value` template <typename T> void @@ -62,6 +72,14 @@ setBit(T& field, const IntegralIndex<T> index, const bool value) assert(testBit(field, index) == value); } +/// Set the `index`th bit in `field` +template <typename T> +void +setBit(T& field, const BitsetIndex<T> index) +{ + field.set(index); +} + /// Set the `index`th bit in `field` to `value` template <typename T> void |