#pragma once #include #include "Iterator.Base.tlh" //----------------------------------------------------------------------------- // Concat_Iterator // 注意: // Count () 已经被定义为 Extension::Count () // 所以这里强行转换为 __CoreIterator // // 注意: // 不要求 IteratorA 和 IteratorB 是同一个类型, // 但是要求两者的 value_type 和 data_type 一样 //----------------------------------------------------------------------------- namespace Iterator { template class Concat_Iterator2 : public __CoreIterator { typedef __CoreIterator inherited; public: using IterType = typename IteratorA::IterType; using value_type = typename IteratorA::value_type; using data_type = typename IteratorA::data_type; using deref_type = value_type; public: Concat_Iterator2 () = delete; Concat_Iterator2 (IteratorA & a, IteratorB & b) : m_IterA (a), m_IterB (b), inherited (a) { __CoreIterator & CA (m_IterA); __CoreIterator & CB (m_IterB); m_Count = CA.Count () + CB.Count (); } Concat_Iterator2 (const Concat_Iterator2 & from) : m_IterA (from.m_IterA), m_IterB (from.m_IterB), inherited (from.m_IterA) { __CoreIterator & CA (m_IterA); __CoreIterator & CB (m_IterB); m_Count = CA.Count () + CB.Count (); } Concat_Iterator2 (Concat_Iterator2 && from) : m_IterA (from.m_IterA), m_IterB (from.m_IterB), inherited (from.m_IterA) { __CoreIterator & CA (m_IterA); __CoreIterator & CB (m_IterB); m_Count = CA.Count () + CB.Count (); } public: inline virtual void Next () override { if (inherited::IsEmpty ()) return; if (! m_IterA.IsEmpty ()) m_IterA.Next (); else if (! m_IterB.IsEmpty ()) m_IterB.Next (); inherited::Next (); } inline data_type Current () { if (! m_IterA.IsEmpty ()) return (m_IterA.Current ()); else return (m_IterB.Current ()); } inline data_type operator () () { return Current (); } inline data_type operator * () { return Current (); } inline virtual bool IsEmpty () const override { if (inherited::IsEmpty ()) return true; return (m_IterA.IsEmpty () && m_IterB.IsEmpty ()); } inline void Skip (int delta) { for (;! IsEmpty () && delta > 0; delta --) Next (); } public: inline IterType stdBegin () { return m_IterA.stdBegin (); } inline IterType stdCurrent () { return m_IterA.stdCurrent (); } inline IterType stdEnd () { return m_IterA.stdEnd (); } private: IteratorA m_IterA; IteratorB m_IterB; }; };