6namespace Stroika::Foundation::Traversal {
16 inline shared_ptr<typename Iterator<T>::IRep> Iterator<T>::Rep_Cloner_::Copy (
const IRep& t)
18 return Iterator<T>::Clone_ (t);
28 inline Iterator<T>::IRep::IRep ()
32 inline Iterator<T>::IRep::~IRep ()
43 inline Iterator<T>::Iterator (
const Iterator<T>& from)
44 : fIterator_ {from.fIterator_}
45 , fCurrent_ (from.fCurrent_)
47 Require (fIterator_.get () !=
nullptr or Done ());
50 inline Iterator<T>::Iterator (
const BidirectionalIteratorRepSharedPtr& rep)
56 const_cast<IRep*
> (rep.get ())->More (&fCurrent_,
false);
59 inline Iterator<T>::Iterator (ConstructionFlagForceAtEnd_)
60 : fIterator_ (nullptr)
66 inline Iterator<T>& Iterator<T>::operator= (
const Iterator<T>& rhs)
68 Require (rhs.fIterator_.get () !=
nullptr or rhs.Done ());
69 fIterator_ = rhs.fIterator_;
70 fCurrent_ = rhs.fCurrent_;
74 inline typename Iterator<T>::IRep& Iterator<T>::GetRep ()
80 inline const typename Iterator<T>::IRep& Iterator<T>::GetRep ()
const
86 inline T Iterator<T>::Current ()
const
89 Require (fCurrent_.has_value ());
93 inline bool Iterator<T>::Done ()
const
95 return not fCurrent_.has_value ();
98 inline T Iterator<T>::operator* ()
const
100 Require (not Done ());
104 template <
typename T>
105 inline T* Iterator<T>::operator-> ()
107 Require (not Done ());
109 return fCurrent_.get ();
111 template <
typename T>
112 inline const T* Iterator<T>::operator-> ()
const
114 Require (not Done ());
116 return fCurrent_.get ();
118 template <
typename T>
119 inline void Iterator<T>::operator++ ()
121 Require (not Done ());
123 fIterator_->More (&fCurrent_,
true);
125 template <
typename T>
126 inline void Iterator<T>::operator++ (
int)
129 Require (not Done ());
130 fIterator_->More (&fCurrent_,
true);
132 template <
typename T>
133 inline Iterator<T>::operator bool ()
const
137 template <
typename T>
138 inline bool Iterator<T>::Equals (
const Iterator& rhs)
const
148 bool lDone = Done ();
149 bool rDone = rhs.Done ();
150 if (lDone != rDone) {
157 Assert (not lDone and not rDone);
159 const Iterator<T>::IRep* lhsRep = fIterator_.get ();
160 const Iterator<T>::IRep* rhsRep = rhs.fIterator_.get ();
161 Ensure (lhsRep->Equals (rhsRep) == rhsRep->Equals (lhsRep));
162 return lhsRep->Equals (rhsRep);
164 template <
typename T>
165 inline bool Iterator<T>::operator== (
const Iterator& rhs)
const
169 template <
typename T>
170 inline bool Iterator<T>::operator!= (
const Iterator& rhs)
const
174 template <
typename T>
175 inline unique_ptr<IRep> Iterator<T>::Clone_ (
const typename Iterator<T>::IRep& rep)
179 template <
typename T>
180 inline Iterator<T> Iterator<T>::GetEmptyIterator ()
182 return Iterator<T> (ConstructionFlagForceAtEnd_::ForceAtEnd);
#define RequireNotNull(p)
bool Equals(const T *lhs, const T *rhs)
strcmp or wsccmp() as appropriate == 0