| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #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> {
- 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> {
- 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> {
- 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> {
- 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; }
- // This shouldn't need to be implemented, but for some reason my traits
- // are not correctly deducing here.
- bool equal_to(Self const & other) const { return distance_to(other) == 0; }
- difference_type distance_to(Self const & other) const {
- return other.impl_ - impl_;
- }
- SFINAE(detail::has_sentinel_type_v<It>, bool) at_end() const {
- return impl() == typename It::sentinel_type();
- }
- protected:
- auto impl() const { return impl_; }
- };
- }
- #include <iterator/detail/undef.h>
|