2012-12-10 17:32:48 -08:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-05-22 10:54:12 -07:00
|
|
|
// xfail-test
|
|
|
|
|
2012-09-11 17:46:20 -07:00
|
|
|
extern mod std;
|
2013-02-01 02:13:36 -05:00
|
|
|
use std::oldmap::{map, hashmap, int_hash};
|
2012-05-24 06:20:46 -07:00
|
|
|
|
2013-02-20 17:07:17 -08:00
|
|
|
class keys<K:Copy,V:Copy,M:Copy + map<K,V>>
|
2012-06-22 18:19:35 -07:00
|
|
|
: iter::base_iter<K> {
|
2012-05-24 06:20:46 -07:00
|
|
|
|
|
|
|
let map: M;
|
|
|
|
|
|
|
|
new(map: M) {
|
|
|
|
self.map = map;
|
|
|
|
}
|
|
|
|
|
2013-03-07 14:38:38 -08:00
|
|
|
fn each(blk: &fn(K) -> bool) { self.map.each(|k, _v| blk(k) ) }
|
2013-01-25 12:31:45 -07:00
|
|
|
fn size_hint() -> Option<uint> { Some(self.map.size()) }
|
2013-03-07 14:38:38 -08:00
|
|
|
fn eachi(blk: &fn(uint, K) -> bool) { iter::eachi(self, blk) }
|
2012-05-24 06:20:46 -07:00
|
|
|
}
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2012-05-24 06:20:46 -07:00
|
|
|
let m = int_hash();
|
|
|
|
m.insert(1, 2);
|
|
|
|
m.insert(3, 4);
|
2013-03-28 18:39:09 -07:00
|
|
|
assert!(iter::to_vec(keys(m)) == ~[1, 3]);
|
2012-05-24 06:20:46 -07:00
|
|
|
}
|