Skip to content

Commit

Permalink
Add 82268
Browse files Browse the repository at this point in the history
  • Loading branch information
fanninpm committed Feb 20, 2021
1 parent 55cf9b0 commit 773b7b0
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions ices/82268.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#![feature(const_generics, const_evaluatable_checked)]

struct True;
struct False;

trait ConstBool {
type Val;
}
struct TypeBool<const X: bool>;

impl ConstBool for TypeBool<true> {
type Val = True;
}

impl ConstBool for TypeBool<false> {
type Val = False;
}

trait Collate<const MASK: u32> {
type Pass;
type Fail;

fn collate(self) -> (Self::Pass, Self::Fail);
}

impl<const MASK: u32> Collate<MASK> for () {
type Pass = ();
type Fail = ();

fn collate(self) -> ((), ()) {
((), ())
}
}

trait CollateStep<X, Prev> {
type Pass;
type Fail;
fn collate_step(x: X, prev: Prev) -> (Self::Pass, Self::Fail);
}

impl<X, P, F> CollateStep<X, (P, F)> for TypeBool<true> {
type Pass = (X, P);
type Fail = F;

fn collate_step(x: X, (p, f): (P, F)) -> ((X, P), F) {
((x, p), f)
}
}

impl<X, P, F> CollateStep<X, (P, F)> for TypeBool<false> {
type Pass = P;
type Fail = (X, F);

fn collate_step(x: X, (p, f): (P, F)) -> (P, (X, F)) {
(p, (x, f))
}
}

impl<H, T: Collate<{ MASK >> 1 }>, const MASK: u32> Collate<MASK> for (H, T)
where
TypeBool<{ 1 == MASK & 1 }>: CollateStep<H, (T::Pass, T::Fail)>,
{
type Pass =
<TypeBool<{ 1 == MASK & 1 }> as CollateStep<H, (T::Pass, T::Fail)>>::Pass;
type Fail =
<TypeBool<{ 1 == MASK & 1 }> as CollateStep<H, (T::Pass, T::Fail)>>::Fail;

fn collate(self) -> (Self::Pass, Self::Fail) {
<TypeBool<{ 1 == MASK & 1 }>
as CollateStep<H, (T::Pass, T::Fail)>>
::collate_step(self.0, self.1.collate())
}
}

fn collate<X,const MASK:u32>(x:X)->(X::Pass, X::Fail)
where X:Collate<MASK> {
x.collate()
}

fn main() {
dbg!(collate::<_,3>((4, ('!',()))));
}

0 comments on commit 773b7b0

Please sign in to comment.