Add hb_lidentity(), and rename hb_rvalue() to hb_ridentity()
authorBehdad Esfahbod <behdad@behdad.org>
Thu, 9 May 2019 19:43:57 +0000 (12:43 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Thu, 9 May 2019 19:43:57 +0000 (12:43 -0700)
src/hb-algs.hh
src/hb-map.hh
src/test-iter.cc

index 6adbade..53bfa1f 100644 (file)
 
 struct
 {
+  /* Note.  This is dangerous in that if it's passed an rvalue, it returns rvalue-reference. */
   template <typename T> auto
   operator () (T&& v) const HB_AUTO_RETURN ( hb_forward<T> (v) )
 }
 HB_FUNCOBJ (hb_identity);
+struct
+{
+  /* Like identity(), but only retains lvalue-references.  Rvalues are returned as rvalues. */
+  template <typename T> T&
+  operator () (T& v) const { return v; }
 
+  template <typename T> hb_remove_reference<T>
+  operator () (T&& v) const { return v; }
+}
+HB_FUNCOBJ (hb_lidentity);
 struct
 {
+  /* Like identity(), but always returns rvalue. */
   template <typename T> hb_remove_reference<T>
   operator () (T&& v) const { return v; }
 }
-HB_FUNCOBJ (hb_rvalue);
+HB_FUNCOBJ (hb_ridentity);
 
 struct
 {
index 2f06595..9dc1788 100644 (file)
@@ -221,14 +221,14 @@ struct hb_hashmap_t
     + hb_array (items, mask ? mask + 1 : 0)
     | hb_filter (&item_t::is_real)
     | hb_map (&item_t::key)
-    | hb_map (hb_rvalue)
+    | hb_map (hb_ridentity)
   )
   auto values () const HB_AUTO_RETURN
   (
     + hb_array (items, mask ? mask + 1 : 0)
     | hb_filter (&item_t::is_real)
     | hb_map (&item_t::value)
-    | hb_map (hb_rvalue)
+    | hb_map (hb_ridentity)
   )
 
   protected:
index 2f6ed74..0d41e76 100644 (file)
@@ -164,7 +164,7 @@ main (int argc, char **argv)
   test_iterator_non_default_constructable (hb_enumerate (hb_iter (st)));
   test_iterator_non_default_constructable (hb_enumerate (hb_iter (st) + 1));
   test_iterator_non_default_constructable (hb_iter (st) | hb_filter ());
-  test_iterator_non_default_constructable (hb_iter (st) | hb_map (hb_rvalue));
+  test_iterator_non_default_constructable (hb_iter (st) | hb_map (hb_lidentity));
 
   assert (true == hb_all (st));
   assert (false == hb_all (st, 42u));