Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
Unique.h
Go to the documentation of this file.
1
// Copyright Epic Games, Inc. All Rights Reserved.
2
3
#
pragma
once
4
5
#
include
"Templates/UnrealTemplate.h"
6
#
include
"Templates/Invoke.h"
7
#
include
"Templates/EqualTo.h"
8
9
namespace
AlgoImpl
10
{
11
template
<
typename
T,
typename
SizeType,
typename
BinaryPredicate>
12
SizeType
Unique
(T* Array, SizeType ArraySize, BinaryPredicate Predicate)
13
{
14
if
(
ArraySize
<= 1)
15
{
16
return
ArraySize
;
17
}
18
19
T
*
Result
=
Array
;
20
for
(
T
*
Iter
=
Array
+ 1;
Iter
!=
Array
+
ArraySize
; ++
Iter
)
21
{
22
if
(!
Invoke
(
Predicate
, *
Result
, *
Iter
))
23
{
24
++
Result
;
25
if
(
Result
!=
Iter
)
26
{
27
*
Result
=
MoveTemp
(*
Iter
);
28
}
29
}
30
}
31
32
return
static_cast
<
SizeType
>(
Result
+ 1 -
Array
);
33
}
34
}
35
36
namespace
Algo
37
{
38
/**
39
* Eliminates all but the first element from every consecutive group of equivalent elements and
40
* returns past-the-end index of unique elements for the new logical end of the range.
41
*
42
* Removing is done by shifting the elements in the range in such a way that elements to be erased are overwritten.
43
* Relative order of the elements that remain is preserved and the physical size of the range is unchanged.
44
* References to an element between the new logical end and the physical end of the range are still
45
* dereferenceable, but the elements themselves have unspecified values. A call to `Unique` is typically followed by a call
46
* to a container's `SetNum` method as:
47
*
48
* ```Container.SetNum(Algo::Unique(Container));```
49
*
50
* that erases the unspecified values and reduces the physical size of the container
51
* to match its new logical size.
52
*
53
* Elements are compared using operator== or given binary predicate. The behavior is undefined if it is not an equivalence relation.
54
*
55
* See https://en.cppreference.com/w/cpp/algorithm/unique
56
*/
57
template
<
typename
RangeType>
58
auto
Unique(
RangeType
&&
Range
) ->
decltype
(
AlgoImpl
::
Unique
(
GetData
(
Range
),
GetNum
(
Range
),
TEqualTo
<>{}))
59
{
60
return
AlgoImpl
::
Unique
(
GetData
(
Range
),
GetNum
(
Range
),
TEqualTo
<>{});
61
}
62
63
template
<
typename
RangeType,
typename
BinaryPredicate>
64
auto
Unique(RangeType&& Range, BinaryPredicate Predicate) ->
decltype
(
AlgoImpl
::Unique(GetData(Range), GetNum(Range), MoveTemp(Predicate)))
65
{
66
return
AlgoImpl
::
Unique
(
GetData
(
Range
),
GetNum
(
Range
),
MoveTemp
(
Predicate
));
67
}
68
}
Algo
Definition
Heapify.h:12
AlgoImpl
Definition
IsHeap.h:12
AlgoImpl::Unique
SizeType Unique(T *Array, SizeType ArraySize, BinaryPredicate Predicate)
Definition
Unique.h:12
Downloads
ArkServerAPI_NEW
ASA
AsaApi
AsaApi
Core
Public
API
UE
Algo
Unique.h
Generated by
1.10.0