From e5f3eb2d7d762dde87b00231c343c8fb141007cc Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Sat, 23 Jul 2022 19:13:09 +0200 Subject: [PATCH] Add operator<< for json_pointer --- include/nlohmann/detail/json_pointer.hpp | 13 +++++++++++++ single_include/nlohmann/json.hpp | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index 35e1ddbc5..41d022994 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp @@ -12,6 +12,9 @@ #include // isdigit #include // errno, ERANGE #include // strtoull +#ifndef JSON_NO_IO + #include // ostream +#endif // JSON_NO_IO #include // max #include // accumulate #include // string @@ -80,6 +83,16 @@ class json_pointer return to_string(); } +#ifndef JSON_NO_IO + /// @brief write string representation of the JSON pointer to stream + /// @sa https://json.nlohmann.me/api/basic_json/operator_ltlt/ + friend std::ostream& operator<<(std::ostream& o, const json_pointer& ptr) + { + o << ptr.to_string(); + return o; + } +#endif + /// @brief append another JSON pointer at the end of this JSON pointer /// @sa https://json.nlohmann.me/api/json_pointer/operator_slasheq/ json_pointer& operator/=(const json_pointer& ptr) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index dd9c39fb5..b1efc7697 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -13455,6 +13455,9 @@ class json_reverse_iterator : public std::reverse_iterator #include // isdigit #include // errno, ERANGE #include // strtoull +#ifndef JSON_NO_IO + #include // ostream +#endif // JSON_NO_IO #include // max #include // accumulate #include // string @@ -13528,6 +13531,16 @@ class json_pointer return to_string(); } +#ifndef JSON_NO_IO + /// @brief write string representation of the JSON pointer to stream + /// @sa https://json.nlohmann.me/api/basic_json/operator_ltlt/ + friend std::ostream& operator<<(std::ostream& o, const json_pointer& ptr) + { + o << ptr.to_string(); + return o; + } +#endif + /// @brief append another JSON pointer at the end of this JSON pointer /// @sa https://json.nlohmann.me/api/json_pointer/operator_slasheq/ json_pointer& operator/=(const json_pointer& ptr)