TArray

Inheritance Hierarchy

Syntax

template<typename InElementType, typename InAllocator>
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

Name Description

Protected variable

ElementAllocato ...

 

AllocatorInstance

Protected variable

int32

 

ArrayMax

Protected variable

int32

 

ArrayNum

Constructors

Name Description

Public function

TArray()

Constructor, initializes element number counters.

Public function

TArray

(
    std::initializer_list< InElementTyp...
)

Initializer list constructor

Public function

TArray

(
    const TArray < OtherElementType, Oth...
)

Copy constructor with changed allocator. Use the common routine to perform the copy.

Public function

TArray

(
    const TArray & Other
)

Copy constructor. Use the common routine to perform the copy.

Public function

TArray

(
    TArray && Other
)

Move constructor.

Public function

TArray

(
    TArray < OtherElementType, OtherAllo...
)

Move constructor.

Public function

TArray

(
    const TArray & Other,
    int32 ExtraSlack
)

Copy constructor. Use the common routine to perform the copy.

Public function

TArray

(
    TArray < OtherElementType, Allocator ...,
    int32 ExtraSlack
)

Move constructor.

Destructors

Name Description

Public function

~TArray()

Destructor.

Functions

Name Description

Public function

int32

 

Add

(
    const ElementType & Item
)

Adds a new item to the end of the array, possibly reallocating the whole array to fit.

Public function

int32

 

Add

(
    ElementType && Item
)

Adds a new item to the end of the array, possibly reallocating the whole array to fit.

Public function

int32

 

AddDefaulted

(
    int32 Count
)

Adds new items to the end of the array, possibly reallocating the whole array to fit.

Public function

int32

 

AddUninitialized

(
    int32 Count
)

Adds a given number of uninitialized elements into the array.

Public function

int32

 

AddUnique

(
    const ElementType & Item
)

Adds unique element to array if it doesn't exist.

Index of the element in the array.

Public function

int32

 

AddUnique

(
    ElementType && Item
)

Adds unique element to array if it doesn't exist.

Public function

int32

 

AddZeroed

(
    int32 Count
)

Adds new items to the end of the array, possibly reallocating the whole array to fit.

Public function

void

 

Append

(
    TArray < OtherElementType, OtherAllo...
)

Appends the specified array to this array.

Public function

void

 

Append

(
    const TArray < OtherElementType, Oth...
)

Appends the specified array to this array.

Allocator changing version.

Public function

void

 

Append

(
    const ElementType * Ptr,
    int32 Count
)

Adds a raw array of elements to the end of the TArray .

Public function

void

 

Append

(
    std::initializer_list< ElementType ...
)

Adds an initializer list of elements to the end of the TArray .

Public function

void

 

BulkSerialize

(
    FArchive & Ar,
    bool bForcePerElementSerialization
)

Bulk serialize array as a single memory blob when loading.

Public function

void

 

CheckAddress

(
    const ElementType * Addr
)

Checks that the specified address is not part of an element within the container.

Public function

void

 

CheckInvariants()

Checks array invariants: if array size is greater than zero and less than maximum.

Public function

bool

 

Contains

(
    const ComparisonType& Item
)

Checks if this array contains the element.

True if found. False otherwise.

Public function

bool

 

ContainsByPredicate

(
    Predicate Pred
)

Checks if this array contains element for which the predicate is true.

Public function

void

 

CountBytes

(
    FArchive & Ar
)

Count bytes needed to serialize this array.

Public function

TConstIterat ...

 

CreateConstIterator()

Creates a const iterator for the contents of this array

The const iterator.

Public function

TIterator

 

CreateIterator()

Creates an iterator for the contents of this array

The iterator.

Public function

int32

 

Emplace

(
    ArgsType&&... Args
)

Constructs a new item at the end of the array, possibly reallocating the whole array to fit.

Public function

void

 

EmplaceAt

(
    int32 Index,
    ArgsType&&... Args
)

Constructs a new item at a specified index, possibly reallocating the whole array to fit.

Public function

void

 

Empty

(
    int32 Slack
)

Empties the array. It calls the destructors on held items if needed.

Public function

TArray < Elem ...

 

FilterByPredicate

(
    Predicate Pred
)

Filters the elements in the array based on a predicate functor.

Public function

bool

 

Find

(
    const ElementType & Item,
    int32 & Index
)

Finds element within the array.

True if found. False otherwise.

Public function

int32

 

Find

(
    const ElementType & Item
)

Finds element within the array.

Index of the found element. INDEX_NONE otherwise.

Public function

const Elemen ...

 

FindByKey

(
    const KeyType& Key
)

Finds an item by key (assuming the ElementType overloads operator== for the comparison).

Public function

ElementType ...

 

FindByKey

(
    const KeyType& Key
)

Finds an item by key (assuming the ElementType overloads operator== for the comparison).

Public function

const Elemen ...

 

FindByPredicate

(
    Predicate Pred
)

Finds an element which matches a predicate functor.

Public function

ElementType ...

 

FindByPredicate

(
    Predicate Pred
)

Finds an element which matches a predicate functor.

Public function

bool

 

FindItemByClass

(
    SearchType** Item,
    int32 * ItemIndex,
    int32 StartIndex
)

Searches for the first entry of the specified type, will only work with TArray .

Public function

bool

 

FindLast

(
    const ElementType & Item,
    int32 & Index
)

Finds element within the array starting from the end.

True if found. False otherwise.

Public function

int32

 

FindLast

(
    const ElementType & Item
)

Finds element within the array starting from the end.

Public function

int32

 

FindLastByPredicate

(
    Predicate Pred,
    int32 Count
)

Searches an initial subrange of the array for the last occurrence of an element which matches the specified predicate.

Public function

int32

 

FindLastByPredicate

(
    Predicate Pred
)

Searches the array for the last occurrence of an element which matches the specified predicate.

Public function

uint32

 

GetAllocatedSize()

Helper function to return the amount of memory allocated by this container.

Public function

const Elemen ...

 

GetData()

Helper function for returning a typed pointer to the first array entry.

Public function

ElementType ...

 

GetData()

Helper function for returning a typed pointer to the first array entry.

Public function

int32

 

GetSlack()

Returns the amount of slack in this array in elements.

Public function

uint32

 

GetTypeSize()

Helper function returning the size of the inner type.

Size in bytes of array type.

Public function

void

 

Heapify()

Builds an implicit heap from the array.

Public function

void

 

Heapify

(
    const PREDICATE_CLASS& Predicate
)

Implicit heaps Builds an implicit heap from the array.

Public function

void

 

HeapPop

(
    ElementType & OutItem,
    const PREDICATE_CLASS& Predicate,
    bool bAllowShrinking
)

Removes the top element from the heap.

Public function

void

 

HeapPop

(
    ElementType & OutItem,
    bool bAllowShrinking
)

Removes the top element from the heap.

Public function

void

 

HeapPopDiscard

(
    bool bAllowShrinking
)

Removes the top element from the heap.

Public function

void

 

HeapPopDiscard

(
    const PREDICATE_CLASS& Predicate,
    bool bAllowShrinking
)

Removes the top element from the heap.

Public function

int32

 

HeapPush

(
    const ElementType & InItem
)

Adds a new element to the heap.

Public function

int32

 

HeapPush

(
    ElementType && InItem,
    const PREDICATE_CLASS& Predicate
)

Adds a new element to the heap.

Public function

int32

 

HeapPush

(
    const ElementType & InItem,
    const PREDICATE_CLASS& Predicate
)

Adds a new element to the heap.

Public function

int32

 

HeapPush

(
    ElementType && InItem
)

Adds a new element to the heap.

Public function

void

 

HeapRemoveAt

(
    int32 Index,
    bool bAllowShrinking
)

Removes an element from the heap.

Public function

void

 

HeapRemoveAt

(
    int32 Index,
    const PREDICATE_CLASS& Predicate,
    bool bAllowShrinking
)

Removes an element from the heap.

Public function

void

 

HeapSort

(
    const PREDICATE_CLASS& Predicate
)

Performs heap sort on the array.

Public function

void

 

HeapSort()

Performs heap sort on the array.

Public function

const Elemen ...

 

HeapTop()

Returns the top element from the heap (does not remove the element).

Public function

ElementType ...

 

HeapTop()

Returns the top element from the heap (does not remove the element).

Public function

int32

 

IndexOfByKey

(
    const KeyType& Key
)

Finds an item by key (assuming the ElementType overloads operator== for the comparison).

Public function

int32

 

IndexOfByPredicate

(
    Predicate Pred
)

Finds an item by predicate.

Index to the first matching element, or INDEX_NONE if none is found.

Public function

void

 

Init

(
    const ElementType & Element,
    int32 Number
)

Sets the size of the array, filling it with the given element.

Public function

int32

 

Insert

(
    const ElementType & Item,
    int32 Index
)

Inserts a given element into the array at given location.

Location at which the insert was done.

Public function

int32

 

Insert

(
    std::initializer_list< ElementType ...,
    const int32 InIndex
)

Inserts given elements into the array at given location.

Public function

int32

 

Insert

(
    const TArray < ElementType >& Items,
    const int32 InIndex
)

Inserts given elements into the array at given location.

Public function

int32

 

Insert

(
    ElementType && Item,
    int32 Index
)

Inserts a given element into the array at given location.

Public function

int32

 

Insert

(
    const ElementType * Ptr,
    int32 Count,
    int32 Index
)

Inserts a raw array of elements at a particular index in the TArray .

Public function

void

 

InsertDefaulted

(
    int32 Index,
    int32 Count
)

Inserts a given number of default-constructed elements into the array at a given location.

Public function

void

 

InsertUninitialized

(
    int32 Index,
    int32 Count
)

Inserts a given number of uninitialized elements into the array at given location.

Public function

void

 

InsertZeroed

(
    int32 Index,
    int32 Count
)

Inserts a given number of zeroed elements into the array at given location.

Public function

bool

 

IsValidIndex

(
    int32 Index
)

Tests if index is valid, i.e. greater than or equal to zero, and less than the number of elements in the array.

Public function

const Elemen ...

 

Last

(
    int32 IndexFromTheEnd
)

Returns n-th last element from the array.

Public function

ElementType ...

 

Last

(
    int32 IndexFromTheEnd
)

Returns n-th last element from the array.

Reference to n-th last element from the array.

Public function

int32

 

Max()

Returns maximum number of elements in array.

Maximum number of elements in array.

Public function

int32

 

Num()

Returns number of elements in array.

Number of elements in array.

Public function

ElementType

 

Pop

(
    bool bAllowShrinking
)

Pops element from the array.

Popped element.

Public function

void

 

Push

(
    ElementType && Item
)

Pushes element into the array.

Public function

void

 

Push

(
    const ElementType & Item
)

Pushes element into the array.

Const ref version of the above.

Public function

void

 

RangeCheck

(
    int32 Index
)

Checks if index is in array range.

Public function

int32

 

Remove

(
    const ElementType & Item
)

Removes as many instances of Item as there are in the array, maintaining order but not indices.

Public function

int32

 

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

Public function

void

 

RemoveAllSwap

(
    const PREDICATE_CLASS& Predicate,
    bool bAllowShrinking
)

Remove all instances that match the predicate

Public function

void

 

RemoveAt

(
    int32 Index,
    CountType Count,
    bool bAllowShrinking
)

Removes an element (or elements) at given location optionally shrinking the array.

Public function

void

 

RemoveAt

(
    int32 Index
)

Removes an element (or elements) at given location optionally shrinking the array.

Public function

void

 

RemoveAtSwap

(
    int32 Index,
    CountType Count,
    bool bAllowShrinking
)

Removes an element (or elements) at given location optionally shrinking the array.

Public function

void

 

RemoveAtSwap

(
    int32 Index
)

Removes an element (or elements) at given location optionally shrinking the array.

Public function

int32

 

RemoveSingle

(
    const ElementType & Item
)

Removes the first occurrence of the specified item in the array, maintaining order but not indices.

Public function

int32

 

RemoveSingleSwap

(
    const ElementType & Item,
    bool bAllowShrinking
)

Removes the first occurrence of the specified item in the array.

Public function

int32

 

RemoveSwap

(
    const ElementType & Item
)

Removes item from the array.

Public function

void

 

Reserve

(
    int32 Number
)

Reserves memory such that the array can contain at least Number elements.

Public function

void

 

Reset

(
    int32 NewSize
)

Same as empty, but doesn't change memory allocations, unless the new size is larger than the current array.

Public function

void

 

SetNum

(
    int32 NewNum,
    bool bAllowShrinking
)

Resizes array to given number of elements.

Public function

void

 

SetNumUninitialized

(
    int32 NewNum,
    bool bAllowShrinking
)

Resizes array to given number of elements. New elements will be uninitialized.

Public function

void

 

SetNumUnsafeInternal

(
    int32 NewNum
)

Does nothing except setting the new number of elements in the array.

Public function

void

 

SetNumZeroed

(
    int32 NewNum,
    bool bAllowShrinking
)

Resizes array to given number of elements. New elements will be zeroed.

Public function

void

 

Shrink()

Shrinks the array's used memory to smallest possible to store elements currently in it.

Public function

void

 

Sort()

Sorts the array assuming < operator is defined for the item type.

Public function

void

 

Sort

(
    const PREDICATE_CLASS& Predicate
)

Sorts the array using user define predicate class.

Public function

void

 

StableSort()

Stable sorts the array assuming < operator is defined for the item type.

Public function

void

 

StableSort

(
    const PREDICATE_CLASS& Predicate
)

Stable sorts the array using user defined predicate class.

Public function

void

 

Swap

(
    int32 FirstIndexToSwap,
    int32 SecondIndexToSwap
)

Element-wise array element swap.

This version is doing more sanity checks than SwapMemory.

Public function

void

 

SwapMemory

(
    int32 FirstIndexToSwap,
    int32 SecondIndexToSwap
)

Element-wise array memory swap.

Public function

const Elemen ...

 

Top()

Returns the top element, i.e. the last one.

Public function

ElementType ...

 

Top()

Returns the top element, i.e. the last one.

Reference to the top element.

Public function

void

 

VerifyHeap

(
    const PREDICATE_CLASS& Predicate
)

Verifies the heap.

Operators

Name Description

Public function

bool

 

operator!=

(
    const TArray & OtherArray
)

Inequality operator.

True if this array is NOT the same as OtherArray. False otherwise.

Public function

const Elemen ...

 

operator[]

(
    int32 Index
)

Array bracket operator.

Public function

ElementType ...

 

operator[]

(
    int32 Index
)

Array bracket operator.

Public function

TArray &

 

operator+=

(
    std::initializer_list< ElementType ...
)

Appends the specified initializer list to this array.

Public function

TArray &

 

operator+=

(
    const TArray & Other
)

Appends the specified array to this array. Cannot append to self.

Public function

TArray &

 

operator+=

(
    TArray && Other
)

Appends the specified array to this array. Cannot append to self.

Move semantics version.

Public function

TArray &

 

operator=

(
    std::initializer_list< InElementTyp...
)

Initializer list assignment operator.

Public function

TArray &

 

operator=

(
    TArray && Other
)

Move assignment operator.

Public function

TArray &

 

operator=

(
    const TArray < ElementType , OtherAll...
)

Assignment operator.

Public function

TArray &

 

operator=

(
    const TArray & Other
)

Assignment operator.

Public function

bool

 

operator==

(
    const TArray & OtherArray
)

Equality operator.

True if this array is the same as OtherArray. False otherwise.

Typedefs

References

Module

Core

Header

Runtime/Core/Public/Containers/Array.h