src/direct_product.rs

branch
dev
changeset 115
f9aec20d0286
parent 114
b53806de0be0
child 116
6f22e4d277b4
--- a/src/direct_product.rs	Thu May 01 01:05:00 2025 -0500
+++ b/src/direct_product.rs	Thu May 01 01:16:13 2025 -0500
@@ -201,32 +201,36 @@
     };
 }
 
-macro_rules! impl_unaryop {
-    (($a : ty, $b : ty), $trait:ident, $fn:ident, $refl:ident) => {
-        impl_unaryop!(@doit: $trait, $fn;
-                             maybe_lifetime!($refl, &'l Pair<$a,$b>),
-                             (maybe_lifetime!($refl, &'l $a),
-                              maybe_lifetime!($refl, &'l $b));
-                             $refl);
-    };
-    (@doit: $trait:ident, $fn:ident;
-            $self:ty, ($aself:ty, $bself:ty);
-            $refl : ident) => {
-        impl<'l> $trait
-        for $self
-        where $aself: $trait,
-              $bself: $trait {
-            type Output = Pair<<$aself as $trait>::Output,
-                               <$bself as $trait>::Output>;
-            #[inline]
+macro_rules! impl_unary {
+    ($trait:ident, $fn:ident) => {
+        impl<A, B> $trait for Pair<A, B>
+        where
+            A: $trait,
+            B: $trait,
+        {
+            type Output = Pair<A::Output, B::Output>;
             fn $fn(self) -> Self::Output {
-                Pair(maybe_ref!($refl, self.0).$fn(),
-                     maybe_ref!($refl, self.1).$fn())
+                let Pair(a, b) = self;
+                Pair(a.$fn(), b.$fn())
             }
         }
-    }
+
+        impl<'a, A, B> $trait for &'a Pair<A, B>
+        where
+            &'a A: $trait,
+            &'a B: $trait,
+        {
+            type Output = Pair<<&'a A as $trait>::Output, <&'a B as $trait>::Output>;
+            fn $fn(self) -> Self::Output {
+                let Pair(ref a, ref b) = self;
+                Pair(a.$fn(), b.$fn())
+            }
+        }
+    };
 }
 
+impl_unary!(Neg, neg);
+
 #[macro_export]
 macro_rules! impl_pair_vectorspace_ops {
     (($a:ty, $b:ty), $field:ty) => {
@@ -266,8 +270,8 @@
         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);
+        //impl_unaryop!(($a, $b), $trait, $fn, ref);
+        //impl_unaryop!(($a, $b), $trait, $fn, noref);
     };
 }
 
@@ -283,7 +287,7 @@
         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_pair_vectorspace_ops_gen!(@unary, Neg, neg);
+        //impl_unary!(Neg, neg);
     };
     // (@binary, $trait : ident, $fn : ident) => {
     //     impl_binop_gen!(($a, $b), $trait, $fn, ref, ref);
@@ -307,8 +311,8 @@
     //     impl_scalar_assignop_gen!(($a, $b), $field, $trait, $fn);
     // };
     // (@unary, $trait : ident, $fn :  ident) => {
-    //     impl_unaryop_gen!(($a, $b), $trait, $fn, ref);
-    //     impl_unaryop_gen!(($a, $b), $trait, $fn, noref);
+    //     //impl_unaryop_gen!($trait, $fn, ref);
+    //     //impl_unaryop_gen!($trait, $fn, noref);
     // };
 }
 
@@ -346,8 +350,7 @@
                 + AddAssign<Self>
                 + for<'b> AddAssign<&'b Self>
                 + SubAssign<Self>
-                + for<'b> SubAssign<&'b Self>
-                + Neg<Output = PairOutput<$field, A, B>>,
+                + for<'b> SubAssign<&'b Self>, //+ Neg<Output = PairOutput<$field, A, B>>,
         {
             type Output = PairOutput<$field, A, B>;
 

mercurial