use internal::*;
use crate::bool::*;
meta!{
pub type IsEven<
N: Expr<USize>
>: Expr<Bool> =
VisitUSize<Bool, N, IsEvenVisitor>;
pub type IsOdd<
N: Expr<USize>
>: Expr<Bool> =
VisitUSize<Bool, N, IsOddVisitor>;
}
mod internal {
pub use super::super::internal::*;
use crate::bool::*;
meta!{
pub struct IsEvenVisitor: USizeVisitor<Bool> {
type VisitZero = True;
type VisitIncrement<N: Expr<USize>> = VisitUSize<Bool, N, IsOddVisitor>;
}
pub struct IsOddVisitor: USizeVisitor<Bool> {
type VisitZero = False;
type VisitIncrement<N: Expr<USize>> = VisitUSize<Bool, N, IsEvenVisitor>;
}
}
}
#[cfg(test)]
#[allow(dead_code)]
mod tests {
use crate::*;
use super::super::*;
use crate::bool::*;
#[test]
fn is_even() {
meta_assert_eq!(Bool, IsEven<Zero>, True);
meta_assert_eq!(Bool, IsEven<Increment<Zero>>, False);
meta_assert_eq!(Bool, IsEven<Increment<Increment<Zero>>>, True);
}
#[test]
fn is_odd() {
meta_assert_eq!(Bool, IsOdd<Zero>, False);
meta_assert_eq!(Bool, IsOdd<Increment<Zero>>, True);
meta_assert_eq!(Bool, IsOdd<Increment<Increment<Zero>>>, False);
}
}