From 07322274a3b88b0fcbaddd87cac4cca992c362cc Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 19 Aug 2018 10:56:38 +0200 Subject: Factor out print operator --- chilbert/BigBitVec.hpp | 9 --------- chilbert/FixBitVec.hpp | 9 --------- chilbert/Operators.hpp | 11 +++++++++++ 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(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 #include namespace chilbert { @@ -78,6 +79,16 @@ operator>>(const T& vec, const size_t bits) return r; } +template +inline std::enable_if_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 -- cgit v1.2.1