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);
105 T
value_or(T default_value)
const {
return data_ !=
nullptr ? T(data_) : default_value; }
108 explicit operator bool()
const {
return *
this !=
nullptr; }
110 bool operator==(std::nullptr_t)
const {
return data_ ==
nullptr; }
111 bool operator!=(std::nullptr_t)
const {
return data_ !=
nullptr; }
114 using RetType = decltype(value() == other.
value());
115 if (same_as(other))
return RetType(
true);
116 if (*
this !=
nullptr && other !=
nullptr) {
117 return value() == other.
value();
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) {
128 return value() != other.
value();
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;
153 static constexpr
bool _type_is_nullable =
true;
163 #endif // TVM_RUNTIME_CONTAINER_OPTIONAL_H_ A custom smart pointer for Object.
Definition: object.h:358
auto operator!=(const Optional< T > &other) const
Definition: optional.h:123
auto operator!=(const T &other) const
Definition: optional.h:140
bool operator==(std::nullptr_t) const
Definition: optional.h:110
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Definition: loop_state.h:456
Base utilities for common POD(plain old data) container types.
base class of all object containers.
Definition: object.h:167
T value_or(T default_value) const
Definition: optional.h:105
Optional(NullOptType)
Nullopt handling.
Definition: optional.h:68
T value() const
Definition: optional.h:92
auto operator==(const T &other) const
Definition: optional.h:134
Optional(std::nullptr_t)
Definition: optional.h:71
auto operator==(const U &other) const
Definition: optional.h:142
Optional< T > & operator=(T other)
Definition: optional.h:79
auto operator!=(const U &other) const
Definition: optional.h:148
Optional< T > & operator=(std::nullptr_t)
Definition: optional.h:72
Base class of all object reference.
Definition: object.h:511
auto operator==(const Optional< T > &other) const
Definition: optional.h:112
Optional(T other)
Definition: optional.h:77
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
constexpr runtime::NullOptType NullOpt
Definition: optional.h:160
Helper to represent nullptr for optional.
Definition: optional.h:35
bool operator!=(std::nullptr_t) const
Definition: optional.h:111
Optional(ObjectPtr< Object > ptr)
Construct from an ObjectPtr whose type already matches the ContainerType.
Definition: optional.h:66