9 template <
typename TYPE>
12 class iterAdaptor final :
public iterator<TYPE>{
17 iterAdaptor* clone()
const override;
18 iterAdaptor* getPrev()
const override;
19 iterAdaptor* getNext()
const override;
21 friend class iterable;
22 iterAdaptor(
const iterAdaptor& other);
23 iterAdaptor& operator=(
const iterAdaptor& other);
25 [[nodiscard]]
bool hasNext()
const override;
26 [[nodiscard]]
bool hasPrev()
const override;
29 void next()
const override;
30 void prev()
const override;
31 void operator+=(int64_t steps)
const override;
32 void operator-=(int64_t steps)
const override;
35 void set(
const TYPE& data)
override;
36 TYPE get()
const override;
37 [[nodiscard]]
bool isValid()
const override;
38 [[nodiscard]] std::string className()
const override;
39 [[nodiscard]] std::string toString(
bool enter)
const override;
40 ~iterAdaptor()
override;
57 template<
typename Callback = transform<TYPE>>
59 void forEach(Callback operation = Callback{});
61 template<
typename Callback = transform<TYPE>>
63 void forEach(
const Callback& operation = Callback{})
const;
67 template <
typename TYPE>
68 original::iterable<TYPE>::iterAdaptor::iterAdaptor(baseIterator<TYPE>* it) : it_(it) {}
70 template <
typename TYPE>
71 auto original::iterable<TYPE>::iterAdaptor::equalPtr(
const iterator<TYPE>* other)
const ->
bool
73 auto* other_it =
dynamic_cast<const iterAdaptor*
>(other);
74 if (other_it ==
nullptr)
75 return this->it_->equal(other);
76 return this->it_->equal(other_it->it_);
79 template <
typename TYPE>
80 auto original::iterable<TYPE>::iterAdaptor::clone() const ->
iterAdaptor*
85 template <
typename TYPE>
86 auto original::iterable<TYPE>::iterAdaptor::getPrev() const ->
iterAdaptor*
88 auto* it = this->clone();
93 template <
typename TYPE>
94 auto original::iterable<TYPE>::iterAdaptor::getNext() const ->
iterAdaptor*
96 auto* it = this->clone();
101 template <
typename TYPE>
104 this->operator=(other);
107 template <
typename TYPE>
110 if (
this == &other)
return *
this;
113 this->it_ = other.it_->clone();
117 template <
typename TYPE>
118 auto original::iterable<TYPE>::iterAdaptor::getIt() const -> const iterator<TYPE>&
123 template <
typename TYPE>
124 auto original::iterable<TYPE>::iterAdaptor::hasNext() const ->
bool
126 return this->it_->hasNext();
129 template <
typename TYPE>
130 auto original::iterable<TYPE>::iterAdaptor::hasPrev() const ->
bool
132 return this->it_->hasPrev();
135 template <
typename TYPE>
136 auto original::iterable<TYPE>::iterAdaptor::atPrev(
const iterator<TYPE>* other)
const ->
bool
138 auto* other_it =
dynamic_cast<const iterAdaptor*
>(other);
139 if (other_it ==
nullptr)
140 return this->it_->atPrev(other);
141 return this->it_->atPrev(other_it->it_);
144 template <
typename TYPE>
145 auto original::iterable<TYPE>::iterAdaptor::atNext(
const iterator<TYPE>* other)
const ->
bool
147 auto* other_it =
dynamic_cast<const iterAdaptor*
>(other);
148 if (other_it ==
nullptr)
149 return this->it_->atNext(other);
150 return this->it_->atNext(other_it->it_);
153 template <
typename TYPE>
154 auto original::iterable<TYPE>::iterAdaptor::next() const ->
void
159 template <
typename TYPE>
160 auto original::iterable<TYPE>::iterAdaptor::prev() const ->
void
165 template <
typename TYPE>
166 auto original::iterable<TYPE>::iterAdaptor::operator+=(int64_t steps)
const ->
void
168 this->it_->operator+=(steps);
171 template <
typename TYPE>
172 auto original::iterable<TYPE>::iterAdaptor::operator-=(int64_t steps)
const ->
void
174 this->it_->operator-=(steps);
177 template <
typename TYPE>
178 auto original::iterable<TYPE>::iterAdaptor::operator-(
const iterator<TYPE>& other)
const -> int64_t
180 auto* other_it =
dynamic_cast<const iterAdaptor*
>(&other);
181 if (other_it ==
nullptr)
182 return this->it_->operator-(other);
183 return this->it_->operator-(*other_it->it_);
186 template <
typename TYPE>
187 auto original::iterable<TYPE>::iterAdaptor::get() -> TYPE&
189 return this->it_->get();
192 template <
typename TYPE>
193 auto original::iterable<TYPE>::iterAdaptor::set(
const TYPE& data) ->
void
195 this->it_->set(data);
198 template<
typename TYPE>
199 auto original::iterable<TYPE>::iterAdaptor::get() const -> TYPE
201 return this->it_->getElem();
204 template<
typename TYPE>
205 bool original::iterable<TYPE>::iterAdaptor::isValid()
const {
206 return this->it_->isValid();
209 template<
typename TYPE>
210 auto original::iterable<TYPE>::iterAdaptor::className() const -> std::
string {
211 return "iterAdaptor";
214 template<
typename TYPE>
215 auto original::iterable<TYPE>::iterAdaptor::toString(
const bool enter)
const -> std::string {
216 std::stringstream ss;
217 ss << this->className();
218 ss <<
"(" << *this->it_ <<
")";
219 if (enter) ss <<
"\n";
223 template<
typename TYPE>
224 original::iterable<TYPE>::iterAdaptor::~iterAdaptor() {
228 template <
typename TYPE>
229 auto original::iterable<TYPE>::begin() ->
iterAdaptor {
233 template <
typename TYPE>
234 auto original::iterable<TYPE>::end() ->
iterAdaptor {
235 auto* it = this->ends();
240 template <
typename TYPE>
241 auto original::iterable<TYPE>::begin() const ->
iterAdaptor {
245 template <
typename TYPE>
246 auto original::iterable<TYPE>::end() const ->
iterAdaptor{
247 auto* it = this->ends();
252 template <
typename TYPE>
253 auto original::iterable<TYPE>::first() ->
iterAdaptor
255 return this->begin();
258 template <
typename TYPE>
259 auto original::iterable<TYPE>::last() ->
iterAdaptor
264 template <
typename TYPE>
265 auto original::iterable<TYPE>::first() const ->
iterAdaptor
267 return this->begin();
270 template <
typename TYPE>
271 auto original::iterable<TYPE>::last() const ->
iterAdaptor
276 template <
typename TYPE>
277 template<
typename Callback>
278 requires original::Operation<Callback, TYPE>
279 auto original::iterable<TYPE>::forEach(Callback operation) ->
void
281 for (
auto* it = this->begins(); it->isValid(); it->next()) {
282 operation(it->get());
286 template<
typename TYPE>
287 template<
typename Callback>
288 requires original::Operation<Callback, TYPE>
289 auto original::iterable<TYPE>::forEach(
const Callback &operation)
const ->
void {
290 for (
auto* it = this->begins(); it->isValid(); it->next()) {
291 operation(it->getElem());