Navigation
API > API/Runtime > API/Runtime/Core
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.
| Name | TArray |
| Type | class |
| Header File | /Engine/Source/Runtime/Core/Public/Containers/Array.h |
| Include Path | #include "Containers/Array.h" |
Syntax
template<typename InElementType, typename InAllocatorType>
class TArray
Derived Classes
TArray derived class hierarchy
- FArchiveDiffMap
- FArrayReader
- TBufferArchive
- FContextCacheElementUStructArray::FInstancedStructArray
- FGLTFMaterialArray
- FGLTFObjectArrayScopeGuard
- FGraphAStar::FNodePool
- FGraphAStar::FOpenList
- FMeshAttributesArray
- FMeshDataSectionArray
- FNameArrayDeprecationWrapper
- FSegmentBlendData
- FSkelMeshSectionArray
- FSlowTaskStack
- FStaticMeshSectionArray
- FTickableObjectRenderThread::FRenderingThreadTickableObjectsArray
- TArrayCollectionArray
- TInlineComponentArray
- TLeafContainer
- TLeafContainer< TAABBTreeLeafArray< FAccelerationStructureHandle, true, FReal > >
- TMaybeMappedArray
- TMRUArray
- TNavStatArray
- TRDGResourceAccessArray
- TResourceArray
- TTransArray
- VectorND
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
| Copy constructor. Use the common routine to perform the copy. | Containers/Array.h | ||
| Move constructor. | Containers/Array.h | ||
TArray
(
const ElementType* Ptr, |
Constructor from a raw array of elements. | Containers/Array.h | |
TArray () |
Constructor, initializes element number counters. | Containers/Array.h | |
TArray
(
const TArrayView< OtherElementType, OtherSizeType >& Other |
Containers/Array.h | ||
TArray
(
std::initializer_list< InElementType > InitList |
Initializer list constructor | Containers/Array.h | |
| Copy constructor with changed allocator. Use the common routine to perform the copy. | Containers/Array.h | ||
| Copy constructor. Use the common routine to perform the copy. | Containers/Array.h | ||
| Move constructor. | Containers/Array.h | ||
| Move constructor. | Containers/Array.h | ||
TArray
(
FIntrusiveUnsetOptionalState Tag |
Containers/Array.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
~TArray() |
Destructor. | Containers/Array.h |
Typedefs
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| AllocatorType | InAllocatorType | Containers/Array.h | |
| ElementAllocatorType | std::conditional_t< AllocatorType::NeedsElementType, typename AllocatorType::template ForElementType< ElementType >, typename AllocatorType::ForAnyElementType > | Containers/Array.h | |
| ElementType | InElementType | Containers/Array.h | |
| IntrusiveUnsetOptionalStateType | TArray | Containers/Array.h | |
| RangedForConstIteratorType | TCheckedPointerIterator< const ElementType, SizeType, false > | Containers/Array.h | |
| RangedForConstReverseIteratorType | TCheckedPointerIterator< const ElementType, SizeType, true > | Containers/Array.h | |
| RangedForIteratorType | TCheckedPointerIterator< ElementType, SizeType, false > | Containers/Array.h | |
| RangedForReverseIteratorType | TCheckedPointerIterator< ElementType, SizeType, true > | Containers/Array.h | |
| SizeType | typename InAllocatorType::SizeType | Containers/Array.h | |
| TConstIterator | TIndexedContainerIterator< const TArray, const ElementType, SizeType > | Containers/Array.h | |
| TIterator | TIndexedContainerIterator< TArray, ElementType, SizeType > | Iterators. | Containers/Array.h |
| USizeType | typename std::make_unsigned_t< SizeType > | Containers/Array.h |
Constants
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| bHasIntrusiveUnsetOptionalState | bool | Start - intrusive TOptional |
Containers/Array.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
SizeType Add
(
ElementType&& Item |
Adds a new item to the end of the array, possibly reallocating the whole array to fit. | Containers/Array.h | |
SizeType Add
(
const ElementType& Item |
Adds a new item to the end of the array, possibly reallocating the whole array to fit. | Containers/Array.h | |
ElementType & Add_GetRef
(
ElementType&& Item |
Adds a new item to the end of the array, possibly reallocating the whole array to fit. | Containers/Array.h | |
ElementType & Add_GetRef
(
const ElementType& Item |
Adds a new item to the end of the array, possibly reallocating the whole array to fit. | Containers/Array.h | |
SizeType AddDefaulted () |
Adds new items to the end of the array, possibly reallocating the whole array to fit. | Containers/Array.h | |
SizeType AddDefaulted
(
SizeType Count |
Containers/Array.h | ||
ElementType & AddDefaulted_GetRef () |
Add a new item to the end of the array, possibly reallocating the whole array to fit. | Containers/Array.h | |
SizeType AddUninitialized () |
Adds a given number of uninitialized elements into the array. | Containers/Array.h | |
SizeType AddUninitialized
(
SizeType Count |
Containers/Array.h | ||
SizeType AddUnique
(
ElementType&& Item |
Adds unique element to array if it doesn't exist.Move semantics version. | Containers/Array.h | |
SizeType AddUnique
(
const ElementType& Item |
Adds unique element to array if it doesn't exist. | Containers/Array.h | |
SizeType AddZeroed () |
Adds new items to the end of the array, possibly reallocating the whole array to fit. | Containers/Array.h | |
SizeType AddZeroed
(
SizeType Count |
Containers/Array.h | ||
ElementType & AddZeroed_GetRef () |
Adds a new item to the end of the array, possibly reallocating the whole array to fit. | Containers/Array.h | |
| Appends the specified array to this array.AllocatorType changing version. | Containers/Array.h | ||
| Appends the specified array to this array. | Containers/Array.h | ||
void Append
(
RangeType&& Source |
Appends the elements from a contiguous range to this array. | Containers/Array.h | |
void Append
(
std::initializer_list< ElementType > InitList |
Adds an initializer list of elements to the end of the TArray. | Containers/Array.h | |
void Append
(
const ElementType* Ptr, |
Adds a raw array of elements to the end of the TArray. | Containers/Array.h | |
void Append
(
const typename TContainerElementTypeCompatibility< ElementType >::CopyFromOtherType* Ptr, |
Adds a raw array of elements to the end of the TArray. | Containers/Array.h | |
RangedForConstIteratorType begin () |
Containers/Array.h | ||
RangedForIteratorType begin () |
DO NOT USE DIRECTLY STL-like iterators to enable range-based for loop support. | Containers/Array.h | |
void BulkSerialize
(
FArchive& Ar, |
Bulk serialize array as a single memory blob when loading. | Containers/Array.h | |
void CheckAddress
(
const ElementType* Addr |
Checks that the specified address is not part of an element within the container. | Containers/Array.h | |
void CheckInvariants() |
Checks array invariants: if array size is greater than or equal to zero and less than or equal to the maximum. | Containers/Array.h | |
bool Contains
(
const ComparisonType& Item |
Checks if this array contains the element. | Containers/Array.h | |
bool ContainsByPredicate
(
Predicate Pred |
Checks if this array contains an element for which the predicate is true. | Containers/Array.h | |
void CopyUnfrozen
(
const FMemoryUnfreezeContent& Context, |
Containers/Array.h | ||
void CountBytes
(
FArchive& Ar |
Count bytes needed to serialize this array. | Containers/Array.h | |
TConstIterator CreateConstIterator() |
Creates a const iterator for the contents of this array | Containers/Array.h | |
TIterator CreateIterator() |
Creates an iterator for the contents of this array | Containers/Array.h | |
SizeType Emplace
(
ArgsType&&... Args |
Constructs a new item at the end of the array, possibly reallocating the whole array to fit. | Containers/Array.h | |
ElementType & Emplace_GetRef
(
ArgsType&&... Args |
Constructs a new item at the end of the array, possibly reallocating the whole array to fit. | Containers/Array.h | |
void EmplaceAt
(
SizeType Index, |
Constructs a new item at a specified index, possibly reallocating the whole array to fit. | Containers/Array.h | |
ElementType & EmplaceAt_GetRef
(
SizeType Index, |
Constructs a new item at a specified index, possibly reallocating the whole array to fit. | Containers/Array.h | |
void Empty
(
SizeType Slack |
Empties the array. It calls the destructors on held items if needed. | Containers/Array.h | |
RangedForIteratorType end () |
Containers/Array.h | ||
RangedForConstIteratorType end () |
Containers/Array.h | ||
TArray< ElementType > FilterByPredicate
(
Predicate Pred |
Filters the elements in the array based on a predicate functor. | Containers/Array.h | |
SizeType Find
(
const ElementType& Item |
Finds element within the array. | Containers/Array.h | |
bool Find
(
const ElementType& Item, |
Finds element within the array. | Containers/Array.h | |
const ElementType * FindByKey
(
const KeyType& Key |
Finds an item by key (assuming the ElementType overloads operator== for the comparison). | Containers/Array.h | |
ElementType * FindByKey
(
const KeyType& Key |
Finds an item by key (assuming the ElementType overloads operator== for the comparison). | Containers/Array.h | |
const ElementType * FindByPredicate
(
Predicate Pred |
Finds an element which matches a predicate functor. | Containers/Array.h | |
ElementType * FindByPredicate
(
Predicate Pred |
Finds an element which matches a predicate functor. | Containers/Array.h | |
bool FindItemByClass
(
SearchType** Item, |
Searches for the first entry of the specified type, will only work with TArray |
Containers/Array.h | |
SizeType FindLast
(
const ElementType& Item |
Finds element within the array starting from the end. | Containers/Array.h | |
bool FindLast
(
const ElementType& Item, |
Finds element within the array starting from the end. | Containers/Array.h | |
SizeType FindLastByPredicate
(
Predicate Pred |
Searches the array for the last occurrence of an element which matches the specified predicate. | Containers/Array.h | |
SizeType FindLastByPredicate
(
Predicate Pred, |
Searches an initial subrange of the array for the last occurrence of an element which matches the specified predicate. | Containers/Array.h | |
SIZE_T GetAllocatedSize () |
Helper function to return the amount of memory allocated by this container. | Containers/Array.h | |
const ElementAllocatorType & GetAllocatorInstance () |
Containers/Array.h | ||
ElementAllocatorType & GetAllocatorInstance () |
Containers/Array.h | ||
const ElementType * GetData () |
Helper function for returning a typed pointer to the first array entry. | Containers/Array.h | |
ElementType * GetData () |
End - intrusive TOptional |
Containers/Array.h | |
SizeType GetSlack () |
Returns the amount of slack in this array in elements. | Containers/Array.h | |
void Heapify () |
Builds an implicit heap from the array. | Containers/Array.h | |
void Heapify
(
const PREDICATE_CLASS& Predicate |
Implicit heaps Builds an implicit heap from the array. | Containers/Array.h | |
void HeapPop
(
ElementType& OutItem, |
Removes the top element from the heap. | Containers/Array.h | |
void HeapPop
(
ElementType& OutItem, |
Containers/Array.h | ||
void HeapPop
(
ElementType& OutItem, |
Removes the top element from the heap. | Containers/Array.h | |
void HeapPop
(
ElementType& OutItem, |
Containers/Array.h | ||
void HeapPopDiscard
(
EAllowShrinking AllowShrinking |
Removes the top element from the heap. | Containers/Array.h | |
void HeapPopDiscard
(
bool bAllowShrinking |
Containers/Array.h | ||
void HeapPopDiscard
(
const PREDICATE_CLASS& Predicate, |
Removes the top element from the heap. | Containers/Array.h | |
void HeapPopDiscard
(
const PREDICATE_CLASS& Predicate, |
Containers/Array.h | ||
SizeType HeapPush
(
ElementType&& InItem |
Adds a new element to the heap. | Containers/Array.h | |
SizeType HeapPush
(
const ElementType& InItem |
Adds a new element to the heap. | Containers/Array.h | |
SizeType HeapPush
(
ElementType&& InItem, |
Adds a new element to the heap. | Containers/Array.h | |
SizeType HeapPush
(
const ElementType& InItem, |
Adds a new element to the heap. | Containers/Array.h | |
void HeapRemoveAt
(
SizeType Index, |
Removes an element from the heap. | Containers/Array.h | |
void HeapRemoveAt
(
SizeType Index, |
Containers/Array.h | ||
void HeapRemoveAt
(
SizeType Index, |
Removes an element from the heap. | Containers/Array.h | |
void HeapRemoveAt
(
SizeType Index, |
Containers/Array.h | ||
void HeapSort () |
Performs heap sort on the array. | Containers/Array.h | |
void HeapSort
(
const PREDICATE_CLASS& Predicate |
Performs heap sort on the array. | Containers/Array.h | |
ElementType & HeapTop () |
Returns the top element from the heap (does not remove the element). | Containers/Array.h | |
const ElementType & HeapTop () |
Returns the top element from the heap (does not remove the element).Const version. | Containers/Array.h | |
SizeType IndexOfByKey
(
const KeyType& Key |
Finds an item by key (assuming the ElementType overloads operator== for the comparison). | Containers/Array.h | |
SizeType IndexOfByPredicate
(
Predicate Pred |
Finds an item by predicate. | Containers/Array.h | |
void Init
(
const ElementType& Element, |
Sets the size of the array, filling it with the given element. | Containers/Array.h | |
| Inserts given elements into the array at given location. | Containers/Array.h | ||
| Inserts given elements into the array at given location. | Containers/Array.h | ||
SizeType Insert
(
ElementType&& Item, |
Inserts a given element into the array at given location. Move semantics version. | Containers/Array.h | |
SizeType Insert
(
const ElementType& Item, |
Inserts a given element into the array at given location. | Containers/Array.h | |
SizeType Insert
(
const TArray< typename TContainerElementTypeCompatibility< ElementType >::CopyFromOtherType, OtherAl..., |
Inserts given elements into the array at given location. Compatible element type version. | Containers/Array.h | |
SizeType Insert
(
TArray< typename TContainerElementTypeCompatibility< ElementType >::CopyFromOtherType, OtherAllocato..., |
Inserts given elements into the array at given location. Compatible element type version. | Containers/Array.h | |
SizeType Insert
(
const ElementType* Ptr, |
Inserts a raw array of elements at a particular index in the TArray. | Containers/Array.h | |
SizeType Insert
(
std::initializer_list< ElementType > InitList, |
Inserts given elements into the array at given location. | Containers/Array.h | |
ElementType & Insert_GetRef
(
ElementType&& Item, |
Inserts a given element into the array at given location. Move semantics version. | Containers/Array.h | |
ElementType & Insert_GetRef
(
const ElementType& Item, |
Inserts a given element into the array at given location. | Containers/Array.h | |
void InsertDefaulted
(
SizeType Index, |
Containers/Array.h | ||
void InsertDefaulted
(
SizeType Index |
Inserts a given number of default-constructed elements into the array at a given location. | Containers/Array.h | |
ElementType & InsertDefaulted_GetRef
(
SizeType Index |
Inserts a default-constructed element into the array at a given location. | Containers/Array.h | |
void InsertUninitialized
(
SizeType Index |
Inserts a given number of uninitialized elements into the array at given location. | Containers/Array.h | |
void InsertUninitialized
(
SizeType Index, |
Containers/Array.h | ||
void InsertZeroed
(
SizeType Index, |
Containers/Array.h | ||
void InsertZeroed
(
SizeType Index |
Inserts a given number of zeroed elements into the array at given location. | Containers/Array.h | |
ElementType & InsertZeroed_GetRef
(
SizeType Index |
Inserts a zeroed element into the array at given location. | Containers/Array.h | |
bool IsEmpty () |
Returns true if the array is empty and contains no elements. | Containers/Array.h | |
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. | Containers/Array.h | |
ElementType & Last
(
SizeType IndexFromTheEnd |
Returns n-th last element from the array. | Containers/Array.h | |
const ElementType & Last
(
SizeType IndexFromTheEnd |
Returns n-th last element from the array.Const version of the above. | Containers/Array.h | |
SizeType Max () |
Returns maximum number of elements in array. | Containers/Array.h | |
SizeType Num () |
Returns number of elements in array. | Containers/Array.h | |
SIZE_T NumBytes() |
Containers/Array.h | ||
ElementType Pop
(
EAllowShrinking AllowShrinking |
Pops element from the array. | Containers/Array.h | |
ElementType Pop
(
bool bAllowShrinking |
Containers/Array.h | ||
void Push
(
ElementType&& Item |
Pushes element into the array. | Containers/Array.h | |
void Push
(
const ElementType& Item |
Pushes element into the array.Const ref version of the above. | Containers/Array.h | |
void RangeCheck
(
SizeType Index |
Checks if index is in array range. | Containers/Array.h | |
void RangeCheck
(
SizeType Index, |
Checks if a range of indices are in the array range. | Containers/Array.h | |
RangedForReverseIteratorType rbegin () |
Containers/Array.h | ||
RangedForConstReverseIteratorType rbegin () |
Containers/Array.h | ||
SizeType Remove
(
const ElementType& Item |
Removes as many instances of Item as there are in the array, maintaining order but not indices. | Containers/Array.h | |
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 | Containers/Array.h | |
SizeType RemoveAllSwap
(
const PREDICATE_CLASS& Predicate, |
Remove all instances that match the predicate | Containers/Array.h | |
SizeType RemoveAllSwap
(
const PREDICATE_CLASS& Predicate, |
Containers/Array.h | ||
void RemoveAt
(
SizeType Index, |
Removes an element (or elements) at given location, optionally shrinking the array. | Containers/Array.h | |
void RemoveAt
(
SizeType Index, |
Containers/Array.h | ||
void RemoveAt
(
SizeType Index, |
Removes an element (or elements) at given location, then shrinks the array. | Containers/Array.h | |
void RemoveAtSwap
(
SizeType Index, |
Removes an element (or elements) at given location, optionally shrinking the array. | Containers/Array.h | |
void RemoveAtSwap
(
SizeType Index, |
Containers/Array.h | ||
void RemoveAtSwap
(
SizeType Index, |
Removes an element (or elements) at given location, then shrinks the array. | Containers/Array.h | |
SizeType RemoveSingle
(
const ElementType& Item |
Removes the first occurrence of the specified item in the array, maintaining order but not indices. | Containers/Array.h | |
SizeType RemoveSingleSwap
(
const ElementType& Item, |
Containers/Array.h | ||
SizeType RemoveSingleSwap
(
const ElementType& Item, |
Removes the first occurrence of the specified item in the array. | Containers/Array.h | |
SizeType RemoveSwap
(
const ElementType& Item, |
Containers/Array.h | ||
SizeType RemoveSwap
(
const ElementType& Item, |
Removes all instances of a given item from the array. | Containers/Array.h | |
RangedForReverseIteratorType rend () |
Containers/Array.h | ||
RangedForConstReverseIteratorType rend () |
Containers/Array.h | ||
void Reserve
(
SizeType Number |
Reserves memory such that the array can contain at least Number elements. | Containers/Array.h | |
void Reset
(
SizeType NewSize |
Same as empty, but doesn't change memory allocations, unless the new size is larger than the current array. | Containers/Array.h | |
void SetNum
(
SizeType NewNum, |
Containers/Array.h | ||
void SetNum
(
SizeType NewNum, |
Resizes array to given number of elements. | Containers/Array.h | |
void SetNumUninitialized
(
SizeType NewNum, |
Containers/Array.h | ||
void SetNumUninitialized
(
SizeType NewNum, |
Resizes array to given number of elements. New elements will be uninitialized. | Containers/Array.h | |
void SetNumUnsafeInternal
(
SizeType NewNum |
Does nothing except setting the new number of elements in the array. | Containers/Array.h | |
void SetNumZeroed
(
SizeType NewNum, |
Containers/Array.h | ||
void SetNumZeroed
(
SizeType NewNum, |
Resizes array to given number of elements, optionally shrinking it. New elements will be zeroed. | Containers/Array.h | |
void Shrink () |
Shrinks the array's used memory to smallest possible to store elements currently in it. | Containers/Array.h | |
void Sort () |
Sorts the array assuming < operator is defined for the item type. | Containers/Array.h | |
void Sort
(
const PREDICATE_CLASS& Predicate |
Sorts the array using user define predicate class. | Containers/Array.h | |
void StableSort () |
Stable sorts the array assuming < operator is defined for the item type. | Containers/Array.h | |
void StableSort
(
const PREDICATE_CLASS& Predicate |
Stable sorts the array using user defined predicate class. | Containers/Array.h | |
void Swap
(
SizeType FirstIndexToSwap, |
Element-wise array element swap.This version is doing more sanity checks than SwapMemory. | Containers/Array.h | |
void SwapMemory
(
SizeType FirstIndexToSwap, |
Element-wise array memory swap. | Containers/Array.h | |
const ElementType & Top () |
Returns the top element, i.e. the last one.Const version of the above. | Containers/Array.h | |
ElementType & Top () |
Returns the top element, i.e. the last one. | Containers/Array.h | |
void ToString
(
const FPlatformTypeLayoutParameters& LayoutParams, |
Containers/Array.h | ||
void VerifyHeap
(
const PREDICATE_CLASS& Predicate |
Verifies the heap. | Containers/Array.h | |
void WriteMemoryImage
(
FMemoryImageWriter& Writer |
Containers/Array.h |
Static
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
static void AppendHash
(
const FPlatformTypeLayoutParameters& LayoutParams, |
Containers/Array.h | ||
static uint32 GetTypeSize() |
Helper function returning the size of the inner type. | Containers/Array.h | |
static void MoveOrCopy
(
ToArrayType& ToArray, |
Moves or copies array. Depends on the array type traits. | Containers/Array.h | |
static void MoveOrCopyWithSlack
(
ToArrayType& ToArray, |
Moves or copies array. Depends on the array type traits. | Containers/Array.h |
Operators
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
bool operator!=
(
const TArray& OtherArray |
Inequality operator. | Containers/Array.h | |
ElementType & operator[]
(
SizeType Index |
Array bracket operator. Returns reference to element at given index. | Containers/Array.h | |
const ElementType & operator[]
(
SizeType Index |
Array bracket operator. Returns reference to element at given index.Const version of the above. | Containers/Array.h | |
TArray & operator+=
(
const TArray& Other |
Appends the specified array to this array. Cannot append to self. | Containers/Array.h | |
TArray & operator+=
(
std::initializer_list< ElementType > InitList |
Appends the specified initializer list to this array. | Containers/Array.h | |
TArray & operator+=
(
TArray&& Other |
Appends the specified array to this array. Cannot append to self.Move semantics version. | Containers/Array.h | |
TArray< InElementType, InAllocatorType > & operator=
(
const TArrayView< OtherElementType, OtherSizeType >& Other |
Containers/ArrayView.h | ||
TArray & operator=
(
const TArray< typename TContainerElementTypeCompatibility< ElementType >::CopyFromOtherType, OtherAl... |
Assignment operator. | Containers/Array.h | |
TArray & operator=
(
TArray< typename TContainerElementTypeCompatibility< ElementType >::CopyFromOtherType, AllocatorType... |
Move assignment operator. Compatible element type version. | Containers/Array.h | |
| Move assignment operator. | Containers/Array.h | ||
TArray & operator=
(
const TArrayView< OtherElementType, OtherSizeType >& Other |
Containers/Array.h | ||
| Assignment operator. | Containers/Array.h | ||
| Assignment operator. | Containers/Array.h | ||
| Initializer list assignment operator. | Containers/Array.h | ||
bool operator==
(
FIntrusiveUnsetOptionalState Tag |
Containers/Array.h | ||
bool operator==
(
const TArray& OtherArray |
Equality operator. | Containers/Array.h |