Navigation
API > API/Runtime > API/Runtime/Core > API/Runtime/Core/Containers
Inheritance Hierarchy
- TArray
- FArchiveDiffMap
- FArrayReader
- FGLTFIndexArray
- FGLTFMaterialArray
- FGLTFObjectArrayScopeGuard
- FGraphAStar::FNodePool
- FGraphAStar::FOpenList
- FSegmentBlendData
- FSlowTaskStack
- FStaticMeshSectionArray
- FTickableCookObject::TTickableObjectsCollection
- FTickableEditorObject::TTickableObjectsCollection
- FTickableObjectRenderThread::FRenderingThreadTickableObjectsArray
- TArrayCollectionArray
- TBufferArchive
- FBufferArchive
- FNetworkFileArchive
- FBufferArchive64
- TInlineComponentArray
- TLeafContainer
- TLeafContainer< TAABBTreeLeafArray< FAccelerationStructureHandle, true, FReal > >
- TMaybeMappedArray
- TMRUArray
- TNavStatArray
- TRDGResourceAccessArray
- TResourceArray
- TSkeletalMeshVertexData
- TTransArray
- VectorND
References
| Module | Core |
| Header | /Engine/Source/Runtime/Core/Public/Containers/Array.h |
| Include | #include "Containers/Array.h" |
Syntax
template<typename InElementType, typename InAllocatorType>
class TArray
Remarks
Templated dynamic array
A dynamically sized array of typed elements. Makes the assumption that your elements are relocate-able; i.e. that they can be transparently moved to new memory without a copy constructor. The main implication is that pointers to elements in the TArray may be invalidated by adding or removing other elements to the array. Removal of elements is O(N) and invalidates the indices of subsequent elements.
Caution: as noted below some methods are not safe for element types that require constructors.
Variables
| Type | Name | Description | |
|---|---|---|---|
| ElementAllocatorType | AllocatorInstance | ||
| SizeType | ArrayMax | ||
| SizeType | ArrayNum |
Constructors
| Type | Name | Description | |
|---|---|---|---|
TArray () |
Constructor, initializes element number counters. | ||
TArray
(
TArray< OtherElementType, AllocatorType >&& Other, |
Move constructor. | ||
TArray
(
const TArrayView< OtherElementType, OtherSizeType >& Other |
|||
TArray
(
std::initializer_list< InElementType > InitList |
Initializer list constructor | ||
| Copy constructor with changed allocator. Use the common routine to perform the copy. | |||
| Copy constructor. Use the common routine to perform the copy. | |||
| Move constructor. | |||
| Move constructor. | |||
TArray
(
const ElementType* Ptr, |
Constructor from a raw array of elements. | ||
| Copy constructor. Use the common routine to perform the copy. |
Destructors
| Type | Name | Description | |
|---|---|---|---|
~TArray () |
Destructor. |
Functions
| Type | Name | Description | |
|---|---|---|---|
| SizeType | Add
(
const ElementType& Item |
Adds a new item to the end of the array, possibly reallocating the whole array to fit. | |
| SizeType | Add
(
ElementType&& Item |
Adds a new item to the end of the array, possibly reallocating the whole array to fit. | |
| ElementType & | Add_GetRef
(
const ElementType& Item |
Adds a new item to the end of the array, possibly reallocating the whole array to fit. | |
| ElementType & | Add_GetRef
(
ElementType&& Item |
Adds a new item to the end of the array, possibly reallocating the whole array to fit. | |
| SizeType | AddDefaulted () |
Adds new items to the end of the array, possibly reallocating the whole array to fit. | |
| SizeType | AddDefaulted
(
SizeType Count |
||
| ElementType & | Add a new item to the end of the array, possibly reallocating the whole array to fit. | ||
| SizeType | AddUninitialized
(
SizeType Count |
||
| SizeType | Adds a given number of uninitialized elements into the array. | ||
| SizeType | AddUnique
(
const ElementType& Item |
Adds unique element to array if it doesn't exist. | |
| SizeType | AddUnique
(
ElementType&& Item |
Adds unique element to array if it doesn't exist.Move semantics version. | |
| SizeType | AddZeroed () |
Adds new items to the end of the array, possibly reallocating the whole array to fit. | |
| SizeType | |||
| ElementType & | Adds a new item to the end of the array, possibly reallocating the whole array to fit. | ||
| void | Appends the specified array to this array.AllocatorType changing version. | ||
| void | Appends the specified array to this array. | ||
| void | Append
(
RangeType&& Source |
Appends the elements from a contiguous range to this array. | |
| void | Append
(
std::initializer_list< ElementType > InitList |
Adds an initializer list of elements to the end of the TArray. | |
| void | Append
(
const ElementType* Ptr, |
Adds a raw array of elements to the end of the TArray. | |
| void | Append
(
const typename TContainerElementTypeCompatibility< ElementType >::CopyFromOtherType* Ptr, |
Adds a raw array of elements to the end of the TArray. | |
| void | AppendHash
(
const FPlatformTypeLayoutParameters& LayoutParams, |
||
| RangedForConstIteratorType | begin () |
||
| RangedForIteratorType | begin () |
DO NOT USE DIRECTLY STL-like iterators to enable range-based for loop support. | |
| void | BulkSerialize
(
FArchive& Ar, |
Bulk serialize array as a single memory blob when loading. | |
| void | CheckAddress
(
const ElementType* Addr |
Checks that the specified address is not part of an element within the container. | |
| void | Checks array invariants: if array size is greater than or equal to zero and less than or equal to the maximum. | ||
| bool | Contains
(
const ComparisonType& Item |
Checks if this array contains the element. | |
| bool | ContainsByPredicate
(
Predicate Pred |
Checks if this array contains an element for which the predicate is true. | |
| void | CopyUnfrozen
(
const FMemoryUnfreezeContent& Context, |
||
| void | CountBytes
(
FArchive& Ar |
Count bytes needed to serialize this array. | |
| TConstIterator | Creates a const iterator for the contents of this array | ||
| TIterator | Creates an iterator for the contents of this array | ||
| SizeType | Emplace
(
ArgsType&&... Args |
Constructs a new item at the end of the array, possibly reallocating the whole array to fit. | |
| ElementType & | Emplace_GetRef
(
ArgsType&&... Args |
Constructs a new item at the end of the array, possibly reallocating the whole array to fit. | |
| void | Constructs a new item at a specified index, possibly reallocating the whole array to fit. | ||
| ElementType & | EmplaceAt_GetRef
(
SizeType Index, |
Constructs a new item at a specified index, possibly reallocating the whole array to fit. | |
| void | Empties the array. It calls the destructors on held items if needed. | ||
| RangedForConstIteratorType | end () |
||
| RangedForIteratorType | end () |
||
| TArray< ElementType > | FilterByPredicate
(
Predicate Pred |
Filters the elements in the array based on a predicate functor. | |
| SizeType | Find
(
const ElementType& Item |
Finds element within the array. | |
| bool | Find
(
const ElementType& Item, |
Finds element within the array. | |
| const ElementType * | FindByKey
(
const KeyType& Key |
Finds an item by key (assuming the ElementType overloads operator== for the comparison). | |
| ElementType * | FindByKey
(
const KeyType& Key |
Finds an item by key (assuming the ElementType overloads operator== for the comparison). | |
| ElementType * | FindByPredicate
(
Predicate Pred |
Finds an element which matches a predicate functor. | |
| const ElementType * | FindByPredicate
(
Predicate Pred |
Finds an element which matches a predicate functor. | |
| bool | FindItemByClass
(
SearchType** Item, |
Searches for the first entry of the specified type, will only work with TArray |
|
| SizeType | FindLast
(
const ElementType& Item |
Finds element within the array starting from the end. | |
| bool | FindLast
(
const ElementType& Item, |
Finds element within the array starting from the end. | |
| SizeType | FindLastByPredicate
(
Predicate Pred |
Searches the array for the last occurrence of an element which matches the specified predicate. | |
| SizeType | FindLastByPredicate
(
Predicate Pred, |
Searches an initial subrange of the array for the last occurrence of an element which matches the specified predicate. | |
| SIZE_T | Helper function to return the amount of memory allocated by this container. | ||
| const ElementAllocatorType & | |||
| ElementAllocatorType & | |||
| ElementType * | GetData () |
Helper function for returning a typed pointer to the first array entry. | |
| const ElementType * | GetData () |
Helper function for returning a typed pointer to the first array entry. | |
| SizeType | GetSlack () |
Returns the amount of slack in this array in elements. | |
| constexpr uint32 | GetTypeSize () |
Helper function returning the size of the inner type. | |
| void | Heapify () |
Builds an implicit heap from the array. | |
| void | Heapify
(
const PREDICATE_CLASS& Predicate |
Implicit heaps Builds an implicit heap from the array. | |
| void | HeapPop
(
ElementType& OutItem, |
Removes the top element from the heap. | |
| void | HeapPop
(
ElementType& OutItem, |
Removes the top element from the heap. | |
| void | HeapPopDiscard
(
bool bAllowShrinking |
Removes the top element from the heap. | |
| void | HeapPopDiscard
(
const PREDICATE_CLASS& Predicate, |
Removes the top element from the heap. | |
| SizeType | HeapPush
(
ElementType&& InItem |
Adds a new element to the heap. | |
| SizeType | HeapPush
(
const ElementType& InItem |
Adds a new element to the heap. | |
| SizeType | HeapPush
(
ElementType&& InItem, |
Adds a new element to the heap. | |
| SizeType | HeapPush
(
const ElementType& InItem, |
Adds a new element to the heap. | |
| void | HeapRemoveAt
(
SizeType Index, |
Removes an element from the heap. | |
| void | HeapRemoveAt
(
SizeType Index, |
Removes an element from the heap. | |
| void | HeapSort () |
Performs heap sort on the array. | |
| void | HeapSort
(
const PREDICATE_CLASS& Predicate |
Performs heap sort on the array. | |
| const ElementType & | HeapTop () |
Returns the top element from the heap (does not remove the element).Const version. | |
| ElementType & | HeapTop () |
Returns the top element from the heap (does not remove the element). | |
| SizeType | IndexOfByKey
(
const KeyType& Key |
Finds an item by key (assuming the ElementType overloads operator== for the comparison). | |
| SizeType | IndexOfByPredicate
(
Predicate Pred |
Finds an item by predicate. | |
| void | Init
(
const ElementType& Element, |
Sets the size of the array, filling it with the given element. | |
| SizeType | Insert
(
const TArray< ElementType, OtherAllocator >& Items, |
Inserts given elements into the array at given location. | |
| SizeType | Insert
(
TArray< ElementType, OtherAllocator >&& Items, |
Inserts given elements into the array at given location. | |
| SizeType | Insert
(
ElementType&& Item, |
Inserts a given element into the array at given location. Move semantics version. | |
| SizeType | Insert
(
const ElementType& Item, |
Inserts a given element into the array at given location. | |
| SizeType | Insert
(
const TArray< typename TContainerElementTypeCompatibility< ElementType >::CopyFromOtherType, OtherAl..., |
Inserts given elements into the array at given location. Compatible element type version. | |
| SizeType | Insert
(
std::initializer_list< ElementType > InitList, |
Inserts given elements into the array at given location. | |
| SizeType | Insert
(
TArray< typename TContainerElementTypeCompatibility< ElementType >::CopyFromOtherType, OtherAllocato..., |
Inserts given elements into the array at given location. Compatible element type version. | |
| SizeType | Insert
(
const ElementType* Ptr, |
Inserts a raw array of elements at a particular index in the TArray. | |
| ElementType & | Insert_GetRef
(
const ElementType& Item, |
Inserts a given element into the array at given location. | |
| ElementType & | Insert_GetRef
(
ElementType&& Item, |
Inserts a given element into the array at given location. Move semantics version. | |
| void | InsertDefaulted
(
SizeType Index |
Inserts a given number of default-constructed elements into the array at a given location. | |
| void | InsertDefaulted
(
SizeType Index, |
||
| ElementType & | InsertDefaulted_GetRef
(
SizeType Index |
Inserts a default-constructed element into the array at a given location. | |
| void | InsertUninitialized
(
SizeType Index |
Inserts a given number of uninitialized elements into the array at given location. | |
| void | InsertUninitialized
(
SizeType Index, |
||
| void | InsertZeroed
(
SizeType Index |
Inserts a given number of zeroed elements into the array at given location. | |
| void | InsertZeroed
(
SizeType Index, |
||
| ElementType & | InsertZeroed_GetRef
(
SizeType Index |
Inserts a zeroed element into the array at given location. | |
| bool | IsEmpty () |
Returns true if the array is empty and contains no elements. | |
| bool | IsValidIndex
(
SizeType Index |
Tests if index is valid, i.e. greater than or equal to zero, and less than the number of elements in the array. | |
| ElementType & | Returns n-th last element from the array. | ||
| const ElementType & | Returns n-th last element from the array.Const version of the above. | ||
| SizeType | Max () |
Returns maximum number of elements in array. | |
| SizeType | Num () |
Returns number of elements in array. | |
| TEnableIfTIsAbstract< ET >::Value, ElementType >::Type | Pop
(
bool bAllowShrinking |
Pops element from the array. | |
| void | Push
(
ElementType&& Item |
Pushes element into the array. | |
| void | Push
(
const ElementType& Item |
Pushes element into the array.Const ref version of the above. | |
| void | RangeCheck
(
SizeType Index |
Checks if index is in array range. | |
| RangedForReverseIteratorType | rbegin () |
||
| RangedForConstReverseIteratorType | rbegin () |
||
| SizeType | Remove
(
const ElementType& Item |
Removes as many instances of Item as there are in the array, maintaining order but not indices. | |
| SizeType | RemoveAll
(
const PREDICATE_CLASS& Predicate |
Remove all instances that match the predicate, maintaining order but not indices Optimized to work with runs of matches/non-matches | |
| SizeType | RemoveAllSwap
(
const PREDICATE_CLASS& Predicate, |
Remove all instances that match the predicate | |
| void | Removes an element (or elements) at given location, then shrinks the array. | ||
| void | Removes an element (or elements) at given location, optionally shrinking the array. | ||
| void | RemoveAtSwap
(
SizeType Index, |
Removes an element (or elements) at given location, optionally shrinking the array. | |
| void | RemoveAtSwap
(
SizeType Index |
Removes an element (or elements) at given location, then shrinks the array. | |
| SizeType | RemoveSingle
(
const ElementType& Item |
Removes the first occurrence of the specified item in the array, maintaining order but not indices. | |
| SizeType | RemoveSingleSwap
(
const ElementType& Item, |
Removes the first occurrence of the specified item in the array. | |
| SizeType | RemoveSwap
(
const ElementType& Item, |
Removes item from the array. | |
| RangedForConstReverseIteratorType | rend () |
||
| RangedForReverseIteratorType | rend () |
||
| void | Reserves memory such that the array can contain at least Number elements. | ||
| void | Same as empty, but doesn't change memory allocations, unless the new size is larger than the current array. | ||
| void | Resizes array to given number of elements. | ||
| void | SetNumUninitialized
(
SizeType NewNum, |
Resizes array to given number of elements. New elements will be uninitialized. | |
| void | SetNumUnsafeInternal
(
SizeType NewNum |
Does nothing except setting the new number of elements in the array. | |
| void | SetNumZeroed
(
SizeType NewNum, |
Resizes array to given number of elements, optionally shrinking it. New elements will be zeroed. | |
| void | Shrink () |
Shrinks the array's used memory to smallest possible to store elements currently in it. | |
| void | Sort
(
const PREDICATE_CLASS& Predicate |
Sorts the array using user define predicate class. | |
| void | Sort () |
Sorts the array assuming < operator is defined for the item type. | |
| void | StableSort () |
Stable sorts the array assuming < operator is defined for the item type. | |
| void | StableSort
(
const PREDICATE_CLASS& Predicate |
Stable sorts the array using user defined predicate class. | |
| void | Element-wise array element swap.This version is doing more sanity checks than SwapMemory. | ||
| void | SwapMemory
(
SizeType FirstIndexToSwap, |
Element-wise array memory swap. | |
| const ElementType & | Top () |
Returns the top element, i.e. the last one.Const version of the above. | |
| ElementType & | Top () |
Returns the top element, i.e. the last one. | |
| void | ToString
(
const FPlatformTypeLayoutParameters& LayoutParams, |
||
| void | VerifyHeap
(
const PREDICATE_CLASS& Predicate |
Verifies the heap. | |
| void | WriteMemoryImage
(
FMemoryImageWriter& Writer |
Operators
| Type | Name | Description | |
|---|---|---|---|
| Immutable implicit conversion operator to constant container of compatible element type. | |||
| Mutable implicit conversion operator to container of compatible element type. | |||
| bool | operator!=
(
const TArray& OtherArray |
Inequality operator. | |
| const ElementType & | operator[]
(
SizeType Index |
Array bracket operator. Returns reference to element at given index.Const version of the above. | |
| ElementType & | operator[]
(
SizeType Index |
Array bracket operator. Returns reference to element at given index. | |
| TArray & | operator+=
(
std::initializer_list< ElementType > InitList |
Appends the specified initializer list to this array. | |
| TArray & | operator+=
(
const TArray& Other |
Appends the specified array to this array. Cannot append to self. | |
| TArray & | operator+=
(
TArray&& Other |
Appends the specified array to this array. Cannot append to self.Move semantics version. | |
| TArray & | operator=
(
const TArray< ElementType, OtherAllocatorType >& Other |
Assignment operator. | |
| TArray & | Assignment operator. | ||
| TArray< InElementType, InAllocatorType > & | operator=
(
const TArrayView< OtherElementType, OtherSizeType >& Other |
||
| TArray & | operator=
(
const TArrayView< OtherElementType, OtherSizeType >& Other |
||
| TArray & | Move assignment operator. | ||
| TArray & | operator=
(
TArray< typename TContainerElementTypeCompatibility< ElementType >::CopyFromOtherType, AllocatorType... |
Move assignment operator. Compatible element type version. | |
| TArray & | operator=
(
const TArray< typename TContainerElementTypeCompatibility< ElementType >::CopyFromOtherType, OtherAl... |
Assignment operator. | |
| TArray & | operator=
(
std::initializer_list< InElementType > InitList |
Initializer list assignment operator. | |
| bool | operator==
(
const TArray& OtherArray |
Equality operator. |