@@ -109,6 +109,9 @@ bool car_test() {
109109}
110110```
111111
112+
113+
114+
112115The ` string_builder ` constructor takes an optional parameter which specifies the initial
113116memory allocation in byte. If you know approximately the size of your JSON output, you can
114117pass this value as a parameter (e.g., ` simdjson::builder::string_builder sb{1233213} ` ).
@@ -124,6 +127,57 @@ The `string_builder` might throw an exception in case of error when you cast it
124127
125128In all cases, the `std::string_view` instance depends the corresponding `string_builder` instance.
126129
130+ ### C++20
131+
132+
133+
134+ If you have C++20, you can simplify the code, as the `std::vector<double>` is automatically
135+ supported.
136+
137+ ```cpp
138+ Car c = {"Toyota", "Corolla", 2017, {30.0,30.2,30.513,30.79}};
139+ simdjson::builder::string_builder sb;
140+ sb.start_object();
141+ sb.append_key_value("make", c.make);
142+ sb.append_comma();
143+ sb.append_key_value("model", c.model);
144+ sb.append_comma();
145+ sb.append_key_value("year", c.year);
146+ sb.append_comma();
147+ sb.append_key_value("tire_pressure", c.tire_pressure);
148+ sb.end_object();
149+ std::string_view p = sb.view();
150+ ```
151+
152+ With C++20, you can similarly handle standard containers transparently.
153+ For example, you can serialize ` std::map<std::string,T> ` types.
154+
155+ ``` cpp
156+ std::map<std::string,double > c = {{"key1", 1}, {"key2", 1}};
157+ simdjson::builder::string_builder sb;
158+ sb.append(c);
159+ std::string_view p = sb.view();
160+ ```
161+
162+ You can also serialize `std::vector<T>` types.
163+
164+ ```cpp
165+ std::vector<std::vector<double>> c = {{1.0, 2.0}, {3.0, 4.0}};
166+ simdjson::builder::string_builder sb;
167+ sb.append(c);
168+ std::string_view p = sb.view();
169+ ```
170+
171+ You can also skip the creation for the ` string_builder ` instance in such simple cases.
172+
173+ ``` cpp
174+ std::vector<std::vector<double >> c = {{1.0, 2.0}, {3.0, 4.0}};
175+ std::string json = simdjson::to_json(c);
176+ ```
177+
178+ We do recommend that you create and reuse the `string_builder` instance for performance
179+ reasons.
180+
127181C++26 static reflection
128182------------------------
129183
0 commit comments