2015-03-30 13:00:05 -05:00
|
|
|
use std::ops::Range;
|
2014-11-02 17:58:00 -06:00
|
|
|
|
2015-01-02 09:25:54 -06:00
|
|
|
trait Itble<'r, T, I: Iterator<Item=T>> { fn iter(&'r self) -> I; }
|
2014-11-02 17:58:00 -06:00
|
|
|
|
2014-12-05 20:12:25 -06:00
|
|
|
impl<'r> Itble<'r, usize, Range<usize>> for (usize, usize) {
|
|
|
|
fn iter(&'r self) -> Range<usize> {
|
2014-11-02 17:58:00 -06:00
|
|
|
let &(min, max) = self;
|
2015-03-30 13:00:05 -05:00
|
|
|
min..max
|
2014-11-02 17:58:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-05 20:12:25 -06:00
|
|
|
fn check<'r, I: Iterator<Item=usize>, T: Itble<'r, usize, I>>(cont: &T) -> bool
|
2014-11-02 17:58:00 -06:00
|
|
|
{
|
|
|
|
let cont_iter = cont.iter();
|
2018-12-25 09:56:47 -06:00
|
|
|
//~^ ERROR explicit lifetime required in the type of `cont` [E0621]
|
2015-03-03 02:42:26 -06:00
|
|
|
let result = cont_iter.fold(Some(0), |state, val| {
|
2014-11-02 17:58:00 -06:00
|
|
|
state.map_or(None, |mask| {
|
|
|
|
let bit = 1 << val;
|
|
|
|
if mask & bit == 0 {Some(mask|bit)} else {None}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
result.is_some()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2018-10-05 11:35:23 -05:00
|
|
|
check(&(3, 5));
|
2014-11-02 17:58:00 -06:00
|
|
|
}
|