Module |
|
Header |
/Engine/Source/Runtime/Core/Public/Containers/ArrayView.h |
Include |
#include "Containers/ArrayView.h" |
template<typename InElementType>
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>"! TArrayViews cannot be implicitly constructed from an rvalue initializer lists:
, as a compile-time guard against :
SumAll({ 1, 2, 3 }); // error
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, TArrayViews are not constructible from rvalue initializer lists:
SumAll({ 1, 2, 3 }); // error
This is to avoid this issue:
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 ( |
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. |
|
CheckInvariants() |
Checks array invariants: if array size is greater than zero and less than maximum. |
|
|
Contains ( |
Checks if this array contains the element. |
|
|
ContainsByPredicate ( |
Checks if this array contains element for which the predicate is true. |
|
|
ElementType ... |
end() |
|
|
TArray< type... |
FilterByPredicate ( |
Filters the elements in the array based on a predicate functor. |
|
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. |
|
FindLast ( |
Finds element within the array starting from the end. |
|
|
FindLastByPredicate ( |
Finds element within the array starting from StartIndex and going backwards. |
|
|
FindLastByPredicate ( |
Finds element within the array starting from the end. Uses predicate to match element. |
|
|
ElementType ... |
GetData() |
Helper function for returning a typed pointer to the first array entry. |
|
size_t |
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. |
|
|
IsValidIndex ( |
Tests if index is valid, i.e. 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. |
|
Num() |
Returns number of elements in array. |
|
|
RangeCheck ( |
Checks if index is in array range. |
|
|
Slice |
Returns a sliced view |
|
|
Sort() |
Sorts the array assuming < operator is defined for the item type. |
|
|
Sort ( |
Sorts the array using user define predicate class. |
|
|
StableSort() |
Stable sorts the array assuming < operator is defined for the item type. |
|
|
StableSort ( |
Stable sorts the array using user defined predicate class. |
Name | Description | ||
---|---|---|---|
|
ElementType ... |
operator[] ( |
Array bracket operator. Returns reference to element at give index. |
Name |
Description |
---|---|
ElementType |
|
TIsCompatibleElementType |
|
TIsCompatibleRangeType |