[iter] Add hb_bool() and make hb_filter default to it for predicate

This commit is contained in:
Behdad Esfahbod 2019-01-27 00:44:45 +01:00
parent 313d63e240
commit fbab07f9b3
3 changed files with 17 additions and 3 deletions

View File

@ -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 <typename T> bool
operator () (const T& v) const { return bool (v); }
} hb_bool;
template <typename T1, typename T2>
struct hb_pair_t
{

View File

@ -281,9 +281,9 @@ struct hb_filter_iter_factory_t
Pred p;
Proj f;
};
template <typename Pred, typename Proj = const hb_identity_ft&>
template <typename Pred = const hb_bool_ft&, typename Proj = const hb_identity_ft&>
inline hb_filter_iter_factory_t<Pred, Proj>
hb_filter (Pred&& p, Proj&& f = hb_identity)
hb_filter (Pred&& p = hb_bool, Proj&& f = hb_identity)
{ return hb_filter_iter_factory_t<Pred, Proj> (p, f); }
/* hb_zip() */

View File

@ -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 <typename Iterable,
@ -134,5 +135,12 @@ main (int argc, char **argv)
hb_array_t<hb_vector_t<int> > pa;
pa->as_array ();
s
| hb_map (hb_identity)
| hb_filter ()
| hb_filter (hb_bool)
| hb_filter (hb_bool, hb_identity)
;
return 0;
}