24 #ifndef TVM_RUNTIME_CONTAINER_OPTIONAL_H_
25 #define TVM_RUNTIME_CONTAINER_OPTIONAL_H_
54 static_assert(std::is_base_of<ObjectRef, T>::value,
"Optional is only defined for ObjectRef.");
80 ObjectRef::operator=(std::move(other));
93 ICHECK(
data_ !=
nullptr);
108 explicit operator bool()
const {
return *
this !=
nullptr; }
114 using RetType = decltype(
value() == other.
value());
115 if (
same_as(other))
return RetType(
true);
116 if (*
this !=
nullptr && other !=
nullptr) {
120 return RetType(
false);
125 using RetType = decltype(
value() != other.
value());
126 if (
same_as(other))
return RetType(
false);
127 if (*
this !=
nullptr && other !=
nullptr) {
131 return RetType(
true);
135 using RetType = decltype(
value() == other);
136 if (
same_as(other))
return RetType(
true);
137 if (*
this !=
nullptr)
return value() == other;
138 return RetType(
false);
140 auto operator!=(
const T& other)
const {
return !(*
this == other); }
141 template <
typename U>
143 using RetType = decltype(
value() == other);
144 if (*
this ==
nullptr)
return RetType(
false);
145 return value() == other;
147 template <
typename U>
149 using RetType = decltype(
value() != other);
150 if (*
this ==
nullptr)
return RetType(
true);
151 return value() != other;
156 template <
typename ObjectRefType,
typename>
158 if (
auto* ptr = this->as<typename ObjectRefType::ContainerType>()) {
159 return GetRef<ObjectRefType>(ptr);
A custom smart pointer for Object.
Definition: object.h:362
Base class of all object reference.
Definition: object.h:519
ObjectPtr< Object > data_
Internal pointer that backs the reference.
Definition: object.h:605
const ObjectType * as() const
Try to downcast the internal Object to a raw pointer of a corresponding type.
Definition: object.h:910
bool same_as(const ObjectRef &other) const
Comparator.
Definition: object.h:530
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
typename T::ContainerType ContainerType
Definition: optional.h:53
const ContainerType * get() const
Definition: optional.h:100
T value_or(T default_value) const
Definition: optional.h:105
auto operator!=(const Optional< T > &other) const
Definition: optional.h:123
Optional(Optional< T > &&)=default
auto operator==(const U &other) const
Definition: optional.h:142
bool operator!=(std::nullptr_t) const
Definition: optional.h:111
Optional< T > & operator=(const Optional< T > &)=default
Optional(NullOptType)
Nullopt handling.
Definition: optional.h:68
Optional(T other)
Definition: optional.h:77
auto operator!=(const T &other) const
Definition: optional.h:140
static constexpr bool _type_is_nullable
Definition: optional.h:153
Optional(std::nullptr_t)
Definition: optional.h:71
Optional< T > & operator=(int val)=delete
Optional(const Optional< T > &)=default
Optional< T > & operator=(T other)
Definition: optional.h:79
Optional(ObjectPtr< Object > ptr)
Construct from an ObjectPtr whose type already matches the ContainerType.
Definition: optional.h:66
Optional< T > & operator=(std::nullptr_t)
Definition: optional.h:72
auto operator==(const Optional< T > &other) const
Definition: optional.h:112
auto operator==(const T &other) const
Definition: optional.h:134
auto operator!=(const U &other) const
Definition: optional.h:148
bool operator==(std::nullptr_t) const
Definition: optional.h:110
T value() const
Definition: optional.h:92
Optional< T > & operator=(Optional< T > &&)=default
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
constexpr runtime::NullOptType NullOpt
Definition: optional.h:169
Helper to represent nullptr for optional.
Definition: optional.h:35