aboutsummaryrefslogtreecommitdiffstats
path: root/chilbert/Operations.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-08-07 17:29:35 +0200
committerDavid Robillard <d@drobilla.net>2018-09-29 14:46:14 +0200
commit4984100559a00e055a502fc8fe85d7ca66589b36 (patch)
treecaf0a0a9e3e3b4e4bee1d1a43b9a9beb30d7610e /chilbert/Operations.hpp
parent0bcaa46d0fb0af324fc2991ddcdf3d34c594f741 (diff)
downloadchilbert-4984100559a00e055a502fc8fe85d7ca66589b36.tar.gz
chilbert-4984100559a00e055a502fc8fe85d7ca66589b36.tar.bz2
chilbert-4984100559a00e055a502fc8fe85d7ca66589b36.zip
Clean up bit vector code
Diffstat (limited to 'chilbert/Operations.hpp')
-rw-r--r--chilbert/Operations.hpp18
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