use core::{
cmp::Ordering,
ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Not, Rem, Shl, Shr, Sub},
};
pub trait Op<R>: Sized {
#[inline(always)]
fn add_c(self, other: Self, k: impl FnOnce(Self::Output) -> R) -> R
where
Self: Add,
{
k(self + other)
}
#[inline(always)]
fn sub_c(self, other: Self, k: impl FnOnce(Self::Output) -> R) -> R
where
Self: Sub,
{
k(self - other)
}
#[inline(always)]
fn mul_c(self, other: Self, k: impl FnOnce(Self::Output) -> R) -> R
where
Self: Mul,
{
k(self * other)
}
#[inline(always)]
fn div_c(self, other: Self, k: impl FnOnce(Self::Output) -> R) -> R
where
Self: Div,
{
k(self / other)
}
#[inline(always)]
fn rem_c(self, other: Self, k: impl FnOnce(Self::Output) -> R) -> R
where
Self: Rem,
{
k(self % other)
}
#[inline(always)]
fn neg_c(self, k: impl FnOnce(Self::Output) -> R) -> R
where
Self: Neg,
{
k(self.neg())
}
#[inline(always)]
fn not_c(self, k: impl FnOnce(Self::Output) -> R) -> R
where
Self: Not,
{
k(self.not())
}
#[inline(always)]
fn shl_c(self, other: Self, k: impl FnOnce(Self::Output) -> R) -> R
where
Self: Shl,
{
k(self << other)
}
#[inline(always)]
fn shr_c(self, other: Self, k: impl FnOnce(Self::Output) -> R) -> R
where
Self: Shr,
{
k(self >> other)
}
#[inline(always)]
fn bit_and_c(self, other: Self, k: impl FnOnce(Self::Output) -> R) -> R
where
Self: BitAnd,
{
k(self & other)
}
#[inline(always)]
fn bit_or_c(self, other: Self, k: impl FnOnce(Self::Output) -> R) -> R
where
Self: BitOr,
{
k(self | other)
}
#[inline(always)]
fn bit_xor_c(self, other: Self, k: impl FnOnce(Self::Output) -> R) -> R
where
Self: BitXor,
{
k(self ^ other)
}
#[inline(always)]
fn cmp_c(&self, other: &Self, k: impl FnOnce(Ordering) -> R) -> R
where
Self: Ord,
{
k(self.cmp(other))
}
}
impl<T, R> Op<R> for T {}