| TArrayView
|
Module |
|
Header |
/Engine/Source/Runtime/Core/Public/Containers/ArrayView.h |
Include |
#include "Containers/ArrayView.h" |
template<typename InElementType, typename InSizeType>
class TArrayView
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
Name | Description | |
---|---|---|
|
TArrayView() |
Constructor. |
|
TArrayView ( |
Constructor from another range |
|
TArrayView ( |
|
|
TArrayView ( |
Construct a view of an initializer list. |
|
TArrayView ( |
Construct a view of an arbitrary pointer |
Name | Description | ||
---|---|---|---|
|
ElementType ... |
begin() |
DO NOT USE DIRECTLY STL-like iterators to enable range-based for loop support. |
|
void |
CheckInvariants() |
Checks array invariants: if array size is greater than or equal to zero. |
|
bool |
Contains ( |
Checks if this array contains the element. |
|
bool |
ContainsByPredicate ( |
Checks if this array contains an element for which the predicate is true. |
|
ElementType ... |
end() |
|
|
TArray< type... |
FilterByPredicate ( |
Filters the elements in the array based on a predicate functor. |
|
bool |
Find ( |
Finds element within the array. |
|
Find ( |
Finds element within the array. |
|
|
ElementType ... |
FindByKey ( |
Finds an item by key (assuming the ElementType overloads operator== for the comparison). |
|
ElementType ... |
FindByPredicate ( |
Finds an element which matches a predicate functor. |
|
bool |
FindLast ( |
Finds element within the array starting from the end. |
|
FindLastByPredicate ( |
Finds element within the array starting from the end. Uses predicate to match element. |
|
|
FindLastByPredicate ( |
Finds element within the array starting from StartIndex and going backwards. |
|
|
ElementType ... |
GetData() |
Helper function for returning a typed pointer to the first array entry. |
|
constexpr si... |
GetTypeAlignment() |
Helper function returning the alignment of the inner type. |
|
constexpr si... |
GetTypeSize() |
Helper function returning the size of the inner type. |
|
IndexOfByKey ( |
Finds an item by key (assuming the ElementType overloads operator== for the comparison). |
|
|
IndexOfByPredicate ( |
Finds an item by predicate. |
|
|
bool |
IsEmpty() |
Returns true if the array view is empty and contains no elements. |
|
bool |
IsValidIndex ( |
Tests if index is valid, i.e. greater than or equal to zero, and less than the number of elements in the array. |
|
ElementType ... |
Last ( |
Returns n-th last element from the array. |
|
Left ( |
Returns the left-most part of the view by taking the given number of elements from the left. |
|
|
LeftChop ( |
Returns the left-most part of the view by chopping the given number of elements from the right. |
|
|
void |
LeftChopInline ( |
Modifies the view by chopping the given number of elements from the right. |
|
void |
LeftInline ( |
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. |
|
|
void |
MidInline |
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. |
|
|
void |
RangeCheck ( |
Checks if index is in array range. |
|
Right ( |
Returns the right-most part of the view by taking the given number of elements from the right. |
|
|
RightChop ( |
Returns the right-most part of the view by chopping the given number of elements from the left. |
|
|
void |
RightChopInline ( |
Modifies the view by chopping the given number of elements from the left. |
|
void |
RightInline ( |
Modifies the view to be the given number of elements from the right. |
|
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. |
|
|
void |
SliceRangeCheck |
Checks if a slice range [Index, Index+InNum) is in array range. |
|
void |
Sort() |
Sorts the array assuming < operator is defined for the item type. |
|
void |
Sort ( |
Sorts the array using user define predicate class. |
|
void |
StableSort() |
Stable sorts the array assuming < operator is defined for the item type. |
|
void |
StableSort ( |
Stable sorts the array using user defined predicate class. |
Name | Description | ||
---|---|---|---|
|
ElementType ... |
operator[] ( |
Array bracket operator. Returns reference to element at given index. |