join.h 765 B

1234567891011121314151617181920212223242526272829303132333435
  1. #pragma once
  2. #include <iterator/join_iterator.h>
  3. #include <stream/forward.h>
  4. #include <stream/detail/traits.h>
  5. #include <stream/detail/macro.h>
  6. namespace stream::ranges {
  7. template <typename S> struct join_view {
  8. private:
  9. S stream_;
  10. public:
  11. join_view(S && stream) : stream_(FWD(stream)) {}
  12. auto begin() const { return iterator::joining_iterator(stream_); }
  13. auto end() const { return iterator::sentinel; }
  14. SFINAE(detail::has_empty_v<S>, bool) empty() const { return stream_.empty(); }
  15. };
  16. template <typename S> join_view(S &&) -> join_view<S>;
  17. }
  18. namespace stream::ranges::views {
  19. struct join {
  20. template <typename Stream> friend auto operator|(Stream && stream, join) {
  21. return join_view(FWD(stream));
  22. }
  23. };
  24. }
  25. #include <stream/detail/undef.h>