diff --git a/include/simdjson/document.h b/include/simdjson/document.h index 0cda430b..1e0e7af5 100644 --- a/include/simdjson/document.h +++ b/include/simdjson/document.h @@ -1215,7 +1215,16 @@ inline std::ostream& operator<<(std::ostream& out, const simdjson_result &value) noexcept(false) { return out << minify>(value); } - +/** + * Send padded_string instance to an output stream. + * + * @param out The output stream. + * @param s The padded_string instance. + * @throw simdjson_error if the result being printed has an error. If there is an error with the + * underlying output stream, that error will be propagated (simdjson_error will not be + * thrown). + */ +inline std::ostream& operator<<(std::ostream& out, simdjson_result &s) noexcept(false) { return out << s.value(); } #endif /** The result of a JSON navigation that may fail. */ diff --git a/include/simdjson/padded_string.h b/include/simdjson/padded_string.h index 780be3db..5f1954ad 100644 --- a/include/simdjson/padded_string.h +++ b/include/simdjson/padded_string.h @@ -7,6 +7,7 @@ #include #include #include +#include namespace simdjson { @@ -110,6 +111,15 @@ private: }; // padded_string +/** + * Send padded_string instance to an output stream. + * + * @param out The output stream. + * @param s The padded_string instance. + * @throw if there is an error with the underlying output stream. simdjson itself will not throw. + */ +inline std::ostream& operator<<(std::ostream& out, const padded_string& s) { return out << s.data(); } + } // namespace simdjson // This is deliberately outside of simdjson so that people get it without having to use the namespace diff --git a/tests/basictests.cpp b/tests/basictests.cpp index 1fbf0e48..4378a542 100644 --- a/tests/basictests.cpp +++ b/tests/basictests.cpp @@ -1607,7 +1607,7 @@ namespace format_tests { const string MINIFIED(R"({"foo":1,"bar":[1,2,3],"baz":{"a":1,"b":2,"c":3}})"); bool assert_minified(ostringstream &actual, const std::string &expected=MINIFIED) { if (actual.str() != expected) { - cerr << "Failed to correctly minify " << DOCUMENT.data() << endl; + cerr << "Failed to correctly minify " << DOCUMENT << endl; cerr << "Expected: " << expected << endl; cerr << "Actual: " << actual.str() << endl; return false;