Merge pull request #89 from joshtriplett/bounded-tuples

traits.rs: Implement Bounded for tuples of Bounded types
This commit is contained in:
Alex Crichton 2015-04-26 23:45:57 -07:00
commit a3d9093938
1 changed files with 30 additions and 0 deletions

View File

@ -463,6 +463,36 @@ bounded_impl!(i64, i64::MIN, i64::MAX);
bounded_impl!(f32, f32::MIN, f32::MAX);
bounded_impl!(f64, f64::MIN, f64::MAX);
macro_rules! for_each_tuple_ {
( $m:ident !! ) => (
$m! { }
);
( $m:ident !! $h:ident, $($t:ident,)* ) => (
$m! { $h $($t)* }
for_each_tuple_! { $m !! $($t,)* }
);
}
macro_rules! for_each_tuple {
( $m:ident ) => (
for_each_tuple_! { $m !! A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, }
);
}
macro_rules! bounded_tuple {
( $($name:ident)* ) => (
impl<$($name: Bounded,)*> Bounded for ($($name,)*) {
fn min_value() -> Self {
($($name::min_value(),)*)
}
fn max_value() -> Self {
($($name::max_value(),)*)
}
}
);
}
for_each_tuple!(bounded_tuple);
/// Saturating math operations
pub trait Saturating {
/// Saturating addition operator.