4#ifndef _Stroika_Foundation_Traversal_Iterator_h_
5#define _Stroika_Foundation_Traversal_Iterator_h_ 1
7#include "Stroika/Foundation/StroikaPreComp.h"
15#include "Stroika/Foundation/Common/Common.h"
69namespace Stroika::Foundation::Traversal {
75 template <
typename CATEGORY,
typename T,
typename DIFF = ptrdiff_t,
typename POINTER = const T*,
typename REFERENCE = const T&>
77 using iterator_category = CATEGORY;
79 using difference_type = DIFF;
80 using pointer = POINTER;
81 using reference = REFERENCE;
224 template <
typename T,
typename ITERATOR_TRAITS = DefaultIteratorTraits<forward_iterator_tag, T>>
227 static_assert (constructible_from<optional<T>, T>,
228 "Must be able to create optional<T> to use Iterator, because Iterator uses this internally");
229 static_assert (copyable<T>);
247 using pointer =
typename ITERATOR_TRAITS::pointer;
267 using RepSmartPtr [[deprecated (
"Since Stroika v3.0d1 - just use unique_ptr<IRep> directly")]] = unique_ptr<IRep>;
273 enum class ConstructionFlagForceAtEnd_ {
294 Iterator (
const unique_ptr<IRep>& rep)
noexcept;
295 Iterator (unique_ptr<IRep>&& rep)
noexcept;
298 constexpr Iterator (
const default_sentinel_t&)
noexcept;
299 constexpr Iterator (nullptr_t)
noexcept;
303 constexpr
Iterator (ConstructionFlagForceAtEnd_) noexcept;
330 nonvirtual const T& operator* () const;
343 nonvirtual const
value_type* operator->() const;
370 nonvirtual
Iterator operator++ (
int);
379 nonvirtual
Iterator operator+ (
int i) const;
397 nonvirtual explicit operator
bool () const;
435 nonvirtual
bool operator== (const
Iterator& rhs) const;
436 nonvirtual
bool operator== (const default_sentinel_t& rhs) const;
463 nonvirtual const T&
Current () const;
485 nonvirtual
bool Done () const;
496 nonvirtual
void reset ();
507 nonvirtual
void clear ();
530 nonvirtual IRep&
GetRep ();
549 nonvirtual
void Refresh ();
555 nonvirtual
void Invariant () const noexcept;
558 unique_ptr<IRep> fRep_;
559 optional<T> fCurrentValue_;
562 static unique_ptr<IRep> Clone_ (const IRep& rep);
565 template <typename SHARED_T>
566 using PtrImplementationTemplate [[deprecated ("Since Stroika v3.0d1 - use unique_ptr directly")]] = unique_ptr<SHARED_T>;
567 template <typename SHARED_T, typename... ARGS_TYPE>
568 [[deprecated ("Since Stroika v3.0d1 - make_unique directly")]] static unique_ptr<SHARED_T> MakeSmartPtr (ARGS_TYPE&&... args)
570 return make_unique<SHARED_T> (forward<ARGS_TYPE> (args)...);
598 template <
typename T,
typename ITERATOR_TRAITS>
604 virtual ~IRep () =
default;
607 using RepSmartPtr [[deprecated (
"Since Stroika v3.0d1 - use unique_ptr<IRep> directly")]] = unique_ptr<IRep>;
614 virtual unique_ptr<IRep>
Clone ()
const = 0;
637 virtual void More (optional<T>* result,
bool advance) = 0;
648#if qStroika_Foundation_Debug_AssertionsChecked
651 virtual void Invariant () const noexcept;
665 template <
typename ITERATOR>
666 constexpr typename iterator_traits<ITERATOR>::pointer
Iterator2Pointer (ITERATOR i);
674 template <
typename ITERATOR,
typename OF_T>
675 concept IInputIterator = input_iterator<ITERATOR> and is_convertible_v<std::iter_value_t<ITERATOR>, OF_T>;
684 static_assert (input_iterator<Iterator<int>>);
685 static_assert (regular<Iterator<int>>);
686 static_assert (sentinel_for<default_sentinel_t, Iterator<int>>);
696#include "Iterator.inl"
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.
virtual void More(optional< T > *result, bool advance)=0
virtual unique_ptr< IRep > Clone() const =0
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.
typename ITERATOR_TRAITS::iterator_category iterator_category
iterator_category = typename ITERATOR_TRAITS::iterator_category;
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,...
typename ITERATOR_TRAITS::difference_type difference_type
difference_type = typename ITERATOR_TRAITS::difference_type;
typename ITERATOR_TRAITS::pointer pointer
pointer = typename ITERATOR_TRAITS::pointer;
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()
typename ITERATOR_TRAITS::reference reference
reference = typename ITERATOR_TRAITS::reference;
static constexpr default_sentinel_t GetEmptyIterator() noexcept
Used by someContainer::end ()
nonvirtual bool Done() const
Done () means there is nothing left in this iterator (a synonym for (it == container....