UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMPtrVariant.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
7
8namespace Verse
9{
10
11template <typename T, typename... Ts>
12struct TagOf;
13
14template <typename T, typename... Ts>
15struct TagOf<T, T, Ts...>
16{
17 static constexpr uintptr_t Value = 0;
18};
19
20template <typename T, typename U, typename... Ts>
21struct TagOf<T, U, Ts...>
22{
23 static constexpr uintptr_t Value = 1 + TagOf<T, Ts...>::Value;
24};
25
26// Can't use std::bit_ceil yet.
27inline constexpr size_t BitCeil(size_t X)
28{
29 size_t Pow2 = 1;
30 while (Pow2 < X)
31 {
32 Pow2 *= 2;
33 }
34 return Pow2;
35}
36
37// Ts... are types which are ultimately pointers.
38// We tag which of Ts... the variant holds by tagging the lower bits, so the pointers
39// must be at least log(sizeof(Ts)...) + 1 byte aligned.
40template <typename... Ts>
42{
43 static_assert(((sizeof(Ts) == sizeof(uintptr_t)) && ...));
44
45 static constexpr uintptr_t Mask = BitCeil(sizeof...(Ts)) - 1;
46
47 template <typename T>
55
56 template <typename T>
57 bool Is()
58 {
59 static_assert((std::is_same_v<T, Ts> || ...));
60 return (Ptr & Mask) == TagOf<T, Ts...>::Value;
61 }
62
63 template <typename T>
64 T As()
65 {
66 static_assert((std::is_same_v<T, Ts> || ...));
68 return BitCast<T>(Ptr & ~Mask);
69 }
70
72 {
73 return Ptr == Other.Ptr;
74 }
75
76 uintptr_t RawPtr() const { return Ptr; }
77
78private:
79 uintptr_t Ptr;
80};
81
82template <typename... Ts>
87
88} // namespace Verse
#define checkSlow(expr)
Definition AssertionMacros.h:332
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define X(Name, Desc)
Definition FormatStringSan.h:47
uint32 PointerHash(const void *Key)
Definition TypeHash.h:91
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:36
uint32 GetTypeHash(TPtrVariant< Ts... > Ptr)
Definition VVMPtrVariant.h:83
constexpr size_t BitCeil(size_t X)
Definition VVMPtrVariant.h:27
Definition VVMPtrVariant.h:42
static constexpr uintptr_t Mask
Definition VVMPtrVariant.h:45
bool operator==(TPtrVariant Other) const
Definition VVMPtrVariant.h:71
uintptr_t RawPtr() const
Definition VVMPtrVariant.h:76
T As()
Definition VVMPtrVariant.h:64
bool Is()
Definition VVMPtrVariant.h:57
TPtrVariant(T InT)
Definition VVMPtrVariant.h:48
Definition VVMPtrVariant.h:12