UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TokenTest.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
8
9template <typename InValueType>
11{
12 static int32 ConstructorCalls;
13 static int32 DestructorCalls;
14 static int32 CopyConstructorCalls;
15 static int32 MoveConstructorCalls;
16 static int32 CopyAssignmentCalls;
17 static int32 MoveAssignmentCalls;
18
19public:
21
22 TTestToken(const ValueType& value)
23 {
24 ConstructorCalls++;
25 Value = value;
26 }
27
28 TTestToken() noexcept : Value(ValueType{}) { ConstructorCalls++; }
29
31 {
32 ensure(&Other != this);
33 MoveConstructorCalls++;
34 }
35
37 {
38 ensure(&Other != this);
39 CopyConstructorCalls++;
40 }
41
43 {
44 DestructorCalls++;
45 }
46
47 const ValueType& operator*() const { return Value; }
48
49 ValueType& operator*() { return Value; }
50
51 const ValueType* operator->() const { return &Value; }
52
53 ValueType* operator->() { return &Value; }
54
56 {
57 ensure(&Other != this);
58 Value = Other.Value;
59 CopyAssignmentCalls++;
60 return *this;
61 }
62
64 {
65 ensure(&Other != this);
66 Value = MoveTemp(Other.Value);
67 MoveAssignmentCalls++;
68 return *this;
69 }
70
71 bool operator<(const TTestToken& Other) const { return Value < Other.Value; }
72
73 static int32 NumConstructionCalls() { return ConstructorCalls + CopyConstructorCalls + MoveConstructorCalls; }
74
75 static int32 NumConstructorCalls() { return ConstructorCalls; }
76
77 static int32 NumCopyConstructorCalls() { return CopyConstructorCalls; }
78
79 static int32 NumMoveConstructorCalls() { return MoveConstructorCalls; }
80
81 static int32 ConstructionDestructionCallDifference() { return NumConstructionCalls() - DestructorCalls; }
82
83 static int32 NumCopyCalls() { return CopyConstructorCalls + CopyAssignmentCalls; }
84
85 static int32 NumCopyAssignmentCalls() { return CopyAssignmentCalls; }
86
87 static int32 NumMoveCalls() { return MoveConstructorCalls + MoveAssignmentCalls; }
88
89 static int32 NumMoveAssignmentCalls() { return MoveAssignmentCalls; }
90
91 static int32 NumDestructionCalls() { return DestructorCalls; }
92
94
95 static bool EvenConstructionDestructionCalls(int32 ExpectedNum)
96 {
97 return EvenConstructionDestructionCalls() && DestructorCalls == ExpectedNum;
98 }
99
100 static void Reset()
101 {
102 ConstructorCalls = 0;
103 DestructorCalls = 0;
104 CopyConstructorCalls = 0;
105 MoveConstructorCalls = 0;
106 CopyAssignmentCalls = 0;
107 MoveAssignmentCalls = 0;
108 }
109
111};
112
113template <typename InValueType>
115
116template <typename InValueType>
118
119template <typename InValueType>
121
122template <typename InValueType>
124
125template <typename InValueType>
127
128template <typename InValueType>
130
132
133template <typename InValueType>
135{
136 return left.Value == right.Value;
137}
138
139template <typename InValueType>
140inline bool operator==(const TTestToken<InValueType>& left, const InValueType& right)
141{
142 return left.Value == right;
143}
144
145template <typename InValueType>
147{
148 return !operator==(left, right);
149}
150
151template <typename InValueType>
152inline bool operator!=(const TTestToken<InValueType>& left, const InValueType& right)
153{
154 return !operator==(left, right);
155}
156
157template <typename InValueType>
159{
160 return Ar << TestToken.Value;
161}
162
163template <typename InValueType>
165{
166 Slot.EnterRecord() << SA_VALUE(TEXT("Value"), TestToken.Value);
167}
#define ensure( InExpression)
Definition AssertionMacros.h:464
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
bool left(const int *a, const int *b, const int *c)
Definition RecastMesh.cpp:182
#define SA_VALUE(Name, Value)
Definition StructuredArchiveNameHelpers.h:77
FArchive & operator<<(FArchive &Ar, TTestToken< InValueType > &TestToken)
Definition TokenTest.h:158
bool operator==(const TTestToken< InValueType > &left, const TTestToken< InValueType > &right)
Definition TokenTest.h:134
bool operator!=(const TTestToken< InValueType > &left, const TTestToken< InValueType > &right)
Definition TokenTest.h:146
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition Archive.h:1208
Definition StructuredArchiveSlots.h:52
UE_API FStructuredArchiveRecord EnterRecord()
Definition StructuredArchiveSlots.h:252
Definition TokenTest.h:11
~TTestToken()
Definition TokenTest.h:42
static bool EvenConstructionDestructionCalls()
Definition TokenTest.h:93
TTestToken & operator=(TTestToken &&Other) noexcept
Definition TokenTest.h:63
static int32 NumMoveCalls()
Definition TokenTest.h:87
const ValueType & operator*() const
Definition TokenTest.h:47
TTestToken() noexcept
Definition TokenTest.h:28
TTestToken(const ValueType &value)
Definition TokenTest.h:22
static int32 NumCopyCalls()
Definition TokenTest.h:83
static bool EvenConstructionDestructionCalls(int32 ExpectedNum)
Definition TokenTest.h:95
static void Reset()
Definition TokenTest.h:100
ValueType * operator->()
Definition TokenTest.h:53
bool operator<(const TTestToken &Other) const
Definition TokenTest.h:71
InValueType ValueType
Definition TokenTest.h:20
const ValueType * operator->() const
Definition TokenTest.h:51
TTestToken(const TTestToken &Other)
Definition TokenTest.h:36
static int32 ConstructionDestructionCallDifference()
Definition TokenTest.h:81
static int32 NumCopyConstructorCalls()
Definition TokenTest.h:77
TTestToken & operator=(const TTestToken &Other)
Definition TokenTest.h:55
static int32 NumMoveAssignmentCalls()
Definition TokenTest.h:89
TTestToken(TTestToken &&Other) noexcept
Definition TokenTest.h:30
static int32 NumMoveConstructorCalls()
Definition TokenTest.h:79
static int32 NumDestructionCalls()
Definition TokenTest.h:91
static int32 NumCopyAssignmentCalls()
Definition TokenTest.h:85
ValueType & operator*()
Definition TokenTest.h:49
static int32 NumConstructionCalls()
Definition TokenTest.h:73
ValueType Value
Definition TokenTest.h:110
static int32 NumConstructorCalls()
Definition TokenTest.h:75