Index: mojo/public/cpp/bindings/array.h |
diff --git a/mojo/public/cpp/bindings/array.h b/mojo/public/cpp/bindings/array.h |
index c03da87a7fab388e9e54fc454af1a98e009c5033..bbf8e5c93cfa74ac10d3bc2ef25b68374ea13665 100644 |
--- a/mojo/public/cpp/bindings/array.h |
+++ b/mojo/public/cpp/bindings/array.h |
@@ -9,6 +9,7 @@ |
#include <algorithm> |
#include <cstddef> |
+#include <iosfwd> |
#include <set> |
#include <string> |
#include <vector> |
@@ -309,6 +310,27 @@ struct TypeConverter<std::set<E>, Array<T>> { |
} |
}; |
+// Prints the contents of an array to an output stream for debugging purposes. |
+template <typename T> |
+std::ostream& operator<<(std::ostream& os, const mojo::Array<T>& array) { |
+ if (array) { |
+ os << "["; |
+ bool first = true; |
+ for (auto it = array.storage().cbegin(); it != array.storage().cend(); |
+ ++it) { |
+ if (first) |
+ first = false; |
+ else |
+ os << ", "; |
+ os << *it; |
+ } |
+ os << "]"; |
+ } else { |
+ os << "null"; |
+ } |
+ return os; |
+} |
+ |
} // namespace mojo |
#endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ |