提交 bdbfdc92 编写于 作者: B Behdad Esfahbod

[iter] Add value and projection to hb_all/any/none

Allows for eg, checking all values equal 2: hb_all (it, 2).
上级 cf61acb9
......@@ -649,11 +649,15 @@ HB_FUNCOBJ (hb_unzip);
struct
{
template <typename Iterable,
typename Val = bool,
typename Proj = decltype ((hb_identity)),
hb_requires (hb_is_iterable (Iterable))>
bool operator () (Iterable&& c) const
bool operator () (Iterable&& c,
Val v = true,
Proj&& f = hb_identity) const
{
for (auto it = hb_iter (c); it; ++it)
if (!*it)
if (!((Val) hb_get (hb_forward<Proj> (f), *it) == v))
return false;
return true;
}
......@@ -662,11 +666,15 @@ HB_FUNCOBJ (hb_all);
struct
{
template <typename Iterable,
typename Val = bool,
typename Proj = decltype ((hb_identity)),
hb_requires (hb_is_iterable (Iterable))>
bool operator () (Iterable&& c) const
bool operator () (Iterable&& c,
Val v = true,
Proj&& f = hb_identity) const
{
for (auto it = hb_iter (c); it; ++it)
if (*it)
if (((Val) hb_get (hb_forward<Proj> (f), *it) == v))
return true;
return false;
}
......@@ -675,11 +683,15 @@ HB_FUNCOBJ (hb_any);
struct
{
template <typename Iterable,
typename Val = bool,
typename Proj = decltype ((hb_identity)),
hb_requires (hb_is_iterable (Iterable))>
bool operator () (Iterable&& c) const
bool operator () (Iterable&& c,
Val v = true,
Proj&& f = hb_identity) const
{
for (auto it = hb_iter (c); it; ++it)
if (*it)
if (((Val) hb_get (hb_forward<Proj> (f), *it) == v))
return false;
return true;
}
......
......@@ -140,6 +140,7 @@ main (int argc, char **argv)
test_iterable (v);
hb_set_t st;
st << 1 << 15 << 43;
test_iterable (st);
hb_sorted_array_t<int> sa;
(void) static_cast<hb_iter_t<hb_sorted_array_t<int>, hb_sorted_array_t<int>::item_t>&> (sa);
......@@ -162,7 +163,14 @@ main (int argc, char **argv)
test_iterator_non_default_constructable (hb_iter (st) | hb_filter ());
test_iterator_non_default_constructable (hb_iter (st) | hb_map (hb_identity));
hb_any (st);
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_none (st));
assert (false == hb_none (st, 15));
assert (true == hb_none (st, 17));
hb_array_t<hb_vector_t<int>> pa;
pa->as_array ();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册