#pragma once #include #include "../../common/specialized.hpp" namespace sprawl { template class DequeIterator; } template class sprawl::DequeIterator : public std::iterator { public: DequeIterator(size_t index, ParentType* parent) : m_currentIndex(index) , m_parent(parent) { // } ValueType& operator*() { return m_parent->operator[](m_currentIndex); } ValueType* operator->() { return &m_parent->operator[](m_currentIndex); } ValueType const& operator*() const { return m_parent->operator[](m_currentIndex); } ValueType const* operator->() const { return &m_parent->operator[](m_currentIndex); } ValueType& Value() { return m_parent->operator[](m_currentIndex); } ValueType const& Value() const { return m_parent->operator[](m_currentIndex); } DequeIterator& operator++() { ++m_currentIndex; return *this; } DequeIterator operator++(int) { return DequeIterator(m_currentIndex++, m_parent); } DequeIterator const& operator++() const { ++m_currentIndex; return *this; } DequeIterator const operator++(int) const { return DequeIterator(m_currentIndex++, m_parent); } DequeIterator operator+(int steps) { return DequeIterator(m_currentIndex+steps, m_parent); } DequeIterator const operator+(int steps) const { return DequeIterator(m_currentIndex+steps, m_parent); } DequeIterator& operator--() { --m_currentIndex; return *this; } DequeIterator operator--(int) { return DequeIterator(m_currentIndex--, m_parent); } DequeIterator const& operator--() const { --m_currentIndex; return *this; } DequeIterator const operator--(int) const { return DequeIterator(m_currentIndex--, m_parent); } DequeIterator operator-(int steps) { return DequeIterator(m_currentIndex - steps, m_parent); } DequeIterator const operator-(int steps) const { return DequeIterator(m_currentIndex - steps, m_parent); } bool operator==(DequeIterator const& rhs) const { return m_currentIndex == rhs.m_currentIndex; } bool operator!=(DequeIterator const& rhs) const { return !this->operator==(rhs); } operator bool() const { return Valid(); } bool operator!() const { return !Valid(); } bool Valid() const { return operator>=(m_parent->begin()) && operator<(m_parent->end()); } bool More() const { return Valid() && Next().Valid(); } DequeIterator Next() { return DequeIterator(m_currentIndex + 1, m_parent); } DequeIterator const Next() const { return DequeIterator(m_currentIndex + 1, m_parent); } size_t operator-(DequeIterator const& other) { return m_currentIndex - other.m_currentIndex; } ValueType& operator[](size_t index) { return m_parent->operator[](m_currentIndex + index); } ValueType const& operator[](size_t index) const { return m_parent->operator[](m_currentIndex + index); } bool operator<(DequeIterator const& rhs) { return m_currentIndex < rhs.m_currentIndex; } bool operator>(DequeIterator const& rhs) { return m_currentIndex > rhs.m_currentIndex; } bool operator<=(DequeIterator const& rhs) { return m_currentIndex <= rhs.m_currentIndex; } bool operator>=(DequeIterator const& rhs) { return m_currentIndex >= rhs.m_currentIndex; } size_t Index() { return m_currentIndex; } protected: mutable size_t m_currentIndex; ParentType* m_parent; };