| 1234567891011121314151617181920212223242526272829303132333435 |
- //
- // for_each.h
- // stream
- //
- // Created by Sam Jaffe on 3/29/23.
- //
- #pragma once
- #define FWD(x) std::forward<decltype(x)>(x)
- namespace stream::ranges {
- template <typename S, typename F> void for_each(S && stream, F func) {
- for (auto && elem : FWD(stream)) {
- func(FWD(elem));
- }
- }
- }
- namespace stream::ranges::views {
- template <typename F> class for_each {
- private:
- F operation_;
- public:
- for_each(F operation) : operation_(operation) {}
- template <typename Stream>
- friend void operator|(Stream && stream, for_each const & each) {
- ranges::for_each(FWD(stream), each.operation_);
- }
- };
- }
- #undef FWD
|