common_iterator.h 794 B

123456789101112131415161718192021222324252627282930313233
  1. //
  2. // common_iterator.h
  3. // stream
  4. //
  5. // Created by Sam Jaffe on 4/2/23.
  6. //
  7. #pragma once
  8. #include <iterator/proxy.h>
  9. #include <stream/forward.h>
  10. namespace stream::ranges {
  11. template <typename It, typename S>
  12. class common_iterator : public proxy<It, common_iterator<It, S>> {
  13. public:
  14. static_assert(!std::is_same_v<It, S>, "cannot operator on common types");
  15. using super_t = proxy<It, common_iterator<It, S>>;
  16. using sentinel_type = common_iterator;
  17. public:
  18. using super_t::super_t;
  19. common_iterator(S) : super_t() {}
  20. bool equal_to(common_iterator const & other) const {
  21. return (at_end() && other.at_end()) || super_t::impl() == other.impl();
  22. }
  23. bool at_end() const { return super_t::impl() == S(); }
  24. };
  25. }
  26. MAKE_ITERATOR_FACADE_TYPEDEFS_T(stream::ranges::common_iterator);