2015-03-30 18:00:05 +00:00
|
|
|
use std::ops::Range;
|
2014-11-02 23:58:00 +00:00
|
|
|
|
2015-01-02 15:25:54 +00:00
|
|
|
trait Itble<'r, T, I: Iterator<Item=T>> { fn iter(&'r self) -> I; }
|
2014-11-02 23:58:00 +00:00
|
|
|
|
2014-12-06 02:12:25 +00:00
|
|
|
impl<'r> Itble<'r, usize, Range<usize>> for (usize, usize) {
|
|
|
|
fn iter(&'r self) -> Range<usize> {
|
2014-11-02 23:58:00 +00:00
|
|
|
let &(min, max) = self;
|
2015-03-30 18:00:05 +00:00
|
|
|
min..max
|
2014-11-02 23:58:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-06 02:12:25 +00:00
|
|
|
fn check<'r, I: Iterator<Item=usize>, T: Itble<'r, usize, I>>(cont: &T) -> bool
|
2014-11-02 23:58:00 +00:00
|
|
|
{
|
|
|
|
let cont_iter = cont.iter();
|
2018-12-25 15:56:47 +00:00
|
|
|
//~^ ERROR explicit lifetime required in the type of `cont` [E0621]
|
2015-03-03 08:42:26 +00:00
|
|
|
let result = cont_iter.fold(Some(0), |state, val| {
|
2014-11-02 23:58:00 +00: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 16:35:23 +00:00
|
|
|
check(&(3, 5));
|
2014-11-02 23:58:00 +00:00
|
|
|
}
|