Template Class Variant#
Defined in File variant.h
Inheritance Relationships#
Base Type#
public tvm::ffi::details::VariantBase< details::all_object_ref_v< V... > >
Class Documentation#
-
template<typename ...V>
class Variant : public tvm::ffi::details::VariantBase<details::all_object_ref_v<V...>># A typed variant container.
When all values are ObjectRef, Variant is backed by ObjectRef, otherwise it is backed by Any.
Public Functions
-
inline Variant(const Variant<V...> &other)#
Constructor from another variant.
- Parameters:
other – The other variant
-
inline Variant(Variant<V...> &&other)#
Constructor from another variant.
- Parameters:
other – The other variant
-
template<typename T, typename = enable_if_variant_contains_t<T>>
inline Variant(T other)# Constructor from another variant.
- Parameters:
other – The other variant
-
template<typename T, typename = enable_if_variant_contains_t<T>>
inline std::optional<T> as() const# Try to cast to a type T, return std::nullopt if the cast is not possible.
- Template Parameters:
T – The type to cast to.
- Returns:
The casted value, or std::nullopt if the cast is not possible.
-
template<typename T, typename = std::enable_if_t<std::is_base_of_v<Object, T>>>
inline const T *as() const# Shortcut of as Object to cast to a const pointer when T is an Object.
- Template Parameters:
T – The object type.
- Returns:
The requested pointer, returns nullptr if type mismatches.
-
template<typename T, typename = enable_if_variant_contains_t<T>>
inline T get() const &# Get the value of the variant in type T, throws an exception if cast fails.
- Template Parameters:
T – The type to get.
- Returns:
The value of the variant
-
template<typename T, typename = enable_if_variant_contains_t<T>>
inline T get() &&# Get the value of the variant in type T, throws an exception if cast fails.
- Template Parameters:
T – The type to get.
- Returns:
The value of the variant
-
inline std::string GetTypeKey() const#
Get the type key of the variant.
- Returns:
The type key of the variant
-
inline Variant(const Variant<V...> &other)#