Index: mojo/public/cpp/bindings/struct_ptr.h |
diff --git a/mojo/public/cpp/bindings/struct_ptr.h b/mojo/public/cpp/bindings/struct_ptr.h |
index 1b34a9ec036149c229d63d1f4a139ceb8de96093..1bfc0ed85b5484dddccf7bb5528bc9e704407a0b 100644 |
--- a/mojo/public/cpp/bindings/struct_ptr.h |
+++ b/mojo/public/cpp/bindings/struct_ptr.h |
@@ -6,6 +6,7 @@ |
#define MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ |
#include <cstddef> |
+#include <iosfwd> |
#include <memory> |
#include <new> |
@@ -127,7 +128,7 @@ class InlinedStructPtr { |
void reset() { |
is_null_ = true; |
- value_. ~Struct(); |
+ value_.~Struct(); |
new (&value_) Struct(); |
} |
@@ -175,6 +176,22 @@ class InlinedStructPtr { |
MOJO_MOVE_ONLY_TYPE(InlinedStructPtr); |
}; |
+// Prints the pointee of a Mojo structure pointer to an output stream |
+// for debugging purposes, assuming there exists an operator<< overload |
+// that accepts a const reference to the object. |
+template <typename T, typename = typename T::Data_> |
+auto operator<<(std::ostream& os, const T* value) -> decltype(os << *value) { |
+ return value ? os << *value : os << "null"; |
+} |
+template <typename T> |
+std::ostream& operator<<(std::ostream& os, const StructPtr<T>& value) { |
+ return os << value.get(); |
+} |
+template <typename T> |
+std::ostream& operator<<(std::ostream& os, const InlinedStructPtr<T>& value) { |
+ return os << value.get(); |
+} |
+ |
} // namespace mojo |
#endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ |