[iter] Add hb_all, hb_any, hb_none

This commit is contained in:
Behdad Esfahbod 2019-02-15 16:55:08 -08:00
parent 72dd5e34e0
commit 77060bcda2
2 changed files with 47 additions and 1 deletions

View File

@ -130,7 +130,7 @@ static const struct
{ {
template <typename T> template <typename T>
hb_iter_t (T) hb_iter_t (T)
operator () (const T& c) const operator () (T&& c) const
{ return c.iter (); } { return c.iter (); }
/* Specialization for C arrays. */ /* Specialization for C arrays. */
@ -490,6 +490,50 @@ static const struct
} }
} hb_drain HB_UNUSED; } hb_drain HB_UNUSED;
/* hb-all, hb-any, hb-none. */
static const struct
{
template <typename Iterable,
hb_enable_if (hb_is_iterable (Iterable))>
bool
operator () (Iterable&& c) const
{
for (auto it = hb_iter (c); it; ++it)
if (!*it)
return false;
return true;
}
} hb_all HB_UNUSED;
static const struct
{
template <typename Iterable,
hb_enable_if (hb_is_iterable (Iterable))>
bool
operator () (Iterable&& c) const
{
for (auto it = hb_iter (c); it; ++it)
if (it)
return true;
return false;
}
} hb_any HB_UNUSED;
static const struct
{
template <typename Iterable,
hb_enable_if (hb_is_iterable (Iterable))>
bool
operator () (Iterable&& c) const
{
for (auto it = hb_iter (c); it; ++it)
if (it)
return false;
return true;
}
} hb_none HB_UNUSED;
/* /*
* Algorithms operating on iterators. * Algorithms operating on iterators.
*/ */

View File

@ -137,6 +137,8 @@ main (int argc, char **argv)
test_iterator (hb_zip (st, v)); test_iterator (hb_zip (st, v));
hb_any (hb_zip (st, v));
hb_array_t<hb_vector_t<int> > pa; hb_array_t<hb_vector_t<int> > pa;
pa->as_array (); pa->as_array ();