add filtered range that stores reference instead of copy if the filter is not an rvalue reference

This commit is contained in:
Max Lyon
2020-05-06 10:45:41 +02:00
parent 9aa99b0375
commit 4e40352a5f

View File

@@ -408,6 +408,20 @@ struct SmartRangeT
return FilteredSmartRangeT<SmartRange, Handle, typename std::decay<Functor>::type>(f, b, e); return FilteredSmartRangeT<SmartRange, Handle, typename std::decay<Functor>::type>(f, b, e);
} }
/** @brief Only iterate over a subset of elements
*
* Returns a smart range which skips all elements that do not satisfy functor \p f
*
* @param f Functor that needs to be evaluated to true if the element should not be skipped.
*/
template <typename Functor>
auto filtered(Functor& f) -> FilteredSmartRangeT<SmartRange, Handle, const typename std::decay<Functor>::type&>
{
auto range = static_cast<const RangeT*>(this);
auto b = (*range).begin();
auto e = (*range).end();
return FilteredSmartRangeT<SmartRange, Handle, const typename std::decay<Functor>::type&>(f, b, e);
}
}; };