TArrayView

Templated fixed-size view of another array

Inheritance Hierarchy

TArrayView

FRDGUploadData

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/Containers/ArrayView.h

Include

#include "Containers/ArrayView.h"

Syntax

template<typename InElementType, typename InSizeType>
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(MakeArrayView(Ptr, Num));

auto Values = { 1, 2, 3 }; SumAll(Values);

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! For this reason, be mindful of lifetimes when constructing TArrayViews from rvalue initializer lists:

TArrayView<int> View = { 1, 2, 3 }; // construction of array view from rvalue initializer list int n = View[0]; // undefined behavior, as the initializer list was destroyed at the end of the previous line

Constructors

Name Description

Public function

TArrayView()

Constructor.

Public function

TArrayView

(
    OtherRangeType&& Other
)

Constructor from another range

Public function

TArrayView

(
    OtherRangeType&& Other
)

Public function

TArrayView

(
    std::initializer_list< ElementType ...
)

Construct a view of an initializer list.

Public function

TArrayView

(
    OtherElementType* InData,
    SizeType 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 or equal to zero.

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 an element for which the predicate is true.

Public function Const

ElementType ...

 

end()

Public function Const

TArray< std:...

 

FilterByPredicate

(
    Predicate Pred
)

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

Public function Const

bool

 

Find

(
    const ElementType& Item,
    SizeType& Index
)

Finds element within the array.

Public function Const

SizeType

 

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,
    SizeType& Index
)

Finds element within the array starting from the end.

Public function Const

SizeType

 

FindLastByPredicate

(
    Predicate Pred
)

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

Public function Const

SizeType

 

FindLastByPredicate

(
    Predicate Pred,
    SizeType StartIndex
)

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

Public function Const

ElementType ...

 

GetData()

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

Public function Static

constexpr si...

 

GetTypeAlignment()

Helper function returning the alignment of the inner type.

Public function Static

constexpr si...

 

GetTypeSize()

Helper function returning the size of the inner type.

Public function Const

SizeType

 

IndexOfByKey

(
    const KeyType& Key
)

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

Public function Const

SizeType

 

IndexOfByPredicate

(
    Predicate Pred
)

Finds an item by predicate.

Public function Const

bool

 

IsEmpty()

Returns true if the array view is empty and contains no elements.

Public function Const

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.

Public function Const

ElementType ...

 

Last

(
    SizeType IndexFromTheEnd
)

Returns n-th last element from the array.

Public function Const

TArrayView

 

Left

(
    SizeType Count
)

Returns the left-most part of the view by taking the given number of elements from the left.

Public function Const

TArrayView

 

LeftChop

(
    SizeType Count
)

Returns the left-most part of the view by chopping the given number of elements from the right.

Public function

void

 

LeftChopInline

(
    SizeType CharCount
)

Modifies the view by chopping the given number of elements from the right.

Public function

void

 

LeftInline

(
    SizeType CharCount
)

Modifies the view to be the given number of elements from the left.

Public function Const

TArrayView

 

Mid

(
    SizeType Index,
    SizeType Count
)

Returns the middle part of the view by taking up to the given number of elements from the given position.

Public function

void

 

MidInline

(
    SizeType Position,
    SizeType CharCount
)

Modifies the view to be the middle part by taking up to the given number of elements from the given position.

Public function Const

SizeType

 

Num()

Returns number of elements in array.

Public function Const

void

 

RangeCheck

(
    SizeType Index
)

Checks if index is in array range.

Public function Const

TReversePoin...

 

rbegin()

Public function Const

TReversePoin...

 

rend()

Public function Const

TArrayView

 

Right

(
    SizeType Count
)

Returns the right-most part of the view by taking the given number of elements from the right.

Public function Const

TArrayView

 

RightChop

(
    SizeType Count
)

Returns the right-most part of the view by chopping the given number of elements from the left.

Public function

void

 

RightChopInline

(
    SizeType CharCount
)

Modifies the view by chopping the given number of elements from the left.

Public function

void

 

RightInline

(
    SizeType CharCount
)

Modifies the view to be the given number of elements from the right.

Public function Const

TArrayView

 

Slice

(
    SizeType Index,
    SizeType InNum
)

Returns a sliced view This is similar to Mid(), but with a narrow contract, i.e. slicing outside of the range of the view is illegal.

Public function Const

void

 

SliceRangeCheck

(
    SizeType Index,
    SizeType InNum
)

Checks if a slice range [Index, Index+InNum) is in array range.

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[]

(
    SizeType Index
)

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

Typedefs

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Cancel