UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
UniquePointerArray.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
7
8namespace uLang
9{
10
14template<typename InElementType, bool AllowNull, typename InElementAllocatorType, typename... RawAllocatorArgsType>
16{
17 template <typename OtherElementType, bool OtherAllowNull, typename OtherElementAllocatorType, typename... OtherRawAllocatorArgsType>
18 friend class TUPtrArrayG;
19
20public:
21
24 using PointerType = TUPtrG<ElementType, AllowNull, typename InElementAllocatorType::RawAllocatorType, RawAllocatorArgsType...>;
26
33
43
55
62 {
63 if (this != &Other)
64 {
65 DeleteAll();
67 }
68 return *this;
69 }
70
73 {
74 DeleteAll();
75 }
76
86
97
105 {
106 return _PointerStorage.Num();
107 }
108
116 {
117 return _PointerStorage.Max();
118 }
119
127 {
128 return _PointerStorage.IsEmpty();
129 }
130
138 {
139 return _PointerStorage.IsFilled();
140 }
141
149
156 ULANG_FORCEINLINE PointerType Pop(bool bAllowShrinking = true)
157 {
159 }
160
167 {
168 ULANG_ASSERTF(_PointerStorage.GetRawAllocator() == Item.GetAllocator(), "Allocators must be compatible.");
169 _PointerStorage.Push(Item.Get());
170 Item._Object = nullptr;
171 }
172
180 {
181 return _PointerStorage.Top();
182 }
183
194
204
214 {
215 return _PointerStorage.Find(Item, Index);
216 }
217
226 {
227 return _PointerStorage.Find(Item);
228 }
229
239 {
240 return _PointerStorage.FindLast(Item.Get(), Index);
241 }
242
250 {
251 return _PointerStorage.FindLast(Item.Get());
252 }
253
261 template <typename Predicate>
266
273 template <typename Predicate>
278
286 template <typename KeyType>
287 int32_t IndexOfByKey(const KeyType& Key) const
288 {
289 return _PointerStorage.IndexOfByPredicate([=](ElementType * Item) -> bool { return *Item == Key; });
290 }
291
298 template <typename Predicate>
300 {
302 }
303
312 template <typename KeyType>
313 ULANG_FORCEINLINE ElementType* FindByKey(const KeyType& Key) const
314 {
315 ElementType * const * Element = _PointerStorage.FindByPredicate([=](ElementType * Item) -> bool { return *Item == Key; });
316 return Element ? *Element : nullptr;
317 }
318
326 template <typename Predicate>
328 {
329 ElementType * const * Element = _PointerStorage.FindByPredicate(Pred);
330 return Element ? *Element : nullptr;
331 }
332
339 bool Contains(const ElementType* Pointer) const
340 {
341 return _PointerStorage.FindByPredicate([=](ElementType * Item) -> bool { return Item == Pointer; }) != nullptr;
342 }
343
350 template <typename ComparisonType>
351 bool ContainsByKey(const ComparisonType& Key) const
352 {
353 return _PointerStorage.FindByPredicate([=](ElementType * Item) -> bool { return *Item == Key; }) != nullptr;
354 }
355
363 template <typename Predicate>
368
385
394 {
395 return _PointerStorage.Insert(ForwardArg<PointerStorageType>(Items._PointerStorage), InIndex);
396 }
397
407 {
408 ElementType* ItemPtr = Item.Get();
409 Item._Object = nullptr;
410 return _PointerStorage.Insert(ItemPtr, Index);
411 }
412
425
434 template <typename CountType>
435 ULANG_FORCEINLINE void RemoveAt(int32_t Index, CountType Count, bool bAllowShrinking = true)
436 {
438 _PointerStorage.RemoveAt(Index, Count, bAllowShrinking);
439 }
440
459
472 template <typename CountType>
473 ULANG_FORCEINLINE void RemoveAtSwap(int32_t Index, CountType Count, bool bAllowShrinking = true)
474 {
476 _PointerStorage.RemoveAtSwap(Index, Count, bAllowShrinking);
477 }
478
488 {
489 Delete(Index);
490 ElementType* ItemPtr = Item.Get();
491 Item._Object = nullptr;
492 _PointerStorage[Index] = ItemPtr;
493 return Index;
494 }
495
502 void Reset(int32_t NewSize = 0)
503 {
504 DeleteAll();
505 _PointerStorage.Reset(NewSize);
506 }
507
513 void Empty(int32_t Slack = 0)
514 {
515 DeleteAll();
516 _PointerStorage.Empty(Slack);
517 }
518
524 void SetNumZeroed(int32_t NewNum, bool bAllowShrinking = true)
525 {
526 if (NewNum < Num())
527 {
529 }
530 _PointerStorage.SetNumZeroed(NewNum, bAllowShrinking);
531 }
532
543
557
564 template <typename... CtorArgsType>
566 {
567 ElementType * Item = new(_PointerStorage.GetRawAllocator()) ElementType(uLang::ForwardArg<CtorArgsType>(CtorArgs)...);
568 return _PointerStorage.Emplace(Item);
569 }
570
577 template <typename... CtorArgsType>
579 {
580 ElementType * Item = new(_PointerStorage.GetRawAllocator()) ElementType(uLang::ForwardArg<CtorArgsType>(CtorArgs)...);
582 }
583
594 {
595 ElementType* ItemPtr = Item.Get();
596 Item._Object = nullptr;
597 return _PointerStorage.Emplace(ItemPtr);
598 }
599
613 {
614 return _PointerStorage.AddZeroed();
615 }
616
625 {
629 {
630 Item._Object = nullptr;
631 }
632 return Index;
633 }
634
645
654 template <typename Predicate>
655 int32_t RemoveAll(const Predicate& Pred)
656 {
657 const typename ElementAllocatorType::RawAllocatorType & RawAllocator = _PointerStorage.GetRawAllocator();
658 return _PointerStorage.RemoveAll([&](ElementType* Item) -> bool {
659 bool RemoveIt = Pred(Item);
660 if (RemoveIt)
661 {
662 Item->~ElementType();
663 RawAllocator.Deallocate(Item);
664 }
665 return RemoveIt;
666 });
667 }
668
675 template <class Predicate>
676 void RemoveAllSwap(const Predicate& Pred, bool bAllowShrinking = true)
677 {
678 const typename ElementAllocatorType::RawAllocatorType & RawAllocator = _PointerStorage.GetRawAllocator();
679 return _PointerStorage.RemoveAllSwap([&](ElementType* Item) -> bool {
680 bool RemoveIt = Pred(Item);
681 if (RemoveIt)
682 {
683 Item->~ElementType();
684 RawAllocator.Deallocate(Item);
685 }
686 return RemoveIt;
687 });
688 }
689
697
703 template <class PredicateType>
704 void Sort(const PredicateType& Predicate)
705 {
706 Algo::Sort( _PointerStorage, Predicate );
707 }
708
716
717public:
718
726 ULANG_FORCEINLINE ElementType * const * end() const { return _PointerStorage.end(); }
727
728protected:
729
732 {
734 if (Item)
735 {
736 Item->~ElementType();
737 _PointerStorage.GetRawAllocator().Deallocate(Item);
738 }
739 }
740
742 ULANG_FORCEINLINE void DeleteRange(int32_t BeginIndex, int32_t EndIndex)
743 {
744 for (int32_t Index = BeginIndex; Index < EndIndex; ++Index)
745 {
746 Delete(Index);
747 }
748 }
749
755
757
758};
759
761template<typename ElementType>
763
765template<typename ElementType>
767
769template<typename ElementType>
771
773template<typename ElementType>
775
776
777template <typename ElementType, bool AllowNull, typename ElementAllocatorType, typename... RawAllocatorArgsType>
782
783template <typename ElementType, bool AllowNull, typename ElementAllocatorType, typename... RawAllocatorArgsType>
784struct TContainerTraits<TUPtrArrayG<ElementType, AllowNull, ElementAllocatorType, RawAllocatorArgsType...>> : public TContainerTraitsBase<TUPtrArrayG<ElementType, AllowNull, ElementAllocatorType, RawAllocatorArgsType...>>
785{
786 static_assert(TAllocatorTraits<ElementAllocatorType>::SupportsMove, "TUPtrArray no longer supports move-unaware allocators");
788};
789
790template <typename ElementType, bool AllowNull, typename ElementAllocatorType, typename... RawAllocatorArgsType>
791struct TIsContiguousContainer<TUPtrArrayG<ElementType, AllowNull, ElementAllocatorType, RawAllocatorArgsType...>>
792{
793 enum { Value = true };
794};
795
796}
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define ULANG_FORCEINLINE
Definition Common.h:188
#define ULANG_ASSERTF(expr, format,...)
Definition Common.h:290
Definition Allocator.h:35
ULANG_FORCEINLINE void Shrink()
Definition Array.h:562
ULANG_FORCEINLINE int32_t Emplace(ArgsType &&... Args)
Definition Array.h:1527
ULANG_FORCEINLINE ElementType & Last(int32_t IndexFromTheEnd=0)
Definition Array.h:537
ULANG_FORCEINLINE int32_t Max() const
Definition Array.h:413
ULANG_FORCEINLINE const ElementType * FindByPredicate(Predicate Pred) const
Definition Array.h:757
ULANG_FORCEINLINE void EmplaceAt(int32_t Index, ArgsType &&... Args)
Definition Array.h:1556
void SetNumZeroed(int32_t NewNum, bool bAllowShrinking=true)
Definition Array.h:1360
void Empty(int32_t Slack=0)
Definition Array.h:1322
ULANG_FORCEINLINE bool ContainsByPredicate(Predicate Pred) const
Definition Array.h:831
ULANG_FORCEINLINE bool Find(const ElementType &Item, int32_t &Index) const
Definition Array.h:579
ULANG_FORCEINLINE void RemoveAt(int32_t Index)
Definition Array.h:1188
void RemoveAllSwap(const PREDICATE_CLASS &Predicate, bool bAllowShrinking=true)
Definition Array.h:1879
ULANG_FORCEINLINE ElementType * begin()
Definition Array.h:1948
void InsertZeroed(int32_t Index, int32_t Count=1)
Definition Array.h:921
int32_t AddZeroed(int32_t Count=1)
Definition Array.h:1646
ULANG_FORCEINLINE void Push(ElementType &&Item)
Definition Array.h:489
void Reset(int32_t NewSize=0)
Definition Array.h:1303
ULANG_FORCEINLINE bool IsEmpty() const
Definition Array.h:430
ULANG_FORCEINLINE bool IsFilled() const
Definition Array.h:441
ULANG_FORCEINLINE int32_t GetSlack() const
Definition Array.h:355
ULANG_FORCEINLINE void RemoveAtSwap(int32_t Index)
Definition Array.h:1252
int32_t Insert(std::initializer_list< ElementType > InitList, const int32_t InIndex)
Definition Array.h:986
void Append(const TArrayG< ElementType, OtherElementAllocatorType, OtherRawAllocatorArgsType... > &Source)
Definition Array.h:1408
ULANG_FORCEINLINE ElementType * end()
Definition Array.h:1950
ULANG_FORCEINLINE ElementType & Top()
Definition Array.h:513
ULANG_FORCEINLINE ElementType Pop(bool bAllowShrinking=true)
Definition Array.h:476
ULANG_FORCEINLINE int32_t AddUnique(ElementType &&Item)
Definition Array.h:1736
ULANG_FORCEINLINE bool FindLast(const ElementType &Item, int32_t &Index) const
Definition Array.h:613
ULANG_FORCEINLINE const ElementAllocatorType::RawAllocatorType & GetRawAllocator() const
Definition Array.h:419
int32_t IndexOfByPredicate(Predicate Pred) const
Definition Array.h:700
int32_t FindLastByPredicate(Predicate Pred, int32_t Count) const
Definition Array.h:646
ULANG_FORCEINLINE void Reserve(int32_t Number)
Definition Array.h:1753
ULANG_FORCEINLINE bool IsValidIndex(int32_t Index) const
Definition Array.h:391
int32_t RemoveAll(const PREDICATE_CLASS &Predicate)
Definition Array.h:1831
ULANG_FORCEINLINE int32_t Num() const
Definition Array.h:402
Definition UniquePointerArray.h:16
ULANG_FORCEINLINE ElementType * FindByPredicate(Predicate Pred) const
Definition UniquePointerArray.h:327
ULANG_FORCEINLINE int32_t AddNew(CtorArgsType &&... CtorArgs)
Definition UniquePointerArray.h:565
ULANG_FORCEINLINE bool Find(ElementType *Item, int32_t &Index) const
Definition UniquePointerArray.h:213
TUPtrArrayG(TUPtrArrayG &&Other, int32_t ExtraSlack)
Definition UniquePointerArray.h:51
InElementAllocatorType ElementAllocatorType
Definition UniquePointerArray.h:23
ULANG_FORCEINLINE int32_t Max() const
Definition UniquePointerArray.h:115
ULANG_FORCEINLINE ElementType * Last(int32_t IndexFromTheEnd=0) const
Definition UniquePointerArray.h:190
int32_t Insert(TUPtrArrayG &&Items, const int32_t InIndex)
Definition UniquePointerArray.h:393
TUPtrArrayG & operator+=(TUPtrArrayG &&Other)
Definition UniquePointerArray.h:552
ULANG_FORCEINLINE ElementType ** end()
Definition UniquePointerArray.h:725
ULANG_FORCEINLINE bool ContainsByPredicate(Predicate Pred) const
Definition UniquePointerArray.h:364
ULANG_FORCEINLINE ElementType ** begin()
Definition UniquePointerArray.h:723
ULANG_FORCEINLINE void Shrink()
Definition UniquePointerArray.h:200
void SetNumZeroed(int32_t NewNum, bool bAllowShrinking=true)
Definition UniquePointerArray.h:524
ULANG_FORCEINLINE PointerType RemoveAt(int32_t Index)
Definition UniquePointerArray.h:419
int32_t RemoveAll(const Predicate &Pred)
Definition UniquePointerArray.h:655
PointerStorageType _PointerStorage
Definition UniquePointerArray.h:756
ULANG_FORCEINLINE void RemoveAt(int32_t Index, CountType Count, bool bAllowShrinking=true)
Definition UniquePointerArray.h:435
ULANG_FORCEINLINE ElementType * operator[](int32_t Index) const
Definition UniquePointerArray.h:145
ULANG_FORCEINLINE TUPtrArrayG< OtherElementType, OtherAllowNull, ElementAllocatorType, RawAllocatorArgsType... > & As()
Definition UniquePointerArray.h:713
ULANG_FORCEINLINE int32_t GetSlack() const
Definition UniquePointerArray.h:82
ULANG_FORCEINLINE void Reserve(int32_t Number)
Definition UniquePointerArray.h:641
void Append(TUPtrArrayG &&Source)
Definition UniquePointerArray.h:539
ULANG_FORCEINLINE ElementType *const * end() const
Definition UniquePointerArray.h:726
int32_t AddZeroed(int32_t Count=1)
Definition UniquePointerArray.h:612
ULANG_FORCEINLINE int32_t AddUnique(PointerType &&Item)
Definition UniquePointerArray.h:624
ULANG_FORCEINLINE void InsertNew(int32_t Index, CtorArgsType &&... CtorArgs)
Definition UniquePointerArray.h:578
ULANG_FORCEINLINE PointerType Pop(bool bAllowShrinking=true)
Definition UniquePointerArray.h:156
ULANG_FORCEINLINE const TUPtrArrayG< OtherElementType, OtherAllowNull, ElementAllocatorType, RawAllocatorArgsType... > & As() const
Definition UniquePointerArray.h:715
int32_t IndexOfByPredicate(Predicate Pred) const
Definition UniquePointerArray.h:299
TUPtrG< ElementType, AllowNull, typename InElementAllocatorType::RawAllocatorType, RawAllocatorArgsType... > PointerType
Definition UniquePointerArray.h:24
ULANG_FORCEINLINE int32_t Num() const
Definition UniquePointerArray.h:104
ULANG_FORCEINLINE int32_t FindLast(const PointerType &Item) const
Definition UniquePointerArray.h:249
ULANG_FORCEINLINE bool IsEmpty() const
Definition UniquePointerArray.h:126
ULANG_FORCEINLINE ElementType * FindByKey(const KeyType &Key) const
Definition UniquePointerArray.h:313
void Empty(int32_t Slack=0)
Definition UniquePointerArray.h:513
void Sort(const PredicateType &Predicate)
Definition UniquePointerArray.h:704
ULANG_FORCEINLINE TUPtrArrayG(TUPtrArrayG &&Other)
Definition UniquePointerArray.h:39
ULANG_FORCEINLINE void DeleteRange(int32_t BeginIndex, int32_t EndIndex)
Definition UniquePointerArray.h:742
ULANG_FORCEINLINE void Push(PointerType &&Item)
Definition UniquePointerArray.h:166
ULANG_FORCEINLINE int32_t Find(ElementType *Item) const
Definition UniquePointerArray.h:225
ULANG_FORCEINLINE void Delete(int32_t Index)
Definition UniquePointerArray.h:731
ULANG_FORCEINLINE TUPtrArrayG(RawAllocatorArgsType &&... RawAllocatorArgs)
Definition UniquePointerArray.h:30
bool Contains(const ElementType *Pointer) const
Definition UniquePointerArray.h:339
ULANG_FORCEINLINE int32_t FindLastByPredicate(Predicate Pred, int32_t Count) const
Definition UniquePointerArray.h:262
int32_t IndexOfByKey(const KeyType &Key) const
Definition UniquePointerArray.h:287
void Sort()
Definition UniquePointerArray.h:693
bool ContainsByKey(const ComparisonType &Key) const
Definition UniquePointerArray.h:351
ULANG_FORCEINLINE bool IsValidIndex(int32_t Index) const
Definition UniquePointerArray.h:93
int32_t ReplaceAt(PointerType &&Item, int32_t Index)
Definition UniquePointerArray.h:487
ULANG_FORCEINLINE int32_t FindLastByPredicate(Predicate Pred) const
Definition UniquePointerArray.h:274
ULANG_FORCEINLINE bool FindLast(const PointerType &Item, int32_t &Index) const
Definition UniquePointerArray.h:238
InElementType ElementType
Definition UniquePointerArray.h:22
TUPtrArrayG & operator=(TUPtrArrayG &&Other)
Definition UniquePointerArray.h:61
ULANG_FORCEINLINE void DeleteAll()
Definition UniquePointerArray.h:751
int32_t Insert(PointerType &&Item, int32_t Index)
Definition UniquePointerArray.h:406
ULANG_FORCEINLINE ElementType *const * begin() const
Definition UniquePointerArray.h:724
ULANG_FORCEINLINE int32_t Add(PointerType &&Item)
Definition UniquePointerArray.h:593
void InsertZeroed(int32_t Index, int32_t Count=1)
Definition UniquePointerArray.h:381
ULANG_FORCEINLINE ElementType * Top() const
Definition UniquePointerArray.h:179
void RemoveAllSwap(const Predicate &Pred, bool bAllowShrinking=true)
Definition UniquePointerArray.h:676
ULANG_FORCEINLINE void RemoveAtSwap(int32_t Index, CountType Count, bool bAllowShrinking=true)
Definition UniquePointerArray.h:473
ULANG_FORCEINLINE bool IsFilled() const
Definition UniquePointerArray.h:137
void Reset(int32_t NewSize=0)
Definition UniquePointerArray.h:502
ULANG_FORCEINLINE PointerType RemoveAtSwap(int32_t Index)
Definition UniquePointerArray.h:453
~TUPtrArrayG()
Definition UniquePointerArray.h:72
Definition UniquePointer.h:15
ULANG_FORCEINLINE ObjectType * Get() const
Definition UniquePointer.h:50
ULANG_FORCEINLINE void Sort(RangeType &&Range)
Definition Sort.h:18
Definition VVMEngineEnvironment.h:23
ULANG_FORCEINLINE T && ForwardArg(typename TRemoveReference< T >::Type &Obj)
Definition References.h:115
ULANG_FORCEINLINE TRemoveReference< T >::Type && Move(T &&Obj)
Definition References.h:86
U16 Index
Definition radfft.cpp:71
Definition Allocator.h:238
Definition TypeTraits.h:451
@ MoveWillEmptyContainer
Definition TypeTraits.h:453
Definition TypeTraits.h:456
Definition Sorting.h:82
Definition TypeTraits.h:263
@ Value
Definition TypeTraits.h:264
Definition TypeTraits.h:325
Definition Sorting.h:36