Navigation
API > API/Runtime > API/Runtime/Core
A type-safe union based loosely on std::variant. This flavor of variant requires that all the types in the declaring template parameter pack be unique. Attempting to use the value of a Get() when the underlying type is different leads to undefined behavior.
| Name | TVariant |
| Type | class |
| Header File | /Engine/Source/Runtime/Core/Public/Misc/TVariant.h |
| Include Path | #include "Misc/TVariant.h" |
Syntax
template<typename T, typename... Ts>
class TVariant : private std::conditional_t<!std::is_trivially_destructible_v< T >||(!std::is_trivially_destructible_v< Ts >||...), UE::Core::Private::TDestructibleVariantStorage< T, Ts... >, UE::Core::Private::TVariantStorage< T, Ts... > >
Inheritance Hierarchy
- std::conditional_t||(!std::is_trivially_destructible_v< Ts >||...), UE::Core::Private::TDestructibleVariantStorage< T, Ts... >, UE::Core::Private::TVariantStorage< T, Ts... > > → TVariant
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
TVariant
(
UE::Core::Private::TUninitializedType< U >&& |
INTERNAL USE ONLY Do not call this constructor, it will put the variant in a bad state. | Misc/TVariant.h | |
TVariant () |
Test for 255 here, because the parameter pack doesn't include the initial T. | Misc/TVariant.h | |
| Copy construct the variant from another variant of the same type | Misc/TVariant.h | ||
| Move construct the variant from another variant of the same type | Misc/TVariant.h | ||
TVariant
(
TInPlaceType< U >&&, |
Perform in-place construction of a type into the variant | Misc/TVariant.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
~TVariant() |
Defer to the storage as to how to destruct the elements. | Misc/TVariant.h |
Typedefs
| Name | Type | Remarks | Include Path | ||||
|---|---|---|---|---|---|---|---|
| Super | std::conditional_t | (!std::is_trivially_destructible_v< Ts > | ...), UE::Core::Private::TDestructibleVariantStorage< T, Ts... >, UE::Core::Private::TVariantStorage< T, Ts... > > | Misc/TVariant.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
void Emplace
(
ArgTypes&&... Args |
Set a specifically-typed value into the variant using in-place construction | Misc/TVariant.h | |
U & Get () |
Get a reference to the held value. | Misc/TVariant.h | |
const U & Get () |
Get a reference to the held value. | Misc/TVariant.h | |
const U & Get
(
const TIdentity_T< U >& DefaultValue |
Get a reference to the held value if set, otherwise the DefaultValue | Misc/TVariant.h | |
SIZE_T GetIndex() |
Returns the currently held type's index into the template parameter pack | Misc/TVariant.h | |
bool IsType() |
Determine if the variant holds the specific type | Misc/TVariant.h | |
| Set a specifically-typed value into the variant | Misc/TVariant.h | ||
| Set a specifically-typed value into the variant | Misc/TVariant.h | ||
U * TryGet () |
Get a pointer to the held value if the held type is the same as the one specified | Misc/TVariant.h | |
const U * TryGet () |
Get a pointer to the held value if the held type is the same as the one specified | Misc/TVariant.h |
Static
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
static SIZE_T IndexOfType() |
Lookup the index of a type in the template parameter pack at compile time. | Misc/TVariant.h |