haar_lib/algebra/
tuple.rs

1//! 直積
2pub use crate::algebra::traits::*;
3
4macro_rules! impl_tuple {
5    ($(#[$meta:meta])* $a:ident; $($t:tt),*; $($i:tt),*) => {
6        $(#[$meta])*
7        #[derive(Clone, Copy, Default, Debug, PartialEq, Eq)]
8        pub struct $a<$($t),*>($(pub $t),*);
9
10        impl<$($t:Set),*> Set for $a<$($t),*> {}
11
12        impl<$($t:BinaryOp),*> BinaryOp for $a<$($t),*> {
13            fn op(self, b: Self) -> Self {
14                Self($($t::op(self.$i, b.$i)),*)
15            }
16        }
17
18        impl<$($t:Identity),*> Identity for $a<$($t),*> {
19            fn id() -> Self {
20                Self($($t::id()),*)
21            }
22        }
23
24        impl<$($t:Inverse),*> Inverse for $a<$($t),*> {
25            fn inv(self) -> Self {
26                Self($($t::inv(self.$i)),*)
27            }
28        }
29
30        impl<$($t:Associative),*> Associative for $a<$($t),*> {}
31        impl<$($t:Commutative),*> Commutative for $a<$($t),*> {}
32        impl<$($t:Idempotence),*> Idempotence for $a<$($t),*> {}
33    };
34}
35
36impl_tuple!(#[doc = "2つの集合の直積"] Tuple2; T0, T1; 0, 1);
37impl_tuple!(#[doc = "3つの集合の直積"] Tuple3; T0, T1, T2; 0, 1, 2);
38impl_tuple!(#[doc = "4つの集合の直積"] Tuple4; T0, T1, T2, T3; 0, 1, 2, 3);
39impl_tuple!(#[doc = "5つの集合の直積"] Tuple5; T0, T1, T2, T3, T4; 0, 1, 2, 3, 4);