From fbab07f9b3dac90ce2136506f72879335193fc02 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 27 Jan 2019 00:44:45 +0100 Subject: [PATCH] [iter] Add hb_bool() and make hb_filter default to it for predicate --- src/hb-algs.hh | 6 ++++++ src/hb-iter.hh | 4 ++-- src/test-iter.cc | 10 +++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index a0896dda9..bd03a74ea 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -41,6 +41,12 @@ static HB_UNUSED const struct hb_identity_ft operator () (const T& v) const { return v; } } hb_identity; +static HB_UNUSED const struct hb_bool_ft +{ + template bool + operator () (const T& v) const { return bool (v); } +} hb_bool; + template struct hb_pair_t { diff --git a/src/hb-iter.hh b/src/hb-iter.hh index eff4e2833..57a687af4 100644 --- a/src/hb-iter.hh +++ b/src/hb-iter.hh @@ -281,9 +281,9 @@ struct hb_filter_iter_factory_t Pred p; Proj f; }; -template +template inline hb_filter_iter_factory_t -hb_filter (Pred&& p, Proj&& f = hb_identity) +hb_filter (Pred&& p = hb_bool, Proj&& f = hb_identity) { return hb_filter_iter_factory_t (p, f); } /* hb_zip() */ diff --git a/src/test-iter.cc b/src/test-iter.cc index 567da72d5..97a739cd2 100644 --- a/src/test-iter.cc +++ b/src/test-iter.cc @@ -84,7 +84,8 @@ test_iterator (Iter it) assert (*it == it[0]); - if (it.is_random_access_iterator) {} + static_assert (true || it.is_random_access_iterator, ""); + static_assert (true || it.is_sorted_iterator, ""); } template > pa; pa->as_array (); + s + | hb_map (hb_identity) + | hb_filter () + | hb_filter (hb_bool) + | hb_filter (hb_bool, hb_identity) + ; + return 0; }