diff -r f9aec20d0286 -r 6f22e4d277b4 src/direct_product.rs --- a/src/direct_product.rs Thu May 01 01:16:13 2025 -0500 +++ b/src/direct_product.rs Thu May 01 01:25:27 2025 -0500 @@ -39,39 +39,6 @@ } } -macro_rules! impl_binop { - (($a : ty, $b : ty), $trait : ident, $fn : ident, $refl:ident, $refr:ident) => { - impl_binop!(@doit: $a, $b, $trait, $fn; - maybe_lifetime!($refl, &'l Pair<$a,$b>), - (maybe_lifetime!($refl, &'l $a), - maybe_lifetime!($refl, &'l $b)); - maybe_lifetime!($refr, &'r Pair), - (maybe_lifetime!($refr, &'r Ai), - maybe_lifetime!($refr, &'r Bi)); - $refl, $refr); - }; - - (@doit: $a:ty, $b:ty, - $trait:ident, $fn:ident; - $self:ty, ($aself:ty, $bself:ty); - $in:ty, ($ain:ty, $bin:ty); - $refl:ident, $refr:ident) => { - impl<'l, 'r, Ai, Bi> $trait<$in> - for $self - where $aself: $trait<$ain>, - $bself: $trait<$bin> { - type Output = Pair<<$aself as $trait<$ain>>::Output, - <$bself as $trait<$bin>>::Output>; - - #[inline] - fn $fn(self, y : $in) -> Self::Output { - Pair(maybe_ref!($refl, self.0).$fn(maybe_ref!($refr, y.0)), - maybe_ref!($refl, self.1).$fn(maybe_ref!($refr, y.1))) - } - } - }; -} - macro_rules! impl_assignop { (($a : ty, $b : ty), $trait : ident, $fn : ident, $refr:ident) => { impl_assignop!(@doit: $a, $b, @@ -231,11 +198,66 @@ impl_unary!(Neg, neg); +macro_rules! impl_binary { + ($trait:ident, $fn:ident) => { + impl $trait> for Pair + where + A: $trait, + B: $trait, + { + type Output = Pair; + fn $fn(self, Pair(c, d): Pair) -> Self::Output { + let Pair(a, b) = self; + Pair(a.$fn(c), b.$fn(d)) + } + } + + impl<'a, A, B, C, D> $trait> for &'a Pair + where + &'a A: $trait, + &'a B: $trait, + { + type Output = Pair<<&'a A as $trait>::Output, <&'a B as $trait>::Output>; + fn $fn(self, Pair(c, d): Pair) -> Self::Output { + let Pair(ref a, ref b) = self; + Pair(a.$fn(c), b.$fn(d)) + } + } + + impl<'a, 'b, A, B, C, D> $trait<&'b Pair> for &'a Pair + where + &'a A: $trait<&'b C>, + &'a B: $trait<&'b D>, + { + type Output = Pair<<&'a A as $trait<&'b C>>::Output, <&'a B as $trait<&'b D>>::Output>; + fn $fn(self, Pair(ref c, ref d): &'b Pair) -> Self::Output { + let Pair(ref a, ref b) = self; + Pair(a.$fn(c), b.$fn(d)) + } + } + + impl<'b, A, B, C, D> $trait<&'b Pair> for Pair + where + A: $trait<&'b C>, + B: $trait<&'b D>, + { + type Output = Pair<>::Output, >::Output>; + fn $fn(self, Pair(ref c, ref d): &'b Pair) -> Self::Output { + let Pair(a, b) = self; + Pair(a.$fn(c), b.$fn(d)) + } + } + }; +} + +impl_binary!(Add, add); +impl_binary!(Sub, sub); + #[macro_export] macro_rules! impl_pair_vectorspace_ops { (($a:ty, $b:ty), $field:ty) => { - impl_pair_vectorspace_ops!(@binary, ($a, $b), Add, add); - impl_pair_vectorspace_ops!(@binary, ($a, $b), Sub, sub); + //impl_pair_vectorspace_ops!(@binary, ($a, $b), Add, add); + //impl_pair_vectorspace_ops!(@binary, ($a, $b), Sub, sub); impl_pair_vectorspace_ops!(@assign, ($a, $b), AddAssign, add_assign); impl_pair_vectorspace_ops!(@assign, ($a, $b), SubAssign, sub_assign); // impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Mul, mul); @@ -246,7 +268,6 @@ // )* impl_pair_vectorspace_ops!(@scalar_assign, ($a, $b), $field, MulAssign, mul_assign); impl_pair_vectorspace_ops!(@scalar_assign, ($a, $b), $field, DivAssign, div_assign); - impl_pair_vectorspace_ops!(@unary, ($a, $b), Neg, neg); }; (@binary, ($a : ty, $b : ty), $trait : ident, $fn : ident) => { impl_binop!(($a, $b), $trait, $fn, ref, ref); @@ -269,10 +290,6 @@ (@scalar_assign, ($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident) => { impl_scalar_assignop!(($a, $b), $field, $trait, $fn); }; - (@unary, ($a : ty, $b : ty), $trait : ident, $fn : ident) => { - //impl_unaryop!(($a, $b), $trait, $fn, ref); - //impl_unaryop!(($a, $b), $trait, $fn, noref); - }; } // TODO: add what we can here. @@ -287,7 +304,6 @@ impl_pair_vectorspace_ops_gen!(@scalar, $field, Div, div); // impl_pair_vectorspace_ops_gen!(@scalar_assign, $field, MulAssign, mul_assign); // impl_pair_vectorspace_ops_gen!(@scalar_assign, $field, DivAssign, div_assign); - //impl_unary!(Neg, neg); }; // (@binary, $trait : ident, $fn : ident) => { // impl_binop_gen!(($a, $b), $trait, $fn, ref, ref); @@ -310,10 +326,6 @@ // (@scalar_assign, $field : ty, $trait : ident, $fn : ident) => { // impl_scalar_assignop_gen!(($a, $b), $field, $trait, $fn); // }; - // (@unary, $trait : ident, $fn : ident) => { - // //impl_unaryop_gen!($trait, $fn, ref); - // //impl_unaryop_gen!($trait, $fn, noref); - // }; } impl_pair_vectorspace_ops_gen!(f32);