aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-08-19 10:56:38 +0200
committerDavid Robillard <d@drobilla.net>2018-09-29 14:48:11 +0200
commit07322274a3b88b0fcbaddd87cac4cca992c362cc (patch)
treeb164587c0efbf39a68dcc110f8fcfce0e839f6e6
parentc99e14d12be7797984cca0614de28ecda86f4af4 (diff)
downloadchilbert-07322274a3b88b0fcbaddd87cac4cca992c362cc.tar.gz
chilbert-07322274a3b88b0fcbaddd87cac4cca992c362cc.tar.bz2
chilbert-07322274a3b88b0fcbaddd87cac4cca992c362cc.zip
Factor out print operator
-rw-r--r--chilbert/BigBitVec.hpp9
-rw-r--r--chilbert/FixBitVec.hpp9
-rw-r--r--chilbert/Operators.hpp11
3 files changed, 11 insertions, 18 deletions
diff --git a/chilbert/BigBitVec.hpp b/chilbert/BigBitVec.hpp
index 5b5f408..70a917b 100644
--- a/chilbert/BigBitVec.hpp
+++ b/chilbert/BigBitVec.hpp
@@ -482,15 +482,6 @@ grayCodeInv(CBigBitVec& value)
}
}
-inline std::ostream&
-operator<<(std::ostream& os, const CBigBitVec& vec)
-{
- for (size_t i = 0; i < vec.size(); ++i) {
- os << vec.test(vec.size() - i - 1);
- }
- return os;
-}
-
} // namespace chilbert
#endif
diff --git a/chilbert/FixBitVec.hpp b/chilbert/FixBitVec.hpp
index 0eab0e9..d4313ba 100644
--- a/chilbert/FixBitVec.hpp
+++ b/chilbert/FixBitVec.hpp
@@ -379,15 +379,6 @@ grayCodeInv(CFixBitVec& value)
grayCodeInv<CFixBitVec::Rack>(value.rack());
}
-inline std::ostream&
-operator<<(std::ostream& os, const CFixBitVec& vec)
-{
- for (size_t i = 0; i < vec.size(); ++i) {
- os << vec.test(vec.size() - i - 1);
- }
- return os;
-}
-
} // namespace chilbert
#endif
diff --git a/chilbert/Operators.hpp b/chilbert/Operators.hpp
index 9ae022a..683c792 100644
--- a/chilbert/Operators.hpp
+++ b/chilbert/Operators.hpp
@@ -21,6 +21,7 @@
#include "chilbert/Traits.hpp"
+#include <iostream>
#include <type_traits>
namespace chilbert {
@@ -78,6 +79,16 @@ operator>>(const T& vec, const size_t bits)
return r;
}
+template <class T>
+inline std::enable_if_t<is_bitvec_v<T>, std::ostream>&
+operator<<(std::ostream& os, const T& vec)
+{
+ for (size_t i = 0; i < vec.size(); ++i) {
+ os << vec.test(vec.size() - i - 1);
+ }
+ return os;
+}
+
} // namespace chilbert
#endif