// // count_if.h // stream // // Created by Sam Jaffe on 4/2/23. // #pragma once #include #include #include namespace stream::ranges { template auto count_if(It it, S end, Pred pred, Proj proj = {}) { size_t result = 0; for (; it != end; ++it) { if (detail::invoke(pred, *it, proj)) { ++result; } } return result; } template auto count_if(Stream const & stream, Pred pred, Proj proj = {}) { return count_if(stream.begin(), stream.end(), std::ref(pred), std::ref(proj)); } }