| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #pragma once
- #include <iterator/facade.h>
- #include <iterator/forwards.h>
- #include <iterator/detail/macro.h>
- namespace iterator {
- template <typename It, typename Self, typename Cat>
- class proxy : public facade<Self, category::single_pass> {
- public:
- using single_pass_iterator = void;
- private:
- It impl_;
- public:
- proxy() = default;
- proxy(It impl) : impl_(impl) {}
- template <typename... Args> proxy(Args &&... args) : impl_(FWD(args)...) {}
- decltype(auto) dereference() const { return *impl_; }
- void increment() { ++impl_; }
- bool equal_to(Self const & other) const { return impl_ == other.impl_; }
- SFINAE(detail::has_sentinel_type_v<It>) bool at_end() const {
- return impl() == typename It::sentinel_type();
- }
- protected:
- auto impl() const { return impl_; }
- };
- template <typename It, typename Self>
- class proxy<It, Self, std::forward_iterator_tag>
- : public facade<Self, category::forward> {
- private:
- It impl_;
- public:
- proxy() = default;
- proxy(It impl) : impl_(impl) {}
- template <typename... Args> proxy(Args &&... args) : impl_(FWD(args)...) {}
- decltype(auto) dereference() const { return *impl_; }
- void increment() { ++impl_; }
- bool equal_to(Self const & other) const { return impl_ == other.impl_; }
- SFINAE(detail::has_sentinel_type_v<It>) bool at_end() const {
- return impl() == typename It::sentinel_type();
- }
- protected:
- auto impl() const { return impl_; }
- };
- template <typename It, typename Self>
- class proxy<It, Self, std::bidirectional_iterator_tag>
- : public facade<Self, category::bidirectional> {
- private:
- It impl_;
- public:
- proxy() = default;
- proxy(It impl) : impl_(impl) {}
- template <typename... Args> proxy(Args &&... args) : impl_(FWD(args)...) {}
- decltype(auto) dereference() const { return *impl_; }
- void increment() { ++impl_; }
- void decrement() { --impl_; }
- bool equal_to(Self const & other) const { return impl_ == other.impl_; }
- SFINAE(detail::has_sentinel_type_v<It>) bool at_end() const {
- return impl() == typename It::sentinel_type();
- }
- protected:
- auto impl() const { return impl_; }
- };
- template <typename It, typename Self>
- class proxy<It, Self, std::random_access_iterator_tag>
- : public facade<Self, category::random_access> {
- public:
- using difference_type = typename std::iterator_traits<It>::difference_type;
- private:
- It impl_;
- public:
- proxy() = default;
- proxy(It impl) : impl_(impl) {}
- template <typename... Args> proxy(Args &&... args) : impl_(FWD(args)...) {}
- decltype(auto) dereference() const { return *impl_; }
- void advance(difference_type off) { impl_ += off; }
- difference_type distance_to(Self const & other) const {
- return other.impl_ - impl_;
- }
-
- template <typename S, REQUIRES((detail::is_sentinel_v<It, S>))>
- friend auto operator-(S sentinel, Self const &self) {
- return sentinel - self.impl();
- }
-
- SFINAE(detail::has_sentinel_type_v<It>) bool at_end() const {
- return (typename It::sentinel_type() - impl()) <= 0;
- }
- protected:
- auto impl() const { return impl_; }
- };
- }
- #include <iterator/detail/undef.h>
|