TArrayView

Inheritance Hierarchy

Syntax

template<typename InElementType>
class TArrayView

Remarks

Templated fixed-size view of another array

A statically sized view of an array of typed elements. Designed to allow functions to take either a fixed C array or a TArray with an arbitrary allocator as an argument when the function neither adds nor removes elements

e.g.: int32 SumAll(TArrayView<const int32> array) { return Algo::Accumulate(array); }

could be called as: SumAll(MyTArray); SumAll(MyCArray); SumAll({1, 2, 3}); SumAll(MakeArrayView(Ptr, Num));

Note: View classes are not const-propagating! If you want a view where the elements are const, you need "TArrayView<const T>" not "const TArrayView<T>"!

Caution: Treat a view like a reference to the elements in the array. DO NOT free or reallocate the array while the view exists!

Constructors

Name Description

Public function

TArrayView()

Constructor.

Public function

TArrayView

(
    const TArrayView < OtherElementType ...
)

Copy constructor from another view

Public function

TArrayView

(
    OtherElementType(&) Other
)

Construct a view of a C array with a compatible element type

Public function

TArrayView

(
    const OtherElementType(&) Other
)

Construct a view of a C array with a compatible element type

Public function

TArrayView

(
    TArray < OtherElementType, OtherAllo...
)

Construct a view of a TArray with a compatible element type

Public function

TArrayView

(
    const TArray < OtherElementType, Oth...
)

Public function

TArrayView

(
    std::initializer_list< OtherElement...
)

Construct a view from an initializer list with a compatible element type

Public function

TArrayView

(
    OtherElementType* InData,
    int32 InCount
)

Construct a view of an arbitrary pointer

Functions

Name Description

Public function Const

ElementType ...

 

begin()

DO NOT USE DIRECTLY STL-like iterators to enable range-based for loop support.

Public function Const

void

 

CheckInvariants()

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

Public function Const

bool

 

Contains

(
    const ComparisonType& Item
)

Checks if this array contains the element.

Public function Const

bool

 

ContainsByPredicate

(
    Predicate Pred
)

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

Public function Const

ElementType ...

 

end()

Public function Const

TArray < type...

 

FilterByPredicate

(
    Predicate Pred
)

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

Public function Const

bool

 

Find

(
    const ElementType & Item,
    int32 & Index
)

Finds element within the array.

Public function Const

int32

 

Find

(
    const ElementType & Item
)

Finds element within the array.

Public function Const

ElementType ...

 

FindByKey

(
    const KeyType& Key
)

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

Public function Const

ElementType ...

 

FindByPredicate

(
    Predicate Pred
)

Finds an element which matches a predicate functor.

Public function Const

bool

 

FindLast

(
    const ElementType & Item,
    int32 & Index
)

Finds element within the array starting from the end.

Public function Const

int32

 

FindLastByPredicate

(
    Predicate Pred,
    int32 StartIndex
)

Finds element within the array starting from StartIndex and going backwards.

Public function Const

int32

 

FindLastByPredicate

(
    Predicate Pred
)

Finds element within the array starting from the end. Uses predicate to match element.

Public function Const

ElementType ...

 

GetData()

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

Public function Const

size_t

 

GetTypeSize()

Helper function returning the size of the inner type.

Public function Const

int32

 

IndexOfByKey

(
    const KeyType& Key
)

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

Public function Const

int32

 

IndexOfByPredicate

(
    Predicate Pred
)

Finds an item by predicate.

Public function Const

bool

 

IsValidIndex

(
    int32 Index
)

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

Public function Const

ElementType ...

 

Last

(
    int32 IndexFromTheEnd
)

Returns n-th last element from the array.

Public function Const

int32

 

Num()

Returns number of elements in array.

Public function Const

void

 

RangeCheck

(
    int32 Index
)

Checks if index is in array range.

Public function

TArrayView

 

Slice

(
    int32 Index,
    int32 InNum
)

Returns a sliced view

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.

Operators

Name Description

Public function Const

ElementType ...

 

operator[]

(
    int32 Index
)

Array bracket operator. Returns reference to element at give index.

Public function

TArrayView &

 

operator=

(
    const TArrayView < OtherElementType ...
)

Assignment operator

Typedefs

References

Module

Core

Header

Runtime/Core/Public/Containers/ArrayView.h