aboutsummaryrefslogtreecommitdiffstats
path: root/chilbert/Operators.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'chilbert/Operators.hpp')
-rw-r--r--chilbert/Operators.hpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/chilbert/Operators.hpp b/chilbert/Operators.hpp
new file mode 100644
index 0000000..9ae022a
--- /dev/null
+++ b/chilbert/Operators.hpp
@@ -0,0 +1,83 @@
+/*
+ Copyright (C) 2018 David Robillard <d@drobilla.net>
+ Copyright (C) 2006-2007 Chris Hamilton <chamilton@cs.dal.ca>
+
+ This program is free software: you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free Software
+ Foundation, either version 2 of the License, or (at your option) any later
+ version.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+#ifndef CHILBERT_OPERATORS_HPP
+#define CHILBERT_OPERATORS_HPP
+
+#include "chilbert/Traits.hpp"
+
+#include <type_traits>
+
+namespace chilbert {
+
+template <class T>
+std::enable_if_t<is_bitvec_v<T>, T> operator&(const T& lhs, const T& rhs)
+{
+ T r{lhs};
+ r &= rhs;
+ return r;
+}
+
+template <class T>
+std::enable_if_t<is_bitvec_v<T>, T>
+operator|(const T& lhs, const T& rhs)
+{
+ T r{lhs};
+ r |= rhs;
+ return r;
+}
+
+template <class T>
+std::enable_if_t<is_bitvec_v<T>, T>
+operator^(const T& lhs, const T& rhs)
+{
+ T r{lhs};
+ r ^= rhs;
+ return r;
+}
+
+template <class T>
+std::enable_if_t<is_bitvec_v<T>, T>
+operator~(const T& vec)
+{
+ T r{vec};
+ r.flip();
+ return r;
+}
+
+template <class T>
+std::enable_if_t<is_bitvec_v<T>, T>
+operator<<(const T& vec, const size_t bits)
+{
+ T r{vec};
+ r <<= bits;
+ return r;
+}
+
+template <class T>
+std::enable_if_t<is_bitvec_v<T>, T>
+operator>>(const T& vec, const size_t bits)
+{
+ T r{vec};
+ r >>= bits;
+ return r;
+}
+
+} // namespace chilbert
+
+#endif