haar_lib/algebra/
tuple.rs1pub 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, PartialOrd, Ord, Hash)]
8 pub struct $a<$($t),*>($(pub $t),*);
9
10 impl<$($t:Set),*> Set for $a<$($t),*> {
11 type Element = ($($t::Element),*);
12 }
13
14 impl<$($t:BinaryOp),*> BinaryOp for $a<$($t),*> {
15 fn op(&self, a: Self::Element, b: Self::Element) -> Self::Element {
16 ($(self.$i.op(a.$i, b.$i)),*)
17 }
18 }
19
20 impl<$($t:Identity),*> Identity for $a<$($t),*> {
21 fn id(&self) -> Self::Element {
22 ($(self.$i.id()),*)
23 }
24 }
25
26 impl<$($t:Inverse),*> Inverse for $a<$($t),*> {
27 fn inv(&self, a: Self::Element) -> Self::Element {
28 ($(self.$i.inv(a.$i)),*)
29 }
30 }
31
32 impl<$($t:Associative),*> Associative for $a<$($t),*> {}
33 impl<$($t:Commutative),*> Commutative for $a<$($t),*> {}
34 impl<$($t:Idempotence),*> Idempotence for $a<$($t),*> {}
35 };
36}
37
38impl_tuple!(#[doc = "2つの集合の直積"] Tuple2; T0, T1; 0, 1);
39impl_tuple!(#[doc = "3つの集合の直積"] Tuple3; T0, T1, T2; 0, 1, 2);
40impl_tuple!(#[doc = "4つの集合の直積"] Tuple4; T0, T1, T2, T3; 0, 1, 2, 3);
41impl_tuple!(#[doc = "5つの集合の直積"] Tuple5; T0, T1, T2, T3, T4; 0, 1, 2, 3, 4);