#pragma once #include "Iterator.Base.tlh" #include "Iterator.Random.tlh" //----------------------------------------------------------------------------- // Iterator // 一般容器 - 常量 //----------------------------------------------------------------------------- namespace Iterator { template class __ConstIterator : public __RandomIterator { typedef __RandomIterator inherited; public: using value_type = typename _Container::value_type; using reference = typename _Container::reference; using const_reference = typename _Container::const_reference; using data_type = const_reference; using deref_type = value_type; public: // 构造一个全空的迭代器, 用于容器指针为空的情形 __ConstIterator () : inherited () { } __ConstIterator (const _Container & ar) { InitFrom (ar); } __ConstIterator (const __ConstIterator & from) : inherited (from) { } __ConstIterator (__ConstIterator && from) : inherited (from) { } ~__ConstIterator () {} public: inline __ConstIterator & operator = (const __ConstIterator & from) { inherited::operator = (from); return (*this); } inline __ConstIterator & operator = (__ConstIterator && from) { inherited::operator = (from); return (*this); } public: inline data_type Current () { return (*m_stdIter); } inline data_type operator () () { return (Current ()); } inline data_type operator * () { return (Current ()); } protected: void InitFrom (const _Container & ar) { m_stdIter = m_stdBegin = ar.cbegin (); m_stdEnd = ar.cend (); m_Count = (int)ar.size (); m_Index = 0; } }; }; //----------------------------------------------------------------------------- // Iterator // 一般容器 - 变量 //----------------------------------------------------------------------------- namespace Iterator { template class __Iterator : public __RandomIterator { typedef __RandomIterator inherited; public: using value_type = typename _Container::value_type; using reference = typename _Container::reference; using data_type = reference; using deref_type = value_type; public: // 构造一个全空的迭代器, 用于容器指针为空的情形 __Iterator () : inherited () { } __Iterator (_Container & ar) { InitFrom (ar); } __Iterator (const __Iterator & from) : inherited (from) { } __Iterator (__Iterator && from) : inherited (from) { } ~__Iterator () {} public: inline __Iterator & operator = (const __Iterator & from) { inherited::operator = (from); return (*this); } inline __Iterator & operator = (__Iterator && from) { inherited::operator = (from); return (*this); } public: inline data_type Current () { return (*m_stdIter); } inline data_type operator () () { return (Current ()); } inline data_type operator * () { return (Current ()); } protected: void InitFrom (_Container & ar) { m_stdIter = m_stdBegin = ar.begin (); m_stdEnd = ar.end (); m_Count = (int) ar.size (); m_Index = 0; } }; }