| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- //
- // common_view.h
- // stream
- //
- // Created by Sam Jaffe on 3/30/23.
- //
- #pragma once
- #include <stream/detail/traits.h>
- #include <stream/forward.h>
- #include <stream/iterator/common_iterator.h>
- #include <stream/detail/macro.h>
- namespace stream::ranges {
- template <typename S> class common_view {
- private:
- using iterator = common_iterator<detail::begin_t<S>, detail::end_t<S>>;
- private:
- S stream_;
- public:
- common_view(S && stream) : stream_(FWD(stream)) {}
- auto begin() const { return iterator(stream_.begin()); }
- auto end() const { return iterator(stream_.end()); }
- SFINAE(detail::has_empty_v<S>, bool) empty() const { return stream_.empty(); }
- SFINAE(detail::has_size_v<S>, bool) size() const { 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) {
- if constexpr (detail::is_sentinal_v<Stream>) {
- return common_view(FWD(stream));
- } else {
- return FWD(stream);
- }
- }
- };
- }
- #include <stream/detail/undef.h>
|