[iter] Add hb_bool() and make hb_filter default to it for predicate
This commit is contained in:
parent
313d63e240
commit
fbab07f9b3
|
@ -41,6 +41,12 @@ static HB_UNUSED const struct hb_identity_ft
|
||||||
operator () (const T& v) const { return v; }
|
operator () (const T& v) const { return v; }
|
||||||
} hb_identity;
|
} 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>
|
template <typename T1, typename T2>
|
||||||
struct hb_pair_t
|
struct hb_pair_t
|
||||||
{
|
{
|
||||||
|
|
|
@ -281,9 +281,9 @@ struct hb_filter_iter_factory_t
|
||||||
Pred p;
|
Pred p;
|
||||||
Proj f;
|
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>
|
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); }
|
{ return hb_filter_iter_factory_t<Pred, Proj> (p, f); }
|
||||||
|
|
||||||
/* hb_zip() */
|
/* hb_zip() */
|
||||||
|
|
|
@ -84,7 +84,8 @@ test_iterator (Iter it)
|
||||||
|
|
||||||
assert (*it == it[0]);
|
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,
|
template <typename Iterable,
|
||||||
|
@ -134,5 +135,12 @@ main (int argc, char **argv)
|
||||||
hb_array_t<hb_vector_t<int> > pa;
|
hb_array_t<hb_vector_t<int> > pa;
|
||||||
pa->as_array ();
|
pa->as_array ();
|
||||||
|
|
||||||
|
s
|
||||||
|
| hb_map (hb_identity)
|
||||||
|
| hb_filter ()
|
||||||
|
| hb_filter (hb_bool)
|
||||||
|
| hb_filter (hb_bool, hb_identity)
|
||||||
|
;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue