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"
71namespace Stroika::Foundation::Traversal {
80 template <
typename T,
typename DIFF = ptrdiff_t,
typename POINTER = const T*,
typename REFERENCE = const T&>
83 using difference_type = DIFF;
84 using pointer = POINTER;
85 using reference = REFERENCE;
95 template <
typename TRAITS>
97 typename TRAITS::value_type;
98 typename TRAITS::difference_type;
99 typename TRAITS::pointer;
100 typename TRAITS::reference;
252 template <
typename T, Support::IIteratorTraits ITERATOR_TRAITS = Support::DefaultIteratorTraits<T>>
255 static_assert (constructible_from<optional<T>, T>,
256 "Must be able to create optional<T> to use Iterator, because Iterator uses this internally");
257 static_assert (copyable<T>);
275 using pointer =
typename ITERATOR_TRAITS::pointer;
303 using RepSmartPtr [[deprecated (
"Since Stroika v3.0d1 - just use unique_ptr<IRep> directly")]] = unique_ptr<IRep>;
323 Iterator (
const unique_ptr<IRep>& rep)
noexcept;
324 Iterator (unique_ptr<IRep>&& rep)
noexcept;
327 constexpr Iterator (
const default_sentinel_t&)
noexcept;
328 constexpr Iterator (nullptr_t)
noexcept;
355 nonvirtual const T& operator* () const;
367 nonvirtual const
value_type* operator->() const;
391 nonvirtual
Iterator operator++ (
int);
401 nonvirtual
Iterator operator+ (ptrdiff_t i) const;
419 nonvirtual explicit operator
bool () const;
455 nonvirtual
bool operator== (const
Iterator& rhs) const;
456 nonvirtual
bool operator== (const default_sentinel_t& rhs) const;
484 nonvirtual const T&
Current () const;
503 nonvirtual
bool AtEnd () const;
513 nonvirtual
void reset ();
523 nonvirtual
void clear ();
565 nonvirtual
void Invariant () const noexcept;
568 unique_ptr<
IRep> fRep_;
572 optional<T> _fCurrentValue;
575 static unique_ptr<
IRep> Clone_ (const
IRep& rep);
578 template <typename SHARED_T>
579 using PtrImplementationTemplate [[deprecated ("Since Stroika v3.0d1 - use unique_ptr directly")]] = unique_ptr<SHARED_T>;
580 template <typename SHARED_T, typename... ARGS_TYPE>
581 [[deprecated ("Since Stroika v3.0d1 - make_unique directly")]] static unique_ptr<SHARED_T> MakeSmartPtr (ARGS_TYPE&&... args)
583 return make_unique<SHARED_T> (forward<ARGS_TYPE> (args)...);
585 [[deprecated (
"Since Stroika v3.0d34 Use AtEnd() instead")]]
586 nonvirtual
bool Done ()
const
615 template <
typename T, Support::IIteratorTraits ITERATOR_TRAITS>
621 virtual ~IRep () =
default;
624 using RepSmartPtr [[deprecated (
"Since Stroika v3.0d1 - use unique_ptr<IRep> directly")]] = unique_ptr<IRep>;
631 virtual unique_ptr<IRep>
Clone ()
const = 0;
664 virtual optional<T>
More () = 0;
678#if qStroika_Foundation_Debug_AssertionsChecked
682 virtual void Invariant () const noexcept;
696 template <
typename ITERATOR>
697 constexpr typename iterator_traits<ITERATOR>::pointer
Iterator2Pointer (ITERATOR i);
705 template <
typename ITERATOR,
typename OF_T>
706 concept IInputIterator = input_iterator<ITERATOR> and is_convertible_v<std::iter_value_t<ITERATOR>, OF_T>;
718 template <
typename ITERATOR,
typename OF_T>
719 concept IForwardIterator = forward_iterator<ITERATOR> and is_convertible_v<std::iter_value_t<ITERATOR>, OF_T>;
728 static_assert (forward_iterator<Iterator<int>>);
729 static_assert (regular<Iterator<int>>);
730 static_assert (sentinel_for<default_sentinel_t, Iterator<int>>);
740#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 optional< T > More()=0
More () advances the iterator to the next position, and returns the value there (nullopt if at end).
virtual optional< T > Current() const =0
Return nullopt if it end of range, else return current value iterator points to.
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 bool AtEnd() const =0
Check if the iterator is at the end of the range.
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 AtEnd and disassociate with owner.
forward_iterator_tag iterator_category
iterator_category = forward_iterator_tag;
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 AtEnd and disassociate with owner.
typename ITERATOR_TRAITS::value_type value_type
value_type = typename ITERATOR_TRAITS::value_type;
nonvirtual void Invariant() const noexcept
Invariant does nothing if !qStroika_Foundation_Debug_AssertionsChecked, but if qStroika_Foundation_De...
nonvirtual const T & Current() const
Returns the value of the current item visited by the Iterator<T>, and is illegal to call if AtEnd()
typename ITERATOR_TRAITS::reference reference
reference = typename ITERATOR_TRAITS::reference;
static constexpr default_sentinel_t GetEmptyIterator() noexcept
Used by someContainer::end ()
nonvirtual bool AtEnd() const
AtEnd () means there is nothing left in this iterator (a synonym for (it == container....
nonvirtual void Refresh()
Refresh the current iterator state based on what is in the underlying IRep.