From 7d4b9cdefa9bceedd5fa37f2284e361bb65340eb Mon Sep 17 00:00:00 2001 From: Dmitry Arkhipov Date: Mon, 24 Oct 2022 15:43:33 +0300 Subject: [PATCH] move operator<< overloads to corresponding headers --- include/boost/json/array.hpp | 24 +++++++++++++++++ include/boost/json/object.hpp | 23 +++++++++++++++++ include/boost/json/serialize.hpp | 44 -------------------------------- include/boost/json/string.hpp | 24 +++++++++++++++++ include/boost/json/value.hpp | 24 +++++++++++++++++ 5 files changed, 95 insertions(+), 44 deletions(-) diff --git a/include/boost/json/array.hpp b/include/boost/json/array.hpp index d6c164ac..50da82aa 100644 --- a/include/boost/json/array.hpp +++ b/include/boost/json/array.hpp @@ -1659,6 +1659,30 @@ public: return ! (lhs == rhs); } + /** Serialize @ref array to an output stream. + + This function serializes an `array` as JSON into the output stream. + + @return Reference to `os`. + + @par Complexity + Constant or linear in the size of `arr`. + + @par Exception Safety + Strong guarantee. + Calls to `memory_resource::allocate` may throw. + + @param os The output stream to serialize to. + + @param arr The value to serialize. + */ + BOOST_JSON_DECL + friend + std::ostream& + operator<<( + std::ostream& os, + array const& arr); + private: template using iter_cat = typename diff --git a/include/boost/json/object.hpp b/include/boost/json/object.hpp index 4ffed1fb..a4ef9351 100644 --- a/include/boost/json/object.hpp +++ b/include/boost/json/object.hpp @@ -1529,6 +1529,29 @@ public: return ! (lhs == rhs); } + /** Serialize @ref object to an output stream. + + This function serializes an `object` as JSON into the output stream. + + @return Reference to `os`. + + @par Complexity + Constant or linear in the size of `obj`. + + @par Exception Safety + Strong guarantee. + Calls to `memory_resource::allocate` may throw. + + @param os The output stream to serialize to. + + @param obj The value to serialize. + */ + BOOST_JSON_DECL + friend + std::ostream& + operator<<( + std::ostream& os, + object const& obj); private: #ifndef BOOST_JSON_DOCS // VFALCO friending a detail function makes it public diff --git a/include/boost/json/serialize.hpp b/include/boost/json/serialize.hpp index 1b1a0d16..e6c8597e 100644 --- a/include/boost/json/serialize.hpp +++ b/include/boost/json/serialize.hpp @@ -55,50 +55,6 @@ std::string serialize(string_view t); /** @} */ -/** Serialize an element to an output stream. - - This function serializes the specified element - as JSON into the output stream. - - @return `os`. - - @par Complexity - Constant or linear in the size of `t`. - - @par Exception Safety - Strong guarantee. - Calls to `memory_resource::allocate` may throw. - - @param os The output stream to serialize to. - - @param t The value to serialize -*/ -/** @{ */ -BOOST_JSON_DECL -std::ostream& -operator<<( - std::ostream& os, - value const& t); - -BOOST_JSON_DECL -std::ostream& -operator<<( - std::ostream& os, - array const& t); - -BOOST_JSON_DECL -std::ostream& -operator<<( - std::ostream& os, - object const& t); - -BOOST_JSON_DECL -std::ostream& -operator<<( - std::ostream& os, - string const& t); -/** @} */ - BOOST_JSON_NS_END #endif diff --git a/include/boost/json/string.hpp b/include/boost/json/string.hpp index 5b438402..4bdb350e 100644 --- a/include/boost/json/string.hpp +++ b/include/boost/json/string.hpp @@ -2738,6 +2738,30 @@ public: return subview().find_last_not_of(ch, pos); } + /** Serialize @ref string to an output stream. + + This function serializes a `string` as JSON into the output stream. + + @return Reference to `os`. + + @par Complexity + Constant or linear in the size of `str`. + + @par Exception Safety + Strong guarantee. + Calls to `memory_resource::allocate` may throw. + + @param os The output stream to serialize to. + + @param str The value to serialize. + */ + BOOST_JSON_DECL + friend + std::ostream& + operator<<( + std::ostream& os, + string const& str); + private: class undo; diff --git a/include/boost/json/value.hpp b/include/boost/json/value.hpp index 3ceb1c15..79fee9ee 100644 --- a/include/boost/json/value.hpp +++ b/include/boost/json/value.hpp @@ -3315,6 +3315,30 @@ public: return ! (lhs == rhs); } + /** Serialize @ref value to an output stream. + + This function serializes a `value` as JSON into the output stream. + + @return Reference to `os`. + + @par Complexity + Constant or linear in the size of `jv`. + + @par Exception Safety + Strong guarantee. + Calls to `memory_resource::allocate` may throw. + + @param os The output stream to serialize to. + + @param jv The value to serialize. + */ + BOOST_JSON_DECL + friend + std::ostream& + operator<<( + std::ostream& os, + value const& jv); + private: static void