| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- //
- // common_view.h
- // stream
- //
- // Created by Sam Jaffe on 3/30/23.
- //
- #pragma once
- #include <iterator/sentinel_iterator.h>
- #include <stream/forward.h>
- #include <stream/detail/traits.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::sentinel_iterator(stream_.begin()); }
- auto end() const { return decltype(begin())(); }
-
- auto empty() const {
- if constexpr (traits::has_empty_v<S>) {
- return stream_.empty();
- }
- }
-
- auto size() {
- if constexpr (traits::has_size_v<S>) {
- return stream_.size();
- }
- }
- };
- template <typename S> common_view(S &&) -> common_view<S>;
- }
- namespace stream::ranges::views {
- struct common {
- template <typename Stream> friend auto operator|(Stream && stream, common) {
- return common_view(FWD(stream));
- }
- };
- }
- #undef FWD
|