File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -8,4 +8,5 @@ int main()
88 object[" test1" ] = " Hello World" ;
99 object[" test2" ] = 123.0 ;
1010 std::println (" {}" , object);
11+ std::println (" object[\" test1\" ] = {}" , object[" test1" ]);
1112}
Original file line number Diff line number Diff line change @@ -92,6 +92,8 @@ namespace cppjson
9292 }
9393 private:
9494 std::reference_wrapper<JsonObject> _object;
95+
96+ friend struct std ::formatter<cppjson::Object::ObjectProxy>;
9597 };
9698
9799
@@ -106,6 +108,8 @@ namespace cppjson
106108 }
107109 private:
108110 std::reference_wrapper<const JsonObject> _object;
111+
112+ friend struct std ::formatter<cppjson::Object::ConstObjectProxy>;
109113 };
110114
111115 ObjectProxy operator [](const std::string& key)
@@ -146,6 +150,29 @@ struct std::formatter<cppjson::JsonObject>
146150 }
147151};
148152
153+ template <>
154+ struct std ::formatter<cppjson::Object::ObjectProxy>
155+ {
156+ constexpr auto parse (std::format_parse_context& context) { return context.begin (); }
157+
158+ auto format (const cppjson::Object::ObjectProxy& object, std::format_context& context) const
159+ {
160+ return std::format_to (context.out (), " {}" , object._object .get ());
161+ }
162+ };
163+
164+
165+ template <>
166+ struct std ::formatter<cppjson::Object::ConstObjectProxy>
167+ {
168+ constexpr auto parse (std::format_parse_context& context) { return context.begin (); }
169+
170+ auto format (const cppjson::Object::ConstObjectProxy& object, std::format_context& context) const
171+ {
172+ return std::format_to (context.out (), " {}" , object._object .get ());
173+ }
174+ };
175+
149176template <>
150177struct std ::formatter<cppjson::Object>
151178{
You can’t perform that action at this time.
0 commit comments