// // unkeyed_iterator.hpp // iterator // // Created by Sam Jaffe on 2/20/17. // #pragma once #include namespace iterator { template class unkeyed_iterator { private: using impl_value_type = typename std::iterator_traits::value_type; using impl_reference = typename std::iterator_traits::reference; static constexpr std::size_t const value_index = std::tuple_size::value - 1; public: using value_type = typename std::remove_reference(std::declval()))>::type; using reference = decltype(std::get(std::declval())); using pointer = value_type *; using difference_type = typename std::iterator_traits::difference_type; using iterator_category = typename std::iterator_traits::iterator_category; unkeyed_iterator() = default; unkeyed_iterator(Iterator it) : base(it) {} reference operator*() const { return std::get(*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; } unkeyed_iterator operator+(difference_type n) const { return unkeyed_iterator{*this} += n; } unkeyed_iterator & operator+=(difference_type n) { base += n; return *this; } unkeyed_iterator operator-(difference_type n) const { return unkeyed_iterator{*this} -= n; } unkeyed_iterator & operator-=(difference_type n) { base -= n;return *this; } bool operator==(unkeyed_iterator const & other) const { return base == other.base; } bool operator!=(unkeyed_iterator const & other) const { return base != other.base; } bool operator< (unkeyed_iterator const & other) const { return base < other.base; } bool operator<=(unkeyed_iterator const & other) const { return !(other < *this); } private: Iterator base; }; }