TVariant

A type-safe union based loosely on std::variant.

Windows
MacOS
Linux

Inheritance Hierarchy

TVariantStorage

TVariant

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/Misc/TVariant.h

Include

#include "Misc/TVariant.h"

Syntax

template<typename T, typename... Ts>
class TVariant : private UE4Variant_Details::TVariantStorage< T, Ts... >

Remarks

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.

Constructors

Name Description

Public function

TVariant()

Default initialize the TVariant to the first type in the parameter pack

Public function

TVariant

(
    const TVariant& Other
)

Copy construct the variant from another variant of the same type

Public function

TVariant

(
    TVariant&& Other
)

Move construct the variant from another variant of the same type

Public function

TVariant

(
    TInPlaceType< U >&&,
    TArgs&&... Args
)

Perform in-place construction of a type into the variant

Destructors

Name Description

Public function

~TVariant()

Destruct the underlying type (if appropriate)

Functions

Name Description

Public function

void

 

Emplace

(
    TArgs&&... Args
)

Set a specifically-typed value into the variant using in-place construction

Public function

U &

 

Get()

Get a reference to the held value.

Public function Const

const U &

 

Get()

Get a reference to the held value.

Public function Const

SIZE_T

 

GetIndex()

Returns the currently held type's index into the template parameter pack

Public function Static

constexpr SI...

 

IndexOfType()

Lookup the index of a type in the template parameter pack at compile time.

Public function Const

bool

 

IsType()

Determine if the variant holds the specific type

Public function

void

 

Set

(
    typename TIdentity< U >::Type&& Va...
)

Set a specifically-typed value into the variant

Public function

void

 

Set

(
    const typename TIdentity< U >::Type...
)

Set a specifically-typed value into the variant

Public function

U *

 

TryGet()

Get a pointer to the held value if the held type is the same as the one specified

Public function Const

const U *...

 

TryGet()

Get a pointer to the held value if the held type is the same as the one specified

Operators

Name Description

Public function

TVariant &

 

operator=

(
    TVariant&& Other
)

Move assign a variant from another variant of the same type

Public function

TVariant &

 

operator=

(
    const TVariant& Other
)

Copy assign a variant from another variant of the same type

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss