| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- //
- // common_iterator.h
- // stream
- //
- // Created by Sam Jaffe on 4/2/23.
- //
- #pragma once
- #include <iterator/proxy.h>
- #include <stream/forward.h>
- #include <stream/detail/macro.h>
- namespace stream::ranges {
- template <typename It, typename S>
- class common_iterator : public proxy<It, common_iterator<It, S>> {
- public:
- static_assert(!std::is_same_v<It, S>, "cannot operator on common types");
- using super_t = proxy<It, common_iterator<It, S>>;
- using sentinel_type = common_iterator;
- public:
- using super_t::super_t;
- common_iterator(S) : super_t() {}
- SFINAE(super_t::category_enum == iterator::category::random_access)
- auto distance_to(common_iterator const & other) const {
- if (at_end()) {
- return other.at_end() ? 0 : -(S() - other);
- } else if (other.at_end()) {
- return S() - *this;
- } else {
- return super_t::distance_to(other);
- }
- }
- bool equal_to(common_iterator const & other) const {
- return (at_end() && other.at_end()) || super_t::impl() == other.impl();
- }
- bool at_end() const { return super_t::impl() == S(); }
- };
- }
- MAKE_ITERATOR_FACADE_TYPEDEFS_T(stream::ranges::common_iterator);
- #include <stream/detail/undef.h>
|