// // max.h // stream // // Created by Sam Jaffe on 4/2/23. // #pragma once #include #include #include #include #include namespace stream::ranges { template , typename Proj = detail::identity> T const & max(T const & l, T const & r, Comp comp = {}, Proj proj = {}) { return detail::invoke(comp, r, l, proj, proj) ? l : r; } template , typename Proj = detail::identity, REQUIRES((detail::is_comparable_v))> auto max_element(It it, S end, Comp comp = {}, Proj proj = {}) { auto rval = it; for (++it; it != end; ++it) { if (detail::invoke(comp, *rval, *it, proj, proj)) { rval = *it; } } return rval; } template , typename Proj = detail::identity> auto max_element(Stream const & stream, Comp comp = {}, Proj proj = {}) { return max_element(stream.begin(), stream.end(), std::ref(comp), std::ref(proj)); } template , typename Proj = detail::identity> auto max(std::initializer_list const & stream, Comp comp = {}, Proj proj = {}) { return *max_element(stream.begin(), stream.end(), std::ref(comp), std::ref(proj)); } template , typename Proj = detail::identity> auto max(Stream const & stream, Comp comp = {}, Proj proj = {}) { return *max_element(stream.begin(), stream.end(), std::ref(comp), std::ref(proj)); } } #include