add any of and all of to smart ranges

This commit is contained in:
Max Lyon
2019-10-17 16:02:00 +02:00
parent 147ae217e4
commit 4c15ff6e60

View File

@@ -116,6 +116,26 @@ struct SmartRangeT
return (1.0 / n_elements) * sum;
}
template <typename Functor>
auto any_of(Functor&& f) -> bool
{
auto range = static_cast<const RangeT*>(this);
for (auto e : *range)
if (f(e))
return true;
return false;
}
template <typename Functor>
auto all_of(Functor&& f) -> bool
{
auto range = static_cast<const RangeT*>(this);
for (auto e : *range)
if (!f(e))
return false;
return true;
}
/** @brief Convert range to array.
*
* Converts the range of elements into an array of objects returned by functor \p f.