Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
Replace.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Templates/Invoke.h"
6#include "Templates/UnrealTemplate.h"
7
8namespace Algo
9{
10 /**
11 * Replaces all elements that compare equal to one value with a new value.
12 *
13 * @param Range The range to search and modify in-place.
14 * @param InOld The value to search for.
15 * @param InNew The value to copy in as a replacement.
16 */
17 template <typename RangeType, typename ValueType>
18 FORCEINLINE void Replace(RangeType&& Range, const ValueType& InOld, const ValueType& InNew)
19 {
20 for (auto& Elem : Forward<RangeType>(Range))
21 {
22 if (Elem == InOld)
23 {
24 Elem = InNew;
25 }
26 }
27 }
28
29 /**
30 * Replaces all elements that satisfy the predicate with the given value.
31 *
32 * @param Range The range to search and modify in-place.
33 * @param InPred The predicate to apply to each element.
34 * @param InNew The value to copy in as a replacement for each element satisfying the predicate.
35 */
36 template <typename RangeType, typename ValueType, typename PredicateType>
37 FORCEINLINE void ReplaceIf(RangeType&& Range, PredicateType InPred, const ValueType& InNew)
38 {
39 for (auto& Elem : Forward<RangeType>(Range))
40 {
41 if (Invoke(InPred, Elem))
42 {
43 Elem = InNew;
44 }
45 }
46 }
47}
#define FORCEINLINE
Definition Platform.h:644
Definition Heapify.h:12
FORCEINLINE void Replace(RangeType &&Range, const ValueType &InOld, const ValueType &InNew)
Definition Replace.h:18
FORCEINLINE void ReplaceIf(RangeType &&Range, PredicateType InPred, const ValueType &InNew)
Definition Replace.h:37