UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IteratorUtil.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3// Port of geometry3cpp iterator_util.h
4
5#pragma once
6#include "IndexTypes.h"
8
9namespace UE
10{
11namespace Geometry
12{
13
14
22template<typename FromType, typename ToType, typename IteratorT>
24{
25 using MapFunctionT = TFunction<ToType(FromType)>;
26
27public:
28 inline MappedIterator() { }
29
30 inline bool operator==(const MappedIterator& Other) const
31 {
32 return Cur == Other.Cur;
33 }
34 inline bool operator!=(const MappedIterator& Other) const
35 {
36 return Cur != Other.Cur;
37 }
38
39 inline ToType operator*() const
40 {
41 return MapFunction(*Cur);
42 }
43
44 inline const MappedIterator& operator++() // prefix
45 {
46 Cur++;
47 return *this;
48 }
49
55
58};
59
60
61
62
63
64
65
70template<typename ValueType, typename IteratorT>
72{
73 using FilterFunctionT = TFunction<bool(ValueType)>;
74
75public:
76 inline FilteredIterator() { }
77
78 inline bool operator==(const FilteredIterator& Other) const
79 {
80 return Cur == Other.Cur;
81 }
82 inline bool operator!=(const FilteredIterator& Other) const
83 {
84 return Cur != Other.Cur;
85 }
86
87 inline ValueType operator*() const
88 {
89 return *Cur;
90 }
91
92 inline const FilteredIterator& operator++() // prefix
93 {
95 return *this;
96 }
97
98 inline void GotoNextElement()
99 {
100 do {
101 Cur++;
102 } while (Cur != End && FilterFunc(*Cur) == false);
103 }
104
106 {
107 Cur = CurItr;
108 End = EndItr;
109 this->FilterFunc = FilterFuncIn;
110 if (Cur != End && FilterFunc(*Cur) == false)
111 {
113 }
114 }
115
119};
120
121
122
123
124
125
126
127
128
129
150template<typename OutputType, typename InputType, typename InputIteratorT>
152{
153 using ExpandFunctionT = TFunction<OutputType(InputType, int&)>;
154
155public:
156 inline ExpandIterator() { }
157
158 inline bool operator==(const ExpandIterator& Other) const
159 {
160 return Cur == Other.Cur;
161 }
162 inline bool operator!=(const ExpandIterator & Other) const
163 {
164 return Cur != Other.Cur;
165 }
166
167 inline OutputType operator*() const
168 {
169 return CurValue;
170 }
171
172 inline const ExpandIterator& operator++() // prefix
173 {
174 goto_next();
175 return *this;
176 }
177
178 inline void goto_next()
179 {
180 while (Cur != End)
181 {
183 if (CurExpandI == -1)
184 {
185 ++Cur; // done with this base value
186 }
187 else
188 {
189 break; // want caller to see current output value
190 }
191 }
192 }
193
195 {
196 Cur = CurItr;
197 End = EndItr;
199 CurExpandI = -1;
200 goto_next();
201 }
202
205 OutputType CurValue;
208};
209
210
211
216template<typename OutputType, typename InputType, typename InputIteratorT>
218{
219 using ExpandFunctionT = TFunction<OutputType(InputType, int&)>;
221
222public:
225
227 {
228 this->BeginItr = BeginIn;
229 this->EndItr = EndIn;
230 this->ExpandFunc = ExpandFuncIn;
231 }
232
233 template<typename IteratorSource>
235 {
236 this->BeginItr = Source.begin();
237 this->EndItr = Source.end();
238 this->ExpandFunc = ExpandFuncIn;
239 }
240
245
250};
251
252
253
254
255
256
257
258
259
260
261
262
274template<typename InputIteratorT>
276{
278
279public:
281
282 inline bool operator==(const TPairExpandIterator& Other) const
283 {
284 return Cur == Other.Cur;
285 }
286 inline bool operator!=(const TPairExpandIterator & Other) const
287 {
288 return Cur != Other.Cur;
289 }
290
291 inline int operator*() const
292 {
293 return CurValue;
294 }
295
296 inline const TPairExpandIterator& operator++() // prefix
297 {
298 goto_next();
299 return *this;
300 }
301
302 inline void goto_next()
303 {
304 while (Cur != End)
305 {
306 if (CurPairI == 0)
307 {
308 CurPair = PairFunc(*Cur);
309 if (CurPair.A >= 0)
310 {
312 CurPairI = 1; // want to take second branch
313 return; // let caller see value
314 }
315 else
316 {
317 CurPairI = 0;
318 ++Cur; // done with this base value
319 }
320 }
321 else if (CurPairI == 1)
322 {
323 if (CurPair.B >= 0)
324 {
326 CurPairI = 2; // want to take third branch
327 return; // let caller see value
328 }
329 else
330 {
331 CurPairI = 0;
332 ++Cur; // done with this base value
333 }
334 }
335 else
336 {
337 CurPairI = 0;
338 ++Cur; // done with this base value
339 }
340 }
341 }
342
344 {
345 Cur = CurItr;
346 End = EndItr;
348 CurPairI = 0;
349 goto_next();
350 }
351
358};
359
360
361
362
367template<typename InputIteratorT>
369{
370 using ExpandFunctionT = TFunction<FIndex2i(int)>;
372
373public:
376
378 {
379 this->BeginItr = BeginIn;
380 this->EndItr = EndIn;
381 this->ExpandFunc = ExpandFuncIn;
382 }
383
384 template<typename IteratorSource>
386 {
387 this->BeginItr = Source.begin();
388 this->EndItr = Source.end();
389 this->ExpandFunc = ExpandFuncIn;
390 }
391
396
401};
402
403
404
428{
430 uint64 ModuloPrime = 4294967311ull; // prime > max_unsigned_int
435
437 {
438 MaxIndex = (uint64)FMath::Max((uint32)0, MaxIndexIn);
439 StartIndex = (uint64)FMath::Max((uint32)0, StartIndexIn);
440 CurIndex = 0;
441 Count = 0;
442 ModuloNum = FMath::Max((uint64)1, MaxIndex); // can't be zero or we hit integer-divide. If MaxIndex is 0 we will terminate on first iteration anyway
445 }
446
453
455 {
458 return (Count++ != MaxIndex);
459 }
460};
461
462
463
464} // end namespace UE::Geometry
465} // end namespace UE
#define check(expr)
Definition AssertionMacros.h:314
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
const bool
Definition NetworkReplayStreaming.h:178
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition IteratorUtil.h:218
ExpandEnumerable(const InputIteratorT &BeginIn, const InputIteratorT &EndIn, ExpandFunctionT ExpandFuncIn)
Definition IteratorUtil.h:226
ExpandFunctionT ExpandFunc
Definition IteratorUtil.h:223
InputIteratorT BeginItr
Definition IteratorUtil.h:224
ExpandIteratorT begin()
Definition IteratorUtil.h:241
ExpandEnumerable(const IteratorSource &Source, ExpandFunctionT ExpandFuncIn)
Definition IteratorUtil.h:234
InputIteratorT EndItr
Definition IteratorUtil.h:224
ExpandIteratorT end()
Definition IteratorUtil.h:246
Definition IteratorUtil.h:152
InputIteratorT End
Definition IteratorUtil.h:204
OutputType operator*() const
Definition IteratorUtil.h:167
int CurExpandI
Definition IteratorUtil.h:206
ExpandFunctionT ExpandFunc
Definition IteratorUtil.h:207
bool operator==(const ExpandIterator &Other) const
Definition IteratorUtil.h:158
void goto_next()
Definition IteratorUtil.h:178
OutputType CurValue
Definition IteratorUtil.h:205
ExpandIterator()
Definition IteratorUtil.h:156
bool operator!=(const ExpandIterator &Other) const
Definition IteratorUtil.h:162
InputIteratorT Cur
Definition IteratorUtil.h:203
ExpandIterator(const InputIteratorT &CurItr, const InputIteratorT &EndItr, const ExpandFunctionT &ExpandFuncIn)
Definition IteratorUtil.h:194
const ExpandIterator & operator++()
Definition IteratorUtil.h:172
Definition IteratorUtil.h:72
FilteredIterator()
Definition IteratorUtil.h:76
bool operator==(const FilteredIterator &Other) const
Definition IteratorUtil.h:78
void GotoNextElement()
Definition IteratorUtil.h:98
FilterFunctionT FilterFunc
Definition IteratorUtil.h:118
IteratorT End
Definition IteratorUtil.h:117
FilteredIterator(const IteratorT &CurItr, const IteratorT &EndItr, const FilterFunctionT &FilterFuncIn)
Definition IteratorUtil.h:105
IteratorT Cur
Definition IteratorUtil.h:116
ValueType operator*() const
Definition IteratorUtil.h:87
const FilteredIterator & operator++()
Definition IteratorUtil.h:92
bool operator!=(const FilteredIterator &Other) const
Definition IteratorUtil.h:82
Definition IteratorUtil.h:24
bool operator==(const MappedIterator &Other) const
Definition IteratorUtil.h:30
const MappedIterator & operator++()
Definition IteratorUtil.h:44
MappedIterator()
Definition IteratorUtil.h:28
MapFunctionT MapFunction
Definition IteratorUtil.h:57
ToType operator*() const
Definition IteratorUtil.h:39
bool operator!=(const MappedIterator &Other) const
Definition IteratorUtil.h:34
IteratorT Cur
Definition IteratorUtil.h:56
MappedIterator(const IteratorT &CurItr, const MapFunctionT &MapFunctionIn)
Definition IteratorUtil.h:50
Definition IteratorUtil.h:369
InputIteratorT BeginItr
Definition IteratorUtil.h:375
ExpandIteratorT begin()
Definition IteratorUtil.h:392
ExpandFunctionT ExpandFunc
Definition IteratorUtil.h:374
InputIteratorT EndItr
Definition IteratorUtil.h:375
TPairExpandEnumerable(const IteratorSource &Source, ExpandFunctionT ExpandFuncIn)
Definition IteratorUtil.h:385
TPairExpandEnumerable(const InputIteratorT &BeginIn, const InputIteratorT &EndIn, ExpandFunctionT ExpandFuncIn)
Definition IteratorUtil.h:377
ExpandIteratorT end()
Definition IteratorUtil.h:397
Definition IteratorUtil.h:276
const TPairExpandIterator & operator++()
Definition IteratorUtil.h:296
InputIteratorT Cur
Definition IteratorUtil.h:352
bool operator==(const TPairExpandIterator &Other) const
Definition IteratorUtil.h:282
int CurPairI
Definition IteratorUtil.h:356
int CurValue
Definition IteratorUtil.h:355
TPairExpandIterator(const InputIteratorT &CurItr, const InputIteratorT &EndItr, const PairExpandFunctionT &PairFuncIn)
Definition IteratorUtil.h:343
void goto_next()
Definition IteratorUtil.h:302
InputIteratorT End
Definition IteratorUtil.h:353
FIndex2i CurPair
Definition IteratorUtil.h:354
PairExpandFunctionT PairFunc
Definition IteratorUtil.h:357
bool operator!=(const TPairExpandIterator &Other) const
Definition IteratorUtil.h:286
int operator*() const
Definition IteratorUtil.h:291
TPairExpandIterator()
Definition IteratorUtil.h:280
Definition AdvancedWidgetsModule.cpp:13
Definition IndexTypes.h:27
int A
Definition IndexTypes.h:32
int B
Definition IndexTypes.h:32
Definition IteratorUtil.h:428
uint64 StartIndex
Definition IteratorUtil.h:432
bool GetNextIndex(int32 &NextIndexOut)
Definition IteratorUtil.h:454
bool GetNextIndex(uint32 &NextIndexOut)
Definition IteratorUtil.h:447
uint64 ModuloPrime
Definition IteratorUtil.h:430
uint64 ModuloNum
Definition IteratorUtil.h:434
FModuloIteration(uint32 MaxIndexIn, uint32 StartIndexIn=0, uint64 ModuloPrimeIn=3208642561)
Definition IteratorUtil.h:436
uint64 Count
Definition IteratorUtil.h:433
uint64 MaxIndex
Definition IteratorUtil.h:429
uint64 CurIndex
Definition IteratorUtil.h:431