| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- //
- // common_view.h
- // stream
- //
- // Created by Sam Jaffe on 3/30/23.
- //
- #pragma once
- #include <stream/forward.h>
- #include <stream/detail/traits.h>
- #include <stream/iterator/common_iterator.h>
- #include <stream/view/interface.h>
- #include <stream/detail/macro.h>
- namespace stream::ranges {
- template <typename S>
- class common_view
- : public view_interface<common_view<S>, common_iterator<detail::begin_t<S>,
- detail::end_t<S>>> {
- 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()); }
- };
- 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::has_sentinal_v<Stream>) {
- return common_view(FWD(stream));
- } else {
- return FWD(stream);
- }
- }
- };
- }
- #include <stream/detail/undef.h>
|