| 1234567891011121314151617181920212223242526272829303132333435363738 |
- //
- // common_view.h
- // stream
- //
- // Created by Sam Jaffe on 3/30/23.
- //
- #pragma once
- #include <iterator/sentinal_iterator.h>
- #include <stream/forward.h>
- #define FWD(x) std::forward<decltype(x)>(x)
- namespace stream::ranges {
- template <typename S> class common_view {
- private:
- S stream_;
- public:
- common_view(S && stream) : stream_(FWD(stream)) {}
- auto begin() const { return iterator::sentinal_iterator(stream_.begin()); }
- auto end() const { return decltype(begin())(); }
- bool empty() const { return stream_.empty(); }
- size_t size() const { return stream_.size(); }
- };
- }
- namespace stream::ranges::views {
- struct common {
- template <typename Stream> friend auto operator|(Stream && stream, common) {
- return common_view(FWD(stream));
- }
- };
- }
- #undef FWD
|