UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TypeTraits.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2// Templates for determining properties/traits of types
3
4#pragma once
5
8#include <initializer_list>
9#include <type_traits>
10
11namespace uLang
12{
13
14//------------------------------------------------------------------
15// From RemoveCV.h
16
22template <typename T> struct TRemoveCV { using Type = T; };
23template <typename T> struct TRemoveCV<const T> { using Type = T; };
24template <typename T> struct TRemoveCV<volatile T> { using Type = T; };
25template <typename T> struct TRemoveCV<const volatile T> { using Type = T; };
26
27//------------------------------------------------------------------
28// From AreTypesEqual.h
29
31template<typename A, typename B>
32struct TAreTypesEqual;
33
34template<typename, typename>
36{
37 enum { Value = false };
38};
39
40template<typename A>
42{
43 enum { Value = true };
44};
45
46//------------------------------------------------------------------
47// From IsEnum.h
48
49template <typename T>
50struct TIsEnum
51{
52 enum { Value = __is_enum(T) };
53};
54
55//------------------------------------------------------------------
56// From IsArithmetic.h
57
61template <typename T>
63{
64 enum { Value = false };
65};
66
67template <> struct TIsArithmetic<float> { enum { Value = true }; };
68template <> struct TIsArithmetic<double> { enum { Value = true }; };
69template <> struct TIsArithmetic<long double> { enum { Value = true }; };
70template <> struct TIsArithmetic<uint8_t> { enum { Value = true }; };
71template <> struct TIsArithmetic<uint16_t> { enum { Value = true }; };
72template <> struct TIsArithmetic<uint32_t> { enum { Value = true }; };
73template <> struct TIsArithmetic<uint64_t> { enum { Value = true }; };
74template <> struct TIsArithmetic<int8_t> { enum { Value = true }; };
75template <> struct TIsArithmetic<int16_t> { enum { Value = true }; };
76template <> struct TIsArithmetic<int32_t> { enum { Value = true }; };
77template <> struct TIsArithmetic<int64_t> { enum { Value = true }; };
78template <> struct TIsArithmetic<bool> { enum { Value = true }; };
79template <> struct TIsArithmetic<char> { enum { Value = true }; };
80template <> struct TIsArithmetic<wchar_t> { enum { Value = true }; };
81
82template <typename T> struct TIsArithmetic<const T> { enum { Value = TIsArithmetic<T>::Value }; };
83template <typename T> struct TIsArithmetic< volatile T> { enum { Value = TIsArithmetic<T>::Value }; };
84template <typename T> struct TIsArithmetic<const volatile T> { enum { Value = TIsArithmetic<T>::Value }; };
85
86//------------------------------------------------------------------
87// From IsIntegral.h
88
92template <typename T>
94{
95 enum { Value = false };
96};
97
98template <> struct TIsIntegral< bool> { enum { Value = true }; };
99template <> struct TIsIntegral< char> { enum { Value = true }; };
100template <> struct TIsIntegral<signed char> { enum { Value = true }; };
101template <> struct TIsIntegral<unsigned char> { enum { Value = true }; };
102template <> struct TIsIntegral< char16_t> { enum { Value = true }; };
103template <> struct TIsIntegral< char32_t> { enum { Value = true }; };
104template <> struct TIsIntegral< wchar_t> { enum { Value = true }; };
105template <> struct TIsIntegral< short> { enum { Value = true }; };
106template <> struct TIsIntegral<unsigned short> { enum { Value = true }; };
107template <> struct TIsIntegral< int> { enum { Value = true }; };
108template <> struct TIsIntegral<unsigned int> { enum { Value = true }; };
109template <> struct TIsIntegral< long> { enum { Value = true }; };
110template <> struct TIsIntegral<unsigned long> { enum { Value = true }; };
111template <> struct TIsIntegral< long long> { enum { Value = true }; };
112template <> struct TIsIntegral<unsigned long long> { enum { Value = true }; };
113
114template <typename T> struct TIsIntegral<const T> { enum { Value = TIsIntegral<T>::Value }; };
115template <typename T> struct TIsIntegral< volatile T> { enum { Value = TIsIntegral<T>::Value }; };
116template <typename T> struct TIsIntegral<const volatile T> { enum { Value = TIsIntegral<T>::Value }; };
117
118//------------------------------------------------------------------
119// From IsPointer.h
120
124template <typename T>
126{
127 enum { Value = false };
128};
129
130template <typename T> struct TIsPointer<T*> { enum { Value = true }; };
131
132template <typename T> struct TIsPointer<const T> { enum { Value = TIsPointer<T>::Value }; };
133template <typename T> struct TIsPointer< volatile T> { enum { Value = TIsPointer<T>::Value }; };
134template <typename T> struct TIsPointer<const volatile T> { enum { Value = TIsPointer<T>::Value }; };
135
136//------------------------------------------------------------------
137// From IsMemberPointer.h
138
142template <typename T>
144{
145 enum { Value = false };
146};
147
148template <typename T, typename U> struct TIsMemberPointer<T U::*> { enum { Value = true }; };
149
150template <typename T> struct TIsMemberPointer<const T> { enum { Value = TIsPointer<T>::Value }; };
151template <typename T> struct TIsMemberPointer< volatile T> { enum { Value = TIsPointer<T>::Value }; };
152template <typename T> struct TIsMemberPointer<const volatile T> { enum { Value = TIsPointer<T>::Value }; };
153
154//------------------------------------------------------------------
155// From IsPODType.h
156
161#if defined(_MSC_VER) && _MSC_VER >= 1900
162 // __is_pod changed in VS2015, however the results are still correct for all usages I've been able to locate.
163 #pragma warning(push)
164 #pragma warning(disable:4647)
165#endif // _MSC_VER == 1900
166
167template <typename T>
172
173#if defined(_MSC_VER) && _MSC_VER >= 1900
174 #pragma warning(pop)
175#endif // _MSC_VER >= 1900
176
177//------------------------------------------------------------------
178// From PointerIsConvertibleFromTo.h
179
183template <typename From, typename To>
185{
186private:
187 static uint8_t Test(...);
188 static uint16_t Test(To*);
189
190public:
191 enum { Value = sizeof(Test((From*)nullptr)) - 1 };
192};
193
194template <typename T1, typename T2>
199
203
207
211
212static_assert(TPointerIsConvertibleFromTo<bool, bool>::Value, "Platform TPointerIsConvertibleFromTo test failed.");
213static_assert(TPointerIsConvertibleFromTo<void, void>::Value, "Platform TPointerIsConvertibleFromTo test failed.");
214static_assert(TPointerIsConvertibleFromTo<bool, void>::Value, "Platform TPointerIsConvertibleFromTo test failed.");
215static_assert(TPointerIsConvertibleFromTo<const bool, const void>::Value, "Platform TPointerIsConvertibleFromTo test failed.");
220static_assert(TPointerIsConvertibleFromTo<TPointerIsConvertibleFromTo_TestBase, void>::Value, "Platform TPointerIsConvertibleFromTo test failed.");
221
223static_assert(!TPointerIsConvertibleFromTo<TPointerIsConvertibleFromTo_Unrelated, TPointerIsConvertibleFromTo_TestBase>::Value, "Platform TPointerIsConvertibleFromTo test failed.");
224static_assert(!TPointerIsConvertibleFromTo<bool, TPointerIsConvertibleFromTo_TestBase>::Value, "Platform TPointerIsConvertibleFromTo test failed.");
225static_assert(!TPointerIsConvertibleFromTo<void, TPointerIsConvertibleFromTo_TestBase>::Value, "Platform TPointerIsConvertibleFromTo test failed.");
226static_assert(!TPointerIsConvertibleFromTo<TPointerIsConvertibleFromTo_TestBase, bool>::Value, "Platform TPointerIsConvertibleFromTo test failed.");
227static_assert(!TPointerIsConvertibleFromTo<void, bool>::Value, "Platform TPointerIsConvertibleFromTo test failed.");
228
229//------------------------------------------------------------------
230// From IsConstructible.h
231
235template <typename T, typename... Args>
237{
238 enum { Value = __is_constructible(T, Args...) };
239};
240
241//------------------------------------------------------------------
242// From IsTriviallyDestructible.h
243
247template <typename T>
249{
250 enum { Value = std::is_trivially_destructible_v<T> };
251};
252
253//------------------------------------------------------------------
254// From IsContiguousContainer.h
255
261template <typename T>
263{
264 enum { Value = false };
265};
266
267template <typename T> struct TIsContiguousContainer< T& > : TIsContiguousContainer<T> {};
268template <typename T> struct TIsContiguousContainer< T&&> : TIsContiguousContainer<T> {};
269template <typename T> struct TIsContiguousContainer<const T> : TIsContiguousContainer<T> {};
270template <typename T> struct TIsContiguousContainer< volatile T> : TIsContiguousContainer<T> {};
271template <typename T> struct TIsContiguousContainer<const volatile T> : TIsContiguousContainer<T> {};
272
276template <typename T, size_t N> struct TIsContiguousContainer< T[N]> { enum { Value = true }; };
277template <typename T, size_t N> struct TIsContiguousContainer<const T[N]> { enum { Value = true }; };
278template <typename T, size_t N> struct TIsContiguousContainer< volatile T[N]> { enum { Value = true }; };
279template <typename T, size_t N> struct TIsContiguousContainer<const volatile T[N]> { enum { Value = true }; };
280
284template <typename T>
286{
287 enum { Value = true };
288};
289
290//------------------------------------------------------------------
291// From UnrealTypeTraits.h
292
298template<typename A, typename B> struct TIsSame { enum { Value = false }; };
299template<typename T> struct TIsSame<T, T> { enum { Value = true }; };
300
304template<typename T> struct TIsReferenceType { enum { Value = false }; };
305template<typename T> struct TIsReferenceType<T&> { enum { Value = true }; };
306template<typename T> struct TIsReferenceType<T&&> { enum { Value = true }; };
307
311template<typename T> struct TIsLValueReferenceType { enum { Value = false }; };
312template<typename T> struct TIsLValueReferenceType<T&> { enum { Value = true }; };
313
317template<typename T> struct TIsRValueReferenceType { enum { Value = false }; };
318template<typename T> struct TIsRValueReferenceType<T&&> { enum { Value = true }; };
319
323template<typename T>
328
329/*-----------------------------------------------------------------------------
330 Call traits - Modeled somewhat after boost's interfaces.
331-----------------------------------------------------------------------------*/
332
336template <typename T, bool TypeIsSmall>
338{
339 using ParamType = const T&;
340 using ConstParamType = const T&;
341};
342template <typename T>
344{
345 using ParamType = const T;
346 using ConstParamType = const T;
347};
348template <typename T>
350{
351 using ParamType = T*;
352 using ConstParamType = const T*;
353};
354
355/*-----------------------------------------------------------------------------
356 * TCallTraits
357 *
358 * Same call traits as boost, though not with as complete a solution.
359 *
360 * The main member to note is ParamType, which specifies the optimal
361 * form to pass the type as a parameter to a function.
362 *
363 * Has a small-value optimization when a type is a POD type and as small as a pointer.
364-----------------------------------------------------------------------------*/
365
369template <typename T>
381
385template <typename T>
386struct TCallTraits : public TCallTraitsBase<T> {};
387
388// Fix reference-to-reference problems.
389template <typename T>
390struct TCallTraits<T&>
391{
392 using ValueType = T&;
393 using Reference = T&;
394 using ConstReference = const T&;
395 using ParamType = T&;
397};
398
399// Array types
400template <typename T, size_t N>
401struct TCallTraits<T [N]>
402{
403private:
404 using ArrayType = T[N];
405public:
406 using ValueType = const T*;
407 using Reference = ArrayType&;
408 using ConstReference = const ArrayType&;
409 using ParamType = const T* const;
410 using ConstPointerType = const T* const;
411};
412
413// const array types
414template <typename T, size_t N>
415struct TCallTraits<const T [N]>
416{
417private:
418 using ArrayType = T[N];
419public:
420 using ValueType = const T*;
421 using Reference = ArrayType&;
422 using ConstReference = const ArrayType&;
423 using ParamType = const T* const;
424 using ConstPointerType = const T* const;
425};
426
431template<typename T>
433{
436
437 // There's no good way of detecting this so we'll just assume it to be true for certain known types and expect
438 // users to customize it for their custom types.
439 enum { IsBytewiseComparable = TOr<TIsEnum<T>, TIsArithmetic<T>, TIsPointer<T>>::Value };
440};
441
445template<typename T> struct TTypeTraits : public TTypeTraitsBase<T> {};
446
450template<typename T> struct TContainerTraitsBase
451{
452 // This should be overridden by every container that supports emptying its contents via a move operation.
453 enum { MoveWillEmptyContainer = false };
454};
455
456template<typename T> struct TContainerTraits : public TContainerTraitsBase<T> {};
457
471template <typename T, typename Arg>
473{
474 static_assert(
477 "TIsBitwiseConstructible is not designed to accept reference types");
478
479 static_assert(
482 "TIsBitwiseConstructible is not designed to accept qualified types");
483
484 // Assume no bitwise construction in general
485 enum { Value = false };
486};
487
488template <typename T>
490{
491 // Ts can always be bitwise constructed from itself if it is trivially copyable.
492 enum { Value = std::is_trivially_copy_constructible_v<T> };
493};
494
495template <typename T, typename U>
497{
498 // Constructing a const T is the same as constructing a T
499};
500
501// Const pointers can be bitwise constructed from non-const pointers.
502// This is not true for pointer conversions in general, e.g. where an offset may need to be applied in the case
503// of multiple inheritance, but there is no way of detecting that at compile-time.
504template <typename T>
505struct TIsBitwiseConstructible<const T*, T*>
506{
507 // Constructing a const T is the same as constructing a T
508 enum { Value = true };
509};
510
511// Unsigned types can be bitwise converted to their signed equivalents, and vice versa.
512// (assuming two's-complement, which we are)
513template <> struct TIsBitwiseConstructible< uint8_t, int8_t> { enum { Value = true }; };
514template <> struct TIsBitwiseConstructible< int8_t, uint8_t> { enum { Value = true }; };
515template <> struct TIsBitwiseConstructible<uint16_t, int16_t> { enum { Value = true }; };
516template <> struct TIsBitwiseConstructible< int16_t, uint16_t> { enum { Value = true }; };
517template <> struct TIsBitwiseConstructible<uint32_t, int32_t> { enum { Value = true }; };
518template <> struct TIsBitwiseConstructible< int32_t, uint32_t> { enum { Value = true }; };
519template <> struct TIsBitwiseConstructible<uint64_t, int64_t> { enum { Value = true }; };
520template <> struct TIsBitwiseConstructible< int64_t, uint64_t> { enum { Value = true }; };
521
522}
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
return true
Definition ExternalRpcRegistry.cpp:601
uint_least16_t char16_t
Definition MarketplaceKitWrapper.h:64
uint_least32_t char32_t
Definition MarketplaceKitWrapper.h:65
const bool
Definition NetworkReplayStreaming.h:178
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
Definition TestUtils.cpp:8
Definition VVMEngineEnvironment.h:23
Definition Conditionals.h:20
Definition TypeTraits.h:36
@ Value
Definition TypeTraits.h:37
Definition TypeTraits.h:371
T ValueType
Definition TypeTraits.h:375
typename TCallTraitsParamTypeHelper< T, PassByValue >::ParamType ParamType
Definition TypeTraits.h:378
T & Reference
Definition TypeTraits.h:376
const T & ConstReference
Definition TypeTraits.h:377
typename TCallTraitsParamTypeHelper< T, PassByValue >::ConstParamType ConstPointerType
Definition TypeTraits.h:379
const T ConstParamType
Definition TypeTraits.h:346
const T ParamType
Definition TypeTraits.h:345
const T * ConstParamType
Definition TypeTraits.h:352
T * ParamType
Definition TypeTraits.h:351
Definition TypeTraits.h:338
const T & ParamType
Definition TypeTraits.h:339
const T & ConstParamType
Definition TypeTraits.h:340
T & Reference
Definition TypeTraits.h:393
T & ParamType
Definition TypeTraits.h:395
T & ValueType
Definition TypeTraits.h:392
const T & ConstReference
Definition TypeTraits.h:394
T & ConstPointerType
Definition TypeTraits.h:396
const ArrayType & ConstReference
Definition TypeTraits.h:408
const T * ValueType
Definition TypeTraits.h:406
ArrayType & Reference
Definition TypeTraits.h:407
const T *const ConstPointerType
Definition TypeTraits.h:410
const T *const ParamType
Definition TypeTraits.h:409
const T *const ConstPointerType
Definition TypeTraits.h:424
ArrayType & Reference
Definition TypeTraits.h:421
const T * ValueType
Definition TypeTraits.h:420
const ArrayType & ConstReference
Definition TypeTraits.h:422
const T *const ParamType
Definition TypeTraits.h:423
Definition TypeTraits.h:386
Definition TypeTraits.h:451
@ MoveWillEmptyContainer
Definition TypeTraits.h:453
Definition TypeTraits.h:456
Definition TypeTraits.h:63
@ Value
Definition TypeTraits.h:64
Definition TypeTraits.h:473
@ Value
Definition TypeTraits.h:485
Definition TypeTraits.h:237
@ Value
Definition TypeTraits.h:238
Definition TypeTraits.h:263
@ Value
Definition TypeTraits.h:264
Definition TypeTraits.h:51
@ Value
Definition TypeTraits.h:52
Definition TypeTraits.h:94
@ Value
Definition TypeTraits.h:95
Definition TypeTraits.h:311
@ Value
Definition TypeTraits.h:311
Definition TypeTraits.h:144
@ Value
Definition TypeTraits.h:145
Definition TypeTraits.h:169
Definition TypeTraits.h:126
@ Value
Definition TypeTraits.h:127
Definition TypeTraits.h:317
@ Value
Definition TypeTraits.h:317
Definition TypeTraits.h:304
@ Value
Definition TypeTraits.h:304
Definition TypeTraits.h:298
@ Value
Definition TypeTraits.h:298
Definition TypeTraits.h:249
@ Value
Definition TypeTraits.h:250
Definition TypeTraits.h:325
Definition Conditionals.h:49
Definition Conditionals.h:45
Definition TypeTraits.h:185
@ Value
Definition TypeTraits.h:191
Definition TypeTraits.h:196
@ Value
Definition TypeTraits.h:197
T Type
Definition TypeTraits.h:23
T Type
Definition TypeTraits.h:25
T Type
Definition TypeTraits.h:24
Definition TypeTraits.h:22
T Type
Definition TypeTraits.h:22
Definition TypeTraits.h:433
typename TCallTraits< T >::ConstPointerType ConstPointerType
Definition TypeTraits.h:435
typename TCallTraits< T >::ParamType ConstInitType
Definition TypeTraits.h:434
Definition TypeTraits.h:445