src/direct_product.rs

branch
dev
changeset 103
e98e1da2530d
parent 94
1f19c6bbf07b
child 114
b53806de0be0
--- a/src/direct_product.rs	Mon Apr 28 21:32:37 2025 -0500
+++ b/src/direct_product.rs	Mon Apr 28 23:16:56 2025 -0500
@@ -98,13 +98,43 @@
     }
 }
 
-macro_rules! impl_scalarop {
-    (($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident, $refl:ident) => {
-        impl_scalarop!(@doit: $field,
+// macro_rules! impl_scalarop {
+//     (($a : ty, $b : ty), $field : ty, $trait : ident, $fn : ident, $refl:ident) => {
+//         impl_scalarop!(@doit: $field,
+//                               $trait, $fn;
+//                               maybe_lifetime!($refl, &'l Pair<$a,$b>),
+//                               (maybe_lifetime!($refl, &'l $a),
+//                                maybe_lifetime!($refl, &'l $b));
+//                               $refl);
+//     };
+//     (@doit: $field : ty,
+//             $trait:ident, $fn:ident;
+//             $self:ty, ($aself:ty, $bself:ty);
+//             $refl:ident) => {
+//         // Scalar as Rhs
+//         impl<'l> $trait<$field>
+//         for $self
+//         where $aself: $trait<$field>,
+//               $bself: $trait<$field> {
+//             type Output = Pair<<$aself as $trait<$field>>::Output,
+//                                <$bself as $trait<$field>>::Output>;
+//             #[inline]
+//             fn $fn(self, a : $field) -> Self::Output {
+//                 Pair(maybe_ref!($refl, self.0).$fn(a),
+//                      maybe_ref!($refl, self.1).$fn(a))
+//             }
+//         }
+//     }
+// }
+//
+
+macro_rules! impl_scalarop_gen {
+    ($field : ty, $trait : ident, $fn : ident, $refl:ident) => {
+        impl_scalarop_gen!(@doit: $field,
                               $trait, $fn;
-                              maybe_lifetime!($refl, &'l Pair<$a,$b>),
-                              (maybe_lifetime!($refl, &'l $a),
-                               maybe_lifetime!($refl, &'l $b));
+                              maybe_lifetime!($refl, &'l Pair<A,B>),
+                              (maybe_lifetime!($refl, &'l A),
+                               maybe_lifetime!($refl, &'l B));
                               $refl);
     };
     (@doit: $field : ty,
@@ -112,7 +142,7 @@
             $self:ty, ($aself:ty, $bself:ty);
             $refl:ident) => {
         // Scalar as Rhs
-        impl<'l> $trait<$field>
+        impl<'l, A, B> $trait<$field>
         for $self
         where $aself: $trait<$field>,
               $bself: $trait<$field> {
@@ -204,8 +234,8 @@
         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);
-        impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Div, div);
+        // impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Mul, mul);
+        // impl_pair_vectorspace_ops!(@scalar, ($a, $b), $field, Div, div);
         // Compiler overflow
         // $(
         //     impl_pair_vectorspace_ops!(@scalar_lhs, ($a, $b), $field, $impl_scalarlhs_op, Mul, mul);
@@ -241,6 +271,50 @@
     };
 }
 
+// TODO: add what we can here.
+#[macro_export]
+macro_rules! impl_pair_vectorspace_ops_gen {
+    ($field:ty) => {
+        // impl_pair_vectorspace_ops_gen!(@binary, Add, add);
+        // impl_pair_vectorspace_ops_gen!(@binary, Sub, sub);
+        // impl_pair_vectorspace_ops_gen!(@assign, AddAssign, add_assign);
+        // impl_pair_vectorspace_ops_gen!(@assign, SubAssign, sub_assign);
+        impl_pair_vectorspace_ops_gen!(@scalar, $field, Mul, mul);
+        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);
+    };
+    // (@binary, $trait : ident, $fn : ident) => {
+    //     impl_binop_gen!(($a, $b), $trait, $fn, ref, ref);
+    //     impl_binop_gen!(($a, $b), $trait, $fn, ref, noref);
+    //     impl_binop_gen!(($a, $b), $trait, $fn, noref, ref);
+    //     impl_binop_gen!(($a, $b), $trait, $fn, noref, noref);
+    // };
+    // (@assign, $trait : ident, $fn :ident) => {
+    //     impl_assignop_gen!(($a, $b), $trait, $fn, ref);
+    //     impl_assignop_gen!(($a, $b), $trait, $fn, noref);
+    // };
+    (@scalar, $field : ty, $trait : ident, $fn :ident) => {
+        impl_scalarop_gen!($field, $trait, $fn, ref);
+        impl_scalarop_gen!($field, $trait, $fn, noref);
+    };
+    // (@scalar_lhs, $field : ty, $trait : ident, $fn : ident) => {
+    //     impl_scalarlhs_op_gen!(($a, $b), $field, $trait, $fn, ref);
+    //     impl_scalarlhs_op_gen!(($a, $b), $field, $trait, $fn, noref);
+    // };
+    // (@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!(($a, $b), $trait, $fn, ref);
+    //     impl_unaryop_gen!(($a, $b), $trait, $fn, noref);
+    // };
+}
+
+impl_pair_vectorspace_ops_gen!(f32);
+impl_pair_vectorspace_ops_gen!(f64);
+
 impl_pair_vectorspace_ops!((f32, f32), f32);
 impl_pair_vectorspace_ops!((f64, f64), f64);
 

mercurial