From c9b287a867d6130a0cc745d7fd3ccfa4dcb4c32e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 9 May 2019 12:43:57 -0700 Subject: [PATCH] Add hb_lidentity(), and rename hb_rvalue() to hb_ridentity() --- src/hb-algs.hh | 15 +++++++++++++-- src/hb-map.hh | 4 ++-- src/test-iter.cc | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 6adbade15..53bfa1fc5 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -36,17 +36,28 @@ struct { + /* Note. This is dangerous in that if it's passed an rvalue, it returns rvalue-reference. */ template auto operator () (T&& v) const HB_AUTO_RETURN ( hb_forward (v) ) } HB_FUNCOBJ (hb_identity); - struct { + /* Like identity(), but only retains lvalue-references. Rvalues are returned as rvalues. */ + template T& + operator () (T& v) const { return v; } + template hb_remove_reference operator () (T&& v) const { return v; } } -HB_FUNCOBJ (hb_rvalue); +HB_FUNCOBJ (hb_lidentity); +struct +{ + /* Like identity(), but always returns rvalue. */ + template hb_remove_reference + operator () (T&& v) const { return v; } +} +HB_FUNCOBJ (hb_ridentity); struct { diff --git a/src/hb-map.hh b/src/hb-map.hh index 2f0659562..9dc178880 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -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: diff --git a/src/test-iter.cc b/src/test-iter.cc index 2f6ed7471..0d41e76f3 100644 --- a/src/test-iter.cc +++ b/src/test-iter.cc @@ -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));