[map] add keys()

This commit is contained in:
rsheeter 2019-05-08 12:47:18 -07:00 committed by Behdad Esfahbod
parent ba60512813
commit 492af0f1bf
2 changed files with 12 additions and 1 deletions

View File

@ -212,11 +212,18 @@ struct hb_hashmap_t
*/ */
auto iter() const HB_AUTO_RETURN auto iter() const HB_AUTO_RETURN
( (
+ hb_array_t<item_t> (items, mask + 1) + hb_array (items, mask + 1)
| hb_filter (&item_t::is_real) | hb_filter (&item_t::is_real)
| hb_map (&item_t::get_pair) | hb_map (&item_t::get_pair)
) )
auto keys() const HB_AUTO_RETURN
(
+ iter()
| hb_map (&hb_pair_t<K, V>::first)
)
// | hb_map ([&] (item_t i) { return i.key; })
protected: protected:
unsigned int bucket_for (K key) const unsigned int bucket_for (K key) const

View File

@ -210,6 +210,10 @@ main (int argc, char **argv)
+ hb_iter (m) + hb_iter (m)
| hb_map ([] (map_pair_t p) { return p.first * p.second; }); | hb_map ([] (map_pair_t p) { return p.first * p.second; });
using map_key_t = decltype (*m.keys());
+ hb_iter (m.keys ())
| hb_filter ([] (map_key_t k) { return k < 42; });
unsigned int temp1 = 10; unsigned int temp1 = 10;
unsigned int temp2 = 0; unsigned int temp2 = 0;
hb_map_t *result = hb_map_t *result =