Add hb_lidentity(), and rename hb_rvalue() to hb_ridentity()

This commit is contained in:
Behdad Esfahbod 2019-05-09 12:43:57 -07:00
parent 00195a22ce
commit c9b287a867
3 changed files with 16 additions and 5 deletions

View File

@ -36,17 +36,28 @@
struct struct
{ {
/* Note. This is dangerous in that if it's passed an rvalue, it returns rvalue-reference. */
template <typename T> auto template <typename T> auto
operator () (T&& v) const HB_AUTO_RETURN ( hb_forward<T> (v) ) operator () (T&& v) const HB_AUTO_RETURN ( hb_forward<T> (v) )
} }
HB_FUNCOBJ (hb_identity); HB_FUNCOBJ (hb_identity);
struct 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> template <typename T> hb_remove_reference<T>
operator () (T&& v) const { return v; } operator () (T&& v) const { return v; }
} }
HB_FUNCOBJ (hb_rvalue); 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_ridentity);
struct struct
{ {

View File

@ -221,14 +221,14 @@ struct hb_hashmap_t
+ hb_array (items, mask ? mask + 1 : 0) + hb_array (items, mask ? mask + 1 : 0)
| hb_filter (&item_t::is_real) | hb_filter (&item_t::is_real)
| hb_map (&item_t::key) | hb_map (&item_t::key)
| hb_map (hb_rvalue) | hb_map (hb_ridentity)
) )
auto values () const HB_AUTO_RETURN auto values () const HB_AUTO_RETURN
( (
+ hb_array (items, mask ? mask + 1 : 0) + hb_array (items, mask ? mask + 1 : 0)
| hb_filter (&item_t::is_real) | hb_filter (&item_t::is_real)
| hb_map (&item_t::value) | hb_map (&item_t::value)
| hb_map (hb_rvalue) | hb_map (hb_ridentity)
) )
protected: protected:

View 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)));
test_iterator_non_default_constructable (hb_enumerate (hb_iter (st) + 1)); 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_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 (true == hb_all (st));
assert (false == hb_all (st, 42u)); assert (false == hb_all (st, 42u));