1use crate::Vector;
2use core::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not};
3
4impl<T, const N: usize> Not for Vector<T, N>
5where
6 T: Not<Output = T>,
7{
8 type Output = Vector<T, N>;
9 fn not(self) -> Self::Output {
10 self.map(|x| !x)
11 }
12}
13
14impl<T, const N: usize> BitAnd for Vector<T, N>
15where
16 T: BitAnd<Output = T>,
17{
18 type Output = Vector<T, N>;
19 fn bitand(self, other: Vector<T, N>) -> Self::Output {
20 self.zip(other).map(|(x, y)| x & y)
21 }
22}
23impl<T, const N: usize> BitOr for Vector<T, N>
24where
25 T: BitOr<Output = T>,
26{
27 type Output = Vector<T, N>;
28 fn bitor(self, other: Vector<T, N>) -> Self::Output {
29 self.zip(other).map(|(x, y)| x | y)
30 }
31}
32impl<T, const N: usize> BitXor for Vector<T, N>
33where
34 T: BitXor<Output = T>,
35{
36 type Output = Vector<T, N>;
37 fn bitxor(self, other: Vector<T, N>) -> Self::Output {
38 self.zip(other).map(|(x, y)| x ^ y)
39 }
40}
41
42impl<T, const N: usize> BitAndAssign for Vector<T, N>
43where
44 T: BitAndAssign,
45{
46 fn bitand_assign(&mut self, other: Vector<T, N>) {
47 self.iter_mut()
48 .zip(other.into_iter())
49 .for_each(|(s, y)| *s &= y)
50 }
51}
52impl<T, const N: usize> BitOrAssign for Vector<T, N>
53where
54 T: BitOrAssign,
55{
56 fn bitor_assign(&mut self, other: Vector<T, N>) {
57 self.iter_mut()
58 .zip(other.into_iter())
59 .for_each(|(s, y)| *s |= y)
60 }
61}
62impl<T, const N: usize> BitXorAssign for Vector<T, N>
63where
64 T: BitXorAssign,
65{
66 fn bitxor_assign(&mut self, other: Vector<T, N>) {
67 self.iter_mut()
68 .zip(other.into_iter())
69 .for_each(|(s, y)| *s ^= y)
70 }
71}
72
73impl<const N: usize> Vector<bool, N> {
74 pub fn any(self) -> bool {
75 self.into_iter().any(|x| x)
76 }
77}
78impl<const N: usize> Vector<bool, N> {
79 pub fn all(self) -> bool {
80 self.into_iter().all(|x| x)
81 }
82}