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);
100 T
value_or(T default_value)
const {
return data_ !=
nullptr ? T(data_) : default_value; }
103 explicit operator bool()
const {
return *
this !=
nullptr; }
105 bool operator==(std::nullptr_t)
const {
return data_ ==
nullptr; }
106 bool operator!=(std::nullptr_t)
const {
return data_ !=
nullptr; }
109 using RetType = decltype(value() == other.
value());
110 if (same_as(other))
return RetType(
true);
111 if (*
this !=
nullptr && other !=
nullptr) {
112 return value() == other.
value();
115 return RetType(
false);
120 using RetType = decltype(value() != other.
value());
121 if (same_as(other))
return RetType(
false);
122 if (*
this !=
nullptr && other !=
nullptr) {
123 return value() != other.
value();
126 return RetType(
true);
130 using RetType = decltype(value() == other);
131 if (same_as(other))
return RetType(
true);
132 if (*
this !=
nullptr)
return value() == other;
133 return RetType(
false);
135 auto operator!=(
const T& other)
const {
return !(*
this == other); }
136 template <
typename U>
138 using RetType = decltype(value() == other);
139 if (*
this ==
nullptr)
return RetType(
false);
140 return value() == other;
142 template <
typename U>
144 using RetType = decltype(value() != other);
145 if (*
this ==
nullptr)
return RetType(
true);
146 return value() != other;
148 static constexpr
bool _type_is_nullable =
true;
158 #endif // TVM_RUNTIME_CONTAINER_OPTIONAL_H_ A custom smart pointer for Object.
Definition: object.h:356
auto operator!=(const Optional< T > &other) const
Definition: optional.h:118
auto operator!=(const T &other) const
Definition: optional.h:135
bool operator==(std::nullptr_t) const
Definition: optional.h:105
Performance counters for profiling via the PAPI library.
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:165
T value_or(T default_value) const
Definition: optional.h:100
Optional(NullOptType)
Nullopt handling.
Definition: optional.h:68
T value() const
Definition: optional.h:92
auto operator==(const T &other) const
Definition: optional.h:129
Optional(std::nullptr_t)
Definition: optional.h:71
auto operator==(const U &other) const
Definition: optional.h:137
Optional< T > & operator=(T other)
Definition: optional.h:79
auto operator!=(const U &other) const
Definition: optional.h:143
Optional< T > & operator=(std::nullptr_t)
Definition: optional.h:72
Base class of all object reference.
Definition: object.h:504
auto operator==(const Optional< T > &other) const
Definition: optional.h:107
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:155
Helper to represent nullptr for optional.
Definition: optional.h:35
bool operator!=(std::nullptr_t) const
Definition: optional.h:106
Optional(ObjectPtr< Object > ptr)
Construct from an ObjectPtr whose type already matches the ContainerType.
Definition: optional.h:66