Type safe union with an enum type, where each type has an associated enum value. More...
#include <TaggedUnion.h>
Classes | |
struct | EnumToType |
Extracts type T corresponding to enumeration wantedEnum at compile time. More... | |
struct | EnumToType< wantedEnum, 0 > |
Public Types | |
using | EnumType = typename TypeAt< 0 >::enumType |
Public Member Functions | |
~TaggedUnion () | |
Destroys the TaggedUnion object. More... | |
TaggedUnion (const TaggedUnion &other) | |
Copy constructor. More... | |
TaggedUnion (TaggedUnion &&other) | |
Move constructor. More... | |
TaggedUnion & | operator= (const TaggedUnion &other) |
Copy assignment operator. More... | |
TaggedUnion & | operator= (TaggedUnion &&other) |
Move assignment operator. More... | |
EnumType | getType () const |
Returns enumeration value of currently active union type. More... | |
void | setType (EnumType newType) |
Sets the currently active type at runtime, destructing and (default) constructing the new type. More... | |
bool | operator== (const TaggedUnion &other) const |
template<EnumType wantedType, typename U > | |
void | assign (U &&other) |
Assigns a compile time known enum type with an object U. More... | |
template<EnumType wantedType> | |
TypeAt< EnumToType< wantedType >::index >::type & | changeTo () |
Changes current active type in union to a different one. More... | |
template<EnumType wantedType> | |
TypeAt< EnumToType< wantedType >::index >::type * | field () |
Get a pointer to currently active field. More... | |
template<EnumType wantedType> | |
const TypeAt< EnumToType< wantedType >::index >::type * | field () const |
Get a pointer to currently active field. More... | |
Static Public Attributes | |
static constexpr auto | NumTypes = Union::FieldsTypes::size |
Type safe union with an enum type, where each type has an associated enum value.
Union | with FieldTypes = TypeList<TaggedType<EnumType, EnumValue, Type>, ...> |
Example:
|
inline |
Destroys the TaggedUnion object.
|
inline |
Copy constructor.
other | Another tagged union |
|
inline |
Move constructor.
other | Another tagged union |
|
inline |
Assigns a compile time known enum type with an object U.
U | Type of object to be assigned. |
wantedType | Compile time known enum type |
other | object to be assigned (move / copy) |
|
inline |
Changes current active type in union to a different one.
wantedType | Compile time know enum value associated to wanted type |
auto
to help intellisense deducing type
|
inline |
Get a pointer to currently active field.
wantedType | Compile time know enum value associated to wanted type |
auto
to help intellisense deducing type
|
inline |
Get a pointer to currently active field.
wantedType | Compile time know enum value associated to wanted type |
auto
to help intellisense deducing type
|
inline |
Returns enumeration value of currently active union type.
|
inline |
Copy assignment operator.
other | Another tagged union |
|
inline |
Move assignment operator.
other | Another tagged union |
|
inline |
Sets the currently active type at runtime, destructing and (default) constructing the new type.