Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
TArrayView< InElementType, InSizeType > Class Template Reference

#include <ArrayView.h>

Public Types

using ElementType = InElementType
 
using SizeType = InSizeType
 

Public Member Functions

 TArrayView ()
 
template<typename OtherRangeType , typename CVUnqualifiedOtherRangeType = typename TRemoveCV<typename TRemoveReference<OtherRangeType>::Type>::Type, typename = typename TEnableIf< TAnd< TIsContiguousContainer<CVUnqualifiedOtherRangeType>, TOr< TIsCompatibleRangeType<OtherRangeType>, TIsReinterpretableRangeType<OtherRangeType> > >::Value >::Type, std::enable_if_t< TIsTArrayView< std::decay_t< OtherRangeType > >::Value > * = nullptr>
FORCEINLINE TArrayView (OtherRangeType &&Other)
 
template<typename OtherRangeType , typename CVUnqualifiedOtherRangeType = typename TRemoveCV<typename TRemoveReference<OtherRangeType>::Type>::Type, typename = typename TEnableIf< TAnd< TIsContiguousContainer<CVUnqualifiedOtherRangeType>, TOr< TIsCompatibleRangeType<OtherRangeType>, TIsReinterpretableRangeType<OtherRangeType> > >::Value >::Type, std::enable_if_t<!TIsTArrayView< std::decay_t< OtherRangeType > >::Value > * = nullptr>
FORCEINLINE TArrayView (OtherRangeType &&Other UE_LIFETIMEBOUND)
 
template<typename OtherElementType , typename = typename TEnableIf<TIsCompatibleElementType<OtherElementType>::Value>::Type>
FORCEINLINE TArrayView (OtherElementType *InData UE_LIFETIMEBOUND, SizeType InCount)
 
FORCEINLINE TArrayView (std::initializer_list< ElementType > List UE_LIFETIMEBOUND)
 
FORCEINLINE ElementTypeGetData () const
 
FORCEINLINE void CheckInvariants () const
 
FORCEINLINE void RangeCheck (SizeType Index) const
 
FORCEINLINE void SliceRangeCheck (SizeType Index, SizeType InNum) const
 
FORCEINLINE bool IsValidIndex (SizeType Index) const
 
bool IsEmpty () const
 
FORCEINLINE SizeType Num () const
 
FORCEINLINE ElementTypeoperator[] (SizeType Index) const
 
FORCEINLINE ElementTypeLast (SizeType IndexFromTheEnd=0) const
 
FORCEINLINE TArrayView Slice (SizeType Index, SizeType InNum) const
 
TArrayView Left (SizeType Count) const
 
TArrayView LeftChop (SizeType Count) const
 
TArrayView Right (SizeType Count) const
 
TArrayView RightChop (SizeType Count) const
 
TArrayView Mid (SizeType Index, SizeType Count=TNumericLimits< SizeType >::Max()) const
 
void LeftInline (SizeType CharCount)
 
void LeftChopInline (SizeType CharCount)
 
void RightInline (SizeType CharCount)
 
void RightChopInline (SizeType CharCount)
 
void MidInline (SizeType Position, SizeType CharCount=TNumericLimits< SizeType >::Max())
 
FORCEINLINE bool Find (const ElementType &Item, SizeType &Index) const
 
SizeType Find (const ElementType &Item) const
 
FORCEINLINE bool FindLast (const ElementType &Item, SizeType &Index) const
 
template<typename Predicate >
SizeType FindLastByPredicate (Predicate Pred, SizeType StartIndex) const
 
template<typename Predicate >
FORCEINLINE SizeType FindLastByPredicate (Predicate Pred) const
 
template<typename KeyType >
SizeType IndexOfByKey (const KeyType &Key) const
 
template<typename Predicate >
SizeType IndexOfByPredicate (Predicate Pred) const
 
template<typename KeyType >
ElementTypeFindByKey (const KeyType &Key) const
 
template<typename Predicate >
ElementTypeFindByPredicate (Predicate Pred) const
 
template<typename Predicate >
TArray< typename TRemoveConst< ElementType >::Type > FilterByPredicate (Predicate Pred) const
 
template<typename ComparisonType >
bool Contains (const ComparisonType &Item) const
 
template<typename Predicate >
FORCEINLINE bool ContainsByPredicate (Predicate Pred) const
 
FORCEINLINE ElementTypebegin () const
 
FORCEINLINE ElementTypeend () const
 
void Sort ()
 
template<class PREDICATE_CLASS >
void Sort (const PREDICATE_CLASS &Predicate)
 
void StableSort ()
 
template<class PREDICATE_CLASS >
void StableSort (const PREDICATE_CLASS &Predicate)
 

Static Public Member Functions

static FORCEINLINE constexpr size_t GetTypeSize ()
 
static FORCEINLINE constexpr size_t GetTypeAlignment ()
 

Private Types

template<typename T >
using TIsCompatibleElementType = ArrayViewPrivate::TIsCompatibleElementType<T, ElementType>
 
template<typename T >
using TIsCompatibleRangeType = ArrayViewPrivate::TIsCompatibleRangeType<T, ElementType>
 
template<typename T >
using TIsReinterpretableRangeType = ArrayViewPrivate::TIsReinterpretableRangeType<T, ElementType>
 

Private Attributes

ElementTypeDataPtr
 
SizeType ArrayNum
 

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

Definition at line 129 of file ArrayView.h.

Member Typedef Documentation

◆ ElementType

Definition at line 132 of file ArrayView.h.

◆ SizeType

Definition at line 133 of file ArrayView.h.

◆ TIsCompatibleElementType

Definition at line 148 of file ArrayView.h.

◆ TIsCompatibleRangeType

Definition at line 151 of file ArrayView.h.

◆ TIsReinterpretableRangeType

Definition at line 154 of file ArrayView.h.

Constructor & Destructor Documentation

◆ TArrayView() [1/5]

Constructor.

Definition at line 140 of file ArrayView.h.

◆ TArrayView() [2/5]

template<typename OtherRangeType , typename CVUnqualifiedOtherRangeType = typename TRemoveCV<typename TRemoveReference<OtherRangeType>::Type>::Type, typename = typename TEnableIf< TAnd< TIsContiguousContainer<CVUnqualifiedOtherRangeType>, TOr< TIsCompatibleRangeType<OtherRangeType>, TIsReinterpretableRangeType<OtherRangeType> > >::Value >::Type, std::enable_if_t< TIsTArrayView< std::decay_t< OtherRangeType > >::Value > * = nullptr>
FORCEINLINE TArrayView< InElementType, InSizeType >::TArrayView ( OtherRangeType && Other)
inline

Constructor from another range

Parameters
OtherThe source range to copy

Definition at line 176 of file ArrayView.h.

◆ TArrayView() [3/5]

template<typename OtherRangeType , typename CVUnqualifiedOtherRangeType = typename TRemoveCV<typename TRemoveReference<OtherRangeType>::Type>::Type, typename = typename TEnableIf< TAnd< TIsContiguousContainer<CVUnqualifiedOtherRangeType>, TOr< TIsCompatibleRangeType<OtherRangeType>, TIsReinterpretableRangeType<OtherRangeType> > >::Value >::Type, std::enable_if_t<!TIsTArrayView< std::decay_t< OtherRangeType > >::Value > * = nullptr>
FORCEINLINE TArrayView< InElementType, InSizeType >::TArrayView ( OtherRangeType &&Other UE_LIFETIMEBOUND)
inline

Definition at line 201 of file ArrayView.h.

◆ TArrayView() [4/5]

template<typename OtherElementType , typename = typename TEnableIf<TIsCompatibleElementType<OtherElementType>::Value>::Type>
FORCEINLINE TArrayView< InElementType, InSizeType >::TArrayView ( OtherElementType *InData UE_LIFETIMEBOUND,
SizeType InCount )
inline

Construct a view of an arbitrary pointer

Parameters
InDataThe data to view
InCountThe number of elements

Definition at line 221 of file ArrayView.h.

◆ TArrayView() [5/5]

FORCEINLINE TArrayView< InElementType, InSizeType >::TArrayView ( std::initializer_list< ElementType > List UE_LIFETIMEBOUND)
inline

Construct a view of an initializer list.

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

Definition at line 233 of file ArrayView.h.

Member Function Documentation

◆ begin()

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

Definition at line 686 of file ArrayView.h.

◆ CheckInvariants()

FORCEINLINE void TArrayView< InElementType, InSizeType >::CheckInvariants ( ) const
inline

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

Definition at line 273 of file ArrayView.h.

◆ Contains()

Checks if this array contains the element.

Returns
True if found. False otherwise.

Definition at line 656 of file ArrayView.h.

◆ ContainsByPredicate()

template<typename Predicate >
FORCEINLINE bool TArrayView< InElementType, InSizeType >::ContainsByPredicate ( Predicate Pred) const
inline

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

Parameters
Predicateto use
Returns
True if found. False otherwise.

Definition at line 676 of file ArrayView.h.

◆ end()

Definition at line 687 of file ArrayView.h.

◆ FilterByPredicate()

template<typename Predicate >
TArray< typename TRemoveConst< ElementType >::Type > TArrayView< InElementType, InSizeType >::FilterByPredicate ( Predicate Pred) const
inline

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.

Definition at line 637 of file ArrayView.h.

◆ Find() [1/2]

Finds element within the array.

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

Definition at line 476 of file ArrayView.h.

◆ Find() [2/2]

Finds element within the array.

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

Definition at line 463 of file ArrayView.h.

◆ FindByKey()

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

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.

Definition at line 593 of file ArrayView.h.

◆ FindByPredicate()

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

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.

Definition at line 615 of file ArrayView.h.

◆ FindLast()

FORCEINLINE bool TArrayView< InElementType, InSizeType >::FindLast ( const ElementType & Item,
SizeType & Index ) const
inline

Finds element within the array starting from the end.

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

Definition at line 497 of file ArrayView.h.

◆ FindLastByPredicate() [1/2]

template<typename Predicate >
FORCEINLINE SizeType TArrayView< InElementType, InSizeType >::FindLastByPredicate ( Predicate Pred) const
inline

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.

Definition at line 534 of file ArrayView.h.

◆ FindLastByPredicate() [2/2]

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

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.

Definition at line 512 of file ArrayView.h.

◆ GetData()

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

Returns
Pointer to first array entry.

Definition at line 247 of file ArrayView.h.

◆ GetTypeAlignment()

static FORCEINLINE constexpr size_t TArrayView< InElementType, InSizeType >::GetTypeAlignment ( )
inlinestaticconstexpr

Helper function returning the alignment of the inner type.

Definition at line 265 of file ArrayView.h.

◆ GetTypeSize()

Helper function returning the size of the inner type.

Returns
Size in bytes of array type.

Definition at line 257 of file ArrayView.h.

◆ IndexOfByKey()

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

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.

Definition at line 549 of file ArrayView.h.

◆ IndexOfByPredicate()

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

Finds an item by predicate.

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

Definition at line 571 of file ArrayView.h.

◆ IsEmpty()

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

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

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

Definition at line 322 of file ArrayView.h.

◆ IsValidIndex()

FORCEINLINE bool TArrayView< InElementType, InSizeType >::IsValidIndex ( SizeType Index) const
inline

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.

Definition at line 311 of file ArrayView.h.

◆ Last()

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

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.

Definition at line 356 of file ArrayView.h.

◆ Left()

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

Definition at line 379 of file ArrayView.h.

◆ LeftChop()

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

Definition at line 385 of file ArrayView.h.

◆ LeftChopInline()

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

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

Definition at line 432 of file ArrayView.h.

◆ LeftInline()

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

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

Definition at line 426 of file ArrayView.h.

◆ Mid()

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

Definition at line 405 of file ArrayView.h.

◆ MidInline()

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

Definition at line 450 of file ArrayView.h.

◆ Num()

Returns number of elements in array.

Returns
Number of elements in array.

Definition at line 332 of file ArrayView.h.

◆ operator[]()

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

Returns
Reference to indexed element.

Definition at line 342 of file ArrayView.h.

◆ RangeCheck()

Checks if index is in array range.

Parameters
IndexIndex to check.

Definition at line 283 of file ArrayView.h.

◆ Right()

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

Definition at line 391 of file ArrayView.h.

◆ RightChop()

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

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

Definition at line 398 of file ArrayView.h.

◆ RightChopInline()

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

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

Definition at line 444 of file ArrayView.h.

◆ RightInline()

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

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

Definition at line 438 of file ArrayView.h.

◆ Slice()

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

Definition at line 372 of file ArrayView.h.

◆ SliceRangeCheck()

FORCEINLINE void TArrayView< InElementType, InSizeType >::SliceRangeCheck ( SizeType Index,
SizeType InNum ) const
inline

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.

Definition at line 297 of file ArrayView.h.

◆ Sort() [1/2]

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

Definition at line 693 of file ArrayView.h.

◆ Sort() [2/2]

Sorts the array using user define predicate class.

Parameters
PredicatePredicate class instance.

Definition at line 704 of file ArrayView.h.

◆ StableSort() [1/2]

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

Stable sort is slower than non-stable algorithm.

Definition at line 714 of file ArrayView.h.

◆ StableSort() [2/2]

Stable sorts the array using user defined predicate class.

Stable sort is slower than non-stable algorithm.

Parameters
PredicatePredicate class instance

Definition at line 727 of file ArrayView.h.

Member Data Documentation

◆ ArrayNum

Definition at line 734 of file ArrayView.h.

◆ DataPtr

Definition at line 733 of file ArrayView.h.


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