|
| 1 | +use std::{ |
| 2 | + fmt, |
| 3 | + iter::{Product, Sum}, |
| 4 | + ops::{ |
| 5 | + Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, |
| 6 | + DivAssign, Mul, MulAssign, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub, |
| 7 | + SubAssign, |
| 8 | + }, |
| 9 | +}; |
1 | 10 |
|
| 11 | +// Skipped: |
| 12 | +// |
| 13 | +// - `is_signed_int_t<T>` (probably won't be used directly in `modint.rs`) |
| 14 | +// - `is_unsigned_int_t<T>` (probably won't be used directly in `modint.rs`) |
| 15 | +// - `to_unsigned_t<T>` (not used in `fenwicktree.rs`) |
| 16 | + |
| 17 | +/// Corresponds to `std::is_integral` in C++. |
| 18 | +// We will remove unnecessary bounds later. |
| 19 | +// |
| 20 | +// Maybe we should rename this to `PrimitiveInteger` or something, as it probably won't be used in the |
| 21 | +// same way as the original ACL. |
| 22 | +pub(crate) trait Integral: |
| 23 | + 'static |
| 24 | + + Send |
| 25 | + + Sync |
| 26 | + + Copy |
| 27 | + + Ord |
| 28 | + + Not<Output = Self> |
| 29 | + + Add<Output = Self> |
| 30 | + + Sub<Output = Self> |
| 31 | + + Mul<Output = Self> |
| 32 | + + Div<Output = Self> |
| 33 | + + Rem<Output = Self> |
| 34 | + + AddAssign |
| 35 | + + SubAssign |
| 36 | + + MulAssign |
| 37 | + + DivAssign |
| 38 | + + RemAssign |
| 39 | + + Sum |
| 40 | + + Product |
| 41 | + + BitOr<Output = Self> |
| 42 | + + BitAnd<Output = Self> |
| 43 | + + BitXor<Output = Self> |
| 44 | + + BitOrAssign |
| 45 | + + BitAndAssign |
| 46 | + + BitXorAssign |
| 47 | + + Shl<Output = Self> |
| 48 | + + Shr<Output = Self> |
| 49 | + + ShlAssign |
| 50 | + + ShrAssign |
| 51 | + + fmt::Display |
| 52 | + + fmt::Debug |
| 53 | + + fmt::Binary |
| 54 | + + fmt::Octal |
| 55 | +{ |
| 56 | + fn zero() -> Self; |
| 57 | + fn one() -> Self; |
| 58 | + fn min_value() -> Self; |
| 59 | + fn max_value() -> Self; |
| 60 | +} |
| 61 | + |
| 62 | +macro_rules! impl_integral { |
| 63 | + ($($ty:ty),*) => { |
| 64 | + $( |
| 65 | + impl Integral for $ty { |
| 66 | + #[inline] |
| 67 | + fn zero() -> Self { |
| 68 | + 0 |
| 69 | + } |
| 70 | + |
| 71 | + #[inline] |
| 72 | + fn one() -> Self { |
| 73 | + 1 |
| 74 | + } |
| 75 | + |
| 76 | + #[inline] |
| 77 | + fn min_value() -> Self { |
| 78 | + Self::min_value() |
| 79 | + } |
| 80 | + |
| 81 | + #[inline] |
| 82 | + fn max_value() -> Self { |
| 83 | + Self::max_value() |
| 84 | + } |
| 85 | + } |
| 86 | + )* |
| 87 | + }; |
| 88 | +} |
| 89 | + |
| 90 | +impl_integral!(i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize); |
0 commit comments