Browse Source

Fix some type issues w/ facade and proxy.

Sam Jaffe 4 years ago
parent
commit
295295c2db
2 changed files with 18 additions and 7 deletions
  1. 2 2
      include/iterator/facade.h
  2. 16 5
      include/iterator/proxy.h

+ 2 - 2
include/iterator/facade.h

@@ -117,7 +117,7 @@ namespace iterator {
 
     self_type & operator++() {
       if constexpr (detail::is_advanceable_iterator_v<self_type>) {
-        *this += 1;
+        self() += 1;
       } else {
         self().increment();
       }
@@ -136,7 +136,7 @@ namespace iterator {
 
     self_type & operator--() {
       if constexpr (detail::is_advanceable_iterator_v<self_type>) {
-        *this -= 1;
+        self() -= 1;
       } else {
         self().decrement();
       }

+ 16 - 5
include/iterator/proxy.h

@@ -20,10 +20,12 @@ namespace iterator {
 
   public:
     proxy(Iter impl = {}) : impl_(impl) {}
+    template <typename... Args>
+    proxy(Args &&... args) : impl_(std::forward<Args>(args)...) {}
 
     decltype(auto) dereference() const { return *impl_; }
     void increment() { ++impl_; }
-    bool equal_to(proxy const & other) const { return impl_ == other.impl_; }
+    bool equal_to(Self const & other) const { return impl_ == other.impl_; }
 
   protected:
     auto & impl() const { return impl_; }
@@ -36,10 +38,12 @@ namespace iterator {
 
   public:
     proxy(Iter impl = {}) : impl_(impl) {}
+    template <typename... Args>
+    proxy(Args &&... args) : impl_(std::forward<Args>(args)...) {}
 
     decltype(auto) dereference() const { return *impl_; }
     void increment() { ++impl_; }
-    bool equal_to(proxy const & other) const { return impl_ == other.impl_; }
+    bool equal_to(Self const & other) const { return impl_ == other.impl_; }
 
   protected:
     auto & impl() const { return impl_; }
@@ -53,11 +57,13 @@ namespace iterator {
 
   public:
     proxy(Iter impl = {}) : impl_(impl) {}
+    template <typename... Args>
+    proxy(Args &&... args) : impl_(std::forward<Args>(args)...) {}
 
     decltype(auto) dereference() const { return *impl_; }
     void increment() { ++impl_; }
     void decrement() { --impl_; }
-    bool equal_to(proxy const & other) const { return impl_ == other.impl_; }
+    bool equal_to(Self const & other) const { return impl_ == other.impl_; }
 
   protected:
     auto & impl() const { return impl_; }
@@ -75,11 +81,16 @@ namespace iterator {
 
   public:
     proxy(Iter impl = {}) : impl_(impl) {}
+    template <typename... Args>
+    proxy(Args &&... args) : impl_(std::forward<Args>(args)...) {}
 
     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_;
+    // 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_;
     }
 
   protected: