Commit 65cafaf1 authored by Max Lyon's avatar Max Lyon
Browse files

add method that returns first element of a smart range that fulfills a condition

parent 2b8a59e2
......@@ -207,6 +207,24 @@ struct SmartRangeT
return res;
/** @brief Get the first element that fulfills a condition.
* Finds the first element of the range for which the functor \p f evaluates to true.
* Returns an invalid handle if none evaluates to true
* @param f Functor that is applied to all elements before putting them into the set. If no functor is provided
* the set will contain the handles.
template <typename Functor>
auto first(Functor&& f = {}) -> HandleT
auto range = static_cast<const RangeT*>(this);
for (const auto& e : *range)
if (f(e))
return e;
return HandleT();
/** @brief Compute minimum.
* Computes the minimum of all objects returned by functor \p f.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment