| 123456789101112131415161718192021222324252627282930 |
- //
- // for_each.h
- // stream
- //
- // Created by Sam Jaffe on 3/29/23.
- //
- #pragma once
- #include <stream/detail/identity.h>
- #include <stream/detail/named_pair.h>
- #define FWD(x) std::forward<decltype(x)>(x)
- namespace stream::ranges {
- template <typename It, typename S, typename F, typename Proj = detail::identity>
- auto for_each(It it, S end, F func, Proj proj = {}) {
- for (; it != end; ++it) {
- std::invoke(func, std::invoke(proj, FWD(*it)));
- }
- return detail::in_fun_result(it, std::move(func));
- }
- template <typename Stream, typename F, typename Proj = detail::identity>
- auto for_each(Stream && stream, F func, Proj proj = {}) {
- return for_each(stream.begin(), stream.end(), std::ref(func), std::ref(proj));
- }
- }
- #undef FWD
|