aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-08-18 09:06:14 +0200
committerDavid Robillard <d@drobilla.net>2018-09-29 14:46:30 +0200
commitfc24951cba40ab471f64f9f2825b4abe541e1283 (patch)
tree10d2fc48dcd6da29a0f3419ccebec1fa70962aa8
parent1d93b32df165b1ad96b2d1b17d553eb2a37b696c (diff)
downloadchilbert-fc24951cba40ab471f64f9f2825b4abe541e1283.tar.gz
chilbert-fc24951cba40ab471f64f9f2825b4abe541e1283.tar.bz2
chilbert-fc24951cba40ab471f64f9f2825b4abe541e1283.zip
Add NOT operators
-rw-r--r--chilbert/BigBitVec.hpp7
-rw-r--r--chilbert/FixBitVec.hpp7
-rw-r--r--test/test_bitvec.cpp13
3 files changed, 27 insertions, 0 deletions
diff --git a/chilbert/BigBitVec.hpp b/chilbert/BigBitVec.hpp
index 37ef870..30b8f82 100644
--- a/chilbert/BigBitVec.hpp
+++ b/chilbert/BigBitVec.hpp
@@ -249,6 +249,13 @@ public:
return t;
}
+ CBigBitVec operator~() const
+ {
+ CBigBitVec t(*this);
+ t.flip();
+ return t;
+ }
+
CBigBitVec& operator<<=(const size_t bits)
{
assert(bits < size());
diff --git a/chilbert/FixBitVec.hpp b/chilbert/FixBitVec.hpp
index 0bc2032..05dae1f 100644
--- a/chilbert/FixBitVec.hpp
+++ b/chilbert/FixBitVec.hpp
@@ -166,6 +166,13 @@ public:
return t;
}
+ CFixBitVec operator~() const
+ {
+ CFixBitVec t(*this);
+ t.flip();
+ return t;
+ }
+
CFixBitVec& operator<<=(const size_t bits)
{
assert(bits < size());
diff --git a/test/test_bitvec.cpp b/test/test_bitvec.cpp
index e547122..61685d1 100644
--- a/test/test_bitvec.cpp
+++ b/test/test_bitvec.cpp
@@ -88,6 +88,18 @@ test_xor()
template <class T, size_t N>
void
+test_not()
+{
+ const T v = make_random_bitvec<T, N>();
+ const T r = ~v;
+
+ for (size_t i = 0; i < N; ++i) {
+ assert(r.test(i) == !v.test(i));
+ }
+}
+
+template <class T, size_t N>
+void
test_flip_one()
{
T v = make_zero_bitvec<T, N>();
@@ -241,6 +253,7 @@ test()
test_and<T, N>();
test_or<T, N>();
test_xor<T, N>();
+ test_not<T, N>();
test_flip_one<T, N>();
test_flip_all<T, N>();
test_none<T, N>();