24 #ifndef TVM_RUNTIME_CONTAINER_VARIANT_H_
25 #define TVM_RUNTIME_CONTAINER_VARIANT_H_
30 #include <type_traits>
37 template <
typename Parent,
typename ChildTuple>
38 constexpr
bool parent_is_base_of_any =
false;
40 template <
typename Parent,
typename... Child>
41 constexpr
bool parent_is_base_of_any<Parent, std::tuple<Child...>> =
42 ((std::is_base_of_v<Parent, Child> && !std::is_same_v<Parent, Child>) || ...);
60 template <
typename ParentTuple,
typename ChildTuple>
61 static constexpr
bool any_parent_is_base_of_any_child =
false;
63 template <
typename ChildTuple,
typename... Parent>
64 static constexpr
bool any_parent_is_base_of_any_child<std::tuple<Parent...>, ChildTuple> =
65 (parent_is_base_of_any<Parent, ChildTuple> || ...);
68 template <
typename... V>
70 static constexpr
bool all_inherit_from_objectref = (std::is_base_of_v<ObjectRef, V> && ...);
71 static_assert(all_inherit_from_objectref,
72 "All types used in Variant<...> must inherit from ObjectRef");
74 static constexpr
bool a_variant_inherits_from_another_variant =
75 detail::any_parent_is_base_of_any_child<std::tuple<V...>, std::tuple<V...>>;
76 static_assert(!a_variant_inherits_from_another_variant,
77 "Due to implementation limitations, "
78 "no type stored in a tvm::runtime::Variant "
79 "may be a subclass of any other type "
80 "stored in the same variant.");
85 static constexpr
bool is_variant = (std::is_base_of_v<V, T> || ...);
91 template <
typename T,
typename = enable_if_variant<T>>
94 template <
typename T,
typename = enable_if_variant<T>>
96 ObjectRef::operator=(std::move(value));
106 CHECK(node ==
nullptr || (node->IsInstance<
typename V::ContainerType>() || ...))
108 <<
static_cast<const std::stringstream&
>(
109 (std::stringstream() << ... << V::ContainerType::_type_key))
111 <<
"> cannot hold an object of type " << node->GetTypeKey();
A custom smart pointer for Object.
Definition: object.h:362
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
Variant(T value)
Definition: variant.h:92
TVM_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(Variant)
Variant & operator=(T value)
Definition: variant.h:95
Variant(ObjectPtr< Object > node)
Definition: variant.h:105
std::enable_if_t< is_variant< T > > enable_if_variant
Definition: variant.h:89
static constexpr bool is_variant
Definition: variant.h:85
Variant()
Definition: variant.h:104
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
A managed object in the TVM runtime.