UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TArrayView< InElementType, InSizeType > Class Template Reference

#include <ArrayView.h>

Public Types

using ElementType = InElementType
 
using SizeType = InSizeType
 
using IntrusiveUnsetOptionalStateType = TArrayView
 

Public Member Functions

constexpr TArrayView (const TArrayView &)=default
 
TArrayViewoperator= (const TArrayView &)=default
 
 ~TArrayView ()=default
 
constexpr TArrayView ()
 
template<typename OtherRangeType , typename CVUnqualifiedOtherRangeType = std::remove_cv_t<std::remove_reference_t<OtherRangeType>> UE_REQUIRES( TAnd< TIsContiguousContainer<CVUnqualifiedOtherRangeType>, TOr< TIsCompatibleRangeType<OtherRangeType>, TIsReinterpretableRangeType<OtherRangeType> > >::Value && TIsTArrayView_V<CVUnqualifiedOtherRangeType> && !std::is_same_v<CVUnqualifiedOtherRangeType, TArrayView> )>
constexpr TArrayView (OtherRangeType &&Other)
 
template<typename OtherRangeType , typename CVUnqualifiedOtherRangeType = std::remove_cv_t<std::remove_reference_t<OtherRangeType>> UE_REQUIRES( TAnd< TIsContiguousContainer<CVUnqualifiedOtherRangeType>, TOr< TIsCompatibleRangeType<OtherRangeType>, TIsReinterpretableRangeType<OtherRangeType> > >::Value && !TIsTArrayView_V<CVUnqualifiedOtherRangeType> )>
constexpr TArrayView (OtherRangeType &&Other UE_LIFETIMEBOUND)
 
template<typename OtherElementType >
constexpr TArrayView (OtherElementType *InData UE_LIFETIMEBOUND, SizeType InCount)
 
constexpr TArrayView (std::initializer_list< ElementType > List UE_LIFETIMEBOUND)
 
constexpr TArrayView (FIntrusiveUnsetOptionalState)
 
constexpr bool UEOpEquals (FIntrusiveUnsetOptionalState) const
 
UE_FORCEINLINE_HINT constexpr ElementTypeGetData () const
 
UE_FORCEINLINE_HINT constexpr void CheckInvariants () const
 
constexpr void RangeCheck (SizeType Index) const
 
constexpr void SliceRangeCheck (SizeType Index, SizeType InNum) const
 
UE_FORCEINLINE_HINT constexpr bool IsValidIndex (SizeType Index) const
 
constexpr bool IsEmpty () const
 
UE_FORCEINLINE_HINT constexpr SizeType Num () const
 
UE_FORCEINLINE_HINT constexpr SIZE_T NumBytes () const
 
constexpr ElementTypeoperator[] (SizeType Index) const
 
constexpr ElementTypeLast (SizeType IndexFromTheEnd=0) const
 
constexpr TArrayView Slice (SizeType Index, SizeType InNum) const
 
constexpr TArrayView Left (SizeType Count) const
 
constexpr TArrayView LeftChop (SizeType Count) const
 
constexpr TArrayView Right (SizeType Count) const
 
constexpr TArrayView RightChop (SizeType Count) const
 
constexpr TArrayView Mid (SizeType Index, SizeType Count=TNumericLimits< SizeType >::Max()) const
 
constexpr void LeftInline (SizeType CharCount)
 
constexpr void LeftChopInline (SizeType CharCount)
 
constexpr void RightInline (SizeType CharCount)
 
constexpr void RightChopInline (SizeType CharCount)
 
constexpr void MidInline (SizeType Position, SizeType CharCount=TNumericLimits< SizeType >::Max())
 
constexpr bool Find (const ElementType &Item, SizeType &Index) const
 
constexpr SizeType Find (const ElementType &Item) const
 
constexpr bool FindLast (const ElementType &Item, SizeType &Index) const
 
constexpr SizeType FindLast (const ElementType &Item) const
 
template<typename Predicate >
constexpr SizeType FindLastByPredicate (Predicate Pred, SizeType StartIndex) const
 
template<typename Predicate >
UE_FORCEINLINE_HINT constexpr SizeType FindLastByPredicate (Predicate Pred) const
 
template<typename KeyType >
constexpr SizeType IndexOfByKey (const KeyType &Key) const
 
template<typename Predicate >
constexpr SizeType IndexOfByPredicate (Predicate Pred) const
 
template<typename KeyType >
constexpr ElementTypeFindByKey (const KeyType &Key) const
 
template<typename Predicate >
constexpr ElementTypeFindByPredicate (Predicate Pred) const
 
template<typename Predicate >
constexpr TArray< std::remove_const_t< ElementType > > FilterByPredicate (Predicate Pred) const
 
template<typename ComparisonType >
constexpr bool Contains (const ComparisonType &Item) const
 
template<typename Predicate >
UE_FORCEINLINE_HINT constexpr bool ContainsByPredicate (Predicate Pred) const
 
UE_FORCEINLINE_HINT constexpr ElementTypebegin () const
 
UE_FORCEINLINE_HINT constexpr ElementTypeend () const
 
UE_FORCEINLINE_HINT constexpr TReversePointerIterator< ElementTyperbegin () const
 
UE_FORCEINLINE_HINT constexpr TReversePointerIterator< ElementTyperend () const
 
constexpr void Sort ()
 
template<class PREDICATE_CLASS >
constexpr void Sort (const PREDICATE_CLASS &Predicate)
 
constexpr void StableSort ()
 
template<class PREDICATE_CLASS >
constexpr void StableSort (const PREDICATE_CLASS &Predicate)
 
template<typename OtherElementType , typename OtherSizeType >
bool UEOpEquals (TArrayView< OtherElementType, OtherSizeType >) const =delete
 
template<typename RangeType >
requires (std::is_convertible_v<decltype(UE::Core::ArrayView::Private::GetDataHelper(std::declval<RangeType&>())), const ElementType*>)
bool UEOpEquals (RangeType &&Rhs) const
 

Static Public Member Functions

static UE_FORCEINLINE_HINT constexpr size_t GetTypeSize ()
 
static UE_FORCEINLINE_HINT constexpr size_t GetTypeAlignment ()
 

Static Public Attributes

static constexpr bool bHasIntrusiveUnsetOptionalState = true
 

Detailed Description

template<typename InElementType, typename InSizeType>
class TArrayView< InElementType, InSizeType >

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

Member Typedef Documentation

◆ ElementType

◆ IntrusiveUnsetOptionalStateType

using TArrayView< InElementType, InSizeType >::IntrusiveUnsetOptionalStateType = TArrayView

◆ SizeType

Constructor & Destructor Documentation

◆ TArrayView() [1/7]

◆ ~TArrayView()

◆ TArrayView() [2/7]

◆ TArrayView() [3/7]

template<typename OtherRangeType , typename CVUnqualifiedOtherRangeType = std::remove_cv_t<std::remove_reference_t<OtherRangeType>> UE_REQUIRES( TAnd< TIsContiguousContainer<CVUnqualifiedOtherRangeType>, TOr< TIsCompatibleRangeType<OtherRangeType>, TIsReinterpretableRangeType<OtherRangeType> > >::Value && TIsTArrayView_V<CVUnqualifiedOtherRangeType> && !std::is_same_v<CVUnqualifiedOtherRangeType, TArrayView> )>
constexpr TArrayView< InElementType, InSizeType >::TArrayView ( OtherRangeType &&  Other)
inlineconstexpr

Constructor from another range

Parameters
OtherThe source range to copy

◆ TArrayView() [4/7]

template<typename OtherRangeType , typename CVUnqualifiedOtherRangeType = std::remove_cv_t<std::remove_reference_t<OtherRangeType>> UE_REQUIRES( TAnd< TIsContiguousContainer<CVUnqualifiedOtherRangeType>, TOr< TIsCompatibleRangeType<OtherRangeType>, TIsReinterpretableRangeType<OtherRangeType> > >::Value && !TIsTArrayView_V<CVUnqualifiedOtherRangeType> )>
constexpr TArrayView< InElementType, InSizeType >::TArrayView ( OtherRangeType &&Other  UE_LIFETIMEBOUND)
inlineconstexpr

◆ TArrayView() [5/7]

Construct a view of an arbitrary pointer

Parameters
InDataThe data to view
InCountThe number of elements

◆ TArrayView() [6/7]

constexpr TArrayView< InElementType, InSizeType >::TArrayView ( std::initializer_list< ElementType > List  UE_LIFETIMEBOUND)
inlineconstexpr

Construct a view of an initializer list.

The caller is responsible for ensuring that the view does not outlive the initializer list.

◆ TArrayView() [7/7]

Member Function Documentation

◆ begin()

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

◆ CheckInvariants()

UE_FORCEINLINE_HINT constexpr void TArrayView< InElementType, InSizeType >::CheckInvariants ( ) const
inlineconstexpr

Checks array invariants: if array size is greater than or equal to zero.

◆ Contains()

constexpr bool TArrayView< InElementType, InSizeType >::Contains ( const ComparisonType Item) const
inlineconstexpr

Checks if this array contains the element.

Returns
True if found. False otherwise.

◆ ContainsByPredicate()

template<typename Predicate >
UE_FORCEINLINE_HINT constexpr bool TArrayView< InElementType, InSizeType >::ContainsByPredicate ( Predicate  Pred) const
inlineconstexpr

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

Parameters
Predicateto use
Returns
True if found. False otherwise.

◆ end()

◆ FilterByPredicate()

template<typename Predicate >
constexpr TArray< std::remove_const_t< ElementType > > TArrayView< InElementType, InSizeType >::FilterByPredicate ( Predicate  Pred) const
inlineconstexpr

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

Parameters
PredThe functor to apply to each element.
Returns
TArray with the same type as this object which contains the subset of elements for which the functor returns true.

◆ Find() [1/2]

constexpr SizeType TArrayView< InElementType, InSizeType >::Find ( const ElementType Item) const
inlineconstexpr

Finds element within the array.

Parameters
ItemItem to look for.
Returns
Index of the found element. INDEX_NONE otherwise.

◆ Find() [2/2]

constexpr bool TArrayView< InElementType, InSizeType >::Find ( const ElementType Item,
SizeType Index 
) const
inlineconstexpr

Finds element within the array.

Parameters
ItemItem to look for.
IndexOutput parameter. Found index.
Returns
True if found. False otherwise.

◆ FindByKey()

template<typename KeyType >
constexpr ElementType * TArrayView< InElementType, InSizeType >::FindByKey ( const KeyType &  Key) const
inlineconstexpr

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

Parameters
KeyThe key to search by.
Returns
Pointer to the first matching element, or nullptr if none is found.

◆ FindByPredicate()

template<typename Predicate >
constexpr ElementType * TArrayView< InElementType, InSizeType >::FindByPredicate ( Predicate  Pred) const
inlineconstexpr

Finds an element which matches a predicate functor.

Parameters
PredThe functor to apply to each element.
Returns
Pointer to the first element for which the predicate returns true, or nullptr if none is found.

◆ FindLast() [1/2]

constexpr SizeType TArrayView< InElementType, InSizeType >::FindLast ( const ElementType Item) const
inlineconstexpr

Finds element within the array starting from the end.

Parameters
ItemItem to look for.
Returns
Index of the found element. INDEX_NONE otherwise.

◆ FindLast() [2/2]

constexpr bool TArrayView< InElementType, InSizeType >::FindLast ( const ElementType Item,
SizeType Index 
) const
inlineconstexpr

Finds element within the array starting from the end.

Parameters
ItemItem to look for.
IndexOutput parameter. Found index.
Returns
True if found. False otherwise.

◆ FindLastByPredicate() [1/2]

template<typename Predicate >
UE_FORCEINLINE_HINT constexpr SizeType TArrayView< InElementType, InSizeType >::FindLastByPredicate ( Predicate  Pred) const
inlineconstexpr

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

Parameters
PredPredicate taking array element and returns true if element matches search criteria, false otherwise.
Returns
Index of the found element. INDEX_NONE otherwise.

◆ FindLastByPredicate() [2/2]

template<typename Predicate >
constexpr SizeType TArrayView< InElementType, InSizeType >::FindLastByPredicate ( Predicate  Pred,
SizeType  StartIndex 
) const
inlineconstexpr

Finds element within the array starting from StartIndex and going backwards. Uses predicate to match element.

Parameters
PredPredicate taking array element and returns true if element matches search criteria, false otherwise.
StartIndexIndex of element from which to start searching.
Returns
Index of the found element. INDEX_NONE otherwise.

◆ GetData()

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

Returns
Pointer to first array entry.

◆ GetTypeAlignment()

Helper function returning the alignment of the inner type.

◆ GetTypeSize()

Helper function returning the size of the inner type.

Returns
Size in bytes of array type.

◆ IndexOfByKey()

template<typename KeyType >
constexpr SizeType TArrayView< InElementType, InSizeType >::IndexOfByKey ( const KeyType &  Key) const
inlineconstexpr

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

Parameters
KeyThe key to search by.
Returns
Index to the first matching element, or INDEX_NONE if none is found.

◆ IndexOfByPredicate()

template<typename Predicate >
constexpr SizeType TArrayView< InElementType, InSizeType >::IndexOfByPredicate ( Predicate  Pred) const
inlineconstexpr

Finds an item by predicate.

Parameters
PredThe predicate to match.
Returns
Index to the first matching element, or INDEX_NONE if none is found.

◆ IsEmpty()

constexpr bool TArrayView< InElementType, InSizeType >::IsEmpty ( ) const
inlineconstexpr

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

Returns
True if the array view is empty.
See also
Num

◆ IsValidIndex()

UE_FORCEINLINE_HINT constexpr bool TArrayView< InElementType, InSizeType >::IsValidIndex ( SizeType  Index) const
inlineconstexpr

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

Parameters
IndexIndex to test.
Returns
True if index is valid. False otherwise.

◆ Last()

constexpr ElementType & TArrayView< InElementType, InSizeType >::Last ( SizeType  IndexFromTheEnd = 0) const
inlineconstexpr

Returns n-th last element from the array.

Parameters
IndexFromTheEnd(Optional) Index from the end of array. Default is 0.
Returns
Reference to n-th last element from the array.

◆ Left()

constexpr TArrayView TArrayView< InElementType, InSizeType >::Left ( SizeType  Count) const
inlineconstexpr

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

◆ LeftChop()

constexpr TArrayView TArrayView< InElementType, InSizeType >::LeftChop ( SizeType  Count) const
inlineconstexpr

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

◆ LeftChopInline()

constexpr void TArrayView< InElementType, InSizeType >::LeftChopInline ( SizeType  CharCount)
inlineconstexpr

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

◆ LeftInline()

constexpr void TArrayView< InElementType, InSizeType >::LeftInline ( SizeType  CharCount)
inlineconstexpr

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

◆ Mid()

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

◆ MidInline()

constexpr void TArrayView< InElementType, InSizeType >::MidInline ( SizeType  Position,
SizeType  CharCount = TNumericLimits<SizeType>::Max() 
)
inlineconstexpr

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

◆ Num()

Returns number of elements in array.

Returns
Number of elements in array.

◆ NumBytes()

Returns
Number of bytes used, excluding slack

◆ operator=()

◆ operator[]()

constexpr ElementType & TArrayView< InElementType, InSizeType >::operator[] ( SizeType  Index) const
inlineconstexpr

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

Returns
Reference to indexed element.

◆ RangeCheck()

constexpr void TArrayView< InElementType, InSizeType >::RangeCheck ( SizeType  Index) const
inlineconstexpr

Checks if index is in array range.

Parameters
IndexIndex to check.

◆ rbegin()

◆ rend()

◆ Right()

constexpr TArrayView TArrayView< InElementType, InSizeType >::Right ( SizeType  Count) const
inlineconstexpr

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

◆ RightChop()

constexpr TArrayView TArrayView< InElementType, InSizeType >::RightChop ( SizeType  Count) const
inlineconstexpr

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

◆ RightChopInline()

constexpr void TArrayView< InElementType, InSizeType >::RightChopInline ( SizeType  CharCount)
inlineconstexpr

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

◆ RightInline()

constexpr void TArrayView< InElementType, InSizeType >::RightInline ( SizeType  CharCount)
inlineconstexpr

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

◆ Slice()

constexpr TArrayView TArrayView< InElementType, InSizeType >::Slice ( SizeType  Index,
SizeType  InNum 
) const
inlineconstexpr

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.

Parameters
Indexstarting index of the new view
InNumnumber of elements in the new view
Returns
Sliced view
See also
Mid

◆ SliceRangeCheck()

constexpr void TArrayView< InElementType, InSizeType >::SliceRangeCheck ( SizeType  Index,
SizeType  InNum 
) const
inlineconstexpr

Checks if a slice range [Index, Index+InNum) is in array range. Length is 0 is allowed on empty arrays; Index must be 0 in that case.

Parameters
IndexStarting index of the slice.
InNumLength of the slice.

◆ Sort() [1/2]

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

Note
: If your array contains raw pointers, they will be automatically dereferenced during sorting. Therefore, your array will be sorted by the values being pointed to, rather than the pointers' values. If this is not desirable, please use Algo::Sort(MyArray) directly instead. The auto-dereferencing behavior does not occur with smart pointers.

◆ Sort() [2/2]

template<class PREDICATE_CLASS >
constexpr void TArrayView< InElementType, InSizeType >::Sort ( const PREDICATE_CLASS Predicate)
inlineconstexpr

Sorts the array using user define predicate class.

Parameters
PredicatePredicate class instance.
Note
: If your array contains raw pointers, they will be automatically dereferenced during sorting. Therefore, your predicate will be passed references rather than pointers. If this is not desirable, please use Algo::Sort(MyArray, Predicate) directly instead. The auto-dereferencing behavior does not occur with smart pointers.

◆ StableSort() [1/2]

constexpr void TArrayView< InElementType, InSizeType >::StableSort ( )
inlineconstexpr

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

Stable sort is slower than non-stable algorithm.

Note
: If your array contains raw pointers, they will be automatically dereferenced during sorting. Therefore, your array will be sorted by the values being pointed to, rather than the pointers' values. If this is not desirable, please use Algo::StableSort(MyArray) directly instead. The auto-dereferencing behavior does not occur with smart pointers.

◆ StableSort() [2/2]

template<class PREDICATE_CLASS >
constexpr void TArrayView< InElementType, InSizeType >::StableSort ( const PREDICATE_CLASS Predicate)
inlineconstexpr

Stable sorts the array using user defined predicate class.

Stable sort is slower than non-stable algorithm.

Parameters
PredicatePredicate class instance
Note
: If your array contains raw pointers, they will be automatically dereferenced during sorting. Therefore, your predicate will be passed references rather than pointers. If this is not desirable, please use Algo::StableSort(MyArray, Predicate) directly instead. The auto-dereferencing behavior does not occur with smart pointers.

◆ UEOpEquals() [1/3]

◆ UEOpEquals() [2/3]

template<typename RangeType >
requires (std::is_convertible_v<decltype(UE::Core::ArrayView::Private::GetDataHelper(std::declval<RangeType&>())), const ElementType*>)
bool TArrayView< InElementType, InSizeType >::UEOpEquals ( RangeType &&  Rhs) const
inline

Equality operator.

Parameters
LhsAnother ranged type to compare.
Returns
True if this array view's contents and the other ranged type match. False otherwise.

◆ UEOpEquals() [3/3]

Member Data Documentation

◆ bHasIntrusiveUnsetOptionalState

constexpr bool TArrayView< InElementType, InSizeType >::bHasIntrusiveUnsetOptionalState = true
staticconstexpr

The documentation for this class was generated from the following file: