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 struct
{ {
template <typename Iterable, template <typename Iterable,
typename Val = bool, typename Pred = decltype ((hb_bool)),
typename Proj = decltype ((hb_identity)), typename Proj = decltype ((hb_identity)),
hb_requires (hb_is_iterable (Iterable))> hb_requires (hb_is_iterable (Iterable))>
bool operator () (Iterable&& c, bool operator () (Iterable&& c,
Val v = true, Pred&& p = hb_bool,
Proj&& f = hb_identity) const Proj&& f = hb_identity) const
{ {
for (auto it = hb_iter (c); it; ++it) 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 false;
return true; return true;
} }
@ -666,15 +666,15 @@ HB_FUNCOBJ (hb_all);
struct struct
{ {
template <typename Iterable, template <typename Iterable,
typename Val = bool, typename Pred = decltype ((hb_bool)),
typename Proj = decltype ((hb_identity)), typename Proj = decltype ((hb_identity)),
hb_requires (hb_is_iterable (Iterable))> hb_requires (hb_is_iterable (Iterable))>
bool operator () (Iterable&& c, bool operator () (Iterable&& c,
Val v = true, Pred&& p = hb_bool,
Proj&& f = hb_identity) const Proj&& f = hb_identity) const
{ {
for (auto it = hb_iter (c); it; ++it) 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 true;
return false; return false;
} }
@ -683,15 +683,15 @@ HB_FUNCOBJ (hb_any);
struct struct
{ {
template <typename Iterable, template <typename Iterable,
typename Val = bool, typename Pred = decltype ((hb_bool)),
typename Proj = decltype ((hb_identity)), typename Proj = decltype ((hb_identity)),
hb_requires (hb_is_iterable (Iterable))> hb_requires (hb_is_iterable (Iterable))>
bool operator () (Iterable&& c, bool operator () (Iterable&& c,
Val v = true, Pred&& p = hb_bool,
Proj&& f = hb_identity) const Proj&& f = hb_identity) const
{ {
for (auto it = hb_iter (c); it; ++it) 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 false;
return true; return true;
} }

View File

@ -166,11 +166,13 @@ main (int argc, char **argv)
assert (true == hb_all (st)); assert (true == hb_all (st));
assert (false == hb_all (st, 42u)); assert (false == hb_all (st, 42u));
assert (true == hb_any (st)); assert (true == hb_any (st));
assert (false == hb_any (st, 14)); assert (false == hb_any (st, 14u));
assert (true == hb_any (st, 15)); 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));
assert (false == hb_none (st, 15)); assert (false == hb_none (st, 15u));
assert (true == hb_none (st, 17)); assert (true == hb_none (st, 17u));
hb_array_t<hb_vector_t<int>> pa; hb_array_t<hb_vector_t<int>> pa;
pa->as_array (); pa->as_array ();