1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use core::ops::Neg;

use array_math::ArrayOps;

use crate::quantities::Polynomial;

macro_rules! impl_neg {
    (($(<$($a:lifetime),* $(,)? $($c:ident),* >)?) $s:ty [$n:tt] $(where $($w:tt)*)?) => {
        impl<$($($a,)* $(const $c: usize,)*)? T> Neg for Polynomial<T, $s>
        where
            Polynomial::<T, [T; $n]>: From<Polynomial<T, $s>> + Neg,
            $($($w)*)?
        {
            type Output = <Polynomial::<T, [T; $n]> as Neg>::Output;

            fn neg(self) -> Self::Output
            {
                -Polynomial::<T, [T; $n]>::from(self)
            }
        }
    };
    (($(<$($a:lifetime),* $(,)? $($c:ident),* >)?) $s:ty $(where $($w:tt)*)?) => {
        impl<$($($a,)* $(const $c: usize,)*)? T> Neg for Polynomial<T, $s>
        where
            Polynomial::<T, Vec<T>>: From<Polynomial<T, $s>> + Neg,
            $($($w)*)?
        {
            type Output = <Polynomial::<T, Vec<T>> as Neg>::Output;

            fn neg(self) -> Self::Output
            {
                -Polynomial::<T, Vec<T>>::from(self)
            }
        }
    };
}

impl_neg!(() () [1]);
impl<const N: usize, T> Neg for Polynomial<T, [T; N]>
where
    T: Neg
{
    type Output = Polynomial<<T as Neg>::Output, [<T as Neg>::Output; N]>;

    fn neg(self) -> Self::Output
    {
        Polynomial::new(self.c.neg_all())
    }
}
impl_neg!((<'a, N>) &'a [T; N] [N]);
impl<T> Neg for Polynomial<T, Vec<T>>
where
    T: Neg
{
    type Output = Polynomial<<T as Neg>::Output, Vec<<T as Neg>::Output>>;

    fn neg(self) -> Self::Output
    {
        Polynomial::new(
            self.c.into_iter()
                .map(|c| -c)
                .collect()
        )
    }
}
impl_neg!((<'a>) &'a [T]);