Adjust hb_all/any/none

This commit is contained in:
Behdad Esfahbod 2019-05-08 09:32:19 -07:00
parent 4a101d8ffc
commit fe14a4000a
2 changed files with 15 additions and 13 deletions

View File

@ -649,15 +649,15 @@ HB_FUNCOBJ (hb_unzip);
struct
{
template <typename Iterable,
typename Val = bool,
typename Pred = decltype ((hb_bool)),
typename Proj = decltype ((hb_identity)),
hb_requires (hb_is_iterable (Iterable))>
bool operator () (Iterable&& c,
Val v = true,
Pred&& p = hb_bool,
Proj&& f = hb_identity) const
{
for (auto it = hb_iter (c); it; ++it)
if (!((Val) hb_get (hb_forward<Proj> (f), *it) == v))
if (!hb_match (hb_forward<Pred> (p), hb_get (hb_forward<Proj> (f), *it)))
return false;
return true;
}
@ -666,15 +666,15 @@ HB_FUNCOBJ (hb_all);
struct
{
template <typename Iterable,
typename Val = bool,
typename Pred = decltype ((hb_bool)),
typename Proj = decltype ((hb_identity)),
hb_requires (hb_is_iterable (Iterable))>
bool operator () (Iterable&& c,
Val v = true,
Pred&& p = hb_bool,
Proj&& f = hb_identity) const
{
for (auto it = hb_iter (c); it; ++it)
if (((Val) hb_get (hb_forward<Proj> (f), *it) == v))
if (hb_match (hb_forward<Pred> (p), hb_get (hb_forward<Proj> (f), *it)))
return true;
return false;
}
@ -683,15 +683,15 @@ HB_FUNCOBJ (hb_any);
struct
{
template <typename Iterable,
typename Val = bool,
typename Pred = decltype ((hb_bool)),
typename Proj = decltype ((hb_identity)),
hb_requires (hb_is_iterable (Iterable))>
bool operator () (Iterable&& c,
Val v = true,
Pred&& p = hb_bool,
Proj&& f = hb_identity) const
{
for (auto it = hb_iter (c); it; ++it)
if (((Val) hb_get (hb_forward<Proj> (f), *it) == v))
if (hb_match (hb_forward<Pred> (p), hb_get (hb_forward<Proj> (f), *it)))
return false;
return true;
}

View File

@ -166,11 +166,13 @@ main (int argc, char **argv)
assert (true == hb_all (st));
assert (false == hb_all (st, 42u));
assert (true == hb_any (st));
assert (false == hb_any (st, 14));
assert (true == hb_any (st, 15));
assert (false == hb_any (st, 14u));
assert (true == hb_any (st, 14u, [] (unsigned _) { return _ - 1u; }));
assert (true == hb_any (st, [] (unsigned _) { return _ == 15u; }));
assert (true == hb_any (st, 15u));
assert (false == hb_none (st));
assert (false == hb_none (st, 15));
assert (true == hb_none (st, 17));
assert (false == hb_none (st, 15u));
assert (true == hb_none (st, 17u));
hb_array_t<hb_vector_t<int>> pa;
pa->as_array ();