Skip to content

Commit 46c1ba5

Browse files
authored
Merge pull request #19 from qryxip/internal-type-traits
Implement `internal_type_traits`
2 parents 6e34caa + 48ece04 commit 46c1ba5

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

src/internal_type_traits.rs

+89
Original file line numberDiff line numberDiff line change
@@ -1 +1,90 @@
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+
};
110

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

Comments
 (0)