For example, if I want to find the smallest element of a collection, but only the smallest even element, I'd like to call ranges::min_element
with a filtered range like so:
using ranges::views::filter;
using ranges::min_element;
std::vector<int> vals{1,2,3,4,5};
auto minVal = min_element(vals | filter([](int next){return next % 2 == 0;}));
How do I check if the returned range is empty, and if not, access the value?
The same applies to other range algorithms like ranges::find
, ranges::find_if
, etc.