123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- #pragma once
- #include "Iterator.Base.tlh"
- #include "Iterator.Random.tlh"
- //-----------------------------------------------------------------------------
- // Iterator
- // 一般容器 - 常量
- //-----------------------------------------------------------------------------
- namespace Iterator
- {
- template <typename _Container>
- class __ConstIterator : public __RandomIterator <typename _Container::const_iterator>
- {
- typedef __RandomIterator <typename _Container::const_iterator> 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 <typename _Container>
- class __Iterator : public __RandomIterator <typename _Container::iterator>
- {
- typedef __RandomIterator <typename _Container::iterator> 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;
- }
- };
- }
|