[map] add keys()
authorrsheeter <rsheeter@google.com>
Wed, 8 May 2019 19:47:18 +0000 (12:47 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Wed, 8 May 2019 22:08:33 +0000 (15:08 -0700)
src/hb-map.hh
src/test-iter.cc

index 5a4f5c3..4a1f75e 100644 (file)
@@ -212,11 +212,18 @@ struct hb_hashmap_t
    */
   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_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:
 
   unsigned int bucket_for (K key) const
index 7e77320..63851a3 100644 (file)
@@ -210,6 +210,10 @@ main (int argc, char **argv)
   + hb_iter (m)
   | 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 temp2 = 0;
   hb_map_t *result =