[iter] Add value and projection to hb_all/any/none
Allows for eg, checking all values equal 2: hb_all (it, 2).
This commit is contained in:
parent
cf61acb9ea
commit
bdbfdc92b5
|
@ -649,11 +649,15 @@ HB_FUNCOBJ (hb_unzip);
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
template <typename Iterable,
|
template <typename Iterable,
|
||||||
|
typename Val = bool,
|
||||||
|
typename Proj = decltype ((hb_identity)),
|
||||||
hb_requires (hb_is_iterable (Iterable))>
|
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)
|
for (auto it = hb_iter (c); it; ++it)
|
||||||
if (!*it)
|
if (!((Val) hb_get (hb_forward<Proj> (f), *it) == v))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -662,11 +666,15 @@ HB_FUNCOBJ (hb_all);
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
template <typename Iterable,
|
template <typename Iterable,
|
||||||
|
typename Val = bool,
|
||||||
|
typename Proj = decltype ((hb_identity)),
|
||||||
hb_requires (hb_is_iterable (Iterable))>
|
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)
|
for (auto it = hb_iter (c); it; ++it)
|
||||||
if (*it)
|
if (((Val) hb_get (hb_forward<Proj> (f), *it) == v))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -675,11 +683,15 @@ HB_FUNCOBJ (hb_any);
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
template <typename Iterable,
|
template <typename Iterable,
|
||||||
|
typename Val = bool,
|
||||||
|
typename Proj = decltype ((hb_identity)),
|
||||||
hb_requires (hb_is_iterable (Iterable))>
|
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)
|
for (auto it = hb_iter (c); it; ++it)
|
||||||
if (*it)
|
if (((Val) hb_get (hb_forward<Proj> (f), *it) == v))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,6 +140,7 @@ main (int argc, char **argv)
|
||||||
|
|
||||||
test_iterable (v);
|
test_iterable (v);
|
||||||
hb_set_t st;
|
hb_set_t st;
|
||||||
|
st << 1 << 15 << 43;
|
||||||
test_iterable (st);
|
test_iterable (st);
|
||||||
hb_sorted_array_t<int> sa;
|
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);
|
(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_filter ());
|
||||||
test_iterator_non_default_constructable (hb_iter (st) | hb_map (hb_identity));
|
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;
|
hb_array_t<hb_vector_t<int>> pa;
|
||||||
pa->as_array ();
|
pa->as_array ();
|
||||||
|
|
Loading…
Reference in New Issue