6namespace Stroika::Foundation::Traversal {
10 struct [[deprecated (
"Since Stroika v3.0d1")]] IteratorBase {
12 template <
typename SHARED_T>
13 using PtrImplementationTemplate [[deprecated (
"Since Stroika v3.0d1 - use unique_ptr directly")]] = unique_ptr<SHARED_T>;
16 template <
typename SHARED_T,
typename... ARGS_TYPE>
17 [[deprecated (
"Since Stroika v3.0d1 - make_unique directly")]]
static unique_ptr<SHARED_T> MakeSmartPtr (ARGS_TYPE&&... args)
19 return make_unique<SHARED_T> (forward<ARGS_TYPE> (args)...);
28#if qStroika_Foundation_Debug_AssertionsChecked
29 template <
typename T,
typename ITERATOR_TRAITS>
30 inline void Iterator<T, ITERATOR_TRAITS>::IRep::Invariant () const noexcept
40 template <
typename T,
typename ITERATOR_TRAITS>
45 fRep_->More (&fCurrentValue_,
false);
48 template <
typename T,
typename ITERATOR_TRAITS>
49 inline Iterator<T, ITERATOR_TRAITS>::Iterator (unique_ptr<IRep>&& rep) noexcept
53 fRep_->More (&fCurrentValue_,
false);
56 template <
typename T,
typename ITERATOR_TRAITS>
57 inline Iterator<T, ITERATOR_TRAITS>::Iterator (
const Iterator& src)
58 : fRep_{src.fRep_ == nullptr ? nullptr : Clone_ (*src.fRep_)}
59 , fCurrentValue_{src.fCurrentValue_}
63 template <
typename T,
typename ITERATOR_TRAITS>
64 inline Iterator<T, ITERATOR_TRAITS>::Iterator (Iterator&& src) noexcept
65 : fRep_{move (src.fRep_)}
66 , fCurrentValue_{move (src.fCurrentValue_)}
70 template <
typename T,
typename ITERATOR_TRAITS>
71 constexpr Iterator<T, ITERATOR_TRAITS>::Iterator (
const default_sentinel_t&) noexcept
72 : Iterator{ConstructionFlagForceAtEnd_::ForceAtEnd}
75 template <
typename T,
typename ITERATOR_TRAITS>
76 constexpr Iterator<T, ITERATOR_TRAITS>::Iterator (nullptr_t) noexcept
77 : Iterator{ConstructionFlagForceAtEnd_::ForceAtEnd}
80 template <
typename T,
typename ITERATOR_TRAITS>
81 constexpr Iterator<T, ITERATOR_TRAITS>::Iterator () noexcept
82 : Iterator{ConstructionFlagForceAtEnd_::ForceAtEnd}
85 template <
typename T,
typename ITERATOR_TRAITS>
86 constexpr Iterator<T, ITERATOR_TRAITS>::Iterator (ConstructionFlagForceAtEnd_) noexcept
91 template <
typename T,
typename ITERATOR_TRAITS>
94 if (&rhs !=
this) [[likely]] {
95 fRep_ = rhs.fRep_ ==
nullptr ? nullptr : Clone_ (*rhs.fRep_);
96 fCurrentValue_ = rhs.fCurrentValue_;
101 template <
typename T,
typename ITERATOR_TRAITS>
104 if (&rhs !=
this) [[likely]] {
105 fRep_ = move (rhs.fRep_);
106 fCurrentValue_ = move (rhs.fCurrentValue_);
111 template <
typename T,
typename ITERATOR_TRAITS>
117 template <
typename T,
typename ITERATOR_TRAITS>
123 template <
typename T,
typename ITERATOR_TRAITS>
126 fRep_->More (&this->fCurrentValue_,
false);
129 template <
typename T,
typename ITERATOR_TRAITS>
138 template <
typename T,
typename ITERATOR_TRAITS>
142 Require (fCurrentValue_.has_value ());
144 return *fCurrentValue_;
146 template <
typename T,
typename ITERATOR_TRAITS>
150 return not fCurrentValue_.has_value ();
152 template <
typename T,
typename ITERATOR_TRAITS>
155 *
this = GetEmptyIterator ();
157 template <
typename T,
typename ITERATOR_TRAITS>
160 *
this = GetEmptyIterator ();
162 template <
typename T,
typename ITERATOR_TRAITS>
165 Require (not Done ());
168 return *fCurrentValue_;
170 template <
typename T,
typename ITERATOR_TRAITS>
173 Require (not Done ());
176 return fCurrentValue_.operator->();
178 template <
typename T,
typename ITERATOR_TRAITS>
181 Require (not Done ());
183 fRep_->More (&fCurrentValue_,
true);
187 template <
typename T,
typename ITERATOR_TRAITS>
194 template <
typename T,
typename ITERATOR_TRAITS>
195 inline Iterator<T, ITERATOR_TRAITS> Iterator<T, ITERATOR_TRAITS>::operator+ (
int i)
const
198 Iterator<T, ITERATOR_TRAITS> tmp{*
this};
205 template <
typename T,
typename ITERATOR_TRAITS>
206 inline Iterator<T, ITERATOR_TRAITS>::operator bool ()
const
210 template <
typename T,
typename ITERATOR_TRAITS>
221 bool lDone = Done ();
222 bool rDone = rhs.
Done ();
223 if (lDone != rDone) [[likely]] {
230 Assert (not lDone and not rDone);
233 Ensure (lhsRep->
Equals (rhsRep) == rhsRep->
Equals (lhsRep));
234 return lhsRep->
Equals (rhsRep);
236 template <
typename T,
typename ITERATOR_TRAITS>
239 return this->Done ();
241 template <
typename T,
typename ITERATOR_TRAITS>
242 inline auto Iterator<T, ITERATOR_TRAITS>::Clone_ (
const typename Iterator<T, ITERATOR_TRAITS>::IRep& rep) -> unique_ptr<IRep>
246 template <
typename T,
typename ITERATOR_TRAITS>
249 return default_sentinel;
257 template <
typename ITERATOR>
#define qStroika_Foundation_Debug_AssertionsChecked
The qStroika_Foundation_Debug_AssertionsChecked flag determines if assertions are checked and validat...
#define RequireNotNull(p)
constexpr iterator_traits< ITERATOR >::pointer Iterator2Pointer(ITERATOR i)
More clear way of writing '&*' - convert iterator to pointer.
Implementation detail for iterator implementors.
virtual bool Equals(const IRep *rhs) const =0
two iterators must be iterating over the same source, and be up to the same position.
An Iterator<T> is a copyable object which allows traversing the contents of some container....
nonvirtual void reset()
Set to done and disassociate with owner.
nonvirtual IRep & GetRep()
Get a reference to the IRep owned by the iterator. This is an implementation detail,...
nonvirtual const IRep & ConstGetRep() const
Get a reference to the IRep owned by the iterator. This is an implementation detail,...
nonvirtual void clear()
Set to done and disassociate with owner.
typename ITERATOR_TRAITS::value_type value_type
value_type = typename ITERATOR_TRAITS::value_type;
nonvirtual void Invariant() const noexcept
, does nothing if !qStroika_Foundation_Debug_AssertionsChecked, but if qStroika_Foundation_Debug_Asse...
nonvirtual const T & Current() const
Returns the value of the current item visited by the Iterator<T>, and is illegal to call if Done()
nonvirtual const value_type * operator->() const
Return a pointer to the current value pointed to by the Iterator<T> (like Current())
static constexpr default_sentinel_t GetEmptyIterator() noexcept
Used by someContainer::end ()
nonvirtual bool operator==(const Iterator &rhs) const
Equals () checks if two iterators are equal to one another (point to the same position in the sequenc...
nonvirtual Iterator & operator=(Iterator &&rhs) noexcept
Iterators are safely copyable, preserving their current position. Copy-Assigning could throw since it...
nonvirtual Iterator & operator++()
preincrement
nonvirtual bool Done() const
Done () means there is nothing left in this iterator (a synonym for (it == container....
nonvirtual const T & operator*() const
Return the Current value pointed to by the Iterator<T> (same as Current())