Variant, an implementation of type-safe union, similar to std::variant or boost::variant.
More...
#include <Variant.h>
|
| Variant () |
| Default constructor, constructs the object of type listed first in the type list using its default constructor. More...
|
|
template<typename T , typename = std::enable_if_t<!std::is_same<std::decay_t<T>, Variant>::value>> |
| Variant (T &&value) |
| Construct variant from value of stored type. More...
|
|
| Variant (const ConstructTypeIdxTag, const Size typeIdx) |
| Default-constructs a type with given type index. More...
|
|
| Variant (const Variant &other) |
|
| Variant (Variant &&other) |
|
| ~Variant () |
|
template<typename T , typename = std::enable_if_t<!std::is_same<std::decay_t<T>, Variant>::value>> |
Variant & | operator= (T &&value) |
| Universal copy/move operator with type of rhs being one of stored types. More...
|
|
Variant & | operator= (const Variant &other) |
| Assigns another variant into this. More...
|
|
Variant & | operator= (Variant &&other) |
| Moves another variant into this. More...
|
|
void | swap (Variant &other) |
| Swaps value stored in the variant with value of different variant. More...
|
|
template<typename T , typename... Ts> |
void | emplace (Ts &&... args) |
| Creates a value of type T in place. More...
|
|
INLINE Size | getTypeIdx () const |
| Returns index of type currently stored in variant. More...
|
|
template<typename T > |
INLINE bool | has () const |
| Checks if the variant currently hold value of given type. More...
|
|
template<typename T > |
INLINE T & | get () |
| Returns the stored value. More...
|
|
template<typename T > |
INLINE const T & | get () const |
| Returns the stored value, const version. More...
|
|
template<typename T , typename = std::enable_if_t<!std::is_same<std::decay_t<T>, Variant>::value>> |
| operator T& () |
| Implicit conversion to one of stored values. More...
|
|
template<typename T , typename = std::enable_if_t<!std::is_same<std::decay_t<T>, Variant>::value>> |
| operator const T & () const |
| Const version of conversion operator. More...
|
|
template<typename T > |
Optional< T > | tryGet () const |
| Returns the stored value in the variant. More...
|
|
|
template<typename T > |
static constexpr INLINE bool | canHold () |
| Checks if the given type is one of the listed ones. More...
|
|
template<typename... TArgs>
class Variant< TArgs >
Variant, an implementation of type-safe union, similar to std::variant or boost::variant.
Definition at line 171 of file Variant.h.
◆ Variant() [1/5]
template<typename... TArgs>
Default constructor, constructs the object of type listed first in the type list using its default constructor.
The default constructor must exist.
Definition at line 188 of file Variant.h.
◆ Variant() [2/5]
template<typename... TArgs>
template<typename T , typename = std::enable_if_t<!std::is_same<std::decay_t<T>, Variant>::value>>
Construct variant from value of stored type.
Definition at line 196 of file Variant.h.
◆ Variant() [3/5]
template<typename... TArgs>
Default-constructs a type with given type index.
Useful for (de)serialization of variant.
Definition at line 207 of file Variant.h.
◆ Variant() [4/5]
template<typename... TArgs>
◆ Variant() [5/5]
template<typename... TArgs>
◆ ~Variant()
template<typename... TArgs>
◆ canHold()
template<typename... TArgs>
template<typename T >
Checks if the given type is one of the listed ones.
Returns true even for references and const/volatile-qualified types.
Definition at line 325 of file Variant.h.
◆ emplace()
template<typename... TArgs>
template<typename T , typename... Ts>
void Variant< TArgs >::emplace |
( |
Ts &&... |
args | ) |
|
|
inline |
Creates a value of type T in place.
Type T must be one of variant types. Any previously stored value is destroyed.
Definition at line 300 of file Variant.h.
◆ get() [1/2]
template<typename... TArgs>
template<typename T >
Returns the stored value.
Performs a compile-time check that the type is contained in Variant, and runtime check that the variant currently holds value of given type.
Definition at line 335 of file Variant.h.
◆ get() [2/2]
template<typename... TArgs>
template<typename T >
Returns the stored value, const version.
Definition at line 344 of file Variant.h.
◆ getTypeIdx()
template<typename... TArgs>
Returns index of type currently stored in variant.
Definition at line 310 of file Variant.h.
◆ has()
template<typename... TArgs>
template<typename T >
Checks if the variant currently hold value of given type.
Definition at line 316 of file Variant.h.
◆ operator const T &()
template<typename... TArgs>
template<typename T , typename = std::enable_if_t<!std::is_same<std::decay_t<T>, Variant>::value>>
Variant< TArgs >::operator const T & |
( |
| ) |
const |
|
inline |
Const version of conversion operator.
Definition at line 362 of file Variant.h.
◆ operator T&()
template<typename... TArgs>
template<typename T , typename = std::enable_if_t<!std::is_same<std::decay_t<T>, Variant>::value>>
Implicit conversion to one of stored values.
Performs a compile-time check that the type is contained in Variant, and runtime check that the variant currently holds value of given type.
Definition at line 356 of file Variant.h.
◆ operator=() [1/3]
template<typename... TArgs>
Assigns another variant into this.
If the type of the currently stored value is the same as type in rhs, the copy operator is utilized, otherwise the current value (if there is one) is destroyed and a new value is created using copy constructor.
Definition at line 257 of file Variant.h.
◆ operator=() [2/3]
template<typename... TArgs>
template<typename T , typename = std::enable_if_t<!std::is_same<std::decay_t<T>, Variant>::value>>
Universal copy/move operator with type of rhs being one of stored types.
Valid type is checked by static assert. If the type of rhs is the same as the type currently stored in variant, the value is copy/move assigned, otherwise the current value is destroyed and a copy/move constructor is used.
Definition at line 236 of file Variant.h.
◆ operator=() [3/3]
template<typename... TArgs>
Moves another variant into this.
If the type of the currently stored value is the same as type in rhs, the move operator is utilized, otherwise the current value is destroyed and a new value is created using move constructor.
Definition at line 274 of file Variant.h.
◆ swap()
template<typename... TArgs>
Swaps value stored in the variant with value of different variant.
Both variants must hold the value of the same type, checked by assert.
Definition at line 290 of file Variant.h.
◆ tryGet()
template<typename... TArgs>
template<typename T >
Returns the stored value in the variant.
Safer than implicit conversion as it returns NOTHING in case the value is currently not stored in variant.
Definition at line 371 of file Variant.h.
The documentation for this class was generated from the following file:
- /home/pavel/projects/astro/sph/src/core/objects/wrappers/Variant.h