Ver Fonte

Upgrade unkeyed_iterator to use facade.

Sam Jaffe há 4 anos atrás
pai
commit
28de1f5c6f
1 ficheiros alterados com 10 adições e 40 exclusões
  1. 10 40
      include/iterator/unkeyed_iterator.hpp

+ 10 - 40
include/iterator/unkeyed_iterator.hpp

@@ -7,6 +7,7 @@
 
 #pragma once
 
+#include "facade.h"
 #include <iterator>
 
 namespace iterator {
@@ -25,57 +26,26 @@ namespace iterator {
    * }
    * \endcode
    */
-  template <typename Iterator> class unkeyed_iterator {
+  template <typename Iterator>
+  class unkeyed_iterator : public facade<unkeyed_iterator<Iterator>> {
   private:
-    using impl_value_type = typename std::iterator_traits<Iterator>::value_type;
-    using impl_reference = typename std::iterator_traits<Iterator>::reference;
     static constexpr std::size_t const value_index =
-        std::tuple_size<impl_value_type>::value - 1;
+        std::tuple_size<typename Iterator::value_type>::value - 1;
 
   public:
-    using value_type = typename std::remove_reference<decltype(
-        std::get<value_index>(std::declval<impl_value_type>()))>::type;
-    using reference =
-        decltype(std::get<value_index>(std::declval<impl_reference>()));
-    using pointer = value_type *;
-    using difference_type =
-        typename std::iterator_traits<Iterator>::difference_type;
-    using iterator_category =
-        typename std::iterator_traits<Iterator>::iterator_category;
-
     unkeyed_iterator() = default;
     unkeyed_iterator(Iterator it) : base(it) {}
 
-    reference operator*() const { return std::get<value_index>(*base); }
-    pointer operator->() const { return std::addressof(operator*()); }
-    unkeyed_iterator & operator++() {
-      ++base;
-      return *this;
-    }
-    unkeyed_iterator operator++(int) {
-      unkeyed_iterator tmp{*this};
-      operator++();
-      return tmp;
-    }
-
-    unkeyed_iterator & operator--() {
-      --base;
-      return *this;
-    }
-    unkeyed_iterator operator--(int) {
-      unkeyed_iterator tmp{*this};
-      operator--();
-      return tmp;
-    }
-
-    bool operator==(unkeyed_iterator const & other) const {
+    decltype(auto) dereference() const { return std::get<value_index>(*base); }
+    void increment() { ++base; }
+    void decrement() { --base; }
+    bool equal_to(unkeyed_iterator const & other) const {
       return base == other.base;
     }
-    bool operator!=(unkeyed_iterator const & other) const {
-      return base != other.base;
-    }
 
   private:
     Iterator base;
   };
 }
+
+MAKE_ITERATOR_FACADE_TYPEDEFS_T(::iterator::unkeyed_iterator)