#pragma once #include #include "../../common/specialized.hpp" namespace sprawl { namespace collections { template class List; template class ForwardList; } template class ListIterator : public std::iterator { public: typedef WrapperType* accessor_type; ListIterator(WrapperType* item) : m_currentItem(item) { // } ValueType& operator*() { return m_currentItem->m_value; } ValueType* operator->() { return &m_currentItem->m_value; } ValueType const& operator*() const { return m_currentItem->m_value; } ValueType const* operator->() const { return &m_currentItem->m_value; } ValueType& Value() { return m_currentItem->m_value; } ValueType const& Value() const { return m_currentItem->m_value; } ListIterator& operator++() { m_currentItem = m_currentItem ? m_currentItem->next : nullptr; return *this; } ListIterator operator++(int) { ListIterator tmp(*this); ++(*this); return tmp; } ListIterator const& operator++() const { m_currentItem = m_currentItem ? m_currentItem->next : nullptr; return *this; } ListIterator const operator++(int) const { ListIterator tmp(*this); ++(*this); return tmp; } ListIterator operator+(int steps) { WrapperType* item = m_currentItem; for(int i = 0; i < steps; ++i) { if(!item) { break; } item = item->next; } return ListIterator(item); } ListIterator const operator+(int steps) const { WrapperType* item = m_currentItem; for(int i = 0; i < steps; ++i) { if(!item) { break; } item = item->next; } return ListIterator(item); } ListIterator& operator--() { m_currentItem = m_currentItem ? m_currentItem->prev : nullptr; return *this; } ListIterator operator--(int) { ListIterator tmp(*this); --(*this); return tmp; } ListIterator const& operator--() const { m_currentItem = m_currentItem ? m_currentItem->prev : nullptr; return *this; } ListIterator const operator--(int) const { ListIterator tmp(*this); --(*this); return tmp; } ListIterator operator-(int steps) { WrapperType* item = m_currentItem; for(int i = 0; i < steps; ++i) { if(!item) { break; } item = item->prev; } return ListIterator(item); } ListIterator const operator-(int steps) const { WrapperType* item = m_currentItem; for(int i = 0; i < steps; ++i) { if(!item) { break; } item = item->prev; } return ListIterator(item); } bool operator==(ListIterator const& rhs) const { return m_currentItem == rhs.m_currentItem; } bool operator!=(ListIterator const& rhs) const { return !this->operator==(rhs); } operator bool() const { return m_currentItem != nullptr; } bool operator!() const { return m_currentItem != nullptr; } bool Valid() const { return m_currentItem != nullptr; } bool More() const { return m_currentItem != nullptr && m_currentItem->next != nullptr; } ListIterator Next() { return ListIterator(m_currentItem ? m_currentItem->next : nullptr); } ListIterator const Next() const { return ListIterator(m_currentItem ? m_currentItem->next : nullptr); } operator bool() { return m_currentItem != nullptr; } protected: friend class sprawl::collections::List; friend class sprawl::collections::ForwardList; mutable WrapperType* m_currentItem; }; }