UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
EnumAsByte.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
20template <class InEnumType>
22{
23 static_assert(std::is_enum_v<InEnumType> && std::is_convertible_v<InEnumType, int>, "TEnumAsByte is not intended for use with enum classes - please derive your enum class from uint8 instead.");
24
25public:
27
28 [[nodiscard]] constexpr TEnumAsByte() = default;
29 [[nodiscard]] constexpr TEnumAsByte(const TEnumAsByte&) = default;
30 constexpr TEnumAsByte& operator=(const TEnumAsByte&) = default;
31
41
48 : Value(static_cast<uint8>(InValue))
49 {
50 }
51
58 : Value(InValue)
59 {
60 }
61
62public:
69 [[nodiscard]] constexpr bool operator==( EnumType InValue ) const
70 {
71 return static_cast<EnumType>(Value) == InValue;
72 }
73
80 [[nodiscard]] constexpr bool operator==(TEnumAsByte InValue) const
81 {
82 return Value == InValue.Value;
83 }
84
86 [[nodiscard]] constexpr operator EnumType() const
87 {
88 return (EnumType)Value;
89 }
90
91public:
92
98 [[nodiscard]] constexpr EnumType GetValue() const
99 {
100 return (EnumType)Value;
101 }
102
108 [[nodiscard]] constexpr uint8 GetIntValue() const
109 {
110 return Value;
111 }
112
113private:
114
116 uint8 Value;
117};
118
119template<class T>
121{
122 return GetTypeHash((uint8)Enum.GetValue());
123}
124
125
126template<class T> struct TIsPODType<TEnumAsByte<T>> { enum { Value = true }; };
127
128#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_6
129#include "Traits/IsTEnumAsByte.h"
130#endif
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define UE_FORCEINLINE_HINT
Definition Platform.h:723
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE_FORCEINLINE_HINT constexpr uint32 GetTypeHash(const TEnumAsByte< T > &Enum)
Definition EnumAsByte.h:120
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition EnumAsByte.h:22
constexpr uint8 GetIntValue() const
Definition EnumAsByte.h:108
UE_FORCEINLINE_HINT constexpr TEnumAsByte(uint8 InValue)
Definition EnumAsByte.h:57
InEnumType EnumType
Definition EnumAsByte.h:26
constexpr TEnumAsByte()=default
constexpr TEnumAsByte & operator=(const TEnumAsByte &)=default
UE_FORCEINLINE_HINT constexpr TEnumAsByte(EnumType InValue)
Definition EnumAsByte.h:37
constexpr EnumType GetValue() const
Definition EnumAsByte.h:98
constexpr TEnumAsByte(const TEnumAsByte &)=default
constexpr bool operator==(EnumType InValue) const
Definition EnumAsByte.h:69
constexpr bool operator==(TEnumAsByte InValue) const
Definition EnumAsByte.h:80
UE_FORCEINLINE_HINT constexpr TEnumAsByte(int32 InValue)
Definition EnumAsByte.h:47
Definition IsPODType.h:12
@ Value
Definition IsPODType.h:13