gemini-code-assist[bot] commented on code in PR #596:
URL: https://github.com/apache/tvm-ffi/pull/596#discussion_r3304842756
##########
include/tvm/ffi/extra/dataclass.h:
##########
@@ -108,6 +112,40 @@ TVM_FFI_EXTRA_CXX_API bool RecursiveGt(const Any& lhs,
const Any& rhs);
*/
TVM_FFI_EXTRA_CXX_API bool RecursiveGe(const Any& lhs, const Any& rhs);
+// ============================================================================
+// std::ostream operator<< overloads
+//
+// Delegate to ReprPrint so std::cout << x and LOG(INFO) << x "just work"
+// for the type-erased FFI value containers.
+// ============================================================================
+
+/*! \brief Stream an ffi::Any using its canonical repr form. */
+inline std::ostream& operator<<(std::ostream& os, const Any& value) {
+ return os << ReprPrint(value);
+}
+
+/*! \brief Stream an ffi::ObjectRef using its canonical repr form. */
+inline std::ostream& operator<<(std::ostream& os, const ObjectRef& value) {
+ return os << ReprPrint(Any(value));
+}
+
+/*! \brief Stream an ffi::Variant<...> using its canonical repr form. */
+template <typename... V>
+inline std::ostream& operator<<(std::ostream& os, const Variant<V...>& value) {
+ return os << ReprPrint(Any(value));
+}
+
+/*!
+ * \brief Stream an ffi::Optional<T> using its canonical repr form.
+ *
+ * Prints `"None"` for empty optionals (Python convention, matches
`ReprPrint`).
+ */
+template <typename T>
+inline std::ostream& operator<<(std::ostream& os, const Optional<T>& value) {
+ if (!value.has_value()) return os << "None";
+ return os << ReprPrint(Any(value));
Review Comment:

Since we have already verified that `value` has a value on line 145, we can
directly dereference it using `*value` when constructing the `Any` object. This
avoids the overhead of wrapping and unwrapping the `Optional` container through
`TypeTraits<Optional<T>>` and directly constructs `Any` from the underlying
type `T`.
```c
return os << ReprPrint(Any(*value));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]