|
|
@@ -0,0 +1,88 @@
|
|
|
+#pragma once
|
|
|
+
|
|
|
+#include <iterator>
|
|
|
+
|
|
|
+#include "facade.h"
|
|
|
+
|
|
|
+namespace iterator {
|
|
|
+ template <typename Iter, typename Self,
|
|
|
+ typename Category =
|
|
|
+ typename std::iterator_traits<Iter>::iterator_category>
|
|
|
+ class proxy;
|
|
|
+
|
|
|
+ template <typename Iter, typename Self>
|
|
|
+ class proxy<Iter, Self, std::input_iterator_tag> : public facade<Self> {
|
|
|
+ public:
|
|
|
+ using single_pass_iterator = void;
|
|
|
+
|
|
|
+ private:
|
|
|
+ Iter impl_;
|
|
|
+
|
|
|
+ public:
|
|
|
+ proxy(Iter impl = {}) : impl_(impl) {}
|
|
|
+
|
|
|
+ decltype(auto) dereference() const { return *impl_; }
|
|
|
+ void increment() { ++impl_; }
|
|
|
+ bool equal_to(proxy const & other) const { return impl_ == other.impl_; }
|
|
|
+
|
|
|
+ protected:
|
|
|
+ auto & impl() const { return impl_; }
|
|
|
+ };
|
|
|
+
|
|
|
+ template <typename Iter, typename Self>
|
|
|
+ class proxy<Iter, Self, std::forward_iterator_tag> : public facade<Self> {
|
|
|
+ private:
|
|
|
+ Iter impl_;
|
|
|
+
|
|
|
+ public:
|
|
|
+ proxy(Iter impl = {}) : impl_(impl) {}
|
|
|
+
|
|
|
+ decltype(auto) dereference() const { return *impl_; }
|
|
|
+ void increment() { ++impl_; }
|
|
|
+ bool equal_to(proxy const & other) const { return impl_ == other.impl_; }
|
|
|
+
|
|
|
+ protected:
|
|
|
+ auto & impl() const { return impl_; }
|
|
|
+ };
|
|
|
+
|
|
|
+ template <typename Iter, typename Self>
|
|
|
+ class proxy<Iter, Self, std::bidirectional_iterator_tag>
|
|
|
+ : public facade<Self> {
|
|
|
+ private:
|
|
|
+ Iter impl_;
|
|
|
+
|
|
|
+ public:
|
|
|
+ proxy(Iter impl = {}) : impl_(impl) {}
|
|
|
+
|
|
|
+ decltype(auto) dereference() const { return *impl_; }
|
|
|
+ void increment() { ++impl_; }
|
|
|
+ void decrement() { --impl_; }
|
|
|
+ bool equal_to(proxy const & other) const { return impl_ == other.impl_; }
|
|
|
+
|
|
|
+ protected:
|
|
|
+ auto & impl() const { return impl_; }
|
|
|
+ };
|
|
|
+
|
|
|
+ template <typename Iter, typename Self>
|
|
|
+ class proxy<Iter, Self, std::random_access_iterator_tag>
|
|
|
+ : public facade<Self> {
|
|
|
+ public:
|
|
|
+ using difference_type =
|
|
|
+ typename std::iterator_traits<Iter>::difference_type;
|
|
|
+
|
|
|
+ private:
|
|
|
+ Iter impl_;
|
|
|
+
|
|
|
+ public:
|
|
|
+ proxy(Iter impl = {}) : impl_(impl) {}
|
|
|
+
|
|
|
+ decltype(auto) dereference() const { return *impl_; }
|
|
|
+ void advance(difference_type off) { impl_ += off; }
|
|
|
+ difference_type distance_to(proxy const & other) const {
|
|
|
+ return impl_ - other.impl_;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected:
|
|
|
+ auto & impl() const { return impl_; }
|
|
|
+ };
|
|
|
+}
|