Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
RandomAccessIterator.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Traversal_RandomAccessIterator_h_
5#define _Stroika_Foundation_Traversal_RandomAccessIterator_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <iterator>
10
11#include "Stroika/Foundation/Common/Common.h"
13
14/**
15 *
16 * \file
17 * ****VERY ROUGH UNUSABLE DRAFT
18 *
19 * \note Code-Status: <a href="Code-Status.md#Draft">Draft</a>
20 *
21 */
22
23namespace Stroika::Foundation::Traversal {
24
25 /**
26 */
27 template <typename T, typename BASE_STD_ITERATOR = DefaultIteratorTraits<random_access_iterator_tag, T>>
28 class RandomAccessIterator : public BidirectionalIterator<T, BASE_STD_ITERATOR> {
29 private:
30 using inherited = Iterator<T, BASE_STD_ITERATOR>;
31
32 public:
33 class IRep;
34
35 public:
36 using RandomAccessIteratorRepSharedPtr = unique_ptr<IRep>;
37
38 public:
39 /**
40 * \brief
41 * This overload is usually not called directly. Instead, iterators are
42 * usually created from a container (eg. Bag<T>::begin()).
43 *
44 * Iterators are safely copyable, preserving their current position.
45 *
46 * \pre RequireNotNull (rep.get ())
47 */
48 explicit RandomAccessIterator (const RandomAccessIteratorRepSharedPtr& rep);
49 RandomAccessIterator (const RandomAccessIterator& from);
50 RandomAccessIterator () = delete;
51
52 private:
53 /**
54 * Mostly internal type to select a constructor for the special END iterator.
55 */
56 enum ConstructionFlagForceAtEnd_ {
57 ForceAtEnd
58 };
59
60 private:
61 RandomAccessIterator (ConstructionFlagForceAtEnd_);
62
63 public:
64 /**
65 * \brief Iterators are safely copyable, preserving their current position.
66 */
67 nonvirtual RandomAccessIterator& operator= (const RandomAccessIterator& rhs);
68
69 public:
70 /**
71 * \brief
72 * Used by *somecontainer*::end ()
73 *
74 * GetEmptyIterator () returns a special iterator which is always empty - always 'at the end'.
75 * This is handy in implementing STL-style 'if (a != b)' style iterator comparisons.
76 */
77 static RandomAccessIterator GetEmptyIterator ();
78
79 public:
80 // @todo add
81 // advance (ptrdiff_t)
82 // difference (iterator) -> ptrdiff_t
83 // global operator +/- calling above
84
85 public:
86 /**
87 * \brief
88 * Get a reference to the IRep owned by the iterator. This is an implementation detail,
89 * mainly intended for implementors.
90 *
91 * Get a reference to the IRep owned by the iterator.
92 * This is an implementation detail, mainly intended for implementors.
93 */
94 nonvirtual IRep& GetRep ();
95 nonvirtual const IRep& GetRep () const;
96 };
97
98 /**
99 *
100 */
101 template <typename T, typename BASE_STD_ITERATOR>
102 class RandomAccessIterator<T, BASE_STD_ITERATOR>::IRep : public BidirectionalIterator<T, BASE_STD_ITERATOR>::IRep {
103 protected:
104 IRep () = default;
105
106 public:
107 /**
108 */
109 virtual ptrdiff_t Difference (const IRep* rhs) const = 0;
110 };
111
112}
113
114/*
115 ********************************************************************************
116 ******************************* Implementation Details *************************
117 ********************************************************************************
118 */
119
120//#include "RandomAccessIterator.inl"
121
122#endif /*_Stroika_Foundation_Traversal_RandomAccessIterator_h_ */