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()
8
8
object[" test1" ] = " Hello World" ;
9
9
object[" test2" ] = 123.0 ;
10
10
std::println (" {}" , object);
11
+ std::println (" object[\" test1\" ] = {}" , object[" test1" ]);
11
12
}
Original file line number Diff line number Diff line change @@ -92,6 +92,8 @@ namespace cppjson
92
92
}
93
93
private:
94
94
std::reference_wrapper<JsonObject> _object;
95
+
96
+ friend struct std ::formatter<cppjson::Object::ObjectProxy>;
95
97
};
96
98
97
99
@@ -106,6 +108,8 @@ namespace cppjson
106
108
}
107
109
private:
108
110
std::reference_wrapper<const JsonObject> _object;
111
+
112
+ friend struct std ::formatter<cppjson::Object::ConstObjectProxy>;
109
113
};
110
114
111
115
ObjectProxy operator [](const std::string& key)
@@ -146,6 +150,29 @@ struct std::formatter<cppjson::JsonObject>
146
150
}
147
151
};
148
152
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
+
149
176
template <>
150
177
struct std ::formatter<cppjson::Object>
151
178
{
You can’t perform that action at this time.
0 commit comments