30 #ifndef INCLUDE_NLOHMANN_JSON_HPP_
31 #define INCLUDE_NLOHMANN_JSON_HPP_
33 #define NLOHMANN_JSON_VERSION_MAJOR 3
34 #define NLOHMANN_JSON_VERSION_MINOR 9
35 #define NLOHMANN_JSON_VERSION_PATCH 1
40 #include <initializer_list>
59 #include <forward_list>
64 #include <type_traits>
65 #include <unordered_map>
116 enum class value_t : std::uint8_t
143 inline bool operator<(
const value_t lhs,
const value_t rhs) noexcept
145 static constexpr std::array<std::uint8_t, 9> order = {{
152 const auto l_index =
static_cast<std::size_t
>(lhs);
153 const auto r_index =
static_cast<std::size_t
>(rhs);
154 return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
180 #if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15)
181 #if defined(JSON_HEDLEY_VERSION)
182 #undef JSON_HEDLEY_VERSION
184 #define JSON_HEDLEY_VERSION 15
186 #if defined(JSON_HEDLEY_STRINGIFY_EX)
187 #undef JSON_HEDLEY_STRINGIFY_EX
189 #define JSON_HEDLEY_STRINGIFY_EX(x) #x
191 #if defined(JSON_HEDLEY_STRINGIFY)
192 #undef JSON_HEDLEY_STRINGIFY
194 #define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
196 #if defined(JSON_HEDLEY_CONCAT_EX)
197 #undef JSON_HEDLEY_CONCAT_EX
199 #define JSON_HEDLEY_CONCAT_EX(a,b) a##b
201 #if defined(JSON_HEDLEY_CONCAT)
202 #undef JSON_HEDLEY_CONCAT
204 #define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
206 #if defined(JSON_HEDLEY_CONCAT3_EX)
207 #undef JSON_HEDLEY_CONCAT3_EX
209 #define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c
211 #if defined(JSON_HEDLEY_CONCAT3)
212 #undef JSON_HEDLEY_CONCAT3
214 #define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c)
216 #if defined(JSON_HEDLEY_VERSION_ENCODE)
217 #undef JSON_HEDLEY_VERSION_ENCODE
219 #define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
221 #if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
222 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
224 #define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
226 #if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
227 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
229 #define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
231 #if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
232 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
234 #define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
236 #if defined(JSON_HEDLEY_GNUC_VERSION)
237 #undef JSON_HEDLEY_GNUC_VERSION
239 #if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
240 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
241 #elif defined(__GNUC__)
242 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
245 #if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
246 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
248 #if defined(JSON_HEDLEY_GNUC_VERSION)
249 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
251 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
254 #if defined(JSON_HEDLEY_MSVC_VERSION)
255 #undef JSON_HEDLEY_MSVC_VERSION
257 #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL)
258 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
259 #elif defined(_MSC_FULL_VER) && !defined(__ICL)
260 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
261 #elif defined(_MSC_VER) && !defined(__ICL)
262 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
265 #if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
266 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
268 #if !defined(JSON_HEDLEY_MSVC_VERSION)
269 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
270 #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
271 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
272 #elif defined(_MSC_VER) && (_MSC_VER >= 1200)
273 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
275 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))
278 #if defined(JSON_HEDLEY_INTEL_VERSION)
279 #undef JSON_HEDLEY_INTEL_VERSION
281 #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL)
282 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
283 #elif defined(__INTEL_COMPILER) && !defined(__ICL)
284 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
287 #if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
288 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
290 #if defined(JSON_HEDLEY_INTEL_VERSION)
291 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
293 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
296 #if defined(JSON_HEDLEY_INTEL_CL_VERSION)
297 #undef JSON_HEDLEY_INTEL_CL_VERSION
299 #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL)
300 #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0)
303 #if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK)
304 #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
306 #if defined(JSON_HEDLEY_INTEL_CL_VERSION)
307 #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
309 #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0)
312 #if defined(JSON_HEDLEY_PGI_VERSION)
313 #undef JSON_HEDLEY_PGI_VERSION
315 #if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
316 #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
319 #if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
320 #undef JSON_HEDLEY_PGI_VERSION_CHECK
322 #if defined(JSON_HEDLEY_PGI_VERSION)
323 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
325 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
328 #if defined(JSON_HEDLEY_SUNPRO_VERSION)
329 #undef JSON_HEDLEY_SUNPRO_VERSION
331 #if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
332 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10)
333 #elif defined(__SUNPRO_C)
334 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
335 #elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
336 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10)
337 #elif defined(__SUNPRO_CC)
338 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
341 #if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
342 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
344 #if defined(JSON_HEDLEY_SUNPRO_VERSION)
345 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
347 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
350 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
351 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
353 #if defined(__EMSCRIPTEN__)
354 #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
357 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
358 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
360 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
361 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
363 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
366 #if defined(JSON_HEDLEY_ARM_VERSION)
367 #undef JSON_HEDLEY_ARM_VERSION
369 #if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
370 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)
371 #elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
372 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
375 #if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
376 #undef JSON_HEDLEY_ARM_VERSION_CHECK
378 #if defined(JSON_HEDLEY_ARM_VERSION)
379 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
381 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
384 #if defined(JSON_HEDLEY_IBM_VERSION)
385 #undef JSON_HEDLEY_IBM_VERSION
387 #if defined(__ibmxl__)
388 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
389 #elif defined(__xlC__) && defined(__xlC_ver__)
390 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
391 #elif defined(__xlC__)
392 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
395 #if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
396 #undef JSON_HEDLEY_IBM_VERSION_CHECK
398 #if defined(JSON_HEDLEY_IBM_VERSION)
399 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
401 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
404 #if defined(JSON_HEDLEY_TI_VERSION)
405 #undef JSON_HEDLEY_TI_VERSION
408 defined(__TI_COMPILER_VERSION__) && \
410 defined(__TMS470__) || defined(__TI_ARM__) || \
411 defined(__MSP430__) || \
412 defined(__TMS320C2000__) \
414 #if (__TI_COMPILER_VERSION__ >= 16000000)
415 #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
419 #if defined(JSON_HEDLEY_TI_VERSION_CHECK)
420 #undef JSON_HEDLEY_TI_VERSION_CHECK
422 #if defined(JSON_HEDLEY_TI_VERSION)
423 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
425 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
428 #if defined(JSON_HEDLEY_TI_CL2000_VERSION)
429 #undef JSON_HEDLEY_TI_CL2000_VERSION
431 #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
432 #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
435 #if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK)
436 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
438 #if defined(JSON_HEDLEY_TI_CL2000_VERSION)
439 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
441 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0)
444 #if defined(JSON_HEDLEY_TI_CL430_VERSION)
445 #undef JSON_HEDLEY_TI_CL430_VERSION
447 #if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__)
448 #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
451 #if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK)
452 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
454 #if defined(JSON_HEDLEY_TI_CL430_VERSION)
455 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
457 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0)
460 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
461 #undef JSON_HEDLEY_TI_ARMCL_VERSION
463 #if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__))
464 #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
467 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK)
468 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
470 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
471 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
473 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0)
476 #if defined(JSON_HEDLEY_TI_CL6X_VERSION)
477 #undef JSON_HEDLEY_TI_CL6X_VERSION
479 #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__)
480 #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
483 #if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK)
484 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
486 #if defined(JSON_HEDLEY_TI_CL6X_VERSION)
487 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
489 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0)
492 #if defined(JSON_HEDLEY_TI_CL7X_VERSION)
493 #undef JSON_HEDLEY_TI_CL7X_VERSION
495 #if defined(__TI_COMPILER_VERSION__) && defined(__C7000__)
496 #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
499 #if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK)
500 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
502 #if defined(JSON_HEDLEY_TI_CL7X_VERSION)
503 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
505 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0)
508 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
509 #undef JSON_HEDLEY_TI_CLPRU_VERSION
511 #if defined(__TI_COMPILER_VERSION__) && defined(__PRU__)
512 #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
515 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK)
516 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
518 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
519 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
521 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0)
524 #if defined(JSON_HEDLEY_CRAY_VERSION)
525 #undef JSON_HEDLEY_CRAY_VERSION
528 #if defined(_RELEASE_PATCHLEVEL)
529 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
531 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
535 #if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
536 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
538 #if defined(JSON_HEDLEY_CRAY_VERSION)
539 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
541 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
544 #if defined(JSON_HEDLEY_IAR_VERSION)
545 #undef JSON_HEDLEY_IAR_VERSION
547 #if defined(__IAR_SYSTEMS_ICC__)
549 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
551 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0)
555 #if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
556 #undef JSON_HEDLEY_IAR_VERSION_CHECK
558 #if defined(JSON_HEDLEY_IAR_VERSION)
559 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
561 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
564 #if defined(JSON_HEDLEY_TINYC_VERSION)
565 #undef JSON_HEDLEY_TINYC_VERSION
567 #if defined(__TINYC__)
568 #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
571 #if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
572 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
574 #if defined(JSON_HEDLEY_TINYC_VERSION)
575 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
577 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
580 #if defined(JSON_HEDLEY_DMC_VERSION)
581 #undef JSON_HEDLEY_DMC_VERSION
584 #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
587 #if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
588 #undef JSON_HEDLEY_DMC_VERSION_CHECK
590 #if defined(JSON_HEDLEY_DMC_VERSION)
591 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
593 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
596 #if defined(JSON_HEDLEY_COMPCERT_VERSION)
597 #undef JSON_HEDLEY_COMPCERT_VERSION
599 #if defined(__COMPCERT_VERSION__)
600 #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)
603 #if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
604 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
606 #if defined(JSON_HEDLEY_COMPCERT_VERSION)
607 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
609 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
612 #if defined(JSON_HEDLEY_PELLES_VERSION)
613 #undef JSON_HEDLEY_PELLES_VERSION
615 #if defined(__POCC__)
616 #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
619 #if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
620 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
622 #if defined(JSON_HEDLEY_PELLES_VERSION)
623 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
625 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
628 #if defined(JSON_HEDLEY_MCST_LCC_VERSION)
629 #undef JSON_HEDLEY_MCST_LCC_VERSION
631 #if defined(__LCC__) && defined(__LCC_MINOR__)
632 #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__)
635 #if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK)
636 #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
638 #if defined(JSON_HEDLEY_MCST_LCC_VERSION)
639 #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
641 #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0)
644 #if defined(JSON_HEDLEY_GCC_VERSION)
645 #undef JSON_HEDLEY_GCC_VERSION
648 defined(JSON_HEDLEY_GNUC_VERSION) && \
649 !defined(__clang__) && \
650 !defined(JSON_HEDLEY_INTEL_VERSION) && \
651 !defined(JSON_HEDLEY_PGI_VERSION) && \
652 !defined(JSON_HEDLEY_ARM_VERSION) && \
653 !defined(JSON_HEDLEY_CRAY_VERSION) && \
654 !defined(JSON_HEDLEY_TI_VERSION) && \
655 !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \
656 !defined(JSON_HEDLEY_TI_CL430_VERSION) && \
657 !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \
658 !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \
659 !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \
660 !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \
661 !defined(__COMPCERT__) && \
662 !defined(JSON_HEDLEY_MCST_LCC_VERSION)
663 #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
666 #if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
667 #undef JSON_HEDLEY_GCC_VERSION_CHECK
669 #if defined(JSON_HEDLEY_GCC_VERSION)
670 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
672 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
675 #if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
676 #undef JSON_HEDLEY_HAS_ATTRIBUTE
679 defined(__has_attribute) && \
681 (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \
683 # define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
685 # define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
688 #if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
689 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
691 #if defined(__has_attribute)
692 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
694 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
697 #if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
698 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
700 #if defined(__has_attribute)
701 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
703 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
706 #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
707 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
710 defined(__has_cpp_attribute) && \
711 defined(__cplusplus) && \
712 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0))
713 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
715 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
718 #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
719 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
721 #if !defined(__cplusplus) || !defined(__has_cpp_attribute)
722 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
724 !defined(JSON_HEDLEY_PGI_VERSION) && \
725 !defined(JSON_HEDLEY_IAR_VERSION) && \
726 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \
727 (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0))
728 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)
730 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
733 #if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
734 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
736 #if defined(__has_cpp_attribute) && defined(__cplusplus)
737 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
739 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
742 #if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
743 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
745 #if defined(__has_cpp_attribute) && defined(__cplusplus)
746 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
748 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
751 #if defined(JSON_HEDLEY_HAS_BUILTIN)
752 #undef JSON_HEDLEY_HAS_BUILTIN
754 #if defined(__has_builtin)
755 #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
757 #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
760 #if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
761 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
763 #if defined(__has_builtin)
764 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
766 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
769 #if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
770 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
772 #if defined(__has_builtin)
773 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
775 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
778 #if defined(JSON_HEDLEY_HAS_FEATURE)
779 #undef JSON_HEDLEY_HAS_FEATURE
781 #if defined(__has_feature)
782 #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
784 #define JSON_HEDLEY_HAS_FEATURE(feature) (0)
787 #if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
788 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
790 #if defined(__has_feature)
791 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
793 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
796 #if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
797 #undef JSON_HEDLEY_GCC_HAS_FEATURE
799 #if defined(__has_feature)
800 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
802 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
805 #if defined(JSON_HEDLEY_HAS_EXTENSION)
806 #undef JSON_HEDLEY_HAS_EXTENSION
808 #if defined(__has_extension)
809 #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
811 #define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
814 #if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
815 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
817 #if defined(__has_extension)
818 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
820 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
823 #if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
824 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
826 #if defined(__has_extension)
827 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
829 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
832 #if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
833 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
835 #if defined(__has_declspec_attribute)
836 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
838 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
841 #if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
842 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
844 #if defined(__has_declspec_attribute)
845 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
847 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
850 #if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
851 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
853 #if defined(__has_declspec_attribute)
854 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
856 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
859 #if defined(JSON_HEDLEY_HAS_WARNING)
860 #undef JSON_HEDLEY_HAS_WARNING
862 #if defined(__has_warning)
863 #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
865 #define JSON_HEDLEY_HAS_WARNING(warning) (0)
868 #if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
869 #undef JSON_HEDLEY_GNUC_HAS_WARNING
871 #if defined(__has_warning)
872 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
874 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
877 #if defined(JSON_HEDLEY_GCC_HAS_WARNING)
878 #undef JSON_HEDLEY_GCC_HAS_WARNING
880 #if defined(__has_warning)
881 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
883 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
887 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
888 defined(__clang__) || \
889 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
890 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
891 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
892 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
893 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
894 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
895 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
896 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
897 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
898 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \
899 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
900 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
901 JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
902 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
903 JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
904 (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
905 #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
906 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
907 #define JSON_HEDLEY_PRAGMA(value) __pragma(value)
909 #define JSON_HEDLEY_PRAGMA(value)
912 #if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
913 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
915 #if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
916 #undef JSON_HEDLEY_DIAGNOSTIC_POP
918 #if defined(__clang__)
919 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
920 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
921 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
922 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
923 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
924 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
925 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
926 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
928 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
929 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
930 #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
931 #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
932 #elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
933 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
934 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
936 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
937 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
938 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \
939 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
940 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
941 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
942 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
943 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
944 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
945 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
946 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
948 #define JSON_HEDLEY_DIAGNOSTIC_PUSH
949 #define JSON_HEDLEY_DIAGNOSTIC_POP
954 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
955 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
957 #if defined(__cplusplus)
958 # if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
959 # if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions")
960 # if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions")
961 # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
962 JSON_HEDLEY_DIAGNOSTIC_PUSH \
963 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
964 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
965 _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \
967 JSON_HEDLEY_DIAGNOSTIC_POP
969 # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
970 JSON_HEDLEY_DIAGNOSTIC_PUSH \
971 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
972 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
974 JSON_HEDLEY_DIAGNOSTIC_POP
977 # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
978 JSON_HEDLEY_DIAGNOSTIC_PUSH \
979 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
981 JSON_HEDLEY_DIAGNOSTIC_POP
985 #if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
986 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
989 #if defined(JSON_HEDLEY_CONST_CAST)
990 #undef JSON_HEDLEY_CONST_CAST
992 #if defined(__cplusplus)
993 # define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
995 JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
996 JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \
997 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
998 # define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \
999 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1000 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
1002 JSON_HEDLEY_DIAGNOSTIC_POP \
1005 # define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
1008 #if defined(JSON_HEDLEY_REINTERPRET_CAST)
1009 #undef JSON_HEDLEY_REINTERPRET_CAST
1011 #if defined(__cplusplus)
1012 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
1014 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr))
1017 #if defined(JSON_HEDLEY_STATIC_CAST)
1018 #undef JSON_HEDLEY_STATIC_CAST
1020 #if defined(__cplusplus)
1021 #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
1023 #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
1026 #if defined(JSON_HEDLEY_CPP_CAST)
1027 #undef JSON_HEDLEY_CPP_CAST
1029 #if defined(__cplusplus)
1030 # if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
1031 # define JSON_HEDLEY_CPP_CAST(T, expr) \
1032 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1033 _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \
1035 JSON_HEDLEY_DIAGNOSTIC_POP
1036 # elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0)
1037 # define JSON_HEDLEY_CPP_CAST(T, expr) \
1038 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1039 _Pragma("diag_suppress=Pe137") \
1040 JSON_HEDLEY_DIAGNOSTIC_POP
1042 # define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr))
1045 # define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
1048 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
1049 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1051 #if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
1052 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
1053 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1054 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
1055 #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1056 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786))
1057 #elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1058 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445")
1059 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1060 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1061 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1062 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1063 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1064 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
1065 #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1066 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1068 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1069 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1070 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1071 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1072 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1073 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1074 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1075 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1076 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1077 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1078 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1079 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
1080 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
1081 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
1082 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
1083 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
1084 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1085 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
1086 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
1087 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
1089 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1092 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
1093 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1095 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1096 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
1097 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1098 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
1099 #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1100 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161))
1101 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1102 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
1103 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1104 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
1105 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1106 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))
1108 JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \
1109 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1110 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1111 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)
1112 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1113 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0)
1114 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1115 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1116 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
1117 #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1118 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161")
1120 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1123 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
1124 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1126 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
1127 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"")
1128 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1129 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1130 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
1131 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
1132 #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1133 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292))
1134 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
1135 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))
1136 #elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1137 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098")
1138 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1139 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1140 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
1141 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
1143 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1144 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1145 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0)
1146 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
1147 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1148 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097")
1149 #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1150 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1152 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1155 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
1156 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1158 #if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
1159 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
1160 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1161 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
1162 #elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
1163 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
1165 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1168 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION)
1169 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1171 #if JSON_HEDLEY_HAS_WARNING("-Wunused-function")
1172 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"")
1173 #elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0)
1174 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"")
1175 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0)
1176 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505))
1177 #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1178 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142")
1180 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1183 #if defined(JSON_HEDLEY_DEPRECATED)
1184 #undef JSON_HEDLEY_DEPRECATED
1186 #if defined(JSON_HEDLEY_DEPRECATED_FOR)
1187 #undef JSON_HEDLEY_DEPRECATED_FOR
1190 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1191 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1192 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
1193 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
1195 (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1196 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1197 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1198 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1199 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \
1200 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1201 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1202 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \
1203 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1204 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1205 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \
1206 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1207 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
1208 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
1209 #elif defined(__cplusplus) && (__cplusplus >= 201402L)
1210 #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
1211 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
1213 JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
1214 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1215 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1216 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1217 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1218 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1219 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1220 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1221 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1222 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1223 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1224 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1225 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1226 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1227 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1228 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1229 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
1230 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
1232 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1233 JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \
1234 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1235 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
1236 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
1237 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1238 #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
1239 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
1241 #define JSON_HEDLEY_DEPRECATED(since)
1242 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
1245 #if defined(JSON_HEDLEY_UNAVAILABLE)
1246 #undef JSON_HEDLEY_UNAVAILABLE
1249 JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
1250 JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
1251 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1252 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1253 #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
1255 #define JSON_HEDLEY_UNAVAILABLE(available_since)
1265 JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
1266 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1267 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1268 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1269 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1270 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1271 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1272 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1273 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1274 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1275 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1276 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1277 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1278 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1279 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1280 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1281 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1282 #define __attribute__((__warn_unused_result__))
1283 #define _MSG(msg) __attribute__((__warn_unused_result__))
1284 #elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)
1285 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1286 #define _MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
1287 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
1288 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1289 #define _MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1290 #elif defined(_Check_return_)
1291 #define _Check_return_
1292 #define _MSG(msg) _Check_return_
1298 #if defined(JSON_HEDLEY_SENTINEL)
1299 #undef JSON_HEDLEY_SENTINEL
1302 JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
1303 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1304 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1305 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1306 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1307 #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
1309 #define JSON_HEDLEY_SENTINEL(position)
1312 #if defined(JSON_HEDLEY_NO_RETURN)
1313 #undef JSON_HEDLEY_NO_RETURN
1315 #if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1316 #define JSON_HEDLEY_NO_RETURN __noreturn
1318 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1319 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1320 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1321 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
1322 #define JSON_HEDLEY_NO_RETURN _Noreturn
1323 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
1324 #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
1326 JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
1327 JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \
1328 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1329 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1330 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1331 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1332 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1333 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1334 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1335 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1336 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1337 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1338 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1339 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1340 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1341 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1342 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1343 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1344 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1345 #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
1347 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1348 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1349 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1350 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1351 #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
1352 #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1353 #define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
1354 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1355 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1357 #define JSON_HEDLEY_NO_RETURN
1360 #if defined(JSON_HEDLEY_NO_ESCAPE)
1361 #undef JSON_HEDLEY_NO_ESCAPE
1363 #if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
1364 #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
1366 #define JSON_HEDLEY_NO_ESCAPE
1369 #if defined(JSON_HEDLEY_UNREACHABLE)
1370 #undef JSON_HEDLEY_UNREACHABLE
1372 #if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
1373 #undef JSON_HEDLEY_UNREACHABLE_RETURN
1375 #if defined(JSON_HEDLEY_ASSUME)
1376 #undef JSON_HEDLEY_ASSUME
1379 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1380 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1381 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1382 #define JSON_HEDLEY_ASSUME(expr) __assume(expr)
1383 #elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
1384 #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
1386 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1387 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1388 #if defined(__cplusplus)
1389 #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
1391 #define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
1395 (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
1396 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1397 JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \
1398 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1399 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \
1400 JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \
1401 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1402 #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
1403 #elif defined(JSON_HEDLEY_ASSUME)
1404 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1406 #if !defined(JSON_HEDLEY_ASSUME)
1407 #if defined(JSON_HEDLEY_UNREACHABLE)
1408 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1)))
1410 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr)
1413 #if defined(JSON_HEDLEY_UNREACHABLE)
1415 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1416 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1417 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))
1419 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
1422 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value)
1424 #if !defined(JSON_HEDLEY_UNREACHABLE)
1425 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1428 JSON_HEDLEY_DIAGNOSTIC_PUSH
1429 #if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
1430 #pragma clang diagnostic ignored "-Wpedantic"
1432 #if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
1433 #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
1435 #if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0)
1436 #if defined(__clang__)
1437 #pragma clang diagnostic ignored "-Wvariadic-macros"
1438 #elif defined(JSON_HEDLEY_GCC_VERSION)
1439 #pragma GCC diagnostic ignored "-Wvariadic-macros"
1442 #if defined(JSON_HEDLEY_NON_NULL)
1443 #undef JSON_HEDLEY_NON_NULL
1446 JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
1447 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1448 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1449 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1450 #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
1452 #define JSON_HEDLEY_NON_NULL(...)
1454 JSON_HEDLEY_DIAGNOSTIC_POP
1456 #if defined(JSON_HEDLEY_PRINTF_FORMAT)
1457 #undef JSON_HEDLEY_PRINTF_FORMAT
1459 #if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO)
1460 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))
1461 #elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO)
1462 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
1464 JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
1465 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1466 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1467 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1468 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1469 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1470 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1471 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1472 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1473 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1474 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1475 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1476 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1477 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1478 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1479 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1480 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1481 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
1482 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
1483 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
1485 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
1488 #if defined(JSON_HEDLEY_CONSTEXPR)
1489 #undef JSON_HEDLEY_CONSTEXPR
1491 #if defined(__cplusplus)
1492 #if __cplusplus >= 201103L
1493 #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)
1496 #if !defined(JSON_HEDLEY_CONSTEXPR)
1497 #define JSON_HEDLEY_CONSTEXPR
1500 #if defined(JSON_HEDLEY_PREDICT)
1501 #undef JSON_HEDLEY_PREDICT
1503 #if defined(JSON_HEDLEY_LIKELY)
1504 #undef JSON_HEDLEY_LIKELY
1506 #if defined(JSON_HEDLEY_UNLIKELY)
1507 #undef JSON_HEDLEY_UNLIKELY
1509 #if defined(JSON_HEDLEY_UNPREDICTABLE)
1510 #undef JSON_HEDLEY_UNPREDICTABLE
1512 #if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
1513 #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
1516 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
1517 JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \
1518 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1519 # define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability))
1520 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability))
1521 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability))
1522 # define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 )
1523 # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 )
1525 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
1526 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1527 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1528 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1529 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1530 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1531 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1532 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1533 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1534 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1535 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1536 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1537 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1538 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \
1539 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1540 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1541 # define JSON_HEDLEY_PREDICT(expr, expected, probability) \
1542 (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))
1543 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
1545 double hedley_probability_ = (probability); \
1546 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
1548 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
1550 double hedley_probability_ = (probability); \
1551 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
1553 # define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1554 # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1556 # define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))
1557 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
1558 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
1559 # define JSON_HEDLEY_LIKELY(expr) (!!(expr))
1560 # define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
1562 #if !defined(JSON_HEDLEY_UNPREDICTABLE)
1563 #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
1566 #if defined(JSON_HEDLEY_MALLOC)
1567 #undef JSON_HEDLEY_MALLOC
1570 JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
1571 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1572 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1573 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1574 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1575 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1576 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1577 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1578 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1579 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1580 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1581 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1582 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1583 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1584 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1585 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1586 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1587 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1588 #define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
1589 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1590 #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
1592 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1593 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1594 #define JSON_HEDLEY_MALLOC __declspec(restrict)
1596 #define JSON_HEDLEY_MALLOC
1599 #if defined(JSON_HEDLEY_PURE)
1600 #undef JSON_HEDLEY_PURE
1603 JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
1604 JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \
1605 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1606 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1607 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1608 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1609 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1610 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1611 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1612 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1613 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1614 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1615 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1616 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1617 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1618 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1619 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1620 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1621 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1622 # define JSON_HEDLEY_PURE __attribute__((__pure__))
1623 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1624 # define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
1625 #elif defined(__cplusplus) && \
1627 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1628 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \
1629 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \
1631 # define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
1633 # define JSON_HEDLEY_PURE
1636 #if defined(JSON_HEDLEY_CONST)
1637 #undef JSON_HEDLEY_CONST
1640 JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
1641 JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \
1642 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1643 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1644 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1645 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1646 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1647 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1648 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1649 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1650 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1651 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1652 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1653 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1654 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1655 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1656 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1657 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1658 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1659 #define JSON_HEDLEY_CONST __attribute__((__const__))
1661 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1662 #define JSON_HEDLEY_CONST _Pragma("no_side_effect")
1664 #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
1667 #if defined(JSON_HEDLEY_RESTRICT)
1668 #undef JSON_HEDLEY_RESTRICT
1670 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
1671 #define JSON_HEDLEY_RESTRICT restrict
1673 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1674 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1675 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1676 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1677 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1678 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1679 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1680 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1681 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \
1682 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1683 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1684 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
1685 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1686 defined(__clang__) || \
1687 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1688 #define JSON_HEDLEY_RESTRICT __restrict
1689 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
1690 #define JSON_HEDLEY_RESTRICT _Restrict
1692 #define JSON_HEDLEY_RESTRICT
1695 #if defined(JSON_HEDLEY_INLINE)
1696 #undef JSON_HEDLEY_INLINE
1699 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1700 (defined(__cplusplus) && (__cplusplus >= 199711L))
1701 #define JSON_HEDLEY_INLINE inline
1703 defined(JSON_HEDLEY_GCC_VERSION) || \
1704 JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
1705 #define JSON_HEDLEY_INLINE __inline__
1707 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1708 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1709 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1710 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \
1711 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1712 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1713 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1714 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1715 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1716 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1717 #define JSON_HEDLEY_INLINE __inline
1719 #define JSON_HEDLEY_INLINE
1722 #if defined(JSON_HEDLEY_ALWAYS_INLINE)
1723 #undef JSON_HEDLEY_ALWAYS_INLINE
1726 JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
1727 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1728 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1729 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1730 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1731 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1732 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1733 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1734 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1735 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1736 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1737 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1738 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1739 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1740 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1741 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1742 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1743 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1744 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1745 # define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
1747 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1748 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1749 # define JSON_HEDLEY_ALWAYS_INLINE __forceinline
1750 #elif defined(__cplusplus) && \
1752 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1753 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1754 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1755 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1756 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1757 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \
1759 # define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
1760 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1761 # define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
1763 # define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
1766 #if defined(JSON_HEDLEY_NEVER_INLINE)
1767 #undef JSON_HEDLEY_NEVER_INLINE
1770 JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
1771 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1772 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1773 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1774 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1775 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1776 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1777 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1778 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1779 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1780 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1781 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1782 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1783 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1784 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1785 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1786 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1787 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1788 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1789 #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
1791 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1792 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1793 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1794 #elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
1795 #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
1796 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1797 #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
1798 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1799 #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
1800 #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1801 #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
1802 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1803 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1805 #define JSON_HEDLEY_NEVER_INLINE
1808 #if defined(JSON_HEDLEY_PRIVATE)
1809 #undef JSON_HEDLEY_PRIVATE
1811 #if defined(JSON_HEDLEY_PUBLIC)
1812 #undef JSON_HEDLEY_PUBLIC
1814 #if defined(JSON_HEDLEY_IMPORT)
1815 #undef JSON_HEDLEY_IMPORT
1817 #if defined(_WIN32) || defined(__CYGWIN__)
1818 # define JSON_HEDLEY_PRIVATE
1819 # define JSON_HEDLEY_PUBLIC __declspec(dllexport)
1820 # define JSON_HEDLEY_IMPORT __declspec(dllimport)
1823 JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
1824 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1825 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1826 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1827 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1828 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1830 defined(__TI_EABI__) && \
1832 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1833 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \
1836 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1837 # define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
1838 # define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
1840 # define JSON_HEDLEY_PRIVATE
1841 # define JSON_HEDLEY_PUBLIC
1843 # define JSON_HEDLEY_IMPORT extern
1846 #if defined(JSON_HEDLEY_NO_THROW)
1847 #undef JSON_HEDLEY_NO_THROW
1850 JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
1851 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1852 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1853 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1854 #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
1856 JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
1857 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1858 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1859 #define JSON_HEDLEY_NO_THROW __declspec(nothrow)
1861 #define JSON_HEDLEY_NO_THROW
1864 #if defined(JSON_HEDLEY_FALL_THROUGH)
1865 #undef JSON_HEDLEY_FALL_THROUGH
1868 JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
1869 JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \
1870 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1871 #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
1872 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
1873 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
1874 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
1875 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])
1876 #elif defined(__fallthrough)
1877 #define JSON_HEDLEY_FALL_THROUGH __fallthrough
1879 #define JSON_HEDLEY_FALL_THROUGH
1886 JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
1887 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
1888 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1889 #define __attribute__((__returns_nonnull__))
1890 #elif defined(_Ret_notnull_)
1891 #define _Ret_notnull_
1896 #if defined(JSON_HEDLEY_ARRAY_PARAM)
1897 #undef JSON_HEDLEY_ARRAY_PARAM
1900 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
1901 !defined(__STDC_NO_VLA__) && \
1902 !defined(__cplusplus) && \
1903 !defined(JSON_HEDLEY_PGI_VERSION) && \
1904 !defined(JSON_HEDLEY_TINYC_VERSION)
1905 #define JSON_HEDLEY_ARRAY_PARAM(name) (name)
1907 #define JSON_HEDLEY_ARRAY_PARAM(name)
1910 #if defined(JSON_HEDLEY_IS_CONSTANT)
1911 #undef JSON_HEDLEY_IS_CONSTANT
1913 #if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
1914 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
1918 #if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1919 #undef JSON_HEDLEY_IS_CONSTEXPR_
1922 JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
1923 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1924 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1925 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
1926 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1927 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1928 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1929 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
1930 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1931 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1932 #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
1934 #if !defined(__cplusplus)
1936 JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
1937 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1938 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1939 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1940 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1941 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1942 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
1943 #if defined(__INTPTR_TYPE__)
1944 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
1947 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
1951 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
1952 !defined(JSON_HEDLEY_SUNPRO_VERSION) && \
1953 !defined(JSON_HEDLEY_PGI_VERSION) && \
1954 !defined(JSON_HEDLEY_IAR_VERSION)) || \
1955 (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1956 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
1957 JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
1958 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1959 JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
1960 #if defined(__INTPTR_TYPE__)
1961 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
1964 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)
1967 defined(JSON_HEDLEY_GCC_VERSION) || \
1968 defined(JSON_HEDLEY_INTEL_VERSION) || \
1969 defined(JSON_HEDLEY_TINYC_VERSION) || \
1970 defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
1971 JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \
1972 defined(JSON_HEDLEY_TI_CL2000_VERSION) || \
1973 defined(JSON_HEDLEY_TI_CL6X_VERSION) || \
1974 defined(JSON_HEDLEY_TI_CL7X_VERSION) || \
1975 defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \
1977 # define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
1981 ((void*) ((expr) * 0L) ) : \
1982 ((struct { char v[sizeof(void) * 2]; } *) 1) \
1988 #if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1989 #if !defined(JSON_HEDLEY_IS_CONSTANT)
1990 #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
1992 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))
1994 #if !defined(JSON_HEDLEY_IS_CONSTANT)
1995 #define JSON_HEDLEY_IS_CONSTANT(expr) (0)
1997 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
2000 #if defined(JSON_HEDLEY_BEGIN_C_DECLS)
2001 #undef JSON_HEDLEY_BEGIN_C_DECLS
2003 #if defined(JSON_HEDLEY_END_C_DECLS)
2004 #undef JSON_HEDLEY_END_C_DECLS
2006 #if defined(JSON_HEDLEY_C_DECL)
2007 #undef JSON_HEDLEY_C_DECL
2009 #if defined(__cplusplus)
2010 #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
2011 #define JSON_HEDLEY_END_C_DECLS }
2012 #define JSON_HEDLEY_C_DECL extern "C"
2014 #define JSON_HEDLEY_BEGIN_C_DECLS
2015 #define JSON_HEDLEY_END_C_DECLS
2016 #define JSON_HEDLEY_C_DECL
2019 #if defined(JSON_HEDLEY_STATIC_ASSERT)
2020 #undef JSON_HEDLEY_STATIC_ASSERT
2023 !defined(__cplusplus) && ( \
2024 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
2025 (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
2026 JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
2027 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2028 defined(_Static_assert) \
2030 # define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
2032 (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
2033 JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \
2034 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2035 # define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
2037 # define JSON_HEDLEY_STATIC_ASSERT(expr, message)
2040 #if defined(JSON_HEDLEY_NULL)
2041 #undef JSON_HEDLEY_NULL
2043 #if defined(__cplusplus)
2044 #if __cplusplus >= 201103L
2045 #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)
2047 #define JSON_HEDLEY_NULL NULL
2049 #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
2052 #define JSON_HEDLEY_NULL NULL
2054 #define JSON_HEDLEY_NULL ((void*) 0)
2057 #if defined(JSON_HEDLEY_MESSAGE)
2058 #undef JSON_HEDLEY_MESSAGE
2060 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2061 # define JSON_HEDLEY_MESSAGE(msg) \
2062 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2063 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2064 JSON_HEDLEY_PRAGMA(message msg) \
2065 JSON_HEDLEY_DIAGNOSTIC_POP
2067 JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
2068 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2069 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
2070 #elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
2071 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
2072 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
2073 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2074 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
2075 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2077 # define JSON_HEDLEY_MESSAGE(msg)
2080 #if defined(JSON_HEDLEY_WARNING)
2081 #undef JSON_HEDLEY_WARNING
2083 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2084 # define JSON_HEDLEY_WARNING(msg) \
2085 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2086 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2087 JSON_HEDLEY_PRAGMA(clang warning msg) \
2088 JSON_HEDLEY_DIAGNOSTIC_POP
2090 JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
2091 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
2092 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2093 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
2095 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
2096 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2097 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
2099 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
2102 #if defined(JSON_HEDLEY_REQUIRE)
2103 #undef JSON_HEDLEY_REQUIRE
2105 #if defined(JSON_HEDLEY_REQUIRE_MSG)
2106 #undef JSON_HEDLEY_REQUIRE_MSG
2108 #if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
2109 # if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
2110 # define JSON_HEDLEY_REQUIRE(expr) \
2111 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2112 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2113 __attribute__((diagnose_if(!(expr), #expr, "error"))) \
2114 JSON_HEDLEY_DIAGNOSTIC_POP
2115 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \
2116 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2117 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2118 __attribute__((diagnose_if(!(expr), msg, "error"))) \
2119 JSON_HEDLEY_DIAGNOSTIC_POP
2121 # define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error")))
2122 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error")))
2125 # define JSON_HEDLEY_REQUIRE(expr)
2126 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg)
2129 #if defined(JSON_HEDLEY_FLAGS)
2130 #undef JSON_HEDLEY_FLAGS
2132 #if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion"))
2133 #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
2135 #define JSON_HEDLEY_FLAGS
2138 #if defined(JSON_HEDLEY_FLAGS_CAST)
2139 #undef JSON_HEDLEY_FLAGS_CAST
2141 #if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)
2142 # define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \
2143 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2144 _Pragma("warning(disable:188)") \
2146 JSON_HEDLEY_DIAGNOSTIC_POP \
2149 # define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
2152 #if defined(JSON_HEDLEY_EMPTY_BASES)
2153 #undef JSON_HEDLEY_EMPTY_BASES
2156 (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \
2157 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2158 #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
2160 #define JSON_HEDLEY_EMPTY_BASES
2165 #if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
2166 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
2168 #if defined(__clang__)
2169 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
2171 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
2174 #if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
2175 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
2177 #define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
2179 #if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
2180 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
2182 #define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
2184 #if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
2185 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
2187 #define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
2189 #if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
2190 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
2192 #define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
2194 #if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
2195 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
2197 #define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
2199 #if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
2200 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
2202 #define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
2204 #if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
2205 #undef JSON_HEDLEY_CLANG_HAS_WARNING
2207 #define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
2216 #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
2217 #if defined(__clang__)
2218 #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
2219 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
2221 #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
2222 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
2223 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
2229 #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
2230 #define JSON_HAS_CPP_20
2231 #define JSON_HAS_CPP_17
2232 #define JSON_HAS_CPP_14
2233 #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1)
2234 #define JSON_HAS_CPP_17
2235 #define JSON_HAS_CPP_14
2236 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
2237 #define JSON_HAS_CPP_14
2241 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
2242 #pragma GCC diagnostic push
2243 #pragma GCC diagnostic ignored "-Wfloat-equal"
2247 #if defined(__clang__)
2248 #pragma GCC diagnostic push
2249 #pragma GCC diagnostic ignored "-Wdocumentation"
2253 #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
2254 #define JSON_THROW(exception) throw exception
2255 #define JSON_TRY try
2256 #define JSON_CATCH(exception) catch(exception)
2257 #define JSON_INTERNAL_CATCH(exception) catch(exception)
2260 #define JSON_THROW(exception) std::abort()
2261 #define JSON_TRY if(true)
2262 #define JSON_CATCH(exception) if(false)
2263 #define JSON_INTERNAL_CATCH(exception) if(false)
2267 #if defined(JSON_THROW_USER)
2269 #define JSON_THROW JSON_THROW_USER
2271 #if defined(JSON_TRY_USER)
2273 #define JSON_TRY JSON_TRY_USER
2275 #if defined(JSON_CATCH_USER)
2277 #define JSON_CATCH JSON_CATCH_USER
2278 #undef JSON_INTERNAL_CATCH
2279 #define JSON_INTERNAL_CATCH JSON_CATCH_USER
2281 #if defined(JSON_INTERNAL_CATCH_USER)
2282 #undef JSON_INTERNAL_CATCH
2283 #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2287 #if !defined(JSON_ASSERT)
2289 #define JSON_ASSERT(x) assert(x)
2293 #if defined(JSON_TESTS_PRIVATE)
2294 #define JSON_PRIVATE_UNLESS_TESTED public
2296 #define JSON_PRIVATE_UNLESS_TESTED private
2304 #define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2305 template<typename BasicJsonType> \
2306 inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
2308 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2309 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2310 auto it = std::find_if(std::begin(m), std::end(m), \
2311 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2313 return ej_pair.first == e; \
2315 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2317 template<typename BasicJsonType> \
2318 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
2320 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2321 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2322 auto it = std::find_if(std::begin(m), std::end(m), \
2323 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2325 return ej_pair.second == j; \
2327 e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2333 #define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2334 template<template<typename, typename, typename...> class ObjectType, \
2335 template<typename, typename...> class ArrayType, \
2336 class StringType, class BooleanType, class NumberIntegerType, \
2337 class NumberUnsignedType, class NumberFloatType, \
2338 template<typename> class AllocatorType, \
2339 template<typename, typename = void> class JSONSerializer, \
2342 #define NLOHMANN_BASIC_JSON_TPL \
2343 basic_json<ObjectType, ArrayType, StringType, BooleanType, \
2344 NumberIntegerType, NumberUnsignedType, NumberFloatType, \
2345 AllocatorType, JSONSerializer, BinaryType>
2349 #define NLOHMANN_JSON_EXPAND( x ) x
2350 #define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME,...) NAME
2351 #define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
2352 NLOHMANN_JSON_PASTE64, \
2353 NLOHMANN_JSON_PASTE63, \
2354 NLOHMANN_JSON_PASTE62, \
2355 NLOHMANN_JSON_PASTE61, \
2356 NLOHMANN_JSON_PASTE60, \
2357 NLOHMANN_JSON_PASTE59, \
2358 NLOHMANN_JSON_PASTE58, \
2359 NLOHMANN_JSON_PASTE57, \
2360 NLOHMANN_JSON_PASTE56, \
2361 NLOHMANN_JSON_PASTE55, \
2362 NLOHMANN_JSON_PASTE54, \
2363 NLOHMANN_JSON_PASTE53, \
2364 NLOHMANN_JSON_PASTE52, \
2365 NLOHMANN_JSON_PASTE51, \
2366 NLOHMANN_JSON_PASTE50, \
2367 NLOHMANN_JSON_PASTE49, \
2368 NLOHMANN_JSON_PASTE48, \
2369 NLOHMANN_JSON_PASTE47, \
2370 NLOHMANN_JSON_PASTE46, \
2371 NLOHMANN_JSON_PASTE45, \
2372 NLOHMANN_JSON_PASTE44, \
2373 NLOHMANN_JSON_PASTE43, \
2374 NLOHMANN_JSON_PASTE42, \
2375 NLOHMANN_JSON_PASTE41, \
2376 NLOHMANN_JSON_PASTE40, \
2377 NLOHMANN_JSON_PASTE39, \
2378 NLOHMANN_JSON_PASTE38, \
2379 NLOHMANN_JSON_PASTE37, \
2380 NLOHMANN_JSON_PASTE36, \
2381 NLOHMANN_JSON_PASTE35, \
2382 NLOHMANN_JSON_PASTE34, \
2383 NLOHMANN_JSON_PASTE33, \
2384 NLOHMANN_JSON_PASTE32, \
2385 NLOHMANN_JSON_PASTE31, \
2386 NLOHMANN_JSON_PASTE30, \
2387 NLOHMANN_JSON_PASTE29, \
2388 NLOHMANN_JSON_PASTE28, \
2389 NLOHMANN_JSON_PASTE27, \
2390 NLOHMANN_JSON_PASTE26, \
2391 NLOHMANN_JSON_PASTE25, \
2392 NLOHMANN_JSON_PASTE24, \
2393 NLOHMANN_JSON_PASTE23, \
2394 NLOHMANN_JSON_PASTE22, \
2395 NLOHMANN_JSON_PASTE21, \
2396 NLOHMANN_JSON_PASTE20, \
2397 NLOHMANN_JSON_PASTE19, \
2398 NLOHMANN_JSON_PASTE18, \
2399 NLOHMANN_JSON_PASTE17, \
2400 NLOHMANN_JSON_PASTE16, \
2401 NLOHMANN_JSON_PASTE15, \
2402 NLOHMANN_JSON_PASTE14, \
2403 NLOHMANN_JSON_PASTE13, \
2404 NLOHMANN_JSON_PASTE12, \
2405 NLOHMANN_JSON_PASTE11, \
2406 NLOHMANN_JSON_PASTE10, \
2407 NLOHMANN_JSON_PASTE9, \
2408 NLOHMANN_JSON_PASTE8, \
2409 NLOHMANN_JSON_PASTE7, \
2410 NLOHMANN_JSON_PASTE6, \
2411 NLOHMANN_JSON_PASTE5, \
2412 NLOHMANN_JSON_PASTE4, \
2413 NLOHMANN_JSON_PASTE3, \
2414 NLOHMANN_JSON_PASTE2, \
2415 NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
2416 #define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
2417 #define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
2418 #define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
2419 #define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
2420 #define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
2421 #define NLOHMANN_JSON_PASTE7(func, v1, v2, v3, v4, v5, v6) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE6(func, v2, v3, v4, v5, v6)
2422 #define NLOHMANN_JSON_PASTE8(func, v1, v2, v3, v4, v5, v6, v7) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE7(func, v2, v3, v4, v5, v6, v7)
2423 #define NLOHMANN_JSON_PASTE9(func, v1, v2, v3, v4, v5, v6, v7, v8) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE8(func, v2, v3, v4, v5, v6, v7, v8)
2424 #define NLOHMANN_JSON_PASTE10(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE9(func, v2, v3, v4, v5, v6, v7, v8, v9)
2425 #define NLOHMANN_JSON_PASTE11(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE10(func, v2, v3, v4, v5, v6, v7, v8, v9, v10)
2426 #define NLOHMANN_JSON_PASTE12(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE11(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11)
2427 #define NLOHMANN_JSON_PASTE13(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE12(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)
2428 #define NLOHMANN_JSON_PASTE14(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE13(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)
2429 #define NLOHMANN_JSON_PASTE15(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE14(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)
2430 #define NLOHMANN_JSON_PASTE16(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE15(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)
2431 #define NLOHMANN_JSON_PASTE17(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE16(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16)
2432 #define NLOHMANN_JSON_PASTE18(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE17(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17)
2433 #define NLOHMANN_JSON_PASTE19(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE18(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18)
2434 #define NLOHMANN_JSON_PASTE20(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE19(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19)
2435 #define NLOHMANN_JSON_PASTE21(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE20(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20)
2436 #define NLOHMANN_JSON_PASTE22(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE21(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21)
2437 #define NLOHMANN_JSON_PASTE23(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE22(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22)
2438 #define NLOHMANN_JSON_PASTE24(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE23(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23)
2439 #define NLOHMANN_JSON_PASTE25(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE24(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24)
2440 #define NLOHMANN_JSON_PASTE26(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE25(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25)
2441 #define NLOHMANN_JSON_PASTE27(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE26(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26)
2442 #define NLOHMANN_JSON_PASTE28(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE27(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27)
2443 #define NLOHMANN_JSON_PASTE29(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE28(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28)
2444 #define NLOHMANN_JSON_PASTE30(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE29(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29)
2445 #define NLOHMANN_JSON_PASTE31(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE30(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30)
2446 #define NLOHMANN_JSON_PASTE32(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE31(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31)
2447 #define NLOHMANN_JSON_PASTE33(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE32(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32)
2448 #define NLOHMANN_JSON_PASTE34(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE33(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33)
2449 #define NLOHMANN_JSON_PASTE35(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE34(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34)
2450 #define NLOHMANN_JSON_PASTE36(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE35(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35)
2451 #define NLOHMANN_JSON_PASTE37(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE36(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36)
2452 #define NLOHMANN_JSON_PASTE38(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE37(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37)
2453 #define NLOHMANN_JSON_PASTE39(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE38(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38)
2454 #define NLOHMANN_JSON_PASTE40(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE39(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39)
2455 #define NLOHMANN_JSON_PASTE41(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE40(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40)
2456 #define NLOHMANN_JSON_PASTE42(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE41(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41)
2457 #define NLOHMANN_JSON_PASTE43(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE42(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42)
2458 #define NLOHMANN_JSON_PASTE44(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE43(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43)
2459 #define NLOHMANN_JSON_PASTE45(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE44(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44)
2460 #define NLOHMANN_JSON_PASTE46(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE45(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45)
2461 #define NLOHMANN_JSON_PASTE47(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE46(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46)
2462 #define NLOHMANN_JSON_PASTE48(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE47(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47)
2463 #define NLOHMANN_JSON_PASTE49(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE48(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48)
2464 #define NLOHMANN_JSON_PASTE50(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE49(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49)
2465 #define NLOHMANN_JSON_PASTE51(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE50(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50)
2466 #define NLOHMANN_JSON_PASTE52(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE51(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51)
2467 #define NLOHMANN_JSON_PASTE53(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE52(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52)
2468 #define NLOHMANN_JSON_PASTE54(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE53(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53)
2469 #define NLOHMANN_JSON_PASTE55(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE54(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54)
2470 #define NLOHMANN_JSON_PASTE56(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE55(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55)
2471 #define NLOHMANN_JSON_PASTE57(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE56(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56)
2472 #define NLOHMANN_JSON_PASTE58(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE57(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57)
2473 #define NLOHMANN_JSON_PASTE59(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE58(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58)
2474 #define NLOHMANN_JSON_PASTE60(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE59(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59)
2475 #define NLOHMANN_JSON_PASTE61(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE60(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60)
2476 #define NLOHMANN_JSON_PASTE62(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE61(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61)
2477 #define NLOHMANN_JSON_PASTE63(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE62(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62)
2478 #define NLOHMANN_JSON_PASTE64(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE63(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63)
2480 #define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2481 #define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2488 #define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
2489 friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2490 friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2497 #define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
2498 inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2499 inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2501 #ifndef JSON_USE_IMPLICIT_CONVERSIONS
2502 #define JSON_USE_IMPLICIT_CONVERSIONS 1
2505 #if JSON_USE_IMPLICIT_CONVERSIONS
2506 #define JSON_EXPLICIT
2508 #define JSON_EXPLICIT explicit
2530 inline void replace_substring(std::string& s,
const std::string& f,
2531 const std::string& t)
2533 JSON_ASSERT(!f.empty());
2534 for (
auto pos = s.find(f);
2535 pos != std::string::npos;
2536 s.replace(pos, f.size(), t),
2537 pos = s.find(f, pos + t.size()))
2548 inline std::string escape(std::string s)
2550 replace_substring(s,
"~",
"~0");
2551 replace_substring(s,
"/",
"~1");
2562 static void unescape(std::string& s)
2564 replace_substring(s,
"~1",
"/");
2565 replace_substring(s,
"~0",
"~");
2584 std::size_t chars_read_total = 0;
2586 std::size_t chars_read_current_line = 0;
2588 std::size_t lines_read = 0;
2591 constexpr
operator size_t()
const
2593 return chars_read_total;
2639 class exception :
public std::exception
2643 const char* what() const noexcept
override
2652 JSON_HEDLEY_NON_NULL(3)
2653 exception(
int id_, const
char* what_arg) :
id(id_), m(what_arg) {}
2655 static std::string name(
const std::string& ename,
int id_)
2657 return "[json.exception." + ename +
"." + std::to_string(id_) +
"] ";
2660 template<
typename BasicJsonType>
2661 static std::string diagnostics(
const BasicJsonType& leaf_element)
2663 #if JSON_DIAGNOSTICS
2664 std::vector<std::string> tokens;
2665 for (
const auto* current = &leaf_element; current->m_parent !=
nullptr; current = current->m_parent)
2667 switch (current->m_parent->type())
2669 case value_t::array:
2671 for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
2673 if (¤t->m_parent->m_value.array->operator[](i) == current)
2675 tokens.emplace_back(std::to_string(i));
2682 case value_t::object:
2684 for (
const auto& element : *current->m_parent->m_value.object)
2686 if (&element.second == current)
2688 tokens.emplace_back(element.first.c_str());
2705 return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
2706 [](
const std::string & a,
const std::string & b)
2708 return a +
"/" + detail::escape(b);
2717 std::runtime_error m;
2765 class parse_error :
public exception
2777 template<
typename BasicJsonType>
2778 static parse_error create(
int id_,
const position_t& pos,
const std::string& what_arg,
const BasicJsonType& context)
2780 std::string w = exception::name(
"parse_error", id_) +
"parse error" +
2781 position_string(pos) +
": " + exception::diagnostics(context) + what_arg;
2782 return parse_error(id_, pos.chars_read_total, w.c_str());
2785 template<
typename BasicJsonType>
2786 static parse_error create(
int id_, std::size_t byte_,
const std::string& what_arg,
const BasicJsonType& context)
2788 std::string w = exception::name(
"parse_error", id_) +
"parse error" +
2789 (byte_ != 0 ? (
" at byte " + std::to_string(byte_)) :
"") +
2790 ": " + exception::diagnostics(context) + what_arg;
2791 return parse_error(id_, byte_, w.c_str());
2803 const std::size_t byte;
2806 parse_error(
int id_, std::size_t byte_,
const char* what_arg)
2807 : exception(id_, what_arg), byte(byte_) {}
2809 static std::string position_string(
const position_t& pos)
2811 return " at line " + std::to_string(pos.lines_read + 1) +
2812 ", column " + std::to_string(pos.chars_read_current_line);
2853 class invalid_iterator :
public exception
2856 template<
typename BasicJsonType>
2857 static invalid_iterator create(
int id_,
const std::string& what_arg,
const BasicJsonType& context)
2859 std::string w = exception::name(
"invalid_iterator", id_) + exception::diagnostics(context) + what_arg;
2860 return invalid_iterator(id_, w.c_str());
2864 JSON_HEDLEY_NON_NULL(3)
2865 invalid_iterator(
int id_, const
char* what_arg)
2866 : exception(id_, what_arg) {}
2908 class type_error :
public exception
2911 template<
typename BasicJsonType>
2912 static type_error create(
int id_,
const std::string& what_arg,
const BasicJsonType& context)
2914 std::string w = exception::name(
"type_error", id_) + exception::diagnostics(context) + what_arg;
2915 return type_error(id_, w.c_str());
2919 JSON_HEDLEY_NON_NULL(3)
2920 type_error(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
2956 class out_of_range :
public exception
2959 template<
typename BasicJsonType>
2960 static out_of_range create(
int id_,
const std::string& what_arg,
const BasicJsonType& context)
2962 std::string w = exception::name(
"out_of_range", id_) + exception::diagnostics(context) + what_arg;
2963 return out_of_range(id_, w.c_str());
2967 JSON_HEDLEY_NON_NULL(3)
2968 out_of_range(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
2995 class other_error :
public exception
2998 template<
typename BasicJsonType>
2999 static other_error create(
int id_,
const std::string& what_arg,
const BasicJsonType& context)
3001 std::string w = exception::name(
"other_error", id_) + exception::diagnostics(context) + what_arg;
3002 return other_error(id_, w.c_str());
3006 JSON_HEDLEY_NON_NULL(3)
3007 other_error(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
3018 #include <type_traits>
3029 template<
typename T>
3030 using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
3032 #ifdef JSON_HAS_CPP_14
3035 using std::enable_if_t;
3036 using std::index_sequence;
3037 using std::make_index_sequence;
3038 using std::index_sequence_for;
3043 template<
bool B,
typename T =
void>
3044 using enable_if_t =
typename std::enable_if<B, T>::type;
3047 template<std::size_t... Ints>
3048 struct index_sequence
3050 using type = index_sequence;
3051 using value_type = std::size_t;
3052 static constexpr std::size_t size() noexcept
3054 return sizeof...(Ints);
3058 template<
class Sequence1,
class Sequence2>
3059 struct merge_and_renumber;
3061 template<std::size_t... I1, std::size_t... I2>
3062 struct merge_and_renumber<index_sequence<I1...>, index_sequence<I2...>>
3063 : index_sequence < I1..., (sizeof...(I1) + I2)... > {};
3065 template<std::
size_t N>
3066 struct make_index_sequence
3067 : merge_and_renumber < typename make_index_sequence < N / 2 >::type,
3068 typename make_index_sequence < N - N / 2 >::type > {};
3070 template<>
struct make_index_sequence<0> : index_sequence<> {};
3071 template<>
struct make_index_sequence<1> : index_sequence<0> {};
3073 template<
typename... Ts>
3074 using index_sequence_for = make_index_sequence<
sizeof...(Ts)>;
3079 template<
unsigned N>
struct priority_tag : priority_tag < N - 1 > {};
3080 template<>
struct priority_tag<0> {};
3083 template<
typename T>
3086 static constexpr T value{};
3089 template<
typename T>
3090 constexpr T static_const<T>::value;
3099 #include <type_traits>
3115 template<
typename ...Ts>
struct make_void
3119 template<
typename ...Ts>
using void_t =
typename make_void<Ts...>::type;
3130 template<
typename It,
typename =
void>
3131 struct iterator_types {};
3133 template<
typename It>
3134 struct iterator_types <
3136 void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
3137 typename It::reference, typename It::iterator_category >>
3139 using difference_type =
typename It::difference_type;
3140 using value_type =
typename It::value_type;
3141 using pointer =
typename It::pointer;
3142 using reference =
typename It::reference;
3143 using iterator_category =
typename It::iterator_category;
3148 template<
typename T,
typename =
void>
3149 struct iterator_traits
3153 template<
typename T>
3154 struct iterator_traits < T, enable_if_t < !std::is_pointer<T>::value >>
3159 template<
typename T>
3160 struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>>
3162 using iterator_category = std::random_access_iterator_tag;
3163 using value_type = T;
3164 using difference_type = ptrdiff_t;
3166 using reference = T&;
3178 #include <type_traits>
3190 nonesuch() =
delete;
3191 ~nonesuch() =
delete;
3192 nonesuch(nonesuch
const&) =
delete;
3193 nonesuch(nonesuch
const&&) =
delete;
3194 void operator=(nonesuch
const&) =
delete;
3195 void operator=(nonesuch&&) =
delete;
3198 template<
class Default,
3200 template<
class...>
class Op,
3204 using value_t = std::false_type;
3205 using type = Default;
3208 template<
class Default,
template<
class...>
class Op,
class... Args>
3209 struct detector<Default, void_t<Op<Args...>>, Op, Args...>
3211 using value_t = std::true_type;
3212 using type = Op<Args...>;
3215 template<
template<
class...>
class Op,
class... Args>
3216 using is_detected =
typename detector<nonesuch, void, Op, Args...>::value_t;
3218 template<
template<
class...>
class Op,
class... Args>
3219 using detected_t =
typename detector<nonesuch, void, Op, Args...>::type;
3221 template<
class Default,
template<
class...>
class Op,
class... Args>
3222 using detected_or = detector<Default, void, Op, Args...>;
3224 template<
class Default,
template<
class...>
class Op,
class... Args>
3225 using detected_or_t =
typename detected_or<Default, Op, Args...>::type;
3227 template<
class Expected,
template<
class...>
class Op,
class... Args>
3228 using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
3230 template<
class To,
template<
class...>
class Op,
class... Args>
3231 using is_detected_convertible =
3232 std::is_convertible<detected_t<Op, Args...>, To>;
3237 #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
3238 #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
3260 template<
typename T =
void,
typename SFINAE =
void>
3261 struct adl_serializer;
3263 template<
template<
typename U,
typename V,
typename... Args>
class ObjectType =
3265 template<
typename U,
typename... Args>
class ArrayType = std::vector,
3266 class StringType = std::string,
class BooleanType = bool,
3267 class NumberIntegerType = std::int64_t,
3268 class NumberUnsignedType = std::uint64_t,
3269 class NumberFloatType = double,
3270 template<
typename U>
class AllocatorType = std::allocator,
3271 template<
typename T,
typename SFINAE =
void>
class JSONSerializer =
3273 class BinaryType = std::vector<std::uint8_t>>
3287 template<
typename BasicJsonType>
3300 template<
class Key,
class T,
class IgnoredLess,
class Allocator>
3342 template<
typename>
struct is_basic_json : std::false_type {};
3344 NLOHMANN_BASIC_JSON_TPL_DECLARATION
3345 struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};
3355 struct is_json_ref : std::false_type {};
3357 template<
typename T>
3358 struct is_json_ref<json_ref<T>> : std::true_type {};
3364 template<
typename T>
3365 using mapped_type_t =
typename T::mapped_type;
3367 template<
typename T>
3368 using key_type_t =
typename T::key_type;
3370 template<
typename T>
3371 using value_type_t =
typename T::value_type;
3373 template<
typename T>
3374 using difference_type_t =
typename T::difference_type;
3376 template<
typename T>
3377 using pointer_t =
typename T::pointer;
3379 template<
typename T>
3380 using reference_t =
typename T::reference;
3382 template<
typename T>
3383 using iterator_category_t =
typename T::iterator_category;
3385 template<
typename T>
3386 using iterator_t =
typename T::iterator;
3388 template<
typename T,
typename... Args>
3389 using to_json_function = decltype(T::to_json(std::declval<Args>()...));
3391 template<
typename T,
typename... Args>
3392 using from_json_function = decltype(T::from_json(std::declval<Args>()...));
3394 template<
typename T,
typename U>
3395 using get_template_function = decltype(std::declval<T>().
template get<U>());
3398 template<
typename BasicJsonType,
typename T,
typename =
void>
3399 struct has_from_json : std::false_type {};
3405 template <
typename BasicJsonType,
typename T>
3408 static constexpr
bool value = is_detected<get_template_function, const BasicJsonType&, T>::value;
3411 template<
typename BasicJsonType,
typename T>
3412 struct has_from_json < BasicJsonType, T,
3413 enable_if_t < !is_basic_json<T>::value >>
3415 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3417 static constexpr
bool value =
3418 is_detected_exact<void, from_json_function, serializer,
3419 const BasicJsonType&, T&>::value;
3424 template<
typename BasicJsonType,
typename T,
typename =
void>
3425 struct has_non_default_from_json : std::false_type {};
3427 template<
typename BasicJsonType,
typename T>
3428 struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3430 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3432 static constexpr
bool value =
3433 is_detected_exact<T, from_json_function, serializer,
3434 const BasicJsonType&>::value;
3439 template<
typename BasicJsonType,
typename T,
typename =
void>
3440 struct has_to_json : std::false_type {};
3442 template<
typename BasicJsonType,
typename T>
3443 struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3445 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3447 static constexpr
bool value =
3448 is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
3457 template<
typename T,
typename =
void>
3458 struct is_iterator_traits : std::false_type {};
3460 template<
typename T>
3461 struct is_iterator_traits<iterator_traits<T>>
3464 using traits = iterator_traits<T>;
3467 static constexpr
auto value =
3468 is_detected<value_type_t, traits>::value &&
3469 is_detected<difference_type_t, traits>::value &&
3470 is_detected<pointer_t, traits>::value &&
3471 is_detected<iterator_category_t, traits>::value &&
3472 is_detected<reference_t, traits>::value;
3479 template<
typename T,
typename =
void>
3480 struct is_complete_type : std::false_type {};
3482 template<
typename T>
3483 struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {};
3485 template<
typename BasicJsonType,
typename CompatibleObjectType,
3487 struct is_compatible_object_type_impl : std::false_type {};
3489 template<
typename BasicJsonType,
typename CompatibleObjectType>
3490 struct is_compatible_object_type_impl <
3491 BasicJsonType, CompatibleObjectType,
3492 enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
3493 is_detected<key_type_t, CompatibleObjectType>::value >>
3495 using object_t =
typename BasicJsonType::object_t;
3498 static constexpr
bool value =
3499 std::is_constructible<
typename object_t::key_type,
3500 typename CompatibleObjectType::key_type>::value &&
3501 std::is_constructible<
typename object_t::mapped_type,
3502 typename CompatibleObjectType::mapped_type>::value;
3505 template<
typename BasicJsonType,
typename CompatibleObjectType>
3506 struct is_compatible_object_type
3507 : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {};
3509 template<
typename BasicJsonType,
typename ConstructibleObjectType,
3511 struct is_constructible_object_type_impl : std::false_type {};
3513 template<
typename BasicJsonType,
typename ConstructibleObjectType>
3514 struct is_constructible_object_type_impl <
3515 BasicJsonType, ConstructibleObjectType,
3516 enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&&
3517 is_detected<key_type_t, ConstructibleObjectType>::value >>
3519 using object_t =
typename BasicJsonType::object_t;
3521 static constexpr
bool value =
3522 (std::is_default_constructible<ConstructibleObjectType>::value &&
3523 (std::is_move_assignable<ConstructibleObjectType>::value ||
3524 std::is_copy_assignable<ConstructibleObjectType>::value) &&
3525 (std::is_constructible<
typename ConstructibleObjectType::key_type,
3526 typename object_t::key_type>::value &&
3528 typename object_t::mapped_type,
3529 typename ConstructibleObjectType::mapped_type >::value)) ||
3530 (has_from_json<BasicJsonType,
3531 typename ConstructibleObjectType::mapped_type>::value ||
3532 has_non_default_from_json <
3534 typename ConstructibleObjectType::mapped_type >::value);
3537 template<
typename BasicJsonType,
typename ConstructibleObjectType>
3538 struct is_constructible_object_type
3539 : is_constructible_object_type_impl<BasicJsonType,
3540 ConstructibleObjectType> {};
3542 template<
typename BasicJsonType,
typename CompatibleStringType,
3544 struct is_compatible_string_type_impl : std::false_type {};
3546 template<
typename BasicJsonType,
typename CompatibleStringType>
3547 struct is_compatible_string_type_impl <
3548 BasicJsonType, CompatibleStringType,
3549 enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
3550 value_type_t, CompatibleStringType>::value >>
3552 static constexpr
auto value =
3553 std::is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value;
3556 template<
typename BasicJsonType,
typename ConstructibleStringType>
3557 struct is_compatible_string_type
3558 : is_compatible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
3560 template<
typename BasicJsonType,
typename ConstructibleStringType,
3562 struct is_constructible_string_type_impl : std::false_type {};
3564 template<
typename BasicJsonType,
typename ConstructibleStringType>
3565 struct is_constructible_string_type_impl <
3566 BasicJsonType, ConstructibleStringType,
3567 enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
3568 value_type_t, ConstructibleStringType>::value >>
3570 static constexpr
auto value =
3571 std::is_constructible<ConstructibleStringType,
3572 typename BasicJsonType::string_t>::value;
3575 template<
typename BasicJsonType,
typename ConstructibleStringType>
3576 struct is_constructible_string_type
3577 : is_constructible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
3579 template<
typename BasicJsonType,
typename CompatibleArrayType,
typename =
void>
3580 struct is_compatible_array_type_impl : std::false_type {};
3582 template<
typename BasicJsonType,
typename CompatibleArrayType>
3583 struct is_compatible_array_type_impl <
3584 BasicJsonType, CompatibleArrayType,
3585 enable_if_t < is_detected<value_type_t, CompatibleArrayType>::value&&
3586 is_detected<iterator_t, CompatibleArrayType>::value&&
3590 !is_iterator_traits <
3591 iterator_traits<CompatibleArrayType >>::value >>
3593 static constexpr
bool value =
3594 std::is_constructible<BasicJsonType,
3595 typename CompatibleArrayType::value_type>::value;
3598 template<
typename BasicJsonType,
typename CompatibleArrayType>
3599 struct is_compatible_array_type
3600 : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {};
3602 template<
typename BasicJsonType,
typename ConstructibleArrayType,
typename =
void>
3603 struct is_constructible_array_type_impl : std::false_type {};
3605 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3606 struct is_constructible_array_type_impl <
3607 BasicJsonType, ConstructibleArrayType,
3608 enable_if_t<std::is_same<ConstructibleArrayType,
3609 typename BasicJsonType::value_type>::value >>
3610 : std::true_type {};
3612 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3613 struct is_constructible_array_type_impl <
3614 BasicJsonType, ConstructibleArrayType,
3615 enable_if_t < !std::is_same<ConstructibleArrayType,
3616 typename BasicJsonType::value_type>::value&&
3617 std::is_default_constructible<ConstructibleArrayType>::value&&
3618 (std::is_move_assignable<ConstructibleArrayType>::value ||
3619 std::is_copy_assignable<ConstructibleArrayType>::value)&&
3620 is_detected<value_type_t, ConstructibleArrayType>::value&&
3621 is_detected<iterator_t, ConstructibleArrayType>::value&&
3623 detected_t<value_type_t, ConstructibleArrayType >>::value >>
3625 static constexpr
bool value =
3631 !is_iterator_traits<iterator_traits<ConstructibleArrayType>>::value &&
3633 (std::is_same<
typename ConstructibleArrayType::value_type,
3634 typename BasicJsonType::array_t::value_type>::value ||
3635 has_from_json<BasicJsonType,
3636 typename ConstructibleArrayType::value_type>::value ||
3637 has_non_default_from_json <
3638 BasicJsonType,
typename ConstructibleArrayType::value_type >::value);
3641 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3642 struct is_constructible_array_type
3643 : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {};
3645 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType,
3647 struct is_compatible_integer_type_impl : std::false_type {};
3649 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3650 struct is_compatible_integer_type_impl <
3651 RealIntegerType, CompatibleNumberIntegerType,
3652 enable_if_t < std::is_integral<RealIntegerType>::value&&
3653 std::is_integral<CompatibleNumberIntegerType>::value&&
3654 !std::is_same<bool, CompatibleNumberIntegerType>::value >>
3657 using RealLimits = std::numeric_limits<RealIntegerType>;
3658 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
3660 static constexpr
auto value =
3661 std::is_constructible<RealIntegerType,
3662 CompatibleNumberIntegerType>::value &&
3663 CompatibleLimits::is_integer &&
3664 RealLimits::is_signed == CompatibleLimits::is_signed;
3667 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3668 struct is_compatible_integer_type
3669 : is_compatible_integer_type_impl<RealIntegerType,
3670 CompatibleNumberIntegerType> {};
3672 template<
typename BasicJsonType,
typename CompatibleType,
typename =
void>
3673 struct is_compatible_type_impl: std::false_type {};
3675 template<
typename BasicJsonType,
typename CompatibleType>
3676 struct is_compatible_type_impl <
3677 BasicJsonType, CompatibleType,
3678 enable_if_t<is_complete_type<CompatibleType>::value >>
3680 static constexpr
bool value =
3681 has_to_json<BasicJsonType, CompatibleType>::value;
3684 template<
typename BasicJsonType,
typename CompatibleType>
3685 struct is_compatible_type
3686 : is_compatible_type_impl<BasicJsonType, CompatibleType> {};
3689 template<
class...>
struct conjunction : std::true_type { };
3690 template<
class B1>
struct conjunction<B1> : B1 { };
3691 template<
class B1,
class... Bn>
3692 struct conjunction<B1, Bn...>
3693 : std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
3695 template<
typename T1,
typename T2>
3696 struct is_constructible_tuple : std::false_type {};
3698 template<
typename T1,
typename... Args>
3699 struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<std::is_constructible<T1, Args>...> {};
3710 template<
typename BasicJsonType>
3711 void from_json(
const BasicJsonType& j,
typename std::nullptr_t& n)
3713 if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
3715 JSON_THROW(type_error::create(302,
"type must be null, but is " + std::string(j.type_name()), j));
3721 template <
typename BasicJsonType,
typename ArithmeticType,
3722 enable_if_t < std::is_arithmetic<ArithmeticType>::value&&
3723 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
3725 void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val)
3727 switch (
static_cast<value_t
>(j))
3729 case value_t::number_unsigned:
3731 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
3734 case value_t::number_integer:
3736 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
3739 case value_t::number_float:
3741 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
3746 JSON_THROW(type_error::create(302,
"type must be number, but is " + std::string(j.type_name()), j));
3750 template<
typename BasicJsonType>
3751 void from_json(
const BasicJsonType& j,
typename BasicJsonType::boolean_t& b)
3753 if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
3755 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + std::string(j.type_name()), j));
3757 b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
3760 template<
typename BasicJsonType>
3761 void from_json(
const BasicJsonType& j,
typename BasicJsonType::string_t& s)
3763 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
3765 JSON_THROW(type_error::create(302,
"type must be string, but is " + std::string(j.type_name()), j));
3767 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
3771 typename BasicJsonType,
typename ConstructibleStringType,
3773 is_constructible_string_type<BasicJsonType, ConstructibleStringType>::value&&
3774 !std::is_same<
typename BasicJsonType::string_t,
3775 ConstructibleStringType>::value,
3777 void from_json(
const BasicJsonType& j, ConstructibleStringType& s)
3779 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
3781 JSON_THROW(type_error::create(302,
"type must be string, but is " + std::string(j.type_name()), j));
3784 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
3787 template<
typename BasicJsonType>
3788 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_float_t& val)
3790 get_arithmetic_value(j, val);
3793 template<
typename BasicJsonType>
3794 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_unsigned_t& val)
3796 get_arithmetic_value(j, val);
3799 template<
typename BasicJsonType>
3800 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_integer_t& val)
3802 get_arithmetic_value(j, val);
3805 template<
typename BasicJsonType,
typename EnumType,
3806 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
3807 void from_json(
const BasicJsonType& j, EnumType& e)
3809 typename std::underlying_type<EnumType>::type val;
3810 get_arithmetic_value(j, val);
3811 e =
static_cast<EnumType
>(val);
3815 template<
typename BasicJsonType,
typename T,
typename Allocator,
3816 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
3817 void from_json(
const BasicJsonType& j, std::forward_list<T, Allocator>& l)
3819 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
3821 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
3824 std::transform(j.rbegin(), j.rend(),
3825 std::front_inserter(l), [](
const BasicJsonType & i)
3827 return i.template get<T>();
3832 template<
typename BasicJsonType,
typename T,
3833 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
3834 void from_json(
const BasicJsonType& j, std::valarray<T>& l)
3836 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
3838 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
3841 std::transform(j.begin(), j.end(), std::begin(l),
3842 [](
const BasicJsonType & elem)
3844 return elem.template get<T>();
3848 template<
typename BasicJsonType,
typename T, std::
size_t N>
3849 auto from_json(
const BasicJsonType& j, T (&arr)[N])
3850 -> decltype(j.template get<T>(),
void())
3852 for (std::size_t i = 0; i < N; ++i)
3854 arr[i] = j.at(i).template get<T>();
3858 template<
typename BasicJsonType>
3859 void from_json_array_impl(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr, priority_tag<3> )
3861 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
3864 template<
typename BasicJsonType,
typename T, std::
size_t N>
3865 auto from_json_array_impl(
const BasicJsonType& j, std::array<T, N>& arr,
3867 -> decltype(j.template get<T>(),
void())
3869 for (std::size_t i = 0; i < N; ++i)
3871 arr[i] = j.at(i).template get<T>();
3875 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3876 auto from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> )
3878 arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
3879 j.template get<typename ConstructibleArrayType::value_type>(),
3884 ConstructibleArrayType ret;
3885 ret.reserve(j.size());
3886 std::transform(j.begin(), j.end(),
3887 std::inserter(ret, end(ret)), [](
const BasicJsonType & i)
3891 return i.template get<typename ConstructibleArrayType::value_type>();
3893 arr = std::move(ret);
3896 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3897 void from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
3902 ConstructibleArrayType ret;
3904 j.begin(), j.end(), std::inserter(ret, end(ret)),
3905 [](
const BasicJsonType & i)
3909 return i.template get<typename ConstructibleArrayType::value_type>();
3911 arr = std::move(ret);
3914 template <
typename BasicJsonType,
typename ConstructibleArrayType,
3916 is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&&
3917 !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&&
3918 !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
3919 !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&&
3920 !is_basic_json<ConstructibleArrayType>::value,
3922 auto from_json(
const BasicJsonType& j, ConstructibleArrayType& arr)
3923 -> decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
3924 j.template get<typename ConstructibleArrayType::value_type>(),
3927 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
3929 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
3932 from_json_array_impl(j, arr, priority_tag<3> {});
3935 template<
typename BasicJsonType>
3936 void from_json(
const BasicJsonType& j,
typename BasicJsonType::binary_t& bin)
3938 if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
3940 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(j.type_name()), j));
3943 bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
3946 template<
typename BasicJsonType,
typename ConstructibleObjectType,
3947 enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value,
int> = 0>
3948 void from_json(
const BasicJsonType& j, ConstructibleObjectType& obj)
3950 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
3952 JSON_THROW(type_error::create(302,
"type must be object, but is " + std::string(j.type_name()), j));
3955 ConstructibleObjectType ret;
3956 auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
3957 using value_type =
typename ConstructibleObjectType::value_type;
3959 inner_object->begin(), inner_object->end(),
3960 std::inserter(ret, ret.begin()),
3961 [](
typename BasicJsonType::object_t::value_type
const & p)
3963 return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
3965 obj = std::move(ret);
3972 template <
typename BasicJsonType,
typename ArithmeticType,
3974 std::is_arithmetic<ArithmeticType>::value&&
3975 !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&&
3976 !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&&
3977 !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&&
3978 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
3980 void from_json(
const BasicJsonType& j, ArithmeticType& val)
3982 switch (
static_cast<value_t
>(j))
3984 case value_t::number_unsigned:
3986 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
3989 case value_t::number_integer:
3991 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
3994 case value_t::number_float:
3996 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
3999 case value_t::boolean:
4001 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
4006 JSON_THROW(type_error::create(302,
"type must be number, but is " + std::string(j.type_name()), j));
4010 template<
typename BasicJsonType,
typename A1,
typename A2>
4011 void from_json(
const BasicJsonType& j, std::pair<A1, A2>& p)
4013 p = {j.at(0).template get<A1>(), j.at(1).template get<A2>()};
4016 template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
4017 void from_json_tuple_impl(
const BasicJsonType& j, Tuple& t, index_sequence<Idx...> )
4019 t = std::make_tuple(j.at(Idx).template get<
typename std::tuple_element<Idx, Tuple>::type>()...);
4022 template<
typename BasicJsonType,
typename... Args>
4023 void from_json(
const BasicJsonType& j, std::tuple<Args...>& t)
4025 from_json_tuple_impl(j, t, index_sequence_for<Args...> {});
4028 template <
typename BasicJsonType,
typename Key,
typename Value,
typename Compare,
typename Allocator,
4029 typename = enable_if_t < !std::is_constructible <
4030 typename BasicJsonType::string_t, Key >::value >>
4031 void from_json(
const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
4033 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4035 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4038 for (
const auto& p : j)
4040 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
4042 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(p.type_name()), j));
4044 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
4048 template <
typename BasicJsonType,
typename Key,
typename Value,
typename Hash,
typename KeyEqual,
typename Allocator,
4049 typename = enable_if_t < !std::is_constructible <
4050 typename BasicJsonType::string_t, Key >::value >>
4051 void from_json(
const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
4053 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4055 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4058 for (
const auto& p : j)
4060 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
4062 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(p.type_name()), j));
4064 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
4070 template<
typename BasicJsonType,
typename T>
4071 auto operator()(
const BasicJsonType& j, T& val)
const
4085 constexpr
const auto&
from_json = detail::static_const<detail::from_json_fn>::value;
4092 #include <algorithm>
4096 #include <type_traits>
4118 template<
typename string_type>
4119 void int_to_string( string_type& target, std::size_t value )
4122 using std::to_string;
4125 template<
typename IteratorType>
class iteration_proxy_value
4128 using difference_type = std::ptrdiff_t;
4129 using value_type = iteration_proxy_value;
4130 using pointer = value_type * ;
4131 using reference = value_type & ;
4132 using iterator_category = std::input_iterator_tag;
4133 using string_type =
typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
4137 IteratorType anchor;
4139 std::size_t array_index = 0;
4141 mutable std::size_t array_index_last = 0;
4143 mutable string_type array_index_str =
"0";
4145 const string_type empty_str{};
4148 explicit iteration_proxy_value(IteratorType it) noexcept : anchor(it) {}
4151 iteration_proxy_value& operator*()
4157 iteration_proxy_value& operator++()
4166 bool operator==(
const iteration_proxy_value& o)
const
4168 return anchor == o.anchor;
4172 bool operator!=(
const iteration_proxy_value& o)
const
4174 return anchor != o.anchor;
4178 const string_type& key()
const
4180 JSON_ASSERT(anchor.m_object !=
nullptr);
4182 switch (anchor.m_object->type())
4185 case value_t::array:
4187 if (array_index != array_index_last)
4189 int_to_string( array_index_str, array_index );
4190 array_index_last = array_index;
4192 return array_index_str;
4196 case value_t::object:
4197 return anchor.key();
4206 typename IteratorType::reference value()
const
4208 return anchor.value();
4213 template<
typename IteratorType>
class iteration_proxy
4217 typename IteratorType::reference container;
4221 explicit iteration_proxy(
typename IteratorType::reference cont) noexcept
4222 : container(cont) {}
4225 iteration_proxy_value<IteratorType> begin() noexcept
4227 return iteration_proxy_value<IteratorType>(container.begin());
4231 iteration_proxy_value<IteratorType> end() noexcept
4233 return iteration_proxy_value<IteratorType>(container.end());
4239 template<std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
4240 auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.key())
4247 template<std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
4248 auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.value())
4261 #if defined(__clang__)
4263 #pragma clang diagnostic push
4264 #pragma clang diagnostic ignored "-Wmismatched-tags"
4266 template<
typename IteratorType>
4267 class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
4268 :
public std::integral_constant<std::size_t, 2> {};
4270 template<std::
size_t N,
typename IteratorType>
4271 class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
4274 using type = decltype(
4275 get<N>(std::declval <
4276 ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));
4278 #if defined(__clang__)
4279 #pragma clang diagnostic pop
4298 template<value_t>
struct external_constructor;
4301 struct external_constructor<value_t::boolean>
4303 template<
typename BasicJsonType>
4304 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t b) noexcept
4306 j.m_type = value_t::boolean;
4308 j.assert_invariant();
4313 struct external_constructor<value_t::string>
4315 template<
typename BasicJsonType>
4316 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t& s)
4318 j.m_type = value_t::string;
4320 j.assert_invariant();
4323 template<
typename BasicJsonType>
4324 static void construct(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
4326 j.m_type = value_t::string;
4327 j.m_value = std::move(s);
4328 j.assert_invariant();
4331 template <
typename BasicJsonType,
typename CompatibleStringType,
4332 enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
4334 static void construct(BasicJsonType& j,
const CompatibleStringType& str)
4336 j.m_type = value_t::string;
4337 j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
4338 j.assert_invariant();
4343 struct external_constructor<value_t::binary>
4345 template<
typename BasicJsonType>
4346 static void construct(BasicJsonType& j,
const typename BasicJsonType::binary_t& b)
4348 j.m_type = value_t::binary;
4349 typename BasicJsonType::binary_t value{b};
4351 j.assert_invariant();
4354 template<
typename BasicJsonType>
4355 static void construct(BasicJsonType& j,
typename BasicJsonType::binary_t&& b)
4357 j.m_type = value_t::binary;
4358 typename BasicJsonType::binary_t value{std::move(b)};
4360 j.assert_invariant();
4365 struct external_constructor<value_t::number_float>
4367 template<
typename BasicJsonType>
4368 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val) noexcept
4370 j.m_type = value_t::number_float;
4372 j.assert_invariant();
4377 struct external_constructor<value_t::number_unsigned>
4379 template<
typename BasicJsonType>
4380 static void construct(BasicJsonType& j,
typename BasicJsonType::number_unsigned_t val) noexcept
4382 j.m_type = value_t::number_unsigned;
4384 j.assert_invariant();
4389 struct external_constructor<value_t::number_integer>
4391 template<
typename BasicJsonType>
4392 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val) noexcept
4394 j.m_type = value_t::number_integer;
4396 j.assert_invariant();
4401 struct external_constructor<value_t::array>
4403 template<
typename BasicJsonType>
4404 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
4406 j.m_type = value_t::array;
4409 j.assert_invariant();
4412 template<
typename BasicJsonType>
4413 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
4415 j.m_type = value_t::array;
4416 j.m_value = std::move(arr);
4418 j.assert_invariant();
4421 template <
typename BasicJsonType,
typename CompatibleArrayType,
4422 enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
4424 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
4428 j.m_type = value_t::array;
4429 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
4431 j.assert_invariant();
4434 template<
typename BasicJsonType>
4435 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
4437 j.m_type = value_t::array;
4438 j.m_value = value_t::array;
4439 j.m_value.array->reserve(arr.size());
4440 for (
const bool x : arr)
4442 j.m_value.array->push_back(x);
4443 j.set_parent(j.m_value.array->back());
4445 j.assert_invariant();
4448 template<
typename BasicJsonType,
typename T,
4449 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
4450 static void construct(BasicJsonType& j,
const std::valarray<T>& arr)
4452 j.m_type = value_t::array;
4453 j.m_value = value_t::array;
4454 j.m_value.array->resize(arr.size());
4457 std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
4460 j.assert_invariant();
4465 struct external_constructor<value_t::object>
4467 template<
typename BasicJsonType>
4468 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
4470 j.m_type = value_t::object;
4473 j.assert_invariant();
4476 template<
typename BasicJsonType>
4477 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
4479 j.m_type = value_t::object;
4480 j.m_value = std::move(obj);
4482 j.assert_invariant();
4485 template <
typename BasicJsonType,
typename CompatibleObjectType,
4486 enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
int > = 0 >
4487 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
4492 j.m_type = value_t::object;
4493 j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
4495 j.assert_invariant();
4503 template<
typename BasicJsonType,
typename T,
4504 enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value,
int> = 0>
4505 void to_json(BasicJsonType& j, T b) noexcept
4507 external_constructor<value_t::boolean>::construct(j, b);
4510 template<
typename BasicJsonType,
typename CompatibleString,
4511 enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value,
int> = 0>
4512 void to_json(BasicJsonType& j,
const CompatibleString& s)
4514 external_constructor<value_t::string>::construct(j, s);
4517 template<
typename BasicJsonType>
4518 void to_json(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
4520 external_constructor<value_t::string>::construct(j, std::move(s));
4523 template<
typename BasicJsonType,
typename FloatType,
4524 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
4525 void to_json(BasicJsonType& j, FloatType val) noexcept
4527 external_constructor<value_t::number_float>::construct(j,
static_cast<typename BasicJsonType::number_float_t
>(val));
4530 template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
4531 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value,
int> = 0>
4532 void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
4534 external_constructor<value_t::number_unsigned>::construct(j,
static_cast<typename BasicJsonType::number_unsigned_t
>(val));
4537 template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
4538 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value,
int> = 0>
4539 void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept
4541 external_constructor<value_t::number_integer>::construct(j,
static_cast<typename BasicJsonType::number_integer_t
>(val));
4544 template<
typename BasicJsonType,
typename EnumType,
4545 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
4546 void to_json(BasicJsonType& j, EnumType e) noexcept
4548 using underlying_type =
typename std::underlying_type<EnumType>::type;
4549 external_constructor<value_t::number_integer>::construct(j,
static_cast<underlying_type
>(e));
4552 template<
typename BasicJsonType>
4553 void to_json(BasicJsonType& j,
const std::vector<bool>& e)
4555 external_constructor<value_t::array>::construct(j, e);
4558 template <
typename BasicJsonType,
typename CompatibleArrayType,
4559 enable_if_t < is_compatible_array_type<BasicJsonType,
4560 CompatibleArrayType>::value&&
4561 !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&&
4562 !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&&
4563 !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
4564 !is_basic_json<CompatibleArrayType>::value,
4566 void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
4568 external_constructor<value_t::array>::construct(j, arr);
4571 template<
typename BasicJsonType>
4572 void to_json(BasicJsonType& j,
const typename BasicJsonType::binary_t& bin)
4574 external_constructor<value_t::binary>::construct(j, bin);
4577 template<
typename BasicJsonType,
typename T,
4578 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
4579 void to_json(BasicJsonType& j,
const std::valarray<T>& arr)
4581 external_constructor<value_t::array>::construct(j, std::move(arr));
4584 template<
typename BasicJsonType>
4585 void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
4587 external_constructor<value_t::array>::construct(j, std::move(arr));
4590 template <
typename BasicJsonType,
typename CompatibleObjectType,
4591 enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value,
int > = 0 >
4592 void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
4594 external_constructor<value_t::object>::construct(j, obj);
4597 template<
typename BasicJsonType>
4598 void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
4600 external_constructor<value_t::object>::construct(j, std::move(obj));
4604 typename BasicJsonType,
typename T, std::size_t N,
4605 enable_if_t < !std::is_constructible<
typename BasicJsonType::string_t,
4606 const T(&)[N]>::value,
4608 void to_json(BasicJsonType& j,
const T(&arr)[N])
4610 external_constructor<value_t::array>::construct(j, arr);
4613 template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value,
int > = 0 >
4614 void to_json(BasicJsonType& j,
const std::pair<T1, T2>& p)
4616 j = { p.first, p.second };
4620 template<
typename BasicJsonType,
typename T,
4621 enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value,
int> = 0>
4622 void to_json(BasicJsonType& j,
const T& b)
4624 j = { {b.key(), b.value()} };
4627 template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
4628 void to_json_tuple_impl(BasicJsonType& j,
const Tuple& t, index_sequence<Idx...> )
4630 j = { std::get<Idx>(t)... };
4633 template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value,
int > = 0>
4634 void to_json(BasicJsonType& j,
const T& t)
4636 to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
4641 template<
typename BasicJsonType,
typename T>
4642 auto operator()(BasicJsonType& j, T&& val)
const noexcept(noexcept(
to_json(j, std::forward<T>(val))))
4643 -> decltype(
to_json(j, std::forward<T>(val)),
void())
4645 return to_json(j, std::forward<T>(val));
4653 constexpr
const auto&
to_json = detail::static_const<detail::to_json_fn>::value;
4661 template<
typename,
typename>
4673 template<
typename BasicJsonType,
typename ValueType>
4674 static auto from_json(BasicJsonType&& j, ValueType& val) noexcept(
4675 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
4676 -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val),
void())
4678 ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
4690 template<
typename BasicJsonType,
typename ValueType>
4691 static auto to_json(BasicJsonType& j, ValueType&& val) noexcept(
4692 noexcept(::nlohmann::to_json(j, std::forward<ValueType>(val))))
4693 -> decltype(::nlohmann::to_json(j, std::forward<ValueType>(val)),
void())
4695 ::nlohmann::to_json(j, std::forward<ValueType>(val));
4724 template<
typename BinaryType>
4745 , m_subtype(subtype_)
4746 , m_has_subtype(true)
4751 , m_subtype(subtype_)
4752 , m_has_subtype(true)
4757 return std::tie(
static_cast<const BinaryType&
>(*
this), m_subtype, m_has_subtype) ==
4758 std::tie(
static_cast<const BinaryType&
>(rhs), rhs.m_subtype, rhs.m_has_subtype);
4763 return !(rhs == *
this);
4786 m_subtype = subtype_;
4787 m_has_subtype =
true;
4834 return m_has_subtype;
4859 m_has_subtype =
false;
4863 std::uint8_t m_subtype = 0;
4864 bool m_has_subtype =
false;
4879 #include <functional>
4890 inline std::size_t combine(std::size_t seed, std::size_t h) noexcept
4892 seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
4907 template<
typename BasicJsonType>
4908 std::size_t hash(
const BasicJsonType& j)
4910 using string_t =
typename BasicJsonType::string_t;
4911 using number_integer_t =
typename BasicJsonType::number_integer_t;
4912 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
4913 using number_float_t =
typename BasicJsonType::number_float_t;
4915 const auto type =
static_cast<std::size_t
>(j.type());
4918 case BasicJsonType::value_t::null:
4919 case BasicJsonType::value_t::discarded:
4921 return combine(type, 0);
4924 case BasicJsonType::value_t::object:
4926 auto seed = combine(type, j.size());
4927 for (
const auto& element : j.items())
4929 const auto h = std::hash<string_t> {}(element.key());
4930 seed = combine(seed, h);
4931 seed = combine(seed, hash(element.value()));
4936 case BasicJsonType::value_t::array:
4938 auto seed = combine(type, j.size());
4939 for (
const auto& element : j)
4941 seed = combine(seed, hash(element));
4946 case BasicJsonType::value_t::string:
4948 const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
4949 return combine(type, h);
4952 case BasicJsonType::value_t::boolean:
4954 const auto h = std::hash<bool> {}(j.template get<bool>());
4955 return combine(type, h);
4958 case BasicJsonType::value_t::number_integer:
4960 const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
4961 return combine(type, h);
4964 case BasicJsonType::value_t::number_unsigned:
4966 const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
4967 return combine(type, h);
4970 case BasicJsonType::value_t::number_float:
4972 const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
4973 return combine(type, h);
4976 case BasicJsonType::value_t::binary:
4978 auto seed = combine(type, j.get_binary().size());
4979 const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
4980 seed = combine(seed, h);
4981 seed = combine(seed, j.get_binary().subtype());
4982 for (
const auto byte : j.get_binary())
4984 seed = combine(seed, std::hash<std::uint8_t> {}(byte));
5001 #include <algorithm>
5028 #include <type_traits>
5041 enum class input_format_t {
json, cbor, msgpack, ubjson, bson };
5051 class file_input_adapter
5054 using char_type = char;
5056 JSON_HEDLEY_NON_NULL(2)
5057 explicit file_input_adapter(std::FILE* f) noexcept
5062 file_input_adapter(
const file_input_adapter&) =
delete;
5063 file_input_adapter(file_input_adapter&&) =
default;
5064 file_input_adapter& operator=(
const file_input_adapter&) =
delete;
5065 file_input_adapter& operator=(file_input_adapter&&) =
delete;
5067 std::char_traits<char>::int_type get_character() noexcept
5069 return std::fgetc(m_file);
5087 class input_stream_adapter
5090 using char_type = char;
5092 ~input_stream_adapter()
5098 is->clear(is->rdstate() & std::ios::eofbit);
5102 explicit input_stream_adapter(std::istream& i)
5103 : is(&i), sb(i.rdbuf())
5107 input_stream_adapter(
const input_stream_adapter&) =
delete;
5108 input_stream_adapter& operator=(input_stream_adapter&) =
delete;
5109 input_stream_adapter& operator=(input_stream_adapter&& rhs) =
delete;
5111 input_stream_adapter(input_stream_adapter&& rhs) noexcept : is(rhs.is), sb(rhs.sb)
5120 std::char_traits<char>::int_type get_character()
5122 auto res = sb->sbumpc();
5124 if (JSON_HEDLEY_UNLIKELY(res == EOF))
5126 is->clear(is->rdstate() | std::ios::eofbit);
5133 std::istream* is =
nullptr;
5134 std::streambuf* sb =
nullptr;
5139 template<
typename IteratorType>
5140 class iterator_input_adapter
5143 using char_type =
typename std::iterator_traits<IteratorType>::value_type;
5145 iterator_input_adapter(IteratorType first, IteratorType last)
5146 : current(std::move(first)), end(std::move(last)) {}
5148 typename std::char_traits<char_type>::int_type get_character()
5150 if (JSON_HEDLEY_LIKELY(current != end))
5152 auto result = std::char_traits<char_type>::to_int_type(*current);
5153 std::advance(current, 1);
5157 return std::char_traits<char_type>::eof();
5161 IteratorType current;
5164 template<
typename BaseInputAdapter,
size_t T>
5165 friend struct wide_string_input_helper;
5169 return current == end;
5175 template<
typename BaseInputAdapter,
size_t T>
5176 struct wide_string_input_helper;
5178 template<
typename BaseInputAdapter>
5179 struct wide_string_input_helper<BaseInputAdapter, 4>
5182 static void fill_buffer(BaseInputAdapter& input,
5183 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
5184 size_t& utf8_bytes_index,
5185 size_t& utf8_bytes_filled)
5187 utf8_bytes_index = 0;
5189 if (JSON_HEDLEY_UNLIKELY(input.empty()))
5191 utf8_bytes[0] = std::char_traits<char>::eof();
5192 utf8_bytes_filled = 1;
5197 const auto wc = input.get_character();
5202 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5203 utf8_bytes_filled = 1;
5205 else if (wc <= 0x7FF)
5207 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
5208 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5209 utf8_bytes_filled = 2;
5211 else if (wc <= 0xFFFF)
5213 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
5214 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5215 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5216 utf8_bytes_filled = 3;
5218 else if (wc <= 0x10FFFF)
5220 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | ((
static_cast<unsigned int>(wc) >> 18u) & 0x07u));
5221 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
5222 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5223 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5224 utf8_bytes_filled = 4;
5229 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5230 utf8_bytes_filled = 1;
5236 template<
typename BaseInputAdapter>
5237 struct wide_string_input_helper<BaseInputAdapter, 2>
5240 static void fill_buffer(BaseInputAdapter& input,
5241 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
5242 size_t& utf8_bytes_index,
5243 size_t& utf8_bytes_filled)
5245 utf8_bytes_index = 0;
5247 if (JSON_HEDLEY_UNLIKELY(input.empty()))
5249 utf8_bytes[0] = std::char_traits<char>::eof();
5250 utf8_bytes_filled = 1;
5255 const auto wc = input.get_character();
5260 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5261 utf8_bytes_filled = 1;
5263 else if (wc <= 0x7FF)
5265 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u)));
5266 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5267 utf8_bytes_filled = 2;
5269 else if (0xD800 > wc || wc >= 0xE000)
5271 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u)));
5272 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5273 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5274 utf8_bytes_filled = 3;
5278 if (JSON_HEDLEY_UNLIKELY(!input.empty()))
5280 const auto wc2 =
static_cast<unsigned int>(input.get_character());
5281 const auto charcode = 0x10000u + (((
static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
5282 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | (charcode >> 18u));
5283 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 12u) & 0x3Fu));
5284 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 6u) & 0x3Fu));
5285 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (charcode & 0x3Fu));
5286 utf8_bytes_filled = 4;
5290 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5291 utf8_bytes_filled = 1;
5299 template<
typename BaseInputAdapter,
typename W
ideCharType>
5300 class wide_string_input_adapter
5303 using char_type = char;
5305 wide_string_input_adapter(BaseInputAdapter base)
5306 : base_adapter(base) {}
5308 typename std::char_traits<char>::int_type get_character() noexcept
5311 if (utf8_bytes_index == utf8_bytes_filled)
5313 fill_buffer<sizeof(WideCharType)>();
5315 JSON_ASSERT(utf8_bytes_filled > 0);
5316 JSON_ASSERT(utf8_bytes_index == 0);
5320 JSON_ASSERT(utf8_bytes_filled > 0);
5321 JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);
5322 return utf8_bytes[utf8_bytes_index++];
5326 BaseInputAdapter base_adapter;
5331 wide_string_input_helper<BaseInputAdapter, T>::fill_buffer(base_adapter, utf8_bytes, utf8_bytes_index, utf8_bytes_filled);
5335 std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
5338 std::size_t utf8_bytes_index = 0;
5340 std::size_t utf8_bytes_filled = 0;
5344 template<
typename IteratorType,
typename Enable =
void>
5345 struct iterator_input_adapter_factory
5347 using iterator_type = IteratorType;
5348 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
5349 using adapter_type = iterator_input_adapter<iterator_type>;
5351 static adapter_type create(IteratorType first, IteratorType last)
5353 return adapter_type(std::move(first), std::move(last));
5357 template<
typename T>
5358 struct is_iterator_of_multibyte
5360 using value_type =
typename std::iterator_traits<T>::value_type;
5363 value =
sizeof(value_type) > 1
5367 template<
typename IteratorType>
5368 struct iterator_input_adapter_factory<IteratorType, enable_if_t<is_iterator_of_multibyte<IteratorType>::value>>
5370 using iterator_type = IteratorType;
5371 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
5372 using base_adapter_type = iterator_input_adapter<iterator_type>;
5373 using adapter_type = wide_string_input_adapter<base_adapter_type, char_type>;
5375 static adapter_type create(IteratorType first, IteratorType last)
5377 return adapter_type(base_adapter_type(std::move(first), std::move(last)));
5382 template<
typename IteratorType>
5383 typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapter(IteratorType first, IteratorType last)
5385 using factory_type = iterator_input_adapter_factory<IteratorType>;
5386 return factory_type::create(first, last);
5393 namespace container_input_adapter_factory_impl
5399 template<
typename ContainerType,
typename Enable =
void>
5400 struct container_input_adapter_factory {};
5402 template<
typename ContainerType>
5403 struct container_input_adapter_factory< ContainerType,
5404 void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
5406 using adapter_type = decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
5408 static adapter_type create(
const ContainerType& container)
5410 return input_adapter(begin(container), end(container));
5416 template<
typename ContainerType>
5417 typename container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::adapter_type input_adapter(
const ContainerType& container)
5419 return container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::create(container);
5423 inline file_input_adapter input_adapter(std::FILE* file)
5425 return file_input_adapter(file);
5428 inline input_stream_adapter input_adapter(std::istream& stream)
5430 return input_stream_adapter(stream);
5433 inline input_stream_adapter input_adapter(std::istream&& stream)
5435 return input_stream_adapter(stream);
5438 using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
5441 template <
typename CharT,
5442 typename std::enable_if <
5443 std::is_pointer<CharT>::value&&
5444 !std::is_array<CharT>::value&&
5445 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
5446 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
5448 contiguous_bytes_input_adapter input_adapter(CharT b)
5450 auto length = std::strlen(
reinterpret_cast<const char*
>(b));
5451 const auto* ptr =
reinterpret_cast<const char*
>(b);
5452 return input_adapter(ptr, ptr + length);
5455 template<
typename T, std::
size_t N>
5456 auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N))
5458 return input_adapter(array, array + N);
5464 class span_input_adapter
5467 template <
typename CharT,
5468 typename std::enable_if <
5469 std::is_pointer<CharT>::value&&
5470 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
5471 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
5473 span_input_adapter(CharT b, std::size_t l)
5474 : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {}
5476 template<
class IteratorType,
5477 typename std::enable_if<
5478 std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
5480 span_input_adapter(IteratorType first, IteratorType last)
5481 : ia(input_adapter(first, last)) {}
5483 contiguous_bytes_input_adapter&& get()
5485 return std::move(ia);
5489 contiguous_bytes_input_adapter ia;
5518 template<
typename BasicJsonType>
5531 virtual bool null() = 0;
5622 const std::string& last_token,
5623 const detail::exception& ex) = 0;
5644 template<
typename BasicJsonType>
5645 class json_sax_dom_parser
5648 using number_integer_t =
typename BasicJsonType::number_integer_t;
5649 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5650 using number_float_t =
typename BasicJsonType::number_float_t;
5651 using string_t =
typename BasicJsonType::string_t;
5652 using binary_t =
typename BasicJsonType::binary_t;
5659 explicit json_sax_dom_parser(BasicJsonType& r,
const bool allow_exceptions_ =
true)
5660 : root(r), allow_exceptions(allow_exceptions_)
5664 json_sax_dom_parser(
const json_sax_dom_parser&) =
delete;
5665 json_sax_dom_parser(json_sax_dom_parser&&) =
default;
5666 json_sax_dom_parser& operator=(
const json_sax_dom_parser&) =
delete;
5667 json_sax_dom_parser& operator=(json_sax_dom_parser&&) =
default;
5668 ~json_sax_dom_parser() =
default;
5672 handle_value(
nullptr);
5676 bool boolean(
bool val)
5682 bool number_integer(number_integer_t val)
5688 bool number_unsigned(number_unsigned_t val)
5694 bool number_float(number_float_t val,
const string_t& )
5700 bool string(string_t& val)
5706 bool binary(binary_t& val)
5708 handle_value(std::move(val));
5712 bool start_object(std::size_t len)
5714 ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
5716 if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
5718 JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len), *ref_stack.back()));
5724 bool key(string_t& val)
5727 object_element = &(ref_stack.back()->m_value.object->operator[](val));
5733 ref_stack.back()->set_parents();
5734 ref_stack.pop_back();
5738 bool start_array(std::size_t len)
5740 ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
5742 if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
5744 JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len), *ref_stack.back()));
5752 ref_stack.back()->set_parents();
5753 ref_stack.pop_back();
5757 template<
class Exception>
5758 bool parse_error(std::size_t ,
const std::string& ,
5759 const Exception& ex)
5762 static_cast<void>(ex);
5763 if (allow_exceptions)
5770 constexpr
bool is_errored()
const
5782 template<
typename Value>
5784 BasicJsonType* handle_value(Value&& v)
5786 if (ref_stack.empty())
5788 root = BasicJsonType(std::forward<Value>(v));
5792 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
5794 if (ref_stack.back()->is_array())
5796 ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
5797 return &(ref_stack.back()->m_value.array->back());
5800 JSON_ASSERT(ref_stack.back()->is_object());
5801 JSON_ASSERT(object_element);
5802 *object_element = BasicJsonType(std::forward<Value>(v));
5803 return object_element;
5807 BasicJsonType& root;
5809 std::vector<BasicJsonType*> ref_stack {};
5811 BasicJsonType* object_element =
nullptr;
5813 bool errored =
false;
5815 const bool allow_exceptions =
true;
5818 template<
typename BasicJsonType>
5819 class json_sax_dom_callback_parser
5822 using number_integer_t =
typename BasicJsonType::number_integer_t;
5823 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5824 using number_float_t =
typename BasicJsonType::number_float_t;
5825 using string_t =
typename BasicJsonType::string_t;
5826 using binary_t =
typename BasicJsonType::binary_t;
5827 using parser_callback_t =
typename BasicJsonType::parser_callback_t;
5828 using parse_event_t =
typename BasicJsonType::parse_event_t;
5830 json_sax_dom_callback_parser(BasicJsonType& r,
5831 const parser_callback_t cb,
5832 const bool allow_exceptions_ =
true)
5833 : root(r), callback(cb), allow_exceptions(allow_exceptions_)
5835 keep_stack.push_back(
true);
5839 json_sax_dom_callback_parser(
const json_sax_dom_callback_parser&) =
delete;
5840 json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) =
default;
5841 json_sax_dom_callback_parser& operator=(
const json_sax_dom_callback_parser&) =
delete;
5842 json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) =
default;
5843 ~json_sax_dom_callback_parser() =
default;
5847 handle_value(
nullptr);
5851 bool boolean(
bool val)
5857 bool number_integer(number_integer_t val)
5863 bool number_unsigned(number_unsigned_t val)
5869 bool number_float(number_float_t val,
const string_t& )
5875 bool string(string_t& val)
5881 bool binary(binary_t& val)
5883 handle_value(std::move(val));
5887 bool start_object(std::size_t len)
5890 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);
5891 keep_stack.push_back(keep);
5893 auto val = handle_value(BasicJsonType::value_t::object,
true);
5894 ref_stack.push_back(val.second);
5897 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
5899 JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len), *ref_stack.back()));
5905 bool key(string_t& val)
5907 BasicJsonType k = BasicJsonType(val);
5910 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::key, k);
5911 key_keep_stack.push_back(keep);
5914 if (keep && ref_stack.back())
5916 object_element = &(ref_stack.back()->m_value.object->operator[](val) = discarded);
5924 if (ref_stack.back())
5926 if (!callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
5929 *ref_stack.back() = discarded;
5933 ref_stack.back()->set_parents();
5937 JSON_ASSERT(!ref_stack.empty());
5938 JSON_ASSERT(!keep_stack.empty());
5939 ref_stack.pop_back();
5940 keep_stack.pop_back();
5942 if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
5945 for (
auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
5947 if (it->is_discarded())
5949 ref_stack.back()->erase(it);
5958 bool start_array(std::size_t len)
5960 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);
5961 keep_stack.push_back(keep);
5963 auto val = handle_value(BasicJsonType::value_t::array,
true);
5964 ref_stack.push_back(val.second);
5967 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
5969 JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len), *ref_stack.back()));
5979 if (ref_stack.back())
5981 keep = callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
5984 ref_stack.back()->set_parents();
5989 *ref_stack.back() = discarded;
5993 JSON_ASSERT(!ref_stack.empty());
5994 JSON_ASSERT(!keep_stack.empty());
5995 ref_stack.pop_back();
5996 keep_stack.pop_back();
5999 if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
6001 ref_stack.back()->m_value.array->pop_back();
6007 template<
class Exception>
6008 bool parse_error(std::size_t ,
const std::string& ,
6009 const Exception& ex)
6012 static_cast<void>(ex);
6013 if (allow_exceptions)
6020 constexpr
bool is_errored()
const
6041 template<
typename Value>
6042 std::pair<bool, BasicJsonType*> handle_value(Value&& v,
const bool skip_callback =
false)
6044 JSON_ASSERT(!keep_stack.empty());
6048 if (!keep_stack.back())
6050 return {
false,
nullptr};
6054 auto value = BasicJsonType(std::forward<Value>(v));
6057 const bool keep = skip_callback || callback(
static_cast<int>(ref_stack.size()), parse_event_t::value, value);
6062 return {
false,
nullptr};
6065 if (ref_stack.empty())
6067 root = std::move(value);
6068 return {
true, &root};
6073 if (!ref_stack.back())
6075 return {
false,
nullptr};
6079 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6082 if (ref_stack.back()->is_array())
6084 ref_stack.back()->m_value.array->emplace_back(std::move(value));
6085 return {
true, &(ref_stack.back()->m_value.array->back())};
6089 JSON_ASSERT(ref_stack.back()->is_object());
6091 JSON_ASSERT(!key_keep_stack.empty());
6092 const bool store_element = key_keep_stack.back();
6093 key_keep_stack.pop_back();
6097 return {
false,
nullptr};
6100 JSON_ASSERT(object_element);
6101 *object_element = std::move(value);
6102 return {
true, object_element};
6106 BasicJsonType& root;
6108 std::vector<BasicJsonType*> ref_stack {};
6110 std::vector<bool> keep_stack {};
6112 std::vector<bool> key_keep_stack {};
6114 BasicJsonType* object_element =
nullptr;
6116 bool errored =
false;
6118 const parser_callback_t callback =
nullptr;
6120 const bool allow_exceptions =
true;
6122 BasicJsonType discarded = BasicJsonType::value_t::discarded;
6125 template<
typename BasicJsonType>
6126 class json_sax_acceptor
6129 using number_integer_t =
typename BasicJsonType::number_integer_t;
6130 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6131 using number_float_t =
typename BasicJsonType::number_float_t;
6132 using string_t =
typename BasicJsonType::string_t;
6133 using binary_t =
typename BasicJsonType::binary_t;
6145 bool number_integer(number_integer_t )
6150 bool number_unsigned(number_unsigned_t )
6155 bool number_float(number_float_t ,
const string_t& )
6160 bool string(string_t& )
6165 bool binary(binary_t& )
6170 bool start_object(std::size_t = std::size_t(-1))
6175 bool key(string_t& )
6185 bool start_array(std::size_t = std::size_t(-1))
6195 bool parse_error(std::size_t ,
const std::string& ,
const detail::exception& )
6212 #include <initializer_list>
6232 template<
typename BasicJsonType>
6237 enum class token_type
6261 static const char* token_type_name(
const token_type t) noexcept
6265 case token_type::uninitialized:
6266 return "<uninitialized>";
6267 case token_type::literal_true:
6268 return "true literal";
6269 case token_type::literal_false:
6270 return "false literal";
6271 case token_type::literal_null:
6272 return "null literal";
6273 case token_type::value_string:
6274 return "string literal";
6275 case token_type::value_unsigned:
6276 case token_type::value_integer:
6277 case token_type::value_float:
6278 return "number literal";
6279 case token_type::begin_array:
6281 case token_type::begin_object:
6283 case token_type::end_array:
6285 case token_type::end_object:
6287 case token_type::name_separator:
6289 case token_type::value_separator:
6291 case token_type::parse_error:
6292 return "<parse error>";
6293 case token_type::end_of_input:
6294 return "end of input";
6295 case token_type::literal_or_value:
6296 return "'[', '{', or a literal";
6299 return "unknown token";
6309 template<
typename BasicJsonType,
typename InputAdapterType>
6310 class lexer :
public lexer_base<BasicJsonType>
6312 using number_integer_t =
typename BasicJsonType::number_integer_t;
6313 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6314 using number_float_t =
typename BasicJsonType::number_float_t;
6315 using string_t =
typename BasicJsonType::string_t;
6316 using char_type =
typename InputAdapterType::char_type;
6317 using char_int_type =
typename std::char_traits<char_type>::int_type;
6320 using token_type =
typename lexer_base<BasicJsonType>::token_type;
6322 explicit lexer(InputAdapterType&& adapter,
bool ignore_comments_ =
false)
6323 : ia(std::move(adapter))
6324 , ignore_comments(ignore_comments_)
6325 , decimal_point_char(static_cast<char_int_type>(get_decimal_point()))
6329 lexer(
const lexer&) =
delete;
6330 lexer(lexer&&) =
default;
6331 lexer& operator=(lexer&) =
delete;
6332 lexer& operator=(lexer&&) =
default;
6342 static char get_decimal_point() noexcept
6344 const auto* loc = localeconv();
6345 JSON_ASSERT(loc !=
nullptr);
6346 return (loc->decimal_point ==
nullptr) ?
'.' : *(loc->decimal_point);
6371 JSON_ASSERT(current ==
'u');
6374 const auto factors = { 12u, 8u, 4u, 0u };
6375 for (
const auto factor : factors)
6379 if (current >=
'0' && current <=
'9')
6381 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x30u) << factor);
6383 else if (current >=
'A' && current <=
'F')
6385 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x37u) << factor);
6387 else if (current >=
'a' && current <=
'f')
6389 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x57u) << factor);
6397 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
6416 bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
6418 JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
6421 for (
auto range = ranges.begin(); range != ranges.end(); ++range)
6424 if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range)))
6430 error_message =
"invalid string: ill-formed UTF-8 byte";
6453 token_type scan_string()
6459 JSON_ASSERT(current ==
'\"');
6467 case std::char_traits<char_type>::eof():
6469 error_message =
"invalid string: missing closing quote";
6470 return token_type::parse_error;
6476 return token_type::value_string;
6520 const int codepoint1 = get_codepoint();
6521 int codepoint = codepoint1;
6523 if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
6525 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
6526 return token_type::parse_error;
6530 if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
6533 if (JSON_HEDLEY_LIKELY(get() ==
'\\' && get() ==
'u'))
6535 const int codepoint2 = get_codepoint();
6537 if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
6539 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
6540 return token_type::parse_error;
6544 if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))
6547 codepoint =
static_cast<int>(
6549 (
static_cast<unsigned int>(codepoint1) << 10u)
6551 +
static_cast<unsigned int>(codepoint2)
6559 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
6560 return token_type::parse_error;
6565 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
6566 return token_type::parse_error;
6571 if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))
6573 error_message =
"invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
6574 return token_type::parse_error;
6579 JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
6582 if (codepoint < 0x80)
6585 add(
static_cast<char_int_type
>(codepoint));
6587 else if (codepoint <= 0x7FF)
6590 add(
static_cast<char_int_type
>(0xC0u | (
static_cast<unsigned int>(codepoint) >> 6u)));
6591 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
6593 else if (codepoint <= 0xFFFF)
6596 add(
static_cast<char_int_type
>(0xE0u | (
static_cast<unsigned int>(codepoint) >> 12u)));
6597 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
6598 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
6603 add(
static_cast<char_int_type
>(0xF0u | (
static_cast<unsigned int>(codepoint) >> 18u)));
6604 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
6605 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
6606 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
6614 error_message =
"invalid string: forbidden character after backslash";
6615 return token_type::parse_error;
6624 error_message =
"invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
6625 return token_type::parse_error;
6630 error_message =
"invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
6631 return token_type::parse_error;
6636 error_message =
"invalid string: control character U+0002 (STX) must be escaped to \\u0002";
6637 return token_type::parse_error;
6642 error_message =
"invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
6643 return token_type::parse_error;
6648 error_message =
"invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
6649 return token_type::parse_error;
6654 error_message =
"invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
6655 return token_type::parse_error;
6660 error_message =
"invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
6661 return token_type::parse_error;
6666 error_message =
"invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
6667 return token_type::parse_error;
6672 error_message =
"invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
6673 return token_type::parse_error;
6678 error_message =
"invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
6679 return token_type::parse_error;
6684 error_message =
"invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
6685 return token_type::parse_error;
6690 error_message =
"invalid string: control character U+000B (VT) must be escaped to \\u000B";
6691 return token_type::parse_error;
6696 error_message =
"invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
6697 return token_type::parse_error;
6702 error_message =
"invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
6703 return token_type::parse_error;
6708 error_message =
"invalid string: control character U+000E (SO) must be escaped to \\u000E";
6709 return token_type::parse_error;
6714 error_message =
"invalid string: control character U+000F (SI) must be escaped to \\u000F";
6715 return token_type::parse_error;
6720 error_message =
"invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
6721 return token_type::parse_error;
6726 error_message =
"invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
6727 return token_type::parse_error;
6732 error_message =
"invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
6733 return token_type::parse_error;
6738 error_message =
"invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
6739 return token_type::parse_error;
6744 error_message =
"invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
6745 return token_type::parse_error;
6750 error_message =
"invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
6751 return token_type::parse_error;
6756 error_message =
"invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
6757 return token_type::parse_error;
6762 error_message =
"invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
6763 return token_type::parse_error;
6768 error_message =
"invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
6769 return token_type::parse_error;
6774 error_message =
"invalid string: control character U+0019 (EM) must be escaped to \\u0019";
6775 return token_type::parse_error;
6780 error_message =
"invalid string: control character U+001A (SUB) must be escaped to \\u001A";
6781 return token_type::parse_error;
6786 error_message =
"invalid string: control character U+001B (ESC) must be escaped to \\u001B";
6787 return token_type::parse_error;
6792 error_message =
"invalid string: control character U+001C (FS) must be escaped to \\u001C";
6793 return token_type::parse_error;
6798 error_message =
"invalid string: control character U+001D (GS) must be escaped to \\u001D";
6799 return token_type::parse_error;
6804 error_message =
"invalid string: control character U+001E (RS) must be escaped to \\u001E";
6805 return token_type::parse_error;
6810 error_message =
"invalid string: control character U+001F (US) must be escaped to \\u001F";
6811 return token_type::parse_error;
6946 if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
6948 return token_type::parse_error;
6956 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
6958 return token_type::parse_error;
6980 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
6982 return token_type::parse_error;
6990 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
6992 return token_type::parse_error;
7000 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7002 return token_type::parse_error;
7012 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7014 return token_type::parse_error;
7022 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
7024 return token_type::parse_error;
7032 error_message =
"invalid string: ill-formed UTF-8 byte";
7033 return token_type::parse_error;
7056 case std::char_traits<char_type>::eof():
7073 case std::char_traits<char_type>::eof():
7076 error_message =
"invalid comment; missing closing '*/'";
7104 error_message =
"invalid comment; expecting '/' or '*' after '/'";
7110 JSON_HEDLEY_NON_NULL(2)
7111 static
void strtof(
float& f, const
char* str,
char** endptr) noexcept
7113 f = std::strtof(str, endptr);
7116 JSON_HEDLEY_NON_NULL(2)
7117 static
void strtof(
double& f, const
char* str,
char** endptr) noexcept
7119 f = std::strtod(str, endptr);
7122 JSON_HEDLEY_NON_NULL(2)
7123 static
void strtof(
long double& f, const
char* str,
char** endptr) noexcept
7125 f = std::strtold(str, endptr);
7168 token_type scan_number()
7175 token_type number_type = token_type::value_unsigned;
7183 goto scan_number_minus;
7189 goto scan_number_zero;
7203 goto scan_number_any1;
7213 number_type = token_type::value_integer;
7219 goto scan_number_zero;
7233 goto scan_number_any1;
7238 error_message =
"invalid number; expected digit after '-'";
7239 return token_type::parse_error;
7249 add(decimal_point_char);
7250 goto scan_number_decimal1;
7257 goto scan_number_exponent;
7261 goto scan_number_done;
7280 goto scan_number_any1;
7285 add(decimal_point_char);
7286 goto scan_number_decimal1;
7293 goto scan_number_exponent;
7297 goto scan_number_done;
7300 scan_number_decimal1:
7302 number_type = token_type::value_float;
7317 goto scan_number_decimal2;
7322 error_message =
"invalid number; expected digit after '.'";
7323 return token_type::parse_error;
7327 scan_number_decimal2:
7343 goto scan_number_decimal2;
7350 goto scan_number_exponent;
7354 goto scan_number_done;
7357 scan_number_exponent:
7359 number_type = token_type::value_float;
7366 goto scan_number_sign;
7381 goto scan_number_any2;
7387 "invalid number; expected '+', '-', or digit after exponent";
7388 return token_type::parse_error;
7408 goto scan_number_any2;
7413 error_message =
"invalid number; expected digit after exponent sign";
7414 return token_type::parse_error;
7434 goto scan_number_any2;
7438 goto scan_number_done;
7446 char* endptr =
nullptr;
7450 if (number_type == token_type::value_unsigned)
7452 const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
7455 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7459 value_unsigned =
static_cast<number_unsigned_t
>(x);
7460 if (value_unsigned == x)
7462 return token_type::value_unsigned;
7466 else if (number_type == token_type::value_integer)
7468 const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
7471 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7475 value_integer =
static_cast<number_integer_t
>(x);
7476 if (value_integer == x)
7478 return token_type::value_integer;
7485 strtof(value_float, token_buffer.data(), &endptr);
7488 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7490 return token_type::value_float;
7498 JSON_HEDLEY_NON_NULL(2)
7499 token_type scan_literal(const char_type* literal_text, const std::
size_t length,
7500 token_type return_type)
7502 JSON_ASSERT(std::char_traits<char_type>::to_char_type(current) == literal_text[0]);
7503 for (std::size_t i = 1; i < length; ++i)
7505 if (JSON_HEDLEY_UNLIKELY(std::char_traits<char_type>::to_char_type(get()) != literal_text[i]))
7507 error_message =
"invalid literal";
7508 return token_type::parse_error;
7519 void reset() noexcept
7521 token_buffer.clear();
7522 token_string.clear();
7523 token_string.push_back(std::char_traits<char_type>::to_char_type(current));
7538 ++position.chars_read_total;
7539 ++position.chars_read_current_line;
7548 current = ia.get_character();
7551 if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
7553 token_string.push_back(std::char_traits<char_type>::to_char_type(current));
7556 if (current ==
'\n')
7558 ++position.lines_read;
7559 position.chars_read_current_line = 0;
7577 --position.chars_read_total;
7580 if (position.chars_read_current_line == 0)
7582 if (position.lines_read > 0)
7584 --position.lines_read;
7589 --position.chars_read_current_line;
7592 if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
7594 JSON_ASSERT(!token_string.empty());
7595 token_string.pop_back();
7600 void add(char_int_type c)
7602 token_buffer.push_back(
static_cast<typename string_t::value_type
>(c));
7611 constexpr number_integer_t get_number_integer() const noexcept
7613 return value_integer;
7617 constexpr number_unsigned_t get_number_unsigned() const noexcept
7619 return value_unsigned;
7623 constexpr number_float_t get_number_float() const noexcept
7629 string_t& get_string()
7631 return token_buffer;
7639 constexpr position_t get_position() const noexcept
7647 std::string get_token_string()
const
7651 for (
const auto c : token_string)
7653 if (
static_cast<unsigned char>(c) <=
'\x1F')
7656 std::array<char, 9> cs{{}};
7657 (std::snprintf)(cs.data(), cs.size(),
"<U+%.4X>",
static_cast<unsigned char>(c));
7658 result += cs.data();
7663 result.push_back(
static_cast<std::string::value_type
>(c));
7672 constexpr
const char* get_error_message() const noexcept
7674 return error_message;
7690 return get() == 0xBB && get() == 0xBF;
7699 void skip_whitespace()
7705 while (current ==
' ' || current ==
'\t' || current ==
'\n' || current ==
'\r');
7711 if (position.chars_read_total == 0 && !skip_bom())
7713 error_message =
"invalid BOM; must be 0xEF 0xBB 0xBF if given";
7714 return token_type::parse_error;
7721 while (ignore_comments && current ==
'/')
7723 if (!scan_comment())
7725 return token_type::parse_error;
7736 return token_type::begin_array;
7738 return token_type::end_array;
7740 return token_type::begin_object;
7742 return token_type::end_object;
7744 return token_type::name_separator;
7746 return token_type::value_separator;
7751 std::array<char_type, 4> true_literal = {{char_type(
't'), char_type(
'r'), char_type(
'u'), char_type(
'e')}};
7752 return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
7756 std::array<char_type, 5> false_literal = {{char_type(
'f'), char_type(
'a'), char_type(
'l'), char_type(
's'), char_type(
'e')}};
7757 return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
7761 std::array<char_type, 4> null_literal = {{char_type(
'n'), char_type(
'u'), char_type(
'l'), char_type(
'l')}};
7762 return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
7767 return scan_string();
7781 return scan_number();
7786 case std::char_traits<char_type>::eof():
7787 return token_type::end_of_input;
7791 error_message =
"invalid literal";
7792 return token_type::parse_error;
7798 InputAdapterType ia;
7801 const bool ignore_comments =
false;
7804 char_int_type current = std::char_traits<char_type>::eof();
7807 bool next_unget =
false;
7810 position_t position {};
7813 std::vector<char_type> token_string {};
7816 string_t token_buffer {};
7819 const char* error_message =
"";
7822 number_integer_t value_integer = 0;
7823 number_unsigned_t value_unsigned = 0;
7824 number_float_t value_float = 0;
7827 const char_int_type decimal_point_char =
'.';
7850 template<
typename T>
7851 using null_function_t = decltype(std::declval<T&>().
null());
7853 template<
typename T>
7854 using boolean_function_t =
7855 decltype(std::declval<T&>().
boolean(std::declval<bool>()));
7857 template<
typename T,
typename Integer>
7858 using number_integer_function_t =
7859 decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
7861 template<
typename T,
typename Un
signed>
7862 using number_unsigned_function_t =
7863 decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
7865 template<
typename T,
typename Float,
typename String>
7866 using number_float_function_t = decltype(std::declval<T&>().number_float(
7867 std::declval<Float>(), std::declval<const String&>()));
7869 template<
typename T,
typename String>
7870 using string_function_t =
7871 decltype(std::declval<T&>().
string(std::declval<String&>()));
7873 template<
typename T,
typename Binary>
7874 using binary_function_t =
7875 decltype(std::declval<T&>().binary(std::declval<Binary&>()));
7877 template<
typename T>
7878 using start_object_function_t =
7879 decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
7881 template<
typename T,
typename String>
7882 using key_function_t =
7883 decltype(std::declval<T&>().key(std::declval<String&>()));
7885 template<
typename T>
7886 using end_object_function_t = decltype(std::declval<T&>().end_object());
7888 template<
typename T>
7889 using start_array_function_t =
7890 decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
7892 template<
typename T>
7893 using end_array_function_t = decltype(std::declval<T&>().end_array());
7895 template<
typename T,
typename Exception>
7896 using parse_error_function_t = decltype(std::declval<T&>().parse_error(
7897 std::declval<std::size_t>(), std::declval<const std::string&>(),
7898 std::declval<const Exception&>()));
7900 template<
typename SAX,
typename BasicJsonType>
7904 static_assert(is_basic_json<BasicJsonType>::value,
7905 "BasicJsonType must be of type basic_json<...>");
7907 using number_integer_t =
typename BasicJsonType::number_integer_t;
7908 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7909 using number_float_t =
typename BasicJsonType::number_float_t;
7910 using string_t =
typename BasicJsonType::string_t;
7911 using binary_t =
typename BasicJsonType::binary_t;
7912 using exception_t =
typename BasicJsonType::exception;
7915 static constexpr
bool value =
7916 is_detected_exact<bool, null_function_t, SAX>::value &&
7917 is_detected_exact<bool, boolean_function_t, SAX>::value &&
7918 is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
7919 is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
7920 is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
7921 is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
7922 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
7923 is_detected_exact<bool, start_object_function_t, SAX>::value &&
7924 is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
7925 is_detected_exact<bool, end_object_function_t, SAX>::value &&
7926 is_detected_exact<bool, start_array_function_t, SAX>::value &&
7927 is_detected_exact<bool, end_array_function_t, SAX>::value &&
7928 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
7931 template<
typename SAX,
typename BasicJsonType>
7932 struct is_sax_static_asserts
7935 static_assert(is_basic_json<BasicJsonType>::value,
7936 "BasicJsonType must be of type basic_json<...>");
7938 using number_integer_t =
typename BasicJsonType::number_integer_t;
7939 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7940 using number_float_t =
typename BasicJsonType::number_float_t;
7941 using string_t =
typename BasicJsonType::string_t;
7942 using binary_t =
typename BasicJsonType::binary_t;
7943 using exception_t =
typename BasicJsonType::exception;
7946 static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
7947 "Missing/invalid function: bool null()");
7948 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
7949 "Missing/invalid function: bool boolean(bool)");
7950 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
7951 "Missing/invalid function: bool boolean(bool)");
7953 is_detected_exact<
bool, number_integer_function_t, SAX,
7954 number_integer_t>::value,
7955 "Missing/invalid function: bool number_integer(number_integer_t)");
7957 is_detected_exact<
bool, number_unsigned_function_t, SAX,
7958 number_unsigned_t>::value,
7959 "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
7960 static_assert(is_detected_exact<
bool, number_float_function_t, SAX,
7961 number_float_t, string_t>::value,
7962 "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
7964 is_detected_exact<bool, string_function_t, SAX, string_t>::value,
7965 "Missing/invalid function: bool string(string_t&)");
7967 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
7968 "Missing/invalid function: bool binary(binary_t&)");
7969 static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
7970 "Missing/invalid function: bool start_object(std::size_t)");
7971 static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
7972 "Missing/invalid function: bool key(string_t&)");
7973 static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
7974 "Missing/invalid function: bool end_object()");
7975 static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
7976 "Missing/invalid function: bool start_array(std::size_t)");
7977 static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
7978 "Missing/invalid function: bool end_array()");
7980 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
7981 "Missing/invalid function: bool parse_error(std::size_t, const "
7982 "std::string&, const exception&)");
7996 enum class cbor_tag_handler_t
8009 static inline bool little_endianess(
int num = 1) noexcept
8011 return *
reinterpret_cast<char*
>(&num) == 1;
8022 template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX = json_sax_dom_parser<BasicJsonType>>
8025 using number_integer_t =
typename BasicJsonType::number_integer_t;
8026 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8027 using number_float_t =
typename BasicJsonType::number_float_t;
8028 using string_t =
typename BasicJsonType::string_t;
8029 using binary_t =
typename BasicJsonType::binary_t;
8030 using json_sax_t = SAX;
8031 using char_type =
typename InputAdapterType::char_type;
8032 using char_int_type =
typename std::char_traits<char_type>::int_type;
8040 explicit binary_reader(InputAdapterType&& adapter) : ia(std::move(adapter))
8042 (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
8046 binary_reader(
const binary_reader&) =
delete;
8047 binary_reader(binary_reader&&) =
default;
8048 binary_reader& operator=(
const binary_reader&) =
delete;
8049 binary_reader& operator=(binary_reader&&) =
default;
8050 ~binary_reader() =
default;
8060 JSON_HEDLEY_NON_NULL(3)
8061 bool sax_parse(const input_format_t format,
8063 const
bool strict = true,
8064 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
8067 bool result =
false;
8071 case input_format_t::bson:
8072 result = parse_bson_internal();
8075 case input_format_t::cbor:
8076 result = parse_cbor_internal(
true, tag_handler);
8079 case input_format_t::msgpack:
8080 result = parse_msgpack_internal();
8083 case input_format_t::ubjson:
8084 result = parse_ubjson_internal();
8092 if (result && strict)
8094 if (format == input_format_t::ubjson)
8103 if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char_type>::eof()))
8105 return sax->parse_error(chars_read, get_token_string(),
8106 parse_error::create(110, chars_read, exception_message(format,
"expected end of input; last byte: 0x" + get_token_string(),
"value"), BasicJsonType()));
8122 bool parse_bson_internal()
8124 std::int32_t document_size{};
8125 get_number<std::int32_t, true>(input_format_t::bson, document_size);
8127 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
8132 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
false)))
8137 return sax->end_object();
8147 bool get_bson_cstr(string_t& result)
8149 auto out = std::back_inserter(result);
8153 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"cstring")))
8157 if (current == 0x00)
8161 *out++ =
static_cast<typename string_t::value_type
>(current);
8176 template<
typename NumberType>
8177 bool get_bson_string(
const NumberType len, string_t& result)
8179 if (JSON_HEDLEY_UNLIKELY(len < 1))
8181 auto last_token = get_token_string();
8182 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson,
"string length must be at least 1, is " + std::to_string(len),
"string"), BasicJsonType()));
8185 return get_string(input_format_t::bson, len -
static_cast<NumberType
>(1), result) && get() != std::char_traits<char_type>::eof();
8197 template<
typename NumberType>
8198 bool get_bson_binary(
const NumberType len, binary_t& result)
8200 if (JSON_HEDLEY_UNLIKELY(len < 0))
8202 auto last_token = get_token_string();
8203 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson,
"byte array length cannot be negative, is " + std::to_string(len),
"binary"), BasicJsonType()));
8207 std::uint8_t subtype{};
8208 get_number<std::uint8_t>(input_format_t::bson, subtype);
8209 result.set_subtype(subtype);
8211 return get_binary(input_format_t::bson, len, result);
8224 bool parse_bson_element_internal(
const char_int_type element_type,
8225 const std::size_t element_type_parse_position)
8227 switch (element_type)
8232 return get_number<double, true>(input_format_t::bson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
8239 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
8244 return parse_bson_internal();
8249 return parse_bson_array();
8256 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
8261 return sax->boolean(get() != 0);
8271 std::int32_t value{};
8272 return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
8277 std::int64_t value{};
8278 return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
8283 std::array<char, 3> cr{{}};
8284 (std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(element_type));
8285 return sax->parse_error(element_type_parse_position, std::string(cr.data()), parse_error::create(114, element_type_parse_position,
"Unsupported BSON record type 0x" + std::string(cr.data()), BasicJsonType()));
8302 bool parse_bson_element_list(
const bool is_array)
8306 while (
auto element_type = get())
8308 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"element list")))
8313 const std::size_t element_type_parse_position = chars_read;
8314 if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key)))
8319 if (!is_array && !sax->key(key))
8324 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
8340 bool parse_bson_array()
8342 std::int32_t document_size{};
8343 get_number<std::int32_t, true>(input_format_t::bson, document_size);
8345 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
8350 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
true)))
8355 return sax->end_array();
8370 bool parse_cbor_internal(
const bool get_char,
8371 const cbor_tag_handler_t tag_handler)
8373 switch (get_char ? get() : current)
8376 case std::char_traits<char_type>::eof():
8377 return unexpect_eof(input_format_t::cbor,
"value");
8404 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
8408 std::uint8_t number{};
8409 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8414 std::uint16_t number{};
8415 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8420 std::uint32_t number{};
8421 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8426 std::uint64_t number{};
8427 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8455 return sax->number_integer(
static_cast<std::int8_t
>(0x20 - 1 - current));
8459 std::uint8_t number{};
8460 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8465 std::uint16_t number{};
8466 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8471 std::uint32_t number{};
8472 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8477 std::uint64_t number{};
8478 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1)
8479 -
static_cast<number_integer_t
>(number));
8514 return get_cbor_binary(b) && sax->binary(b);
8549 return get_cbor_string(s) && sax->string(s);
8577 return get_cbor_array(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
8582 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
8587 std::uint16_t len{};
8588 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
8593 std::uint32_t len{};
8594 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
8599 std::uint64_t len{};
8600 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
8604 return get_cbor_array(std::size_t(-1), tag_handler);
8631 return get_cbor_object(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
8636 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
8641 std::uint16_t len{};
8642 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
8647 std::uint32_t len{};
8648 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
8653 std::uint64_t len{};
8654 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
8658 return get_cbor_object(std::size_t(-1), tag_handler);
8680 switch (tag_handler)
8682 case cbor_tag_handler_t::error:
8684 auto last_token = get_token_string();
8685 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor,
"invalid byte: 0x" + last_token,
"value"), BasicJsonType()));
8688 case cbor_tag_handler_t::ignore:
8695 get_number(input_format_t::cbor, len);
8700 std::uint16_t len{};
8701 get_number(input_format_t::cbor, len);
8706 std::uint32_t len{};
8707 get_number(input_format_t::cbor, len);
8712 std::uint64_t len{};
8713 get_number(input_format_t::cbor, len);
8719 return parse_cbor_internal(
true, tag_handler);
8729 return sax->boolean(
false);
8732 return sax->boolean(
true);
8739 const auto byte1_raw = get();
8740 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
8744 const auto byte2_raw = get();
8745 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
8750 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
8751 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
8761 const auto half =
static_cast<unsigned int>((byte1 << 8u) + byte2);
8762 const double val = [&half]
8764 const int exp = (half >> 10u) & 0x1Fu;
8765 const unsigned int mant = half & 0x3FFu;
8766 JSON_ASSERT(0 <= exp&& exp <= 32);
8767 JSON_ASSERT(mant <= 1024);
8771 return std::ldexp(mant, -24);
8774 ? std::numeric_limits<double>::infinity()
8775 : std::numeric_limits<double>::quiet_NaN();
8777 return std::ldexp(mant + 1024, exp - 25);
8780 return sax->number_float((half & 0x8000u) != 0
8781 ?
static_cast<number_float_t
>(-val)
8782 :
static_cast<number_float_t
>(val),
"");
8788 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
8794 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
8799 auto last_token = get_token_string();
8800 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor,
"invalid byte: 0x" + last_token,
"value"), BasicJsonType()));
8816 bool get_cbor_string(string_t& result)
8818 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"string")))
8851 return get_string(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
8857 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
8862 std::uint16_t len{};
8863 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
8868 std::uint32_t len{};
8869 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
8874 std::uint64_t len{};
8875 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
8880 while (get() != 0xFF)
8883 if (!get_cbor_string(chunk))
8887 result.append(chunk);
8894 auto last_token = get_token_string();
8895 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor,
"expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x" + last_token,
"string"), BasicJsonType()));
8911 bool get_cbor_binary(binary_t& result)
8913 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"binary")))
8946 return get_binary(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
8952 return get_number(input_format_t::cbor, len) &&
8953 get_binary(input_format_t::cbor, len, result);
8958 std::uint16_t len{};
8959 return get_number(input_format_t::cbor, len) &&
8960 get_binary(input_format_t::cbor, len, result);
8965 std::uint32_t len{};
8966 return get_number(input_format_t::cbor, len) &&
8967 get_binary(input_format_t::cbor, len, result);
8972 std::uint64_t len{};
8973 return get_number(input_format_t::cbor, len) &&
8974 get_binary(input_format_t::cbor, len, result);
8979 while (get() != 0xFF)
8982 if (!get_cbor_binary(chunk))
8986 result.insert(result.end(), chunk.begin(), chunk.end());
8993 auto last_token = get_token_string();
8994 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor,
"expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x" + last_token,
"binary"), BasicJsonType()));
9005 bool get_cbor_array(
const std::size_t len,
9006 const cbor_tag_handler_t tag_handler)
9008 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
9013 if (len != std::size_t(-1))
9015 for (std::size_t i = 0; i < len; ++i)
9017 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
9025 while (get() != 0xFF)
9027 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
false, tag_handler)))
9034 return sax->end_array();
9043 bool get_cbor_object(
const std::size_t len,
9044 const cbor_tag_handler_t tag_handler)
9046 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
9052 if (len != std::size_t(-1))
9054 for (std::size_t i = 0; i < len; ++i)
9057 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
9062 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
9071 while (get() != 0xFF)
9073 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
9078 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
9086 return sax->end_object();
9096 bool parse_msgpack_internal()
9101 case std::char_traits<char_type>::eof():
9102 return unexpect_eof(input_format_t::msgpack,
"value");
9233 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
9252 return get_msgpack_object(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x0Fu));
9271 return get_msgpack_array(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x0Fu));
9311 return get_msgpack_string(s) && sax->string(s);
9318 return sax->boolean(
false);
9321 return sax->boolean(
true);
9336 return get_msgpack_binary(b) && sax->binary(b);
9342 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9348 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9353 std::uint8_t number{};
9354 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9359 std::uint16_t number{};
9360 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9365 std::uint32_t number{};
9366 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9371 std::uint64_t number{};
9372 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9377 std::int8_t number{};
9378 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9383 std::int16_t number{};
9384 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9389 std::int32_t number{};
9390 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9395 std::int64_t number{};
9396 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9401 std::uint16_t len{};
9402 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
9407 std::uint32_t len{};
9408 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
9413 std::uint16_t len{};
9414 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
9419 std::uint32_t len{};
9420 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
9456 return sax->number_integer(
static_cast<std::int8_t
>(current));
9460 auto last_token = get_token_string();
9461 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::msgpack,
"invalid byte: 0x" + last_token,
"value"), BasicJsonType()));
9476 bool get_msgpack_string(string_t& result)
9478 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack,
"string")))
9519 return get_string(input_format_t::msgpack,
static_cast<unsigned int>(current) & 0x1Fu, result);
9525 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9530 std::uint16_t len{};
9531 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9536 std::uint32_t len{};
9537 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9542 auto last_token = get_token_string();
9543 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::msgpack,
"expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x" + last_token,
"string"), BasicJsonType()));
9558 bool get_msgpack_binary(binary_t& result)
9561 auto assign_and_return_true = [&result](std::int8_t subtype)
9563 result.set_subtype(
static_cast<std::uint8_t
>(subtype));
9572 return get_number(input_format_t::msgpack, len) &&
9573 get_binary(input_format_t::msgpack, len, result);
9578 std::uint16_t len{};
9579 return get_number(input_format_t::msgpack, len) &&
9580 get_binary(input_format_t::msgpack, len, result);
9585 std::uint32_t len{};
9586 return get_number(input_format_t::msgpack, len) &&
9587 get_binary(input_format_t::msgpack, len, result);
9593 std::int8_t subtype{};
9594 return get_number(input_format_t::msgpack, len) &&
9595 get_number(input_format_t::msgpack, subtype) &&
9596 get_binary(input_format_t::msgpack, len, result) &&
9597 assign_and_return_true(subtype);
9602 std::uint16_t len{};
9603 std::int8_t subtype{};
9604 return get_number(input_format_t::msgpack, len) &&
9605 get_number(input_format_t::msgpack, subtype) &&
9606 get_binary(input_format_t::msgpack, len, result) &&
9607 assign_and_return_true(subtype);
9612 std::uint32_t len{};
9613 std::int8_t subtype{};
9614 return get_number(input_format_t::msgpack, len) &&
9615 get_number(input_format_t::msgpack, subtype) &&
9616 get_binary(input_format_t::msgpack, len, result) &&
9617 assign_and_return_true(subtype);
9622 std::int8_t subtype{};
9623 return get_number(input_format_t::msgpack, subtype) &&
9624 get_binary(input_format_t::msgpack, 1, result) &&
9625 assign_and_return_true(subtype);
9630 std::int8_t subtype{};
9631 return get_number(input_format_t::msgpack, subtype) &&
9632 get_binary(input_format_t::msgpack, 2, result) &&
9633 assign_and_return_true(subtype);
9638 std::int8_t subtype{};
9639 return get_number(input_format_t::msgpack, subtype) &&
9640 get_binary(input_format_t::msgpack, 4, result) &&
9641 assign_and_return_true(subtype);
9646 std::int8_t subtype{};
9647 return get_number(input_format_t::msgpack, subtype) &&
9648 get_binary(input_format_t::msgpack, 8, result) &&
9649 assign_and_return_true(subtype);
9654 std::int8_t subtype{};
9655 return get_number(input_format_t::msgpack, subtype) &&
9656 get_binary(input_format_t::msgpack, 16, result) &&
9657 assign_and_return_true(subtype);
9669 bool get_msgpack_array(
const std::size_t len)
9671 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
9676 for (std::size_t i = 0; i < len; ++i)
9678 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
9684 return sax->end_array();
9691 bool get_msgpack_object(
const std::size_t len)
9693 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
9699 for (std::size_t i = 0; i < len; ++i)
9702 if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key)))
9707 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
9714 return sax->end_object();
9728 bool parse_ubjson_internal(
const bool get_char =
true)
9730 return get_ubjson_value(get_char ? get_ignore_noop() : current);
9747 bool get_ubjson_string(string_t& result,
const bool get_char =
true)
9754 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"value")))
9764 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
9770 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
9776 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
9782 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
9788 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
9792 auto last_token = get_token_string();
9793 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson,
"expected length type specification (U, i, I, l, L); last byte: 0x" + last_token,
"string"), BasicJsonType()));
9801 bool get_ubjson_size_value(std::size_t& result)
9803 switch (get_ignore_noop())
9807 std::uint8_t number{};
9808 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
9812 result =
static_cast<std::size_t
>(number);
9818 std::int8_t number{};
9819 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
9823 result =
static_cast<std::size_t
>(number);
9829 std::int16_t number{};
9830 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
9834 result =
static_cast<std::size_t
>(number);
9840 std::int32_t number{};
9841 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
9845 result =
static_cast<std::size_t
>(number);
9851 std::int64_t number{};
9852 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
9856 result =
static_cast<std::size_t
>(number);
9862 auto last_token = get_token_string();
9863 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson,
"expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token,
"size"), BasicJsonType()));
9878 bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result)
9880 result.first = string_t::npos;
9887 result.second = get();
9888 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"type")))
9894 if (JSON_HEDLEY_UNLIKELY(current !=
'#'))
9896 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"value")))
9900 auto last_token = get_token_string();
9901 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::ubjson,
"expected '#' after type information; last byte: 0x" + last_token,
"size"), BasicJsonType()));
9904 return get_ubjson_size_value(result.first);
9909 return get_ubjson_size_value(result.first);
9919 bool get_ubjson_value(
const char_int_type prefix)
9923 case std::char_traits<char_type>::eof():
9924 return unexpect_eof(input_format_t::ubjson,
"value");
9927 return sax->boolean(
true);
9929 return sax->boolean(
false);
9936 std::uint8_t number{};
9937 return get_number(input_format_t::ubjson, number) && sax->number_unsigned(number);
9942 std::int8_t number{};
9943 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
9948 std::int16_t number{};
9949 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
9954 std::int32_t number{};
9955 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
9960 std::int64_t number{};
9961 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
9967 return get_number(input_format_t::ubjson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9973 return get_number(input_format_t::ubjson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9978 return get_ubjson_high_precision_number();
9984 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"char")))
9988 if (JSON_HEDLEY_UNLIKELY(current > 127))
9990 auto last_token = get_token_string();
9991 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson,
"byte after 'C' must be in range 0x00..0x7F; last byte: 0x" + last_token,
"char"), BasicJsonType()));
9993 string_t s(1,
static_cast<typename string_t::value_type
>(current));
9994 return sax->string(s);
10000 return get_ubjson_string(s) && sax->string(s);
10004 return get_ubjson_array();
10007 return get_ubjson_object();
10011 auto last_token = get_token_string();
10012 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::ubjson,
"invalid byte: 0x" + last_token,
"value"), BasicJsonType()));
10020 bool get_ubjson_array()
10022 std::pair<std::size_t, char_int_type> size_and_type;
10023 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
10028 if (size_and_type.first != string_t::npos)
10030 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
10035 if (size_and_type.second != 0)
10037 if (size_and_type.second !=
'N')
10039 for (std::size_t i = 0; i < size_and_type.first; ++i)
10041 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
10050 for (std::size_t i = 0; i < size_and_type.first; ++i)
10052 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
10061 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
10066 while (current !=
']')
10068 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(
false)))
10076 return sax->end_array();
10082 bool get_ubjson_object()
10084 std::pair<std::size_t, char_int_type> size_and_type;
10085 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
10091 if (size_and_type.first != string_t::npos)
10093 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))
10098 if (size_and_type.second != 0)
10100 for (std::size_t i = 0; i < size_and_type.first; ++i)
10102 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
10106 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
10115 for (std::size_t i = 0; i < size_and_type.first; ++i)
10117 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
10121 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
10131 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
10136 while (current !=
'}')
10138 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key,
false) || !sax->key(key)))
10142 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
10151 return sax->end_object();
10157 bool get_ubjson_high_precision_number()
10160 std::size_t size{};
10161 auto res = get_ubjson_size_value(size);
10162 if (JSON_HEDLEY_UNLIKELY(!res))
10168 std::vector<char> number_vector;
10169 for (std::size_t i = 0; i < size; ++i)
10172 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"number")))
10176 number_vector.push_back(
static_cast<char>(current));
10180 auto number_ia = detail::input_adapter(std::forward<decltype(number_vector)>(number_vector));
10181 auto number_lexer = detail::lexer<BasicJsonType, decltype(number_ia)>(std::move(number_ia),
false);
10182 const auto result_number = number_lexer.scan();
10183 const auto number_string = number_lexer.get_token_string();
10184 const auto result_remainder = number_lexer.scan();
10186 using token_type =
typename detail::lexer_base<BasicJsonType>::token_type;
10188 if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
10190 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson,
"invalid number text: " + number_lexer.get_token_string(),
"high-precision number"), BasicJsonType()));
10193 switch (result_number)
10195 case token_type::value_integer:
10196 return sax->number_integer(number_lexer.get_number_integer());
10197 case token_type::value_unsigned:
10198 return sax->number_unsigned(number_lexer.get_number_unsigned());
10199 case token_type::value_float:
10200 return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
10202 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson,
"invalid number text: " + number_lexer.get_token_string(),
"high-precision number"), BasicJsonType()));
10219 char_int_type get()
10222 return current = ia.get_character();
10228 char_int_type get_ignore_noop()
10234 while (current ==
'N');
10252 template<
typename NumberType,
bool InputIsLittleEndian = false>
10253 bool get_number(
const input_format_t format, NumberType& result)
10256 std::array<std::uint8_t,
sizeof(NumberType)> vec;
10257 for (std::size_t i = 0; i <
sizeof(NumberType); ++i)
10260 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"number")))
10266 if (is_little_endian != InputIsLittleEndian)
10268 vec[
sizeof(NumberType) - i - 1] =
static_cast<std::uint8_t
>(current);
10272 vec[i] =
static_cast<std::uint8_t
>(current);
10277 std::memcpy(&result, vec.data(),
sizeof(NumberType));
10295 template<
typename NumberType>
10296 bool get_string(
const input_format_t format,
10297 const NumberType len,
10300 bool success =
true;
10301 for (NumberType i = 0; i < len; i++)
10304 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"string")))
10309 result.push_back(
static_cast<typename string_t::value_type
>(current));
10328 template<
typename NumberType>
10329 bool get_binary(
const input_format_t format,
10330 const NumberType len,
10333 bool success =
true;
10334 for (NumberType i = 0; i < len; i++)
10337 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"binary")))
10342 result.push_back(
static_cast<std::uint8_t
>(current));
10352 JSON_HEDLEY_NON_NULL(3)
10353 bool unexpect_eof(const input_format_t format, const
char* context)
const
10355 if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char_type>::eof()))
10357 return sax->parse_error(chars_read,
"<end of file>",
10358 parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context), BasicJsonType()));
10366 std::string get_token_string()
const
10368 std::array<char, 3> cr{{}};
10369 (std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(current));
10370 return std::string{cr.data()};
10379 std::string exception_message(
const input_format_t format,
10380 const std::string& detail,
10381 const std::string& context)
const
10383 std::string error_msg =
"syntax error while parsing ";
10387 case input_format_t::cbor:
10388 error_msg +=
"CBOR";
10391 case input_format_t::msgpack:
10392 error_msg +=
"MessagePack";
10395 case input_format_t::ubjson:
10396 error_msg +=
"UBJSON";
10399 case input_format_t::bson:
10400 error_msg +=
"BSON";
10404 JSON_ASSERT(
false);
10407 return error_msg +
" " + context +
": " + detail;
10412 InputAdapterType ia;
10415 char_int_type current = std::char_traits<char_type>::eof();
10418 std::size_t chars_read = 0;
10421 const bool is_little_endian = little_endianess();
10424 json_sax_t* sax =
nullptr;
10438 #include <functional>
10466 enum class parse_event_t : uint8_t
10482 template<
typename BasicJsonType>
10483 using parser_callback_t =
10484 std::function<bool(
int depth, parse_event_t event, BasicJsonType& parsed)>;
10491 template<
typename BasicJsonType,
typename InputAdapterType>
10494 using number_integer_t =
typename BasicJsonType::number_integer_t;
10495 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
10496 using number_float_t =
typename BasicJsonType::number_float_t;
10497 using string_t =
typename BasicJsonType::string_t;
10498 using lexer_t = lexer<BasicJsonType, InputAdapterType>;
10499 using token_type =
typename lexer_t::token_type;
10503 explicit parser(InputAdapterType&& adapter,
10504 const parser_callback_t<BasicJsonType> cb =
nullptr,
10505 const bool allow_exceptions_ =
true,
10506 const bool skip_comments =
false)
10508 , m_lexer(std::move(adapter), skip_comments)
10509 , allow_exceptions(allow_exceptions_)
10525 void parse(
const bool strict, BasicJsonType& result)
10529 json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions);
10530 sax_parse_internal(&sdp);
10533 if (strict && (get_token() != token_type::end_of_input))
10535 sdp.parse_error(m_lexer.get_position(),
10536 m_lexer.get_token_string(),
10537 parse_error::create(101, m_lexer.get_position(),
10538 exception_message(token_type::end_of_input,
"value"), BasicJsonType()));
10542 if (sdp.is_errored())
10544 result = value_t::discarded;
10550 if (result.is_discarded())
10557 json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions);
10558 sax_parse_internal(&sdp);
10561 if (strict && (get_token() != token_type::end_of_input))
10563 sdp.parse_error(m_lexer.get_position(),
10564 m_lexer.get_token_string(),
10565 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"), BasicJsonType()));
10569 if (sdp.is_errored())
10571 result = value_t::discarded;
10576 result.assert_invariant();
10585 bool accept(
const bool strict =
true)
10587 json_sax_acceptor<BasicJsonType> sax_acceptor;
10588 return sax_parse(&sax_acceptor, strict);
10591 template<
typename SAX>
10592 JSON_HEDLEY_NON_NULL(2)
10593 bool sax_parse(SAX* sax, const
bool strict = true)
10595 (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
10596 const bool result = sax_parse_internal(sax);
10599 if (result && strict && (get_token() != token_type::end_of_input))
10601 return sax->parse_error(m_lexer.get_position(),
10602 m_lexer.get_token_string(),
10603 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"), BasicJsonType()));
10610 template<
typename SAX>
10611 JSON_HEDLEY_NON_NULL(2)
10612 bool sax_parse_internal(SAX* sax)
10616 std::vector<bool> states;
10618 bool skip_to_state_evaluation =
false;
10622 if (!skip_to_state_evaluation)
10625 switch (last_token)
10627 case token_type::begin_object:
10629 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
10635 if (get_token() == token_type::end_object)
10637 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
10645 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
10647 return sax->parse_error(m_lexer.get_position(),
10648 m_lexer.get_token_string(),
10649 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"), BasicJsonType()));
10651 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
10657 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
10659 return sax->parse_error(m_lexer.get_position(),
10660 m_lexer.get_token_string(),
10661 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"), BasicJsonType()));
10665 states.push_back(
false);
10672 case token_type::begin_array:
10674 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
10680 if (get_token() == token_type::end_array)
10682 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
10690 states.push_back(
true);
10696 case token_type::value_float:
10698 const auto res = m_lexer.get_number_float();
10700 if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))
10702 return sax->parse_error(m_lexer.get_position(),
10703 m_lexer.get_token_string(),
10704 out_of_range::create(406,
"number overflow parsing '" + m_lexer.get_token_string() +
"'", BasicJsonType()));
10707 if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
10715 case token_type::literal_false:
10717 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
false)))
10724 case token_type::literal_null:
10726 if (JSON_HEDLEY_UNLIKELY(!sax->null()))
10733 case token_type::literal_true:
10735 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
true)))
10742 case token_type::value_integer:
10744 if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer())))
10751 case token_type::value_string:
10753 if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))
10760 case token_type::value_unsigned:
10762 if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned())))
10769 case token_type::parse_error:
10772 return sax->parse_error(m_lexer.get_position(),
10773 m_lexer.get_token_string(),
10774 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized,
"value"), BasicJsonType()));
10779 return sax->parse_error(m_lexer.get_position(),
10780 m_lexer.get_token_string(),
10781 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value,
"value"), BasicJsonType()));
10787 skip_to_state_evaluation =
false;
10791 if (states.empty())
10800 if (get_token() == token_type::value_separator)
10808 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
10810 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
10819 JSON_ASSERT(!states.empty());
10821 skip_to_state_evaluation =
true;
10825 return sax->parse_error(m_lexer.get_position(),
10826 m_lexer.get_token_string(),
10827 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array,
"array"), BasicJsonType()));
10833 if (get_token() == token_type::value_separator)
10836 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
10838 return sax->parse_error(m_lexer.get_position(),
10839 m_lexer.get_token_string(),
10840 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"), BasicJsonType()));
10843 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
10849 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
10851 return sax->parse_error(m_lexer.get_position(),
10852 m_lexer.get_token_string(),
10853 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"), BasicJsonType()));
10862 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
10864 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
10873 JSON_ASSERT(!states.empty());
10875 skip_to_state_evaluation =
true;
10879 return sax->parse_error(m_lexer.get_position(),
10880 m_lexer.get_token_string(),
10881 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object,
"object"), BasicJsonType()));
10886 token_type get_token()
10888 return last_token = m_lexer.scan();
10891 std::string exception_message(
const token_type expected,
const std::string& context)
10893 std::string error_msg =
"syntax error ";
10895 if (!context.empty())
10897 error_msg +=
"while parsing " + context +
" ";
10902 if (last_token == token_type::parse_error)
10904 error_msg += std::string(m_lexer.get_error_message()) +
"; last read: '" +
10905 m_lexer.get_token_string() +
"'";
10909 error_msg +=
"unexpected " + std::string(lexer_t::token_type_name(last_token));
10912 if (expected != token_type::uninitialized)
10914 error_msg +=
"; expected " + std::string(lexer_t::token_type_name(expected));
10922 const parser_callback_t<BasicJsonType> callback =
nullptr;
10924 token_type last_token = token_type::uninitialized;
10928 const bool allow_exceptions =
true;
10958 class primitive_iterator_t
10961 using difference_type = std::ptrdiff_t;
10962 static constexpr difference_type begin_value = 0;
10963 static constexpr difference_type end_value = begin_value + 1;
10965 JSON_PRIVATE_UNLESS_TESTED:
10967 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
10970 constexpr difference_type get_value() const noexcept
10976 void set_begin() noexcept
10978 m_it = begin_value;
10982 void set_end() noexcept
10988 constexpr
bool is_begin() const noexcept
10990 return m_it == begin_value;
10994 constexpr
bool is_end() const noexcept
10996 return m_it == end_value;
10999 friend constexpr
bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
11001 return lhs.m_it == rhs.m_it;
11004 friend constexpr
bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
11006 return lhs.m_it < rhs.m_it;
11009 primitive_iterator_t operator+(difference_type n) noexcept
11011 auto result = *
this;
11016 friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
11018 return lhs.m_it - rhs.m_it;
11021 primitive_iterator_t& operator++() noexcept
11027 primitive_iterator_t
const operator++(
int) noexcept
11029 auto result = *
this;
11034 primitive_iterator_t& operator--() noexcept
11040 primitive_iterator_t
const operator--(
int) noexcept
11042 auto result = *
this;
11047 primitive_iterator_t& operator+=(difference_type n) noexcept
11053 primitive_iterator_t& operator-=(difference_type n) noexcept
11073 template<
typename BasicJsonType>
struct internal_iterator
11076 typename BasicJsonType::object_t::iterator object_iterator {};
11078 typename BasicJsonType::array_t::iterator array_iterator {};
11080 primitive_iterator_t primitive_iterator {};
11088 #include <iterator>
11089 #include <type_traits>
11111 template<
typename IteratorType>
class iteration_proxy;
11112 template<
typename IteratorType>
class iteration_proxy_value;
11130 template<
typename BasicJsonType>
11134 using other_iter_impl = iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value,
typename std::remove_const<BasicJsonType>::type,
const BasicJsonType>::type>;
11136 friend other_iter_impl;
11137 friend BasicJsonType;
11138 friend iteration_proxy<iter_impl>;
11139 friend iteration_proxy_value<iter_impl>;
11141 using object_t =
typename BasicJsonType::object_t;
11142 using array_t =
typename BasicJsonType::array_t;
11144 static_assert(is_basic_json<
typename std::remove_const<BasicJsonType>::type>::value,
11145 "iter_impl only accepts (const) basic_json");
11154 using iterator_category = std::bidirectional_iterator_tag;
11157 using value_type =
typename BasicJsonType::value_type;
11159 using difference_type =
typename BasicJsonType::difference_type;
11161 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
11162 typename BasicJsonType::const_pointer,
11163 typename BasicJsonType::pointer>::type;
11166 typename std::conditional<std::is_const<BasicJsonType>::value,
11167 typename BasicJsonType::const_reference,
11168 typename BasicJsonType::reference>::type;
11171 iter_impl() =
default;
11179 explicit iter_impl(pointer
object) noexcept : m_object(
object)
11181 JSON_ASSERT(m_object !=
nullptr);
11183 switch (m_object->m_type)
11185 case value_t::object:
11187 m_it.object_iterator =
typename object_t::iterator();
11191 case value_t::array:
11193 m_it.array_iterator =
typename array_t::iterator();
11199 m_it.primitive_iterator = primitive_iterator_t();
11221 iter_impl(
const iter_impl<const BasicJsonType>& other) noexcept
11222 : m_object(other.m_object), m_it(other.m_it)
11231 iter_impl& operator=(
const iter_impl<const BasicJsonType>& other) noexcept
11233 m_object = other.m_object;
11243 iter_impl(
const iter_impl<
typename std::remove_const<BasicJsonType>::type>& other) noexcept
11244 : m_object(other.m_object), m_it(other.m_it)
11253 iter_impl& operator=(
const iter_impl<
typename std::remove_const<BasicJsonType>::type>& other) noexcept
11255 m_object = other.m_object;
11260 JSON_PRIVATE_UNLESS_TESTED:
11265 void set_begin() noexcept
11267 JSON_ASSERT(m_object !=
nullptr);
11269 switch (m_object->m_type)
11271 case value_t::object:
11273 m_it.object_iterator = m_object->m_value.object->begin();
11277 case value_t::array:
11279 m_it.array_iterator = m_object->m_value.array->begin();
11283 case value_t::null:
11286 m_it.primitive_iterator.set_end();
11292 m_it.primitive_iterator.set_begin();
11302 void set_end() noexcept
11304 JSON_ASSERT(m_object !=
nullptr);
11306 switch (m_object->m_type)
11308 case value_t::object:
11310 m_it.object_iterator = m_object->m_value.object->end();
11314 case value_t::array:
11316 m_it.array_iterator = m_object->m_value.array->end();
11322 m_it.primitive_iterator.set_end();
11333 reference operator*()
const
11335 JSON_ASSERT(m_object !=
nullptr);
11337 switch (m_object->m_type)
11339 case value_t::object:
11341 JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
11342 return m_it.object_iterator->second;
11345 case value_t::array:
11347 JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
11348 return *m_it.array_iterator;
11351 case value_t::null:
11352 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11356 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
11361 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11370 pointer operator->()
const
11372 JSON_ASSERT(m_object !=
nullptr);
11374 switch (m_object->m_type)
11376 case value_t::object:
11378 JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
11379 return &(m_it.object_iterator->second);
11382 case value_t::array:
11384 JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
11385 return &*m_it.array_iterator;
11390 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
11395 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11404 iter_impl
const operator++(
int)
11406 auto result = *
this;
11415 iter_impl& operator++()
11417 JSON_ASSERT(m_object !=
nullptr);
11419 switch (m_object->m_type)
11421 case value_t::object:
11423 std::advance(m_it.object_iterator, 1);
11427 case value_t::array:
11429 std::advance(m_it.array_iterator, 1);
11435 ++m_it.primitive_iterator;
11447 iter_impl
const operator--(
int)
11449 auto result = *
this;
11458 iter_impl& operator--()
11460 JSON_ASSERT(m_object !=
nullptr);
11462 switch (m_object->m_type)
11464 case value_t::object:
11466 std::advance(m_it.object_iterator, -1);
11470 case value_t::array:
11472 std::advance(m_it.array_iterator, -1);
11478 --m_it.primitive_iterator;
11490 template <
typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::
nullptr_t > =
nullptr >
11491 bool operator==(
const IterImpl& other)
const
11494 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
11496 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", *m_object));
11499 JSON_ASSERT(m_object !=
nullptr);
11501 switch (m_object->m_type)
11503 case value_t::object:
11504 return (m_it.object_iterator == other.m_it.object_iterator);
11506 case value_t::array:
11507 return (m_it.array_iterator == other.m_it.array_iterator);
11510 return (m_it.primitive_iterator == other.m_it.primitive_iterator);
11518 template <
typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::
nullptr_t > =
nullptr >
11519 bool operator!=(
const IterImpl& other)
const
11521 return !operator==(other);
11528 bool operator<(
const iter_impl& other)
const
11531 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
11533 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", *m_object));
11536 JSON_ASSERT(m_object !=
nullptr);
11538 switch (m_object->m_type)
11540 case value_t::object:
11541 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators", *m_object));
11543 case value_t::array:
11544 return (m_it.array_iterator < other.m_it.array_iterator);
11547 return (m_it.primitive_iterator < other.m_it.primitive_iterator);
11555 bool operator<=(
const iter_impl& other)
const
11557 return !other.operator < (*this);
11564 bool operator>(
const iter_impl& other)
const
11566 return !operator<=(other);
11573 bool operator>=(
const iter_impl& other)
const
11575 return !operator<(other);
11582 iter_impl& operator+=(difference_type i)
11584 JSON_ASSERT(m_object !=
nullptr);
11586 switch (m_object->m_type)
11588 case value_t::object:
11589 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", *m_object));
11591 case value_t::array:
11593 std::advance(m_it.array_iterator, i);
11599 m_it.primitive_iterator += i;
11611 iter_impl& operator-=(difference_type i)
11613 return operator+=(-i);
11620 iter_impl operator+(difference_type i)
const
11622 auto result = *
this;
11631 friend iter_impl operator+(difference_type i,
const iter_impl& it)
11642 iter_impl operator-(difference_type i)
const
11644 auto result = *
this;
11653 difference_type operator-(
const iter_impl& other)
const
11655 JSON_ASSERT(m_object !=
nullptr);
11657 switch (m_object->m_type)
11659 case value_t::object:
11660 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", *m_object));
11662 case value_t::array:
11663 return m_it.array_iterator - other.m_it.array_iterator;
11666 return m_it.primitive_iterator - other.m_it.primitive_iterator;
11674 reference operator[](difference_type n)
const
11676 JSON_ASSERT(m_object !=
nullptr);
11678 switch (m_object->m_type)
11680 case value_t::object:
11681 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators", *m_object));
11683 case value_t::array:
11684 return *std::next(m_it.array_iterator, n);
11686 case value_t::null:
11687 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11691 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n))
11696 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11705 const typename object_t::key_type& key()
const
11707 JSON_ASSERT(m_object !=
nullptr);
11709 if (JSON_HEDLEY_LIKELY(m_object->is_object()))
11711 return m_it.object_iterator->first;
11714 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators", *m_object));
11721 reference value()
const
11723 return operator*();
11726 JSON_PRIVATE_UNLESS_TESTED:
11728 pointer m_object =
nullptr;
11730 internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it {};
11741 #include <iterator>
11770 template<
typename Base>
11771 class json_reverse_iterator :
public std::reverse_iterator<Base>
11774 using difference_type = std::ptrdiff_t;
11776 using base_iterator = std::reverse_iterator<Base>;
11778 using reference =
typename Base::reference;
11781 explicit json_reverse_iterator(
const typename base_iterator::iterator_type& it) noexcept
11782 : base_iterator(it) {}
11785 explicit json_reverse_iterator(
const base_iterator& it) noexcept : base_iterator(it) {}
11788 json_reverse_iterator
const operator++(
int)
11790 return static_cast<json_reverse_iterator
>(base_iterator::operator++(1));
11794 json_reverse_iterator& operator++()
11796 return static_cast<json_reverse_iterator&
>(base_iterator::operator++());
11800 json_reverse_iterator
const operator--(
int)
11802 return static_cast<json_reverse_iterator
>(base_iterator::operator--(1));
11806 json_reverse_iterator& operator--()
11808 return static_cast<json_reverse_iterator&
>(base_iterator::operator--());
11812 json_reverse_iterator& operator+=(difference_type i)
11814 return static_cast<json_reverse_iterator&
>(base_iterator::operator+=(i));
11818 json_reverse_iterator operator+(difference_type i)
const
11820 return static_cast<json_reverse_iterator
>(base_iterator::operator+(i));
11824 json_reverse_iterator operator-(difference_type i)
const
11826 return static_cast<json_reverse_iterator
>(base_iterator::operator-(i));
11830 difference_type operator-(
const json_reverse_iterator& other)
const
11832 return base_iterator(*
this) - base_iterator(other);
11836 reference operator[](difference_type n)
const
11838 return *(this->operator+(n));
11842 auto key() const -> decltype(std::declval<Base>().key())
11844 auto it = --this->base();
11849 reference value()
const
11851 auto it = --this->base();
11852 return it.operator * ();
11863 #include <algorithm>
11882 template<
typename BasicJsonType>
11886 NLOHMANN_BASIC_JSON_TPL_DECLARATION
11912 : reference_tokens(split(s))
11931 return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
11933 [](
const std::string & a,
const std::string & b)
11935 return a +
"/" + detail::escape(b);
11940 operator std::string()
const
11963 reference_tokens.insert(reference_tokens.end(),
11964 ptr.reference_tokens.begin(),
11965 ptr.reference_tokens.end());
12009 return *
this /= std::to_string(array_idx);
12113 if (JSON_HEDLEY_UNLIKELY(
empty()))
12115 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent", BasicJsonType()));
12118 reference_tokens.pop_back();
12137 if (JSON_HEDLEY_UNLIKELY(
empty()))
12139 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent", BasicJsonType()));
12142 return reference_tokens.back();
12159 reference_tokens.push_back(token);
12165 reference_tokens.push_back(std::move(token));
12184 return reference_tokens.empty();
12198 static typename BasicJsonType::size_type array_index(
const std::string& s)
12200 using size_type =
typename BasicJsonType::size_type;
12203 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] ==
'0'))
12205 JSON_THROW(detail::parse_error::create(106, 0,
"array index '" + s +
"' must not begin with '0'", BasicJsonType()));
12209 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >=
'1' && s[0] <=
'9')))
12211 JSON_THROW(detail::parse_error::create(109, 0,
"array index '" + s +
"' is not a number", BasicJsonType()));
12214 std::size_t processed_chars = 0;
12215 unsigned long long res = 0;
12218 res = std::stoull(s, &processed_chars);
12220 JSON_CATCH(std::out_of_range&)
12222 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + s +
"'", BasicJsonType()));
12226 if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size()))
12228 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + s +
"'", BasicJsonType()));
12233 if (res >=
static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))
12235 JSON_THROW(detail::out_of_range::create(410,
"array index " + s +
" exceeds size_type", BasicJsonType()));
12238 return static_cast<size_type
>(res);
12241 JSON_PRIVATE_UNLESS_TESTED:
12244 if (JSON_HEDLEY_UNLIKELY(
empty()))
12246 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent", BasicJsonType()));
12250 result.reference_tokens = {reference_tokens[0]};
12263 BasicJsonType& get_and_create(BasicJsonType& j)
const
12269 for (
const auto& reference_token : reference_tokens)
12271 switch (result->type())
12273 case detail::value_t::null:
12275 if (reference_token ==
"0")
12278 result = &result->operator[](0);
12283 result = &result->operator[](reference_token);
12288 case detail::value_t::object:
12291 result = &result->operator[](reference_token);
12295 case detail::value_t::array:
12298 result = &result->operator[](array_index(reference_token));
12309 JSON_THROW(detail::type_error::create(313,
"invalid value to unflatten", j));
12335 BasicJsonType& get_unchecked(BasicJsonType* ptr)
const
12337 for (
const auto& reference_token : reference_tokens)
12340 if (ptr->is_null())
12344 std::all_of(reference_token.begin(), reference_token.end(),
12345 [](
const unsigned char x)
12347 return std::isdigit(x);
12351 *ptr = (nums || reference_token ==
"-")
12352 ? detail::value_t::array
12353 : detail::value_t::object;
12356 switch (ptr->type())
12358 case detail::value_t::object:
12361 ptr = &ptr->operator[](reference_token);
12365 case detail::value_t::array:
12367 if (reference_token ==
"-")
12370 ptr = &ptr->operator[](ptr->m_value.array->size());
12375 ptr = &ptr->operator[](array_index(reference_token));
12381 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
12394 BasicJsonType& get_checked(BasicJsonType* ptr)
const
12396 for (
const auto& reference_token : reference_tokens)
12398 switch (ptr->type())
12400 case detail::value_t::object:
12403 ptr = &ptr->at(reference_token);
12407 case detail::value_t::array:
12409 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
12412 JSON_THROW(detail::out_of_range::create(402,
12413 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
12414 ") is out of range", *ptr));
12418 ptr = &ptr->at(array_index(reference_token));
12423 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
12443 const BasicJsonType& get_unchecked(
const BasicJsonType* ptr)
const
12445 for (
const auto& reference_token : reference_tokens)
12447 switch (ptr->type())
12449 case detail::value_t::object:
12452 ptr = &ptr->operator[](reference_token);
12456 case detail::value_t::array:
12458 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
12461 JSON_THROW(detail::out_of_range::create(402,
"array index '-' (" + std::to_string(ptr->m_value.array->size()) +
") is out of range", *ptr));
12465 ptr = &ptr->operator[](array_index(reference_token));
12470 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
12483 const BasicJsonType& get_checked(
const BasicJsonType* ptr)
const
12485 for (
const auto& reference_token : reference_tokens)
12487 switch (ptr->type())
12489 case detail::value_t::object:
12492 ptr = &ptr->at(reference_token);
12496 case detail::value_t::array:
12498 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
12501 JSON_THROW(detail::out_of_range::create(402,
12502 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
12503 ") is out of range", *ptr));
12507 ptr = &ptr->at(array_index(reference_token));
12512 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
12523 bool contains(
const BasicJsonType* ptr)
const
12525 for (
const auto& reference_token : reference_tokens)
12527 switch (ptr->type())
12529 case detail::value_t::object:
12531 if (!ptr->contains(reference_token))
12537 ptr = &ptr->operator[](reference_token);
12541 case detail::value_t::array:
12543 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
12548 if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !(
"0" <= reference_token && reference_token <=
"9")))
12553 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
12555 if (JSON_HEDLEY_UNLIKELY(!(
'1' <= reference_token[0] && reference_token[0] <=
'9')))
12560 for (std::size_t i = 1; i < reference_token.size(); i++)
12562 if (JSON_HEDLEY_UNLIKELY(!(
'0' <= reference_token[i] && reference_token[i] <=
'9')))
12570 const auto idx = array_index(reference_token);
12571 if (idx >= ptr->size())
12577 ptr = &ptr->operator[](idx);
12603 static std::vector<std::string> split(
const std::string& reference_string)
12605 std::vector<std::string> result;
12608 if (reference_string.empty())
12614 if (JSON_HEDLEY_UNLIKELY(reference_string[0] !=
'/'))
12616 JSON_THROW(detail::parse_error::create(107, 1,
"JSON pointer must be empty or begin with '/' - was: '" + reference_string +
"'", BasicJsonType()));
12624 std::size_t slash = reference_string.find_first_of(
'/', 1),
12631 start = (slash == std::string::npos) ? 0 : slash + 1,
12633 slash = reference_string.find_first_of(
'/', start))
12637 auto reference_token = reference_string.substr(start, slash - start);
12640 for (std::size_t pos = reference_token.find_first_of(
'~');
12641 pos != std::string::npos;
12642 pos = reference_token.find_first_of(
'~', pos + 1))
12644 JSON_ASSERT(reference_token[pos] ==
'~');
12647 if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
12648 (reference_token[pos + 1] !=
'0' &&
12649 reference_token[pos + 1] !=
'1')))
12651 JSON_THROW(detail::parse_error::create(108, 0,
"escape character '~' must be followed with '0' or '1'", BasicJsonType()));
12656 detail::unescape(reference_token);
12657 result.push_back(reference_token);
12671 static void flatten(
const std::string& reference_string,
12672 const BasicJsonType& value,
12673 BasicJsonType& result)
12675 switch (value.type())
12677 case detail::value_t::array:
12679 if (value.m_value.array->empty())
12682 result[reference_string] =
nullptr;
12687 for (std::size_t i = 0; i < value.m_value.array->size(); ++i)
12689 flatten(reference_string +
"/" + std::to_string(i),
12690 value.m_value.array->operator[](i), result);
12696 case detail::value_t::object:
12698 if (value.m_value.object->empty())
12701 result[reference_string] =
nullptr;
12706 for (
const auto& element : *value.m_value.object)
12708 flatten(reference_string +
"/" + detail::escape(element.first), element.second, result);
12717 result[reference_string] = value;
12733 static BasicJsonType
12734 unflatten(
const BasicJsonType& value)
12736 if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
12738 JSON_THROW(detail::type_error::create(314,
"only objects can be unflattened", value));
12741 BasicJsonType result;
12744 for (
const auto& element : *value.m_value.object)
12746 if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
12748 JSON_THROW(detail::type_error::create(315,
"values in object must be primitive", element.second));
12755 json_pointer(element.first).get_and_create(result) = element.second;
12775 return lhs.reference_tokens == rhs.reference_tokens;
12792 return !(lhs == rhs);
12796 std::vector<std::string> reference_tokens;
12803 #include <initializer_list>
12813 template<
typename BasicJsonType>
12817 using value_type = BasicJsonType;
12819 json_ref(value_type&& value)
12820 : owned_value(std::move(value))
12823 json_ref(
const value_type& value)
12824 : value_ref(&value)
12827 json_ref(std::initializer_list<json_ref> init)
12828 : owned_value(init)
12833 enable_if_t<std::is_constructible<value_type, Args...>::value,
int> = 0 >
12834 json_ref(Args && ... args)
12835 : owned_value(std::forward<Args>(args)...)
12839 json_ref(json_ref&&) =
default;
12840 json_ref(
const json_ref&) =
delete;
12841 json_ref& operator=(
const json_ref&) =
delete;
12842 json_ref& operator=(json_ref&&) =
delete;
12843 ~json_ref() =
default;
12845 value_type moved_or_copied()
const
12847 if (value_ref ==
nullptr)
12849 return std::move(owned_value);
12854 value_type
const& operator*()
const
12856 return value_ref ? *value_ref : owned_value;
12859 value_type
const* operator->()
const
12865 mutable value_type owned_value =
nullptr;
12866 value_type
const* value_ref =
nullptr;
12880 #include <algorithm>
12895 #include <algorithm>
12898 #include <iterator>
12911 template<
typename CharType>
struct output_adapter_protocol
12913 virtual void write_character(CharType c) = 0;
12914 virtual void write_characters(
const CharType* s, std::size_t length) = 0;
12915 virtual ~output_adapter_protocol() =
default;
12919 template<
typename CharType>
12920 using output_adapter_t = std::shared_ptr<output_adapter_protocol<CharType>>;
12923 template<
typename CharType>
12924 class output_vector_adapter :
public output_adapter_protocol<CharType>
12927 explicit output_vector_adapter(std::vector<CharType>& vec) noexcept
12931 void write_character(CharType c)
override
12936 JSON_HEDLEY_NON_NULL(2)
12937 void write_characters(const CharType* s, std::
size_t length)
override
12939 std::copy(s, s + length, std::back_inserter(v));
12943 std::vector<CharType>& v;
12947 template<
typename CharType>
12948 class output_stream_adapter :
public output_adapter_protocol<CharType>
12951 explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
12955 void write_character(CharType c)
override
12960 JSON_HEDLEY_NON_NULL(2)
12961 void write_characters(const CharType* s, std::
size_t length)
override
12963 stream.write(s,
static_cast<std::streamsize
>(length));
12967 std::basic_ostream<CharType>& stream;
12971 template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
12972 class output_string_adapter :
public output_adapter_protocol<CharType>
12975 explicit output_string_adapter(StringType& s) noexcept
12979 void write_character(CharType c)
override
12984 JSON_HEDLEY_NON_NULL(2)
12985 void write_characters(const CharType* s, std::
size_t length)
override
12987 str.append(s, length);
12994 template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
12995 class output_adapter
12998 output_adapter(std::vector<CharType>& vec)
12999 : oa(std::make_shared<output_vector_adapter<CharType>>(vec)) {}
13001 output_adapter(std::basic_ostream<CharType>& s)
13002 : oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
13004 output_adapter(StringType& s)
13005 : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
13007 operator output_adapter_t<CharType>()
13013 output_adapter_t<CharType> oa =
nullptr;
13030 template<
typename BasicJsonType,
typename CharType>
13031 class binary_writer
13033 using string_t =
typename BasicJsonType::string_t;
13034 using binary_t =
typename BasicJsonType::binary_t;
13035 using number_float_t =
typename BasicJsonType::number_float_t;
13043 explicit binary_writer(output_adapter_t<CharType> adapter) : oa(adapter)
13052 void write_bson(
const BasicJsonType& j)
13056 case value_t::object:
13058 write_bson_object(*j.m_value.object);
13064 JSON_THROW(type_error::create(317,
"to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j));;
13072 void write_cbor(
const BasicJsonType& j)
13076 case value_t::null:
13078 oa->write_character(to_char_type(0xF6));
13082 case value_t::boolean:
13084 oa->write_character(j.m_value.boolean
13085 ? to_char_type(0xF5)
13086 : to_char_type(0xF4));
13090 case value_t::number_integer:
13092 if (j.m_value.number_integer >= 0)
13097 if (j.m_value.number_integer <= 0x17)
13099 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13101 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
13103 oa->write_character(to_char_type(0x18));
13104 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13106 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
13108 oa->write_character(to_char_type(0x19));
13109 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
13111 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
13113 oa->write_character(to_char_type(0x1A));
13114 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
13118 oa->write_character(to_char_type(0x1B));
13119 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
13126 const auto positive_number = -1 - j.m_value.number_integer;
13127 if (j.m_value.number_integer >= -24)
13129 write_number(
static_cast<std::uint8_t
>(0x20 + positive_number));
13131 else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
13133 oa->write_character(to_char_type(0x38));
13134 write_number(
static_cast<std::uint8_t
>(positive_number));
13136 else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
13138 oa->write_character(to_char_type(0x39));
13139 write_number(
static_cast<std::uint16_t
>(positive_number));
13141 else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
13143 oa->write_character(to_char_type(0x3A));
13144 write_number(
static_cast<std::uint32_t
>(positive_number));
13148 oa->write_character(to_char_type(0x3B));
13149 write_number(
static_cast<std::uint64_t
>(positive_number));
13155 case value_t::number_unsigned:
13157 if (j.m_value.number_unsigned <= 0x17)
13159 write_number(
static_cast<std::uint8_t
>(j.m_value.number_unsigned));
13161 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13163 oa->write_character(to_char_type(0x18));
13164 write_number(
static_cast<std::uint8_t
>(j.m_value.number_unsigned));
13166 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13168 oa->write_character(to_char_type(0x19));
13169 write_number(
static_cast<std::uint16_t
>(j.m_value.number_unsigned));
13171 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13173 oa->write_character(to_char_type(0x1A));
13174 write_number(
static_cast<std::uint32_t
>(j.m_value.number_unsigned));
13178 oa->write_character(to_char_type(0x1B));
13179 write_number(
static_cast<std::uint64_t
>(j.m_value.number_unsigned));
13184 case value_t::number_float:
13186 if (std::isnan(j.m_value.number_float))
13189 oa->write_character(to_char_type(0xF9));
13190 oa->write_character(to_char_type(0x7E));
13191 oa->write_character(to_char_type(0x00));
13193 else if (std::isinf(j.m_value.number_float))
13196 oa->write_character(to_char_type(0xf9));
13197 oa->write_character(j.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
13198 oa->write_character(to_char_type(0x00));
13202 write_compact_float(j.m_value.number_float, detail::input_format_t::cbor);
13207 case value_t::string:
13210 const auto N = j.m_value.string->size();
13213 write_number(
static_cast<std::uint8_t
>(0x60 + N));
13215 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13217 oa->write_character(to_char_type(0x78));
13218 write_number(
static_cast<std::uint8_t
>(N));
13220 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13222 oa->write_character(to_char_type(0x79));
13223 write_number(
static_cast<std::uint16_t
>(N));
13225 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13227 oa->write_character(to_char_type(0x7A));
13228 write_number(
static_cast<std::uint32_t
>(N));
13231 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13233 oa->write_character(to_char_type(0x7B));
13234 write_number(
static_cast<std::uint64_t
>(N));
13239 oa->write_characters(
13240 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
13241 j.m_value.string->size());
13245 case value_t::array:
13248 const auto N = j.m_value.array->size();
13251 write_number(
static_cast<std::uint8_t
>(0x80 + N));
13253 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13255 oa->write_character(to_char_type(0x98));
13256 write_number(
static_cast<std::uint8_t
>(N));
13258 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13260 oa->write_character(to_char_type(0x99));
13261 write_number(
static_cast<std::uint16_t
>(N));
13263 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13265 oa->write_character(to_char_type(0x9A));
13266 write_number(
static_cast<std::uint32_t
>(N));
13269 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13271 oa->write_character(to_char_type(0x9B));
13272 write_number(
static_cast<std::uint64_t
>(N));
13277 for (
const auto& el : *j.m_value.array)
13284 case value_t::binary:
13286 if (j.m_value.binary->has_subtype())
13288 write_number(
static_cast<std::uint8_t
>(0xd8));
13289 write_number(j.m_value.binary->subtype());
13293 const auto N = j.m_value.binary->size();
13296 write_number(
static_cast<std::uint8_t
>(0x40 + N));
13298 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13300 oa->write_character(to_char_type(0x58));
13301 write_number(
static_cast<std::uint8_t
>(N));
13303 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13305 oa->write_character(to_char_type(0x59));
13306 write_number(
static_cast<std::uint16_t
>(N));
13308 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13310 oa->write_character(to_char_type(0x5A));
13311 write_number(
static_cast<std::uint32_t
>(N));
13314 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13316 oa->write_character(to_char_type(0x5B));
13317 write_number(
static_cast<std::uint64_t
>(N));
13322 oa->write_characters(
13323 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
13329 case value_t::object:
13332 const auto N = j.m_value.object->size();
13335 write_number(
static_cast<std::uint8_t
>(0xA0 + N));
13337 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13339 oa->write_character(to_char_type(0xB8));
13340 write_number(
static_cast<std::uint8_t
>(N));
13342 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13344 oa->write_character(to_char_type(0xB9));
13345 write_number(
static_cast<std::uint16_t
>(N));
13347 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13349 oa->write_character(to_char_type(0xBA));
13350 write_number(
static_cast<std::uint32_t
>(N));
13353 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13355 oa->write_character(to_char_type(0xBB));
13356 write_number(
static_cast<std::uint64_t
>(N));
13361 for (
const auto& el : *j.m_value.object)
13363 write_cbor(el.first);
13364 write_cbor(el.second);
13377 void write_msgpack(
const BasicJsonType& j)
13381 case value_t::null:
13383 oa->write_character(to_char_type(0xC0));
13387 case value_t::boolean:
13389 oa->write_character(j.m_value.boolean
13390 ? to_char_type(0xC3)
13391 : to_char_type(0xC2));
13395 case value_t::number_integer:
13397 if (j.m_value.number_integer >= 0)
13402 if (j.m_value.number_unsigned < 128)
13405 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13407 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13410 oa->write_character(to_char_type(0xCC));
13411 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13413 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13416 oa->write_character(to_char_type(0xCD));
13417 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
13419 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13422 oa->write_character(to_char_type(0xCE));
13423 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
13425 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
13428 oa->write_character(to_char_type(0xCF));
13429 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
13434 if (j.m_value.number_integer >= -32)
13437 write_number(
static_cast<std::int8_t
>(j.m_value.number_integer));
13439 else if (j.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&
13440 j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
13443 oa->write_character(to_char_type(0xD0));
13444 write_number(
static_cast<std::int8_t
>(j.m_value.number_integer));
13446 else if (j.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&
13447 j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
13450 oa->write_character(to_char_type(0xD1));
13451 write_number(
static_cast<std::int16_t
>(j.m_value.number_integer));
13453 else if (j.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&
13454 j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
13457 oa->write_character(to_char_type(0xD2));
13458 write_number(
static_cast<std::int32_t
>(j.m_value.number_integer));
13460 else if (j.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&
13461 j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
13464 oa->write_character(to_char_type(0xD3));
13465 write_number(
static_cast<std::int64_t
>(j.m_value.number_integer));
13471 case value_t::number_unsigned:
13473 if (j.m_value.number_unsigned < 128)
13476 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13478 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13481 oa->write_character(to_char_type(0xCC));
13482 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13484 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13487 oa->write_character(to_char_type(0xCD));
13488 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
13490 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13493 oa->write_character(to_char_type(0xCE));
13494 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
13496 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
13499 oa->write_character(to_char_type(0xCF));
13500 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
13505 case value_t::number_float:
13507 write_compact_float(j.m_value.number_float, detail::input_format_t::msgpack);
13511 case value_t::string:
13514 const auto N = j.m_value.string->size();
13518 write_number(
static_cast<std::uint8_t
>(0xA0 | N));
13520 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13523 oa->write_character(to_char_type(0xD9));
13524 write_number(
static_cast<std::uint8_t
>(N));
13526 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13529 oa->write_character(to_char_type(0xDA));
13530 write_number(
static_cast<std::uint16_t
>(N));
13532 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13535 oa->write_character(to_char_type(0xDB));
13536 write_number(
static_cast<std::uint32_t
>(N));
13540 oa->write_characters(
13541 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
13542 j.m_value.string->size());
13546 case value_t::array:
13549 const auto N = j.m_value.array->size();
13553 write_number(
static_cast<std::uint8_t
>(0x90 | N));
13555 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13558 oa->write_character(to_char_type(0xDC));
13559 write_number(
static_cast<std::uint16_t
>(N));
13561 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13564 oa->write_character(to_char_type(0xDD));
13565 write_number(
static_cast<std::uint32_t
>(N));
13569 for (
const auto& el : *j.m_value.array)
13576 case value_t::binary:
13580 const bool use_ext = j.m_value.binary->has_subtype();
13583 const auto N = j.m_value.binary->size();
13584 if (N <= (std::numeric_limits<std::uint8_t>::max)())
13586 std::uint8_t output_type{};
13593 output_type = 0xD4;
13596 output_type = 0xD5;
13599 output_type = 0xD6;
13602 output_type = 0xD7;
13605 output_type = 0xD8;
13608 output_type = 0xC7;
13616 output_type = 0xC4;
13620 oa->write_character(to_char_type(output_type));
13623 write_number(
static_cast<std::uint8_t
>(N));
13626 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13628 std::uint8_t output_type = use_ext
13632 oa->write_character(to_char_type(output_type));
13633 write_number(
static_cast<std::uint16_t
>(N));
13635 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13637 std::uint8_t output_type = use_ext
13641 oa->write_character(to_char_type(output_type));
13642 write_number(
static_cast<std::uint32_t
>(N));
13648 write_number(
static_cast<std::int8_t
>(j.m_value.binary->subtype()));
13652 oa->write_characters(
13653 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
13659 case value_t::object:
13662 const auto N = j.m_value.object->size();
13666 write_number(
static_cast<std::uint8_t
>(0x80 | (N & 0xF)));
13668 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13671 oa->write_character(to_char_type(0xDE));
13672 write_number(
static_cast<std::uint16_t
>(N));
13674 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13677 oa->write_character(to_char_type(0xDF));
13678 write_number(
static_cast<std::uint32_t
>(N));
13682 for (
const auto& el : *j.m_value.object)
13684 write_msgpack(el.first);
13685 write_msgpack(el.second);
13701 void write_ubjson(
const BasicJsonType& j,
const bool use_count,
13702 const bool use_type,
const bool add_prefix =
true)
13706 case value_t::null:
13710 oa->write_character(to_char_type(
'Z'));
13715 case value_t::boolean:
13719 oa->write_character(j.m_value.boolean
13720 ? to_char_type(
'T')
13721 : to_char_type(
'F'));
13726 case value_t::number_integer:
13728 write_number_with_ubjson_prefix(j.m_value.number_integer, add_prefix);
13732 case value_t::number_unsigned:
13734 write_number_with_ubjson_prefix(j.m_value.number_unsigned, add_prefix);
13738 case value_t::number_float:
13740 write_number_with_ubjson_prefix(j.m_value.number_float, add_prefix);
13744 case value_t::string:
13748 oa->write_character(to_char_type(
'S'));
13750 write_number_with_ubjson_prefix(j.m_value.string->size(),
true);
13751 oa->write_characters(
13752 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
13753 j.m_value.string->size());
13757 case value_t::array:
13761 oa->write_character(to_char_type(
'['));
13764 bool prefix_required =
true;
13765 if (use_type && !j.m_value.array->empty())
13767 JSON_ASSERT(use_count);
13768 const CharType first_prefix = ubjson_prefix(j.front());
13769 const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
13770 [
this, first_prefix](
const BasicJsonType & v)
13772 return ubjson_prefix(v) == first_prefix;
13777 prefix_required =
false;
13778 oa->write_character(to_char_type(
'$'));
13779 oa->write_character(first_prefix);
13785 oa->write_character(to_char_type(
'#'));
13786 write_number_with_ubjson_prefix(j.m_value.array->size(),
true);
13789 for (
const auto& el : *j.m_value.array)
13791 write_ubjson(el, use_count, use_type, prefix_required);
13796 oa->write_character(to_char_type(
']'));
13802 case value_t::binary:
13806 oa->write_character(to_char_type(
'['));
13809 if (use_type && !j.m_value.binary->empty())
13811 JSON_ASSERT(use_count);
13812 oa->write_character(to_char_type(
'$'));
13813 oa->write_character(
'U');
13818 oa->write_character(to_char_type(
'#'));
13819 write_number_with_ubjson_prefix(j.m_value.binary->size(),
true);
13824 oa->write_characters(
13825 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
13826 j.m_value.binary->size());
13830 for (
size_t i = 0; i < j.m_value.binary->size(); ++i)
13832 oa->write_character(to_char_type(
'U'));
13833 oa->write_character(j.m_value.binary->data()[i]);
13839 oa->write_character(to_char_type(
']'));
13845 case value_t::object:
13849 oa->write_character(to_char_type(
'{'));
13852 bool prefix_required =
true;
13853 if (use_type && !j.m_value.object->empty())
13855 JSON_ASSERT(use_count);
13856 const CharType first_prefix = ubjson_prefix(j.front());
13857 const bool same_prefix = std::all_of(j.begin(), j.end(),
13858 [
this, first_prefix](
const BasicJsonType & v)
13860 return ubjson_prefix(v) == first_prefix;
13865 prefix_required =
false;
13866 oa->write_character(to_char_type(
'$'));
13867 oa->write_character(first_prefix);
13873 oa->write_character(to_char_type(
'#'));
13874 write_number_with_ubjson_prefix(j.m_value.object->size(),
true);
13877 for (
const auto& el : *j.m_value.object)
13879 write_number_with_ubjson_prefix(el.first.size(),
true);
13880 oa->write_characters(
13881 reinterpret_cast<const CharType*
>(el.first.c_str()),
13883 write_ubjson(el.second, use_count, use_type, prefix_required);
13888 oa->write_character(to_char_type(
'}'));
13908 static std::size_t calc_bson_entry_header_size(
const string_t& name,
const BasicJsonType& j)
13910 const auto it = name.find(
static_cast<typename string_t::value_type
>(0));
13911 if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
13913 JSON_THROW(out_of_range::create(409,
"BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) +
")", j));
13916 return 1ul + name.size() + 1u;
13922 void write_bson_entry_header(
const string_t& name,
13923 const std::uint8_t element_type)
13925 oa->write_character(to_char_type(element_type));
13926 oa->write_characters(
13927 reinterpret_cast<const CharType*
>(name.c_str()),
13934 void write_bson_boolean(
const string_t& name,
13937 write_bson_entry_header(name, 0x08);
13938 oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
13944 void write_bson_double(
const string_t& name,
13945 const double value)
13947 write_bson_entry_header(name, 0x01);
13948 write_number<double, true>(value);
13954 static std::size_t calc_bson_string_size(
const string_t& value)
13956 return sizeof(std::int32_t) + value.size() + 1ul;
13962 void write_bson_string(
const string_t& name,
13963 const string_t& value)
13965 write_bson_entry_header(name, 0x02);
13967 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value.size() + 1ul));
13968 oa->write_characters(
13969 reinterpret_cast<const CharType*
>(value.c_str()),
13976 void write_bson_null(
const string_t& name)
13978 write_bson_entry_header(name, 0x0A);
13984 static std::size_t calc_bson_integer_size(
const std::int64_t value)
13986 return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()
13987 ?
sizeof(std::int32_t)
13988 :
sizeof(std::int64_t);
13994 void write_bson_integer(
const string_t& name,
13995 const std::int64_t value)
13997 if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
13999 write_bson_entry_header(name, 0x10);
14000 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value));
14004 write_bson_entry_header(name, 0x12);
14005 write_number<std::int64_t, true>(
static_cast<std::int64_t
>(value));
14012 static constexpr std::size_t calc_bson_unsigned_size(
const std::uint64_t value) noexcept
14014 return (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14015 ?
sizeof(std::int32_t)
14016 :
sizeof(std::int64_t);
14022 void write_bson_unsigned(
const string_t& name,
14023 const BasicJsonType& j)
14025 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14027 write_bson_entry_header(name, 0x10 );
14028 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(j.m_value.number_unsigned));
14030 else if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
14032 write_bson_entry_header(name, 0x12 );
14033 write_number<std::int64_t, true>(
static_cast<std::int64_t
>(j.m_value.number_unsigned));
14037 JSON_THROW(out_of_range::create(407,
"integer number " + std::to_string(j.m_value.number_unsigned) +
" cannot be represented by BSON as it does not fit int64", j));
14044 void write_bson_object_entry(
const string_t& name,
14045 const typename BasicJsonType::object_t& value)
14047 write_bson_entry_header(name, 0x03);
14048 write_bson_object(value);
14054 static std::size_t calc_bson_array_size(
const typename BasicJsonType::array_t& value)
14056 std::size_t array_index = 0ul;
14058 const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), std::size_t(0), [&array_index](std::size_t result,
const typename BasicJsonType::array_t::value_type & el)
14060 return result + calc_bson_element_size(std::to_string(array_index++), el);
14063 return sizeof(std::int32_t) + embedded_document_size + 1ul;
14069 static std::size_t calc_bson_binary_size(
const typename BasicJsonType::binary_t& value)
14071 return sizeof(std::int32_t) + value.size() + 1ul;
14077 void write_bson_array(
const string_t& name,
14078 const typename BasicJsonType::array_t& value)
14080 write_bson_entry_header(name, 0x04);
14081 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(calc_bson_array_size(value)));
14083 std::size_t array_index = 0ul;
14085 for (
const auto& el : value)
14087 write_bson_element(std::to_string(array_index++), el);
14090 oa->write_character(to_char_type(0x00));
14096 void write_bson_binary(
const string_t& name,
14097 const binary_t& value)
14099 write_bson_entry_header(name, 0x05);
14101 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value.size()));
14102 write_number(value.has_subtype() ? value.subtype() : std::uint8_t(0x00));
14104 oa->write_characters(
reinterpret_cast<const CharType*
>(value.data()), value.size());
14111 static std::size_t calc_bson_element_size(
const string_t& name,
14112 const BasicJsonType& j)
14114 const auto header_size = calc_bson_entry_header_size(name, j);
14117 case value_t::object:
14118 return header_size + calc_bson_object_size(*j.m_value.object);
14120 case value_t::array:
14121 return header_size + calc_bson_array_size(*j.m_value.array);
14123 case value_t::binary:
14124 return header_size + calc_bson_binary_size(*j.m_value.binary);
14126 case value_t::boolean:
14127 return header_size + 1ul;
14129 case value_t::number_float:
14130 return header_size + 8ul;
14132 case value_t::number_integer:
14133 return header_size + calc_bson_integer_size(j.m_value.number_integer);
14135 case value_t::number_unsigned:
14136 return header_size + calc_bson_unsigned_size(j.m_value.number_unsigned);
14138 case value_t::string:
14139 return header_size + calc_bson_string_size(*j.m_value.string);
14141 case value_t::null:
14142 return header_size + 0ul;
14146 JSON_ASSERT(
false);
14159 void write_bson_element(
const string_t& name,
14160 const BasicJsonType& j)
14164 case value_t::object:
14165 return write_bson_object_entry(name, *j.m_value.object);
14167 case value_t::array:
14168 return write_bson_array(name, *j.m_value.array);
14170 case value_t::binary:
14171 return write_bson_binary(name, *j.m_value.binary);
14173 case value_t::boolean:
14174 return write_bson_boolean(name, j.m_value.boolean);
14176 case value_t::number_float:
14177 return write_bson_double(name, j.m_value.number_float);
14179 case value_t::number_integer:
14180 return write_bson_integer(name, j.m_value.number_integer);
14182 case value_t::number_unsigned:
14183 return write_bson_unsigned(name, j);
14185 case value_t::string:
14186 return write_bson_string(name, *j.m_value.string);
14188 case value_t::null:
14189 return write_bson_null(name);
14193 JSON_ASSERT(
false);
14205 static std::size_t calc_bson_object_size(
const typename BasicJsonType::object_t& value)
14207 std::size_t document_size = std::accumulate(value.begin(), value.end(), std::size_t(0),
14208 [](
size_t result,
const typename BasicJsonType::object_t::value_type & el)
14210 return result += calc_bson_element_size(el.first, el.second);
14213 return sizeof(std::int32_t) + document_size + 1ul;
14220 void write_bson_object(
const typename BasicJsonType::object_t& value)
14222 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(calc_bson_object_size(value)));
14224 for (
const auto& el : value)
14226 write_bson_element(el.first, el.second);
14229 oa->write_character(to_char_type(0x00));
14236 static constexpr CharType get_cbor_float_prefix(
float )
14238 return to_char_type(0xFA);
14241 static constexpr CharType get_cbor_float_prefix(
double )
14243 return to_char_type(0xFB);
14250 static constexpr CharType get_msgpack_float_prefix(
float )
14252 return to_char_type(0xCA);
14255 static constexpr CharType get_msgpack_float_prefix(
double )
14257 return to_char_type(0xCB);
14265 template<
typename NumberType,
typename std::enable_if<
14266 std::is_floating_point<NumberType>::value,
int>::type = 0>
14267 void write_number_with_ubjson_prefix(
const NumberType n,
14268 const bool add_prefix)
14272 oa->write_character(get_ubjson_float_prefix(n));
14278 template<
typename NumberType,
typename std::enable_if<
14279 std::is_unsigned<NumberType>::value,
int>::type = 0>
14280 void write_number_with_ubjson_prefix(
const NumberType n,
14281 const bool add_prefix)
14283 if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
14287 oa->write_character(to_char_type(
'i'));
14289 write_number(
static_cast<std::uint8_t
>(n));
14291 else if (n <= (std::numeric_limits<std::uint8_t>::max)())
14295 oa->write_character(to_char_type(
'U'));
14297 write_number(
static_cast<std::uint8_t
>(n));
14299 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
14303 oa->write_character(to_char_type(
'I'));
14305 write_number(
static_cast<std::int16_t
>(n));
14307 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14311 oa->write_character(to_char_type(
'l'));
14313 write_number(
static_cast<std::int32_t
>(n));
14315 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
14319 oa->write_character(to_char_type(
'L'));
14321 write_number(
static_cast<std::int64_t
>(n));
14327 oa->write_character(to_char_type(
'H'));
14330 const auto number = BasicJsonType(n).dump();
14331 write_number_with_ubjson_prefix(number.size(),
true);
14332 for (std::size_t i = 0; i < number.size(); ++i)
14334 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
14340 template <
typename NumberType,
typename std::enable_if <
14341 std::is_signed<NumberType>::value&&
14342 !std::is_floating_point<NumberType>::value,
int >::type = 0 >
14343 void write_number_with_ubjson_prefix(
const NumberType n,
14344 const bool add_prefix)
14346 if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
14350 oa->write_character(to_char_type(
'i'));
14352 write_number(
static_cast<std::int8_t
>(n));
14354 else if (
static_cast<std::int64_t
>((std::numeric_limits<std::uint8_t>::min)()) <= n && n <=
static_cast<std::int64_t
>((std::numeric_limits<std::uint8_t>::max)()))
14358 oa->write_character(to_char_type(
'U'));
14360 write_number(
static_cast<std::uint8_t
>(n));
14362 else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
14366 oa->write_character(to_char_type(
'I'));
14368 write_number(
static_cast<std::int16_t
>(n));
14370 else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
14374 oa->write_character(to_char_type(
'l'));
14376 write_number(
static_cast<std::int32_t
>(n));
14378 else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
14382 oa->write_character(to_char_type(
'L'));
14384 write_number(
static_cast<std::int64_t
>(n));
14391 oa->write_character(to_char_type(
'H'));
14394 const auto number = BasicJsonType(n).dump();
14395 write_number_with_ubjson_prefix(number.size(),
true);
14396 for (std::size_t i = 0; i < number.size(); ++i)
14398 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
14407 CharType ubjson_prefix(
const BasicJsonType& j)
const noexcept
14411 case value_t::null:
14414 case value_t::boolean:
14415 return j.m_value.boolean ?
'T' :
'F';
14417 case value_t::number_integer:
14419 if ((std::numeric_limits<std::int8_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
14423 if ((std::numeric_limits<std::uint8_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
14427 if ((std::numeric_limits<std::int16_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
14431 if ((std::numeric_limits<std::int32_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
14435 if ((std::numeric_limits<std::int64_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
14443 case value_t::number_unsigned:
14445 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
14449 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint8_t>::max)()))
14453 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
14457 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14461 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
14469 case value_t::number_float:
14470 return get_ubjson_float_prefix(j.m_value.number_float);
14472 case value_t::string:
14475 case value_t::array:
14476 case value_t::binary:
14479 case value_t::object:
14487 static constexpr CharType get_ubjson_float_prefix(
float )
14492 static constexpr CharType get_ubjson_float_prefix(
double )
14512 template<
typename NumberType,
bool OutputIsLittleEndian = false>
14513 void write_number(
const NumberType n)
14516 std::array<CharType,
sizeof(NumberType)> vec;
14517 std::memcpy(vec.data(), &n,
sizeof(NumberType));
14520 if (is_little_endian != OutputIsLittleEndian)
14523 std::reverse(vec.begin(), vec.end());
14526 oa->write_characters(vec.data(),
sizeof(NumberType));
14529 void write_compact_float(
const number_float_t n, detail::input_format_t format)
14531 if (
static_cast<double>(n) >=
static_cast<double>(std::numeric_limits<float>::lowest()) &&
14532 static_cast<double>(n) <=
static_cast<double>((std::numeric_limits<float>::max)()) &&
14533 static_cast<double>(
static_cast<float>(n)) ==
static_cast<double>(n))
14535 oa->write_character(format == detail::input_format_t::cbor
14536 ? get_cbor_float_prefix(
static_cast<float>(n))
14537 : get_msgpack_float_prefix(
static_cast<float>(n)));
14538 write_number(
static_cast<float>(n));
14542 oa->write_character(format == detail::input_format_t::cbor
14543 ? get_cbor_float_prefix(n)
14544 : get_msgpack_float_prefix(n));
14554 template <
typename C = CharType,
14555 enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * =
nullptr >
14556 static constexpr CharType to_char_type(std::uint8_t x) noexcept
14558 return *
reinterpret_cast<char*
>(&x);
14561 template <
typename C = CharType,
14562 enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * =
nullptr >
14563 static CharType to_char_type(std::uint8_t x) noexcept
14565 static_assert(
sizeof(std::uint8_t) ==
sizeof(CharType),
"size of CharType must be equal to std::uint8_t");
14566 static_assert(std::is_trivial<CharType>::value,
"CharType must be trivial");
14568 std::memcpy(&result, &x,
sizeof(x));
14572 template<
typename C = CharType,
14573 enable_if_t<std::is_unsigned<C>::value>* =
nullptr>
14574 static constexpr CharType to_char_type(std::uint8_t x) noexcept
14579 template <
typename InputCharType,
typename C = CharType,
14581 std::is_signed<C>::value &&
14582 std::is_signed<char>::value &&
14583 std::is_same<char, typename std::remove_cv<InputCharType>::type>::value
14585 static constexpr CharType to_char_type(InputCharType x) noexcept
14592 const bool is_little_endian = little_endianess();
14595 output_adapter_t<CharType> oa =
nullptr;
14605 #include <algorithm>
14614 #include <type_traits>
14625 #include <type_traits>
14654 namespace dtoa_impl
14657 template<
typename Target,
typename Source>
14658 Target reinterpret_bits(
const Source source)
14660 static_assert(
sizeof(Target) ==
sizeof(Source),
"size mismatch");
14663 std::memcpy(&target, &source,
sizeof(Source));
14669 static constexpr
int kPrecision = 64;
14671 std::uint64_t f = 0;
14674 constexpr diyfp(std::uint64_t f_,
int e_) noexcept : f(f_), e(e_) {}
14680 static diyfp sub(
const diyfp& x,
const diyfp& y) noexcept
14682 JSON_ASSERT(x.e == y.e);
14683 JSON_ASSERT(x.f >= y.f);
14685 return {x.f - y.f, x.e};
14692 static diyfp mul(
const diyfp& x,
const diyfp& y) noexcept
14694 static_assert(kPrecision == 64,
"internal error");
14719 const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
14720 const std::uint64_t u_hi = x.f >> 32u;
14721 const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
14722 const std::uint64_t v_hi = y.f >> 32u;
14724 const std::uint64_t p0 = u_lo * v_lo;
14725 const std::uint64_t p1 = u_lo * v_hi;
14726 const std::uint64_t p2 = u_hi * v_lo;
14727 const std::uint64_t p3 = u_hi * v_hi;
14729 const std::uint64_t p0_hi = p0 >> 32u;
14730 const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
14731 const std::uint64_t p1_hi = p1 >> 32u;
14732 const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
14733 const std::uint64_t p2_hi = p2 >> 32u;
14735 std::uint64_t Q = p0_hi + p1_lo + p2_lo;
14746 Q += std::uint64_t{1} << (64u - 32u - 1u);
14748 const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
14750 return {h, x.e + y.e + 64};
14757 static diyfp normalize(diyfp x) noexcept
14759 JSON_ASSERT(x.f != 0);
14761 while ((x.f >> 63u) == 0)
14774 static diyfp normalize_to(
const diyfp& x,
const int target_exponent) noexcept
14776 const int delta = x.e - target_exponent;
14778 JSON_ASSERT(delta >= 0);
14779 JSON_ASSERT(((x.f << delta) >> delta) == x.f);
14781 return {x.f << delta, target_exponent};
14798 template<
typename FloatType>
14799 boundaries compute_boundaries(FloatType value)
14801 JSON_ASSERT(std::isfinite(value));
14802 JSON_ASSERT(value > 0);
14811 static_assert(std::numeric_limits<FloatType>::is_iec559,
14812 "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
14814 constexpr
int kPrecision = std::numeric_limits<FloatType>::digits;
14815 constexpr
int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
14816 constexpr
int kMinExp = 1 - kBias;
14817 constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
14819 using bits_type =
typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
14821 const std::uint64_t bits = reinterpret_bits<bits_type>(value);
14822 const std::uint64_t E = bits >> (kPrecision - 1);
14823 const std::uint64_t F = bits & (kHiddenBit - 1);
14825 const bool is_denormal = E == 0;
14826 const diyfp v = is_denormal
14827 ? diyfp(F, kMinExp)
14828 : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias);
14851 const bool lower_boundary_is_closer = F == 0 && E > 1;
14852 const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1);
14853 const diyfp m_minus = lower_boundary_is_closer
14854 ? diyfp(4 * v.f - 1, v.e - 2)
14855 : diyfp(2 * v.f - 1, v.e - 1);
14858 const diyfp w_plus = diyfp::normalize(m_plus);
14861 const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
14863 return {diyfp::normalize(v), w_minus, w_plus};
14921 constexpr
int kAlpha = -60;
14922 constexpr
int kGamma = -32;
14924 struct cached_power
14938 inline cached_power get_cached_power_for_binary_exponent(
int e)
14990 constexpr
int kCachedPowersMinDecExp = -300;
14991 constexpr
int kCachedPowersDecStep = 8;
14993 static constexpr std::array<cached_power, 79> kCachedPowers =
14996 { 0xAB70FE17C79AC6CA, -1060, -300 },
14997 { 0xFF77B1FCBEBCDC4F, -1034, -292 },
14998 { 0xBE5691EF416BD60C, -1007, -284 },
14999 { 0x8DD01FAD907FFC3C, -980, -276 },
15000 { 0xD3515C2831559A83, -954, -268 },
15001 { 0x9D71AC8FADA6C9B5, -927, -260 },
15002 { 0xEA9C227723EE8BCB, -901, -252 },
15003 { 0xAECC49914078536D, -874, -244 },
15004 { 0x823C12795DB6CE57, -847, -236 },
15005 { 0xC21094364DFB5637, -821, -228 },
15006 { 0x9096EA6F3848984F, -794, -220 },
15007 { 0xD77485CB25823AC7, -768, -212 },
15008 { 0xA086CFCD97BF97F4, -741, -204 },
15009 { 0xEF340A98172AACE5, -715, -196 },
15010 { 0xB23867FB2A35B28E, -688, -188 },
15011 { 0x84C8D4DFD2C63F3B, -661, -180 },
15012 { 0xC5DD44271AD3CDBA, -635, -172 },
15013 { 0x936B9FCEBB25C996, -608, -164 },
15014 { 0xDBAC6C247D62A584, -582, -156 },
15015 { 0xA3AB66580D5FDAF6, -555, -148 },
15016 { 0xF3E2F893DEC3F126, -529, -140 },
15017 { 0xB5B5ADA8AAFF80B8, -502, -132 },
15018 { 0x87625F056C7C4A8B, -475, -124 },
15019 { 0xC9BCFF6034C13053, -449, -116 },
15020 { 0x964E858C91BA2655, -422, -108 },
15021 { 0xDFF9772470297EBD, -396, -100 },
15022 { 0xA6DFBD9FB8E5B88F, -369, -92 },
15023 { 0xF8A95FCF88747D94, -343, -84 },
15024 { 0xB94470938FA89BCF, -316, -76 },
15025 { 0x8A08F0F8BF0F156B, -289, -68 },
15026 { 0xCDB02555653131B6, -263, -60 },
15027 { 0x993FE2C6D07B7FAC, -236, -52 },
15028 { 0xE45C10C42A2B3B06, -210, -44 },
15029 { 0xAA242499697392D3, -183, -36 },
15030 { 0xFD87B5F28300CA0E, -157, -28 },
15031 { 0xBCE5086492111AEB, -130, -20 },
15032 { 0x8CBCCC096F5088CC, -103, -12 },
15033 { 0xD1B71758E219652C, -77, -4 },
15034 { 0x9C40000000000000, -50, 4 },
15035 { 0xE8D4A51000000000, -24, 12 },
15036 { 0xAD78EBC5AC620000, 3, 20 },
15037 { 0x813F3978F8940984, 30, 28 },
15038 { 0xC097CE7BC90715B3, 56, 36 },
15039 { 0x8F7E32CE7BEA5C70, 83, 44 },
15040 { 0xD5D238A4ABE98068, 109, 52 },
15041 { 0x9F4F2726179A2245, 136, 60 },
15042 { 0xED63A231D4C4FB27, 162, 68 },
15043 { 0xB0DE65388CC8ADA8, 189, 76 },
15044 { 0x83C7088E1AAB65DB, 216, 84 },
15045 { 0xC45D1DF942711D9A, 242, 92 },
15046 { 0x924D692CA61BE758, 269, 100 },
15047 { 0xDA01EE641A708DEA, 295, 108 },
15048 { 0xA26DA3999AEF774A, 322, 116 },
15049 { 0xF209787BB47D6B85, 348, 124 },
15050 { 0xB454E4A179DD1877, 375, 132 },
15051 { 0x865B86925B9BC5C2, 402, 140 },
15052 { 0xC83553C5C8965D3D, 428, 148 },
15053 { 0x952AB45CFA97A0B3, 455, 156 },
15054 { 0xDE469FBD99A05FE3, 481, 164 },
15055 { 0xA59BC234DB398C25, 508, 172 },
15056 { 0xF6C69A72A3989F5C, 534, 180 },
15057 { 0xB7DCBF5354E9BECE, 561, 188 },
15058 { 0x88FCF317F22241E2, 588, 196 },
15059 { 0xCC20CE9BD35C78A5, 614, 204 },
15060 { 0x98165AF37B2153DF, 641, 212 },
15061 { 0xE2A0B5DC971F303A, 667, 220 },
15062 { 0xA8D9D1535CE3B396, 694, 228 },
15063 { 0xFB9B7CD9A4A7443C, 720, 236 },
15064 { 0xBB764C4CA7A44410, 747, 244 },
15065 { 0x8BAB8EEFB6409C1A, 774, 252 },
15066 { 0xD01FEF10A657842C, 800, 260 },
15067 { 0x9B10A4E5E9913129, 827, 268 },
15068 { 0xE7109BFBA19C0C9D, 853, 276 },
15069 { 0xAC2820D9623BF429, 880, 284 },
15070 { 0x80444B5E7AA7CF85, 907, 292 },
15071 { 0xBF21E44003ACDD2D, 933, 300 },
15072 { 0x8E679C2F5E44FF8F, 960, 308 },
15073 { 0xD433179D9C8CB841, 986, 316 },
15074 { 0x9E19DB92B4E31BA9, 1013, 324 },
15082 JSON_ASSERT(e >= -1500);
15083 JSON_ASSERT(e <= 1500);
15084 const int f = kAlpha - e - 1;
15085 const int k = (f * 78913) / (1 << 18) +
static_cast<int>(f > 0);
15087 const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
15088 JSON_ASSERT(index >= 0);
15089 JSON_ASSERT(
static_cast<std::size_t
>(index) < kCachedPowers.size());
15091 const cached_power cached = kCachedPowers[
static_cast<std::size_t
>(index)];
15092 JSON_ASSERT(kAlpha <= cached.e + e + 64);
15093 JSON_ASSERT(kGamma >= cached.e + e + 64);
15102 inline int find_largest_pow10(
const std::uint32_t n, std::uint32_t& pow10)
15105 if (n >= 1000000000)
15107 pow10 = 1000000000;
15111 if (n >= 100000000)
15156 inline void grisu2_round(
char* buf,
int len, std::uint64_t dist, std::uint64_t delta,
15157 std::uint64_t rest, std::uint64_t ten_k)
15159 JSON_ASSERT(len >= 1);
15160 JSON_ASSERT(dist <= delta);
15161 JSON_ASSERT(rest <= delta);
15162 JSON_ASSERT(ten_k > 0);
15184 && delta - rest >= ten_k
15185 && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
15187 JSON_ASSERT(buf[len - 1] !=
'0');
15197 inline void grisu2_digit_gen(
char* buffer,
int& length,
int& decimal_exponent,
15198 diyfp M_minus, diyfp w, diyfp M_plus)
15200 static_assert(kAlpha >= -60,
"internal error");
15201 static_assert(kGamma <= -32,
"internal error");
15215 JSON_ASSERT(M_plus.e >= kAlpha);
15216 JSON_ASSERT(M_plus.e <= kGamma);
15218 std::uint64_t delta = diyfp::sub(M_plus, M_minus).f;
15219 std::uint64_t dist = diyfp::sub(M_plus, w ).f;
15228 const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
15230 auto p1 =
static_cast<std::uint32_t
>(M_plus.f >> -one.e);
15231 std::uint64_t p2 = M_plus.f & (one.f - 1);
15237 JSON_ASSERT(p1 > 0);
15239 std::uint32_t pow10;
15240 const int k = find_largest_pow10(p1, pow10);
15267 const std::uint32_t d = p1 / pow10;
15268 const std::uint32_t r = p1 % pow10;
15273 JSON_ASSERT(d <= 9);
15274 buffer[length++] =
static_cast<char>(
'0' + d);
15293 const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
15298 decimal_exponent += n;
15309 const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
15310 grisu2_round(buffer, length, dist, delta, rest, ten_n);
15360 JSON_ASSERT(p2 > delta);
15371 JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
15373 const std::uint64_t d = p2 >> -one.e;
15374 const std::uint64_t r = p2 & (one.f - 1);
15380 JSON_ASSERT(d <= 9);
15381 buffer[length++] =
static_cast<char>(
'0' + d);
15406 decimal_exponent -= m;
15414 const std::uint64_t ten_m = one.f;
15415 grisu2_round(buffer, length, dist, delta, p2, ten_m);
15437 JSON_HEDLEY_NON_NULL(1)
15438 inline
void grisu2(
char* buf,
int& len,
int& decimal_exponent,
15439 diyfp m_minus, diyfp v, diyfp m_plus)
15441 JSON_ASSERT(m_plus.e == m_minus.e);
15442 JSON_ASSERT(m_plus.e == v.e);
15453 const cached_power cached = get_cached_power_for_binary_exponent(m_plus.e);
15455 const diyfp c_minus_k(cached.f, cached.e);
15458 const diyfp w = diyfp::mul(v, c_minus_k);
15459 const diyfp w_minus = diyfp::mul(m_minus, c_minus_k);
15460 const diyfp w_plus = diyfp::mul(m_plus, c_minus_k);
15483 const diyfp M_minus(w_minus.f + 1, w_minus.e);
15484 const diyfp M_plus (w_plus.f - 1, w_plus.e );
15486 decimal_exponent = -cached.k;
15488 grisu2_digit_gen(buf, len, decimal_exponent, M_minus, w, M_plus);
15496 template<
typename FloatType>
15497 JSON_HEDLEY_NON_NULL(1)
15498 void grisu2(
char* buf,
int& len,
int& decimal_exponent, FloatType value)
15500 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
15501 "internal error: not enough precision");
15503 JSON_ASSERT(std::isfinite(value));
15504 JSON_ASSERT(value > 0);
15523 const boundaries w = compute_boundaries(
static_cast<double>(value));
15525 const boundaries w = compute_boundaries(value);
15528 grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
15536 JSON_HEDLEY_NON_NULL(1)
15538 inline
char* append_exponent(
char* buf,
int e)
15540 JSON_ASSERT(e > -1000);
15541 JSON_ASSERT(e < 1000);
15553 auto k =
static_cast<std::uint32_t
>(e);
15559 *buf++ =
static_cast<char>(
'0' + k);
15563 *buf++ =
static_cast<char>(
'0' + k / 10);
15565 *buf++ =
static_cast<char>(
'0' + k);
15569 *buf++ =
static_cast<char>(
'0' + k / 100);
15571 *buf++ =
static_cast<char>(
'0' + k / 10);
15573 *buf++ =
static_cast<char>(
'0' + k);
15588 JSON_HEDLEY_NON_NULL(1)
15590 inline
char* format_buffer(
char* buf,
int len,
int decimal_exponent,
15591 int min_exp,
int max_exp)
15593 JSON_ASSERT(min_exp < 0);
15594 JSON_ASSERT(max_exp > 0);
15597 const int n = len + decimal_exponent;
15603 if (k <= n && n <= max_exp)
15608 std::memset(buf + k,
'0',
static_cast<size_t>(n) -
static_cast<size_t>(k));
15612 return buf + (
static_cast<size_t>(n) + 2);
15615 if (0 < n && n <= max_exp)
15620 JSON_ASSERT(k > n);
15622 std::memmove(buf + (
static_cast<size_t>(n) + 1), buf + n,
static_cast<size_t>(k) -
static_cast<size_t>(n));
15624 return buf + (
static_cast<size_t>(k) + 1U);
15627 if (min_exp < n && n <= 0)
15632 std::memmove(buf + (2 +
static_cast<size_t>(-n)), buf,
static_cast<size_t>(k));
15635 std::memset(buf + 2,
'0',
static_cast<size_t>(-n));
15636 return buf + (2U +
static_cast<size_t>(-n) +
static_cast<size_t>(k));
15651 std::memmove(buf + 2, buf + 1,
static_cast<size_t>(k) - 1);
15653 buf += 1 +
static_cast<size_t>(k);
15657 return append_exponent(buf, n - 1);
15672 template<
typename FloatType>
15673 JSON_HEDLEY_NON_NULL(1, 2)
15675 char* to_chars(
char* first, const
char* last, FloatType value)
15677 static_cast<void>(last);
15678 JSON_ASSERT(std::isfinite(value));
15681 if (std::signbit(value))
15696 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
15703 int decimal_exponent = 0;
15704 dtoa_impl::grisu2(first, len, decimal_exponent, value);
15706 JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
15709 constexpr
int kMinExp = -4;
15711 constexpr
int kMaxExp = std::numeric_limits<FloatType>::digits10;
15713 JSON_ASSERT(last - first >= kMaxExp + 2);
15714 JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
15715 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
15717 return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);
15745 enum class error_handler_t
15752 template<
typename BasicJsonType>
15755 using string_t =
typename BasicJsonType::string_t;
15756 using number_float_t =
typename BasicJsonType::number_float_t;
15757 using number_integer_t =
typename BasicJsonType::number_integer_t;
15758 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
15759 using binary_char_t =
typename BasicJsonType::binary_t::value_type;
15760 static constexpr std::uint8_t UTF8_ACCEPT = 0;
15761 static constexpr std::uint8_t UTF8_REJECT = 1;
15769 serializer(output_adapter_t<char> s,
const char ichar,
15770 error_handler_t error_handler_ = error_handler_t::strict)
15772 , loc(std::localeconv())
15773 , thousands_sep(loc->thousands_sep == nullptr ?
'\0' : std::char_traits<char>::to_char_type(* (loc->thousands_sep)))
15774 , decimal_point(loc->decimal_point == nullptr ?
'\0' : std::char_traits<char>::to_char_type(* (loc->decimal_point)))
15775 , indent_char(ichar)
15776 , indent_string(512, indent_char)
15777 , error_handler(error_handler_)
15781 serializer(
const serializer&) =
delete;
15782 serializer& operator=(
const serializer&) =
delete;
15783 serializer(serializer&&) =
delete;
15784 serializer& operator=(serializer&&) =
delete;
15785 ~serializer() =
default;
15809 void dump(
const BasicJsonType& val,
15810 const bool pretty_print,
15811 const bool ensure_ascii,
15812 const unsigned int indent_step,
15813 const unsigned int current_indent = 0)
15815 switch (val.m_type)
15817 case value_t::object:
15819 if (val.m_value.object->empty())
15821 o->write_characters(
"{}", 2);
15827 o->write_characters(
"{\n", 2);
15830 const auto new_indent = current_indent + indent_step;
15831 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
15833 indent_string.resize(indent_string.size() * 2,
' ');
15837 auto i = val.m_value.object->cbegin();
15838 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
15840 o->write_characters(indent_string.c_str(), new_indent);
15841 o->write_character(
'\"');
15842 dump_escaped(i->first, ensure_ascii);
15843 o->write_characters(
"\": ", 3);
15844 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
15845 o->write_characters(
",\n", 2);
15849 JSON_ASSERT(i != val.m_value.object->cend());
15850 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
15851 o->write_characters(indent_string.c_str(), new_indent);
15852 o->write_character(
'\"');
15853 dump_escaped(i->first, ensure_ascii);
15854 o->write_characters(
"\": ", 3);
15855 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
15857 o->write_character(
'\n');
15858 o->write_characters(indent_string.c_str(), current_indent);
15859 o->write_character(
'}');
15863 o->write_character(
'{');
15866 auto i = val.m_value.object->cbegin();
15867 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
15869 o->write_character(
'\"');
15870 dump_escaped(i->first, ensure_ascii);
15871 o->write_characters(
"\":", 2);
15872 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
15873 o->write_character(
',');
15877 JSON_ASSERT(i != val.m_value.object->cend());
15878 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
15879 o->write_character(
'\"');
15880 dump_escaped(i->first, ensure_ascii);
15881 o->write_characters(
"\":", 2);
15882 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
15884 o->write_character(
'}');
15890 case value_t::array:
15892 if (val.m_value.array->empty())
15894 o->write_characters(
"[]", 2);
15900 o->write_characters(
"[\n", 2);
15903 const auto new_indent = current_indent + indent_step;
15904 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
15906 indent_string.resize(indent_string.size() * 2,
' ');
15910 for (
auto i = val.m_value.array->cbegin();
15911 i != val.m_value.array->cend() - 1; ++i)
15913 o->write_characters(indent_string.c_str(), new_indent);
15914 dump(*i,
true, ensure_ascii, indent_step, new_indent);
15915 o->write_characters(
",\n", 2);
15919 JSON_ASSERT(!val.m_value.array->empty());
15920 o->write_characters(indent_string.c_str(), new_indent);
15921 dump(val.m_value.array->back(),
true, ensure_ascii, indent_step, new_indent);
15923 o->write_character(
'\n');
15924 o->write_characters(indent_string.c_str(), current_indent);
15925 o->write_character(
']');
15929 o->write_character(
'[');
15932 for (
auto i = val.m_value.array->cbegin();
15933 i != val.m_value.array->cend() - 1; ++i)
15935 dump(*i,
false, ensure_ascii, indent_step, current_indent);
15936 o->write_character(
',');
15940 JSON_ASSERT(!val.m_value.array->empty());
15941 dump(val.m_value.array->back(),
false, ensure_ascii, indent_step, current_indent);
15943 o->write_character(
']');
15949 case value_t::string:
15951 o->write_character(
'\"');
15952 dump_escaped(*val.m_value.string, ensure_ascii);
15953 o->write_character(
'\"');
15957 case value_t::binary:
15961 o->write_characters(
"{\n", 2);
15964 const auto new_indent = current_indent + indent_step;
15965 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
15967 indent_string.resize(indent_string.size() * 2,
' ');
15970 o->write_characters(indent_string.c_str(), new_indent);
15972 o->write_characters(
"\"bytes\": [", 10);
15974 if (!val.m_value.binary->empty())
15976 for (
auto i = val.m_value.binary->cbegin();
15977 i != val.m_value.binary->cend() - 1; ++i)
15980 o->write_characters(
", ", 2);
15982 dump_integer(val.m_value.binary->back());
15985 o->write_characters(
"],\n", 3);
15986 o->write_characters(indent_string.c_str(), new_indent);
15988 o->write_characters(
"\"subtype\": ", 11);
15989 if (val.m_value.binary->has_subtype())
15991 dump_integer(val.m_value.binary->subtype());
15995 o->write_characters(
"null", 4);
15997 o->write_character(
'\n');
15998 o->write_characters(indent_string.c_str(), current_indent);
15999 o->write_character(
'}');
16003 o->write_characters(
"{\"bytes\":[", 10);
16005 if (!val.m_value.binary->empty())
16007 for (
auto i = val.m_value.binary->cbegin();
16008 i != val.m_value.binary->cend() - 1; ++i)
16011 o->write_character(
',');
16013 dump_integer(val.m_value.binary->back());
16016 o->write_characters(
"],\"subtype\":", 12);
16017 if (val.m_value.binary->has_subtype())
16019 dump_integer(val.m_value.binary->subtype());
16020 o->write_character(
'}');
16024 o->write_characters(
"null}", 5);
16030 case value_t::boolean:
16032 if (val.m_value.boolean)
16034 o->write_characters(
"true", 4);
16038 o->write_characters(
"false", 5);
16043 case value_t::number_integer:
16045 dump_integer(val.m_value.number_integer);
16049 case value_t::number_unsigned:
16051 dump_integer(val.m_value.number_unsigned);
16055 case value_t::number_float:
16057 dump_float(val.m_value.number_float);
16061 case value_t::discarded:
16063 o->write_characters(
"<discarded>", 11);
16067 case value_t::null:
16069 o->write_characters(
"null", 4);
16074 JSON_ASSERT(
false);
16078 JSON_PRIVATE_UNLESS_TESTED:
16093 void dump_escaped(
const string_t& s,
const bool ensure_ascii)
16095 std::uint32_t codepoint;
16096 std::uint8_t state = UTF8_ACCEPT;
16097 std::size_t bytes = 0;
16100 std::size_t bytes_after_last_accept = 0;
16101 std::size_t undumped_chars = 0;
16103 for (std::size_t i = 0; i < s.size(); ++i)
16105 const auto byte =
static_cast<uint8_t
>(s[i]);
16107 switch (decode(state, codepoint,
byte))
16115 string_buffer[bytes++] =
'\\';
16116 string_buffer[bytes++] =
'b';
16122 string_buffer[bytes++] =
'\\';
16123 string_buffer[bytes++] =
't';
16129 string_buffer[bytes++] =
'\\';
16130 string_buffer[bytes++] =
'n';
16136 string_buffer[bytes++] =
'\\';
16137 string_buffer[bytes++] =
'f';
16143 string_buffer[bytes++] =
'\\';
16144 string_buffer[bytes++] =
'r';
16150 string_buffer[bytes++] =
'\\';
16151 string_buffer[bytes++] =
'\"';
16157 string_buffer[bytes++] =
'\\';
16158 string_buffer[bytes++] =
'\\';
16166 if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
16168 if (codepoint <= 0xFFFF)
16170 (std::snprintf)(string_buffer.data() + bytes, 7,
"\\u%04x",
16171 static_cast<std::uint16_t
>(codepoint));
16176 (std::snprintf)(string_buffer.data() + bytes, 13,
"\\u%04x\\u%04x",
16177 static_cast<std::uint16_t
>(0xD7C0u + (codepoint >> 10u)),
16178 static_cast<std::uint16_t
>(0xDC00u + (codepoint & 0x3FFu)));
16186 string_buffer[bytes++] = s[i];
16195 if (string_buffer.size() - bytes < 13)
16197 o->write_characters(string_buffer.data(), bytes);
16202 bytes_after_last_accept = bytes;
16203 undumped_chars = 0;
16209 switch (error_handler)
16211 case error_handler_t::strict:
16213 std::string sn(3,
'\0');
16214 (std::snprintf)(&sn[0], sn.size(),
"%.2X", byte);
16215 JSON_THROW(type_error::create(316,
"invalid UTF-8 byte at index " + std::to_string(i) +
": 0x" + sn, BasicJsonType()));
16218 case error_handler_t::ignore:
16219 case error_handler_t::replace:
16225 if (undumped_chars > 0)
16232 bytes = bytes_after_last_accept;
16234 if (error_handler == error_handler_t::replace)
16239 string_buffer[bytes++] =
'\\';
16240 string_buffer[bytes++] =
'u';
16241 string_buffer[bytes++] =
'f';
16242 string_buffer[bytes++] =
'f';
16243 string_buffer[bytes++] =
'f';
16244 string_buffer[bytes++] =
'd';
16248 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xEF');
16249 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBF');
16250 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBD');
16256 if (string_buffer.size() - bytes < 13)
16258 o->write_characters(string_buffer.data(), bytes);
16262 bytes_after_last_accept = bytes;
16265 undumped_chars = 0;
16268 state = UTF8_ACCEPT;
16273 JSON_ASSERT(
false);
16283 string_buffer[bytes++] = s[i];
16292 if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
16297 o->write_characters(string_buffer.data(), bytes);
16303 switch (error_handler)
16305 case error_handler_t::strict:
16307 std::string sn(3,
'\0');
16308 (std::snprintf)(&sn[0], sn.size(),
"%.2X",
static_cast<std::uint8_t
>(s.back()));
16309 JSON_THROW(type_error::create(316,
"incomplete UTF-8 string; last byte: 0x" + sn, BasicJsonType()));
16312 case error_handler_t::ignore:
16315 o->write_characters(string_buffer.data(), bytes_after_last_accept);
16319 case error_handler_t::replace:
16322 o->write_characters(string_buffer.data(), bytes_after_last_accept);
16326 o->write_characters(
"\\ufffd", 6);
16330 o->write_characters(
"\xEF\xBF\xBD", 3);
16336 JSON_ASSERT(
false);
16350 inline unsigned int count_digits(number_unsigned_t x) noexcept
16352 unsigned int n_digits = 1;
16361 return n_digits + 1;
16365 return n_digits + 2;
16369 return n_digits + 3;
16385 template <
typename NumberType, detail::enable_if_t <
16386 std::is_same<NumberType, number_unsigned_t>::value ||
16387 std::is_same<NumberType, number_integer_t>::value ||
16388 std::is_same<NumberType, binary_char_t>::value,
16390 void dump_integer(NumberType x)
16392 static constexpr std::array<std::array<char, 2>, 100> digits_to_99
16395 {{
'0',
'0'}}, {{
'0',
'1'}}, {{
'0',
'2'}}, {{
'0',
'3'}}, {{
'0',
'4'}}, {{
'0',
'5'}}, {{
'0',
'6'}}, {{
'0',
'7'}}, {{
'0',
'8'}}, {{
'0',
'9'}},
16396 {{
'1',
'0'}}, {{
'1',
'1'}}, {{
'1',
'2'}}, {{
'1',
'3'}}, {{
'1',
'4'}}, {{
'1',
'5'}}, {{
'1',
'6'}}, {{
'1',
'7'}}, {{
'1',
'8'}}, {{
'1',
'9'}},
16397 {{
'2',
'0'}}, {{
'2',
'1'}}, {{
'2',
'2'}}, {{
'2',
'3'}}, {{
'2',
'4'}}, {{
'2',
'5'}}, {{
'2',
'6'}}, {{
'2',
'7'}}, {{
'2',
'8'}}, {{
'2',
'9'}},
16398 {{
'3',
'0'}}, {{
'3',
'1'}}, {{
'3',
'2'}}, {{
'3',
'3'}}, {{
'3',
'4'}}, {{
'3',
'5'}}, {{
'3',
'6'}}, {{
'3',
'7'}}, {{
'3',
'8'}}, {{
'3',
'9'}},
16399 {{
'4',
'0'}}, {{
'4',
'1'}}, {{
'4',
'2'}}, {{
'4',
'3'}}, {{
'4',
'4'}}, {{
'4',
'5'}}, {{
'4',
'6'}}, {{
'4',
'7'}}, {{
'4',
'8'}}, {{
'4',
'9'}},
16400 {{
'5',
'0'}}, {{
'5',
'1'}}, {{
'5',
'2'}}, {{
'5',
'3'}}, {{
'5',
'4'}}, {{
'5',
'5'}}, {{
'5',
'6'}}, {{
'5',
'7'}}, {{
'5',
'8'}}, {{
'5',
'9'}},
16401 {{
'6',
'0'}}, {{
'6',
'1'}}, {{
'6',
'2'}}, {{
'6',
'3'}}, {{
'6',
'4'}}, {{
'6',
'5'}}, {{
'6',
'6'}}, {{
'6',
'7'}}, {{
'6',
'8'}}, {{
'6',
'9'}},
16402 {{
'7',
'0'}}, {{
'7',
'1'}}, {{
'7',
'2'}}, {{
'7',
'3'}}, {{
'7',
'4'}}, {{
'7',
'5'}}, {{
'7',
'6'}}, {{
'7',
'7'}}, {{
'7',
'8'}}, {{
'7',
'9'}},
16403 {{
'8',
'0'}}, {{
'8',
'1'}}, {{
'8',
'2'}}, {{
'8',
'3'}}, {{
'8',
'4'}}, {{
'8',
'5'}}, {{
'8',
'6'}}, {{
'8',
'7'}}, {{
'8',
'8'}}, {{
'8',
'9'}},
16404 {{
'9',
'0'}}, {{
'9',
'1'}}, {{
'9',
'2'}}, {{
'9',
'3'}}, {{
'9',
'4'}}, {{
'9',
'5'}}, {{
'9',
'6'}}, {{
'9',
'7'}}, {{
'9',
'8'}}, {{
'9',
'9'}},
16411 o->write_character(
'0');
16416 auto buffer_ptr = number_buffer.begin();
16418 const bool is_negative = std::is_same<NumberType, number_integer_t>::value && !(x >= 0);
16419 number_unsigned_t abs_value;
16421 unsigned int n_chars;
16426 abs_value = remove_sign(
static_cast<number_integer_t
>(x));
16429 n_chars = 1 + count_digits(abs_value);
16433 abs_value =
static_cast<number_unsigned_t
>(x);
16434 n_chars = count_digits(abs_value);
16438 JSON_ASSERT(n_chars < number_buffer.size() - 1);
16442 buffer_ptr += n_chars;
16446 while (abs_value >= 100)
16448 const auto digits_index =
static_cast<unsigned>((abs_value % 100));
16450 *(--buffer_ptr) = digits_to_99[digits_index][1];
16451 *(--buffer_ptr) = digits_to_99[digits_index][0];
16454 if (abs_value >= 10)
16456 const auto digits_index =
static_cast<unsigned>(abs_value);
16457 *(--buffer_ptr) = digits_to_99[digits_index][1];
16458 *(--buffer_ptr) = digits_to_99[digits_index][0];
16462 *(--buffer_ptr) =
static_cast<char>(
'0' + abs_value);
16465 o->write_characters(number_buffer.data(), n_chars);
16476 void dump_float(number_float_t x)
16479 if (!std::isfinite(x))
16481 o->write_characters(
"null", 4);
16490 static constexpr
bool is_ieee_single_or_double
16491 = (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 24 && std::numeric_limits<number_float_t>::max_exponent == 128) ||
16492 (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 53 && std::numeric_limits<number_float_t>::max_exponent == 1024);
16494 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
16497 void dump_float(number_float_t x, std::true_type )
16499 char* begin = number_buffer.data();
16500 char* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
16502 o->write_characters(begin,
static_cast<size_t>(end - begin));
16505 void dump_float(number_float_t x, std::false_type )
16508 static constexpr
auto d = std::numeric_limits<number_float_t>::max_digits10;
16511 std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(),
"%.*g", d, x);
16514 JSON_ASSERT(len > 0);
16516 JSON_ASSERT(
static_cast<std::size_t
>(len) < number_buffer.size());
16519 if (thousands_sep !=
'\0')
16521 const auto end = std::remove(number_buffer.begin(),
16522 number_buffer.begin() + len, thousands_sep);
16523 std::fill(end, number_buffer.end(),
'\0');
16524 JSON_ASSERT((end - number_buffer.begin()) <= len);
16525 len = (end - number_buffer.begin());
16529 if (decimal_point !=
'\0' && decimal_point !=
'.')
16531 const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
16532 if (dec_pos != number_buffer.end())
16538 o->write_characters(number_buffer.data(),
static_cast<std::size_t
>(len));
16541 const bool value_is_int_like =
16542 std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
16545 return c ==
'.' || c ==
'e';
16548 if (value_is_int_like)
16550 o->write_characters(
".0", 2);
16575 static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep,
const std::uint8_t
byte) noexcept
16577 static const std::array<std::uint8_t, 400> utf8d =
16580 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16581 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16582 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16583 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16584 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
16585 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
16586 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
16587 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3,
16588 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
16589 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1,
16590 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1,
16591 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1,
16592 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1,
16593 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
16597 JSON_ASSERT(
byte < utf8d.size());
16598 const std::uint8_t type = utf8d[byte];
16600 codep = (state != UTF8_ACCEPT)
16601 ? (
byte & 0x3fu) | (codep << 6u)
16602 : (0xFFu >> type) & (byte);
16604 std::size_t index = 256u +
static_cast<size_t>(state) * 16u +
static_cast<size_t>(type);
16605 JSON_ASSERT(index < 400);
16606 state = utf8d[index];
16615 number_unsigned_t remove_sign(number_unsigned_t x)
16617 JSON_ASSERT(
false);
16630 inline number_unsigned_t remove_sign(number_integer_t x) noexcept
16632 JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)());
16633 return static_cast<number_unsigned_t
>(-(x + 1)) + 1;
16638 output_adapter_t<char> o =
nullptr;
16641 std::array<char, 64> number_buffer{{}};
16644 const std::lconv* loc =
nullptr;
16646 const char thousands_sep =
'\0';
16648 const char decimal_point =
'\0';
16651 std::array<char, 512> string_buffer{{}};
16654 const char indent_char;
16656 string_t indent_string;
16659 const error_handler_t error_handler;
16671 #include <functional>
16684 template <
class Key,
class T,
class IgnoredLess = std::less<Key>,
16685 class Allocator = std::allocator<std::pair<const Key, T>>>
16690 using Container = std::vector<std::pair<const Key, T>, Allocator>;
16691 using typename Container::iterator;
16692 using typename Container::const_iterator;
16693 using typename Container::size_type;
16694 using typename Container::value_type;
16699 template <
class It>
16702 ordered_map(std::initializer_list<T> init,
const Allocator& alloc = Allocator() )
16707 for (
auto it = this->begin(); it != this->end(); ++it)
16709 if (it->first == key)
16711 return {it,
false};
16714 Container::emplace_back(key, t);
16715 return {--this->end(),
true};
16720 return emplace(key, T{}).first->second;
16730 for (
auto it = this->begin(); it != this->end(); ++it)
16732 if (it->first == key)
16738 JSON_THROW(std::out_of_range(
"key not found"));
16741 const T&
at(
const Key& key)
const
16743 for (
auto it = this->begin(); it != this->end(); ++it)
16745 if (it->first == key)
16751 JSON_THROW(std::out_of_range(
"key not found"));
16756 for (
auto it = this->begin(); it != this->end(); ++it)
16758 if (it->first == key)
16761 for (
auto next = it; ++next != this->end(); ++it)
16764 new (&*it) value_type{std::move(*next)};
16766 Container::pop_back();
16778 for (
auto next = it; ++next != this->end(); ++it)
16781 new (&*it) value_type{std::move(*next)};
16783 Container::pop_back();
16789 for (
auto it = this->begin(); it != this->end(); ++it)
16791 if (it->first == key)
16801 for (
auto it = this->begin(); it != this->end(); ++it)
16803 if (it->first == key)
16808 return Container::end();
16811 const_iterator
find(
const Key& key)
const
16813 for (
auto it = this->begin(); it != this->end(); ++it)
16815 if (it->first == key)
16820 return Container::end();
16823 std::pair<iterator, bool>
insert( value_type&& value )
16825 return emplace(value.first, std::move(value.second));
16828 std::pair<iterator, bool>
insert(
const value_type& value )
16830 for (
auto it = this->begin(); it != this->end(); ++it)
16832 if (it->first == value.first)
16834 return {it,
false};
16837 Container::push_back(value);
16838 return {--this->end(),
true};
16841 template<
typename InputIt>
16842 using require_input_iter =
typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
16843 std::input_iterator_tag>::value>::type;
16845 template<
typename InputIt,
typename = require_input_iter<InputIt>>
16848 for (
auto it = first; it != last; ++it)
16858 #if defined(JSON_HAS_CPP_17)
16859 #include <string_view>
16954 NLOHMANN_BASIC_JSON_TPL_DECLARATION
16959 friend ::nlohmann::json_pointer<basic_json>;
16961 template<
typename BasicJsonType,
typename InputType>
16962 friend class ::nlohmann::detail::parser;
16963 friend ::nlohmann::detail::serializer<basic_json>;
16964 template<
typename BasicJsonType>
16965 friend class ::nlohmann::detail::iter_impl;
16966 template<
typename BasicJsonType,
typename CharType>
16967 friend class ::nlohmann::detail::binary_writer;
16968 template<
typename BasicJsonType,
typename InputType,
typename SAX>
16969 friend class ::nlohmann::detail::binary_reader;
16970 template<
typename BasicJsonType>
16971 friend class ::nlohmann::detail::json_sax_dom_parser;
16972 template<
typename BasicJsonType>
16973 friend class ::nlohmann::detail::json_sax_dom_callback_parser;
16974 friend class ::nlohmann::detail::exception;
16977 using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
16979 JSON_PRIVATE_UNLESS_TESTED:
16981 using lexer = ::nlohmann::detail::lexer_base<basic_json>;
16983 template<
typename InputAdapterType>
16984 static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
16985 InputAdapterType adapter,
16986 detail::parser_callback_t<basic_json>cb =
nullptr,
16987 const bool allow_exceptions =
true,
16988 const bool ignore_comments =
false
16991 return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
16992 std::move(cb), allow_exceptions, ignore_comments);
16996 using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
16997 template<
typename BasicJsonType>
16998 using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
16999 template<
typename BasicJsonType>
17000 using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>;
17001 template<
typename Iterator>
17002 using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>;
17003 template<
typename Base>
using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>;
17005 template<
typename CharType>
17006 using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>;
17008 template<
typename InputType>
17009 using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
17010 template<
typename CharType>
using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
17012 JSON_PRIVATE_UNLESS_TESTED:
17013 using serializer = ::nlohmann::detail::serializer<basic_json>;
17016 using value_t = detail::value_t;
17019 template<
typename T,
typename SFINAE>
17022 using error_handler_t = detail::error_handler_t;
17024 using cbor_tag_handler_t = detail::cbor_tag_handler_t;
17028 using input_format_t = detail::input_format_t;
17082 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
17084 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
17137 result[
"copyright"] =
"(C) 2013-2021 Niels Lohmann";
17138 result[
"name"] =
"JSON for Modern C++";
17139 result[
"url"] =
"https://github.com/nlohmann/json";
17140 result[
"version"][
"string"] =
17141 std::to_string(NLOHMANN_JSON_VERSION_MAJOR) +
"." +
17142 std::to_string(NLOHMANN_JSON_VERSION_MINOR) +
"." +
17143 std::to_string(NLOHMANN_JSON_VERSION_PATCH);
17144 result[
"version"][
"major"] = NLOHMANN_JSON_VERSION_MAJOR;
17145 result[
"version"][
"minor"] = NLOHMANN_JSON_VERSION_MINOR;
17146 result[
"version"][
"patch"] = NLOHMANN_JSON_VERSION_PATCH;
17149 result[
"platform"] =
"win32";
17150 #elif defined __linux__
17151 result[
"platform"] =
"linux";
17152 #elif defined __APPLE__
17153 result[
"platform"] =
"apple";
17154 #elif defined __unix__
17155 result[
"platform"] =
"unix";
17157 result[
"platform"] =
"unknown";
17160 #if defined(__ICC) || defined(__INTEL_COMPILER)
17161 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
17162 #elif defined(__clang__)
17163 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
17164 #elif defined(__GNUC__) || defined(__GNUG__)
17165 result[
"compiler"] = {{
"family",
"gcc"}, {
"version", std::to_string(__GNUC__) +
"." + std::to_string(__GNUC_MINOR__) +
"." + std::to_string(__GNUC_PATCHLEVEL__)}};
17166 #elif defined(__HP_cc) || defined(__HP_aCC)
17167 result[
"compiler"] =
"hp"
17168 #elif defined(__IBMCPP__)
17169 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
17170 #elif defined(_MSC_VER)
17171 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
17172 #elif defined(__PGI)
17173 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
17174 #elif defined(__SUNPRO_CC)
17175 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
17177 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
17181 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
17183 result[
"compiler"][
"c++"] =
"unknown";
17198 #if defined(JSON_HAS_CPP_14)
17292 AllocatorType<std::pair<
const StringType,
17339 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
17706 template<
typename T,
typename... Args>
17708 static T* create(Args&& ... args)
17710 AllocatorType<T> alloc;
17711 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
17713 auto deleter = [&](T * obj)
17715 AllocatorTraits::deallocate(alloc, obj, 1);
17717 std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
17718 AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
17719 JSON_ASSERT(obj !=
nullptr);
17720 return obj.release();
17727 JSON_PRIVATE_UNLESS_TESTED:
17773 json_value() =
default;
17775 json_value(
boolean_t v) noexcept : boolean(v) {}
17787 case value_t::object:
17789 object = create<object_t>();
17793 case value_t::array:
17795 array = create<array_t>();
17799 case value_t::string:
17801 string = create<string_t>(
"");
17805 case value_t::binary:
17807 binary = create<binary_t>();
17811 case value_t::boolean:
17817 case value_t::number_integer:
17823 case value_t::number_unsigned:
17829 case value_t::number_float:
17835 case value_t::null:
17844 if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
17846 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.9.1",
basic_json()));
17856 string = create<string_t>(
value);
17862 string = create<string_t>(std::move(
value));
17868 object = create<object_t>(
value);
17874 object = create<object_t>(std::move(
value));
17880 array = create<array_t>(
value);
17886 array = create<array_t>(std::move(
value));
17892 binary = create<binary_t>(
value);
17898 binary = create<binary_t>(std::move(
value));
17904 binary = create<binary_t>(
value);
17910 binary = create<binary_t>(std::move(
value));
17913 void destroy(
value_t t) noexcept
17916 std::vector<basic_json> stack;
17919 if (t == value_t::array)
17921 stack.reserve(array->size());
17922 std::move(array->begin(), array->end(), std::back_inserter(stack));
17924 else if (t == value_t::object)
17927 for (
auto&& it : *
object)
17929 stack.push_back(std::move(it.second));
17933 while (!stack.empty())
17936 basic_json current_item(std::move(stack.back()));
17941 if (current_item.is_array())
17943 std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(),
17944 std::back_inserter(stack));
17946 current_item.m_value.array->clear();
17948 else if (current_item.is_object())
17950 for (
auto&& it : *current_item.m_value.object)
17952 stack.push_back(std::move(it.second));
17955 current_item.m_value.object->clear();
17964 case value_t::object:
17966 AllocatorType<object_t> alloc;
17967 std::allocator_traits<decltype(alloc)>::destroy(alloc,
object);
17968 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
object, 1);
17972 case value_t::array:
17974 AllocatorType<array_t> alloc;
17975 std::allocator_traits<decltype(alloc)>::destroy(alloc, array);
17976 std::allocator_traits<decltype(alloc)>::deallocate(alloc, array, 1);
17980 case value_t::string:
17982 AllocatorType<string_t> alloc;
17983 std::allocator_traits<decltype(alloc)>::destroy(alloc,
string);
17984 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
string, 1);
17988 case value_t::binary:
17990 AllocatorType<binary_t> alloc;
17991 std::allocator_traits<decltype(alloc)>::destroy(alloc, binary);
17992 std::allocator_traits<decltype(alloc)>::deallocate(alloc, binary, 1);
18023 void assert_invariant(
bool check_parents =
true) const noexcept
18025 JSON_ASSERT(m_type != value_t::object ||
m_value.object !=
nullptr);
18026 JSON_ASSERT(m_type != value_t::array ||
m_value.array !=
nullptr);
18027 JSON_ASSERT(m_type != value_t::string ||
m_value.string !=
nullptr);
18028 JSON_ASSERT(m_type != value_t::binary ||
m_value.binary !=
nullptr);
18030 #if JSON_DIAGNOSTICS
18033 return j.m_parent ==
this;
18036 static_cast<void>(check_parents);
18042 #if JSON_DIAGNOSTICS
18045 case value_t::array:
18047 for (
auto& element : *
m_value.array)
18049 element.m_parent =
this;
18054 case value_t::object:
18056 for (
auto& element : *
m_value.object)
18058 element.second.m_parent =
this;
18071 #if JSON_DIAGNOSTICS
18072 for (
typename iterator::difference_type i = 0; i <
count; ++i)
18074 (it + i)->m_parent =
this;
18077 static_cast<void>(
count);
18084 #if JSON_DIAGNOSTICS
18087 static_cast<void>(j);
18112 using parse_event_t = detail::parse_event_t;
18207 assert_invariant();
18231 assert_invariant();
18297 template <
typename CompatibleType,
18298 typename U = detail::uncvref_t<CompatibleType>,
18299 detail::enable_if_t <
18300 !detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value,
int > = 0 >
18302 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
18303 std::forward<CompatibleType>(val))))
18305 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
18307 assert_invariant();
18336 template <
typename BasicJsonType,
18337 detail::enable_if_t <
18338 detail::is_basic_json<BasicJsonType>::value&& !std::is_same<basic_json, BasicJsonType>::value,
int > = 0 >
18341 using other_boolean_t =
typename BasicJsonType::boolean_t;
18342 using other_number_float_t =
typename BasicJsonType::number_float_t;
18343 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
18344 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
18345 using other_string_t =
typename BasicJsonType::string_t;
18346 using other_object_t =
typename BasicJsonType::object_t;
18347 using other_array_t =
typename BasicJsonType::array_t;
18348 using other_binary_t =
typename BasicJsonType::binary_t;
18350 switch (val.type())
18352 case value_t::boolean:
18353 JSONSerializer<other_boolean_t>::to_json(*
this, val.template get<other_boolean_t>());
18355 case value_t::number_float:
18356 JSONSerializer<other_number_float_t>::to_json(*
this, val.template get<other_number_float_t>());
18358 case value_t::number_integer:
18359 JSONSerializer<other_number_integer_t>::to_json(*
this, val.template get<other_number_integer_t>());
18361 case value_t::number_unsigned:
18362 JSONSerializer<other_number_unsigned_t>::to_json(*
this, val.template get<other_number_unsigned_t>());
18364 case value_t::string:
18365 JSONSerializer<other_string_t>::to_json(*
this, val.template get_ref<const other_string_t&>());
18367 case value_t::object:
18368 JSONSerializer<other_object_t>::to_json(*
this, val.template get_ref<const other_object_t&>());
18370 case value_t::array:
18371 JSONSerializer<other_array_t>::to_json(*
this, val.template get_ref<const other_array_t&>());
18373 case value_t::binary:
18374 JSONSerializer<other_binary_t>::to_json(*
this, val.template get_ref<const other_binary_t&>());
18376 case value_t::null:
18379 case value_t::discarded:
18380 m_type = value_t::discarded;
18383 JSON_ASSERT(
false);
18386 assert_invariant();
18464 bool type_deduction =
true,
18465 value_t manual_type = value_t::array)
18469 bool is_an_object = std::all_of(init.begin(), init.end(),
18470 [](
const detail::json_ref<basic_json>& element_ref)
18472 return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string();
18476 if (!type_deduction)
18479 if (manual_type == value_t::array)
18481 is_an_object =
false;
18485 if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))
18487 JSON_THROW(type_error::create(301,
"cannot create object from initializer list",
basic_json()));
18494 m_type = value_t::object;
18497 for (
auto& element_ref : init)
18499 auto element = element_ref.moved_or_copied();
18501 std::move(*((*element.m_value.array)[0].m_value.string)),
18502 std::move((*element.m_value.array)[1]));
18508 m_type = value_t::array;
18509 m_value.array = create<array_t>(init.begin(), init.end());
18513 assert_invariant();
18547 res.m_type = value_t::binary;
18548 res.m_value = init;
18584 res.m_type = value_t::binary;
18585 res.m_value =
binary_t(init, subtype);
18594 res.m_type = value_t::binary;
18595 res.m_value = std::move(init);
18604 res.m_type = value_t::binary;
18605 res.m_value =
binary_t(std::move(init), subtype);
18649 return basic_json(init,
false, value_t::array);
18693 return basic_json(init,
false, value_t::object);
18719 : m_type(value_t::array)
18721 m_value.array = create<array_t>(cnt, val);
18723 assert_invariant();
18781 template <
class InputIT,
typename std::enable_if <
18782 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
18783 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int >
::type = 0 >
18786 JSON_ASSERT(first.m_object !=
nullptr);
18787 JSON_ASSERT(last.m_object !=
nullptr);
18790 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
18792 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible",
basic_json()));
18796 m_type = first.m_object->m_type;
18801 case value_t::boolean:
18802 case value_t::number_float:
18803 case value_t::number_integer:
18804 case value_t::number_unsigned:
18805 case value_t::string:
18807 if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
18808 || !last.m_it.primitive_iterator.is_end()))
18810 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", *first.m_object));
18821 case value_t::number_integer:
18823 m_value.number_integer = first.m_object->m_value.number_integer;
18827 case value_t::number_unsigned:
18829 m_value.number_unsigned = first.m_object->m_value.number_unsigned;
18833 case value_t::number_float:
18835 m_value.number_float = first.m_object->m_value.number_float;
18839 case value_t::boolean:
18841 m_value.boolean = first.m_object->m_value.boolean;
18845 case value_t::string:
18847 m_value = *first.m_object->m_value.string;
18851 case value_t::object:
18853 m_value.object = create<object_t>(first.m_it.object_iterator,
18854 last.m_it.object_iterator);
18858 case value_t::array:
18860 m_value.array = create<array_t>(first.m_it.array_iterator,
18861 last.m_it.array_iterator);
18865 case value_t::binary:
18867 m_value = *first.m_object->m_value.binary;
18872 JSON_THROW(invalid_iterator::create(206,
"cannot construct with iterators from " + std::string(first.m_object->type_name()), *first.m_object));
18876 assert_invariant();
18884 template<
typename JsonRef,
18885 detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
18886 std::is_same<typename JsonRef::value_type, basic_json>>
::value,
int> = 0 >
18915 : m_type(other.m_type)
18918 other.assert_invariant();
18922 case value_t::object:
18928 case value_t::array:
18934 case value_t::string:
18940 case value_t::boolean:
18946 case value_t::number_integer:
18952 case value_t::number_unsigned:
18958 case value_t::number_float:
18964 case value_t::binary:
18975 assert_invariant();
19005 : m_type(std::move(other.m_type)),
19006 m_value(std::move(other.m_value))
19009 other.assert_invariant(
false);
19012 other.m_type = value_t::null;
19013 other.m_value = {};
19016 assert_invariant();
19043 std::is_nothrow_move_constructible<value_t>::value&&
19044 std::is_nothrow_move_assignable<value_t>::value&&
19045 std::is_nothrow_move_constructible<json_value>::value&&
19046 std::is_nothrow_move_assignable<json_value>::value
19050 other.assert_invariant();
19053 swap(m_type, other.m_type);
19057 assert_invariant();
19078 assert_invariant(
false);
19141 const char indent_char =
' ',
19142 const bool ensure_ascii =
false,
19143 const error_handler_t error_handler = error_handler_t::strict)
const
19146 serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler);
19150 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
19154 s.dump(*
this,
false, ensure_ascii, 0);
19193 constexpr value_t
type() const noexcept
19275 return m_type == value_t::null;
19297 return m_type == value_t::boolean;
19356 return m_type == value_t::number_integer || m_type == value_t::number_unsigned;
19384 return m_type == value_t::number_unsigned;
19412 return m_type == value_t::number_float;
19434 return m_type == value_t::object;
19456 return m_type == value_t::array;
19478 return m_type == value_t::string;
19500 return m_type == value_t::binary;
19527 return m_type == value_t::discarded;
19571 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + std::string(
type_name()), *
this));
19593 constexpr
const array_t* get_impl_ptr(
const array_t* )
const noexcept
19681 template<
typename ReferenceType,
typename ThisType>
19682 static ReferenceType get_ref_impl(ThisType& obj)
19685 auto ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
19687 if (JSON_HEDLEY_LIKELY(ptr !=
nullptr))
19692 JSON_THROW(type_error::create(303,
"incompatible ReferenceType for get_ref, actual type is " + std::string(obj.type_name()), obj));
19714 template<
typename BasicJsonType, detail::enable_if_t<
19715 std::is_same<typename std::remove_const<BasicJsonType>::type, basic_json_t>
::value,
19737 template <
typename BasicJsonType, detail::enable_if_t <
19738 !std::is_same<BasicJsonType, basic_json>::value&&
19739 detail::is_basic_json<BasicJsonType>::value,
int > = 0 >
19784 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>,
19785 detail::enable_if_t <
19786 !detail::is_basic_json<ValueType>::value &&
19787 detail::has_from_json<basic_json_t, ValueType>::value &&
19788 !detail::has_non_default_from_json<basic_json_t, ValueType>::value,
19790 ValueType
get() const noexcept(noexcept(
19791 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
19796 static_assert(!std::is_reference<ValueTypeCV>::value,
19797 "get() cannot be used with reference types, you might want to use get_ref()");
19798 static_assert(std::is_default_constructible<ValueType>::value,
19799 "types must be DefaultConstructible when used with get()");
19802 JSONSerializer<ValueType>::from_json(*
this, ret);
19837 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>,
19838 detail::enable_if_t < !std::is_same<basic_json_t, ValueType>::value &&
19839 detail::has_non_default_from_json<basic_json_t, ValueType>::value,
19841 ValueType
get() const noexcept(noexcept(
19842 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
19844 static_assert(!std::is_reference<ValueTypeCV>::value,
19845 "get() cannot be used with reference types, you might want to use get_ref()");
19846 return JSONSerializer<ValueType>::from_json(*
this);
19882 template <
typename ValueType,
19883 detail::enable_if_t <
19884 !detail::is_basic_json<ValueType>::value&&
19885 detail::has_from_json<basic_json_t, ValueType>::value,
19887 ValueType &
get_to(ValueType& v)
const noexcept(noexcept(
19888 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
19890 JSONSerializer<ValueType>::from_json(*
this, v);
19896 template<
typename ValueType,
19897 detail::enable_if_t <
19898 detail::is_basic_json<ValueType>::value,
19907 typename T, std::size_t N,
19908 typename Array = T (&)[N],
19909 detail::enable_if_t <
19910 detail::has_from_json<basic_json_t, Array>::value,
int > = 0 >
19912 noexcept(noexcept(JSONSerializer<Array>::from_json(
19913 std::declval<const basic_json_t&>(), v)))
19915 JSONSerializer<Array>::from_json(*
this, v);
19946 template<
typename PointerType,
typename std::enable_if<
19947 std::is_pointer<PointerType>::value,
int>
::type = 0>
19948 auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
19951 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
19958 template <
typename PointerType,
typename std::enable_if <
19959 std::is_pointer<PointerType>::value&&
19960 std::is_const<typename std::remove_pointer<PointerType>::type>
::value,
int >
::type = 0 >
19961 constexpr
auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
19964 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
19994 template<
typename PointerType,
typename std::enable_if<
19995 std::is_pointer<PointerType>::value,
int>
::type = 0>
19996 auto get() noexcept -> decltype(std::declval<basic_json_t&>().template
get_ptr<PointerType>())
19999 return get_ptr<PointerType>();
20006 template<
typename PointerType,
typename std::enable_if<
20007 std::is_pointer<PointerType>::value,
int>
::type = 0>
20008 constexpr
auto get() const noexcept -> decltype(std::declval<const basic_json_t&>().template
get_ptr<PointerType>())
20011 return get_ptr<PointerType>();
20040 template<
typename ReferenceType,
typename std::enable_if<
20041 std::is_reference<ReferenceType>::value,
int>
::type = 0>
20045 return get_ref_impl<ReferenceType>(*
this);
20052 template <
typename ReferenceType,
typename std::enable_if <
20053 std::is_reference<ReferenceType>::value&&
20054 std::is_const<typename std::remove_reference<ReferenceType>::type>
::value,
int >
::type = 0 >
20058 return get_ref_impl<ReferenceType>(*
this);
20090 template <
typename ValueType,
typename std::enable_if <
20091 !std::is_pointer<ValueType>::value&&
20092 !std::is_same<ValueType, detail::json_ref<basic_json>>
::value&&
20093 !std::is_same<ValueType, typename string_t::value_type>::value&&
20094 !detail::is_basic_json<ValueType>::value
20095 && !std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>
::value
20096 #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
20097 && !std::is_same<ValueType, typename std::string_view>::value
20099 && detail::is_detected<detail::get_template_function, const basic_json_t&, ValueType>::value
20101 JSON_EXPLICIT
operator ValueType()
const
20104 return get<ValueType>();
20120 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(
type_name()), *
this));
20123 return *get_ptr<binary_t*>();
20131 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(
type_name()), *
this));
20134 return *get_ptr<const binary_t*>();
20177 if (JSON_HEDLEY_LIKELY(
is_array()))
20181 return set_parent(
m_value.array->at(idx));
20183 JSON_CATCH (std::out_of_range&)
20186 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
20191 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
20224 if (JSON_HEDLEY_LIKELY(
is_array()))
20228 return m_value.array->at(idx);
20230 JSON_CATCH (std::out_of_range&)
20233 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
20238 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
20272 reference at(
const typename object_t::key_type& key)
20279 return set_parent(
m_value.object->at(key));
20281 JSON_CATCH (std::out_of_range&)
20284 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found", *
this));
20289 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
20330 return m_value.object->at(key);
20332 JSON_CATCH (std::out_of_range&)
20335 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found", *
this));
20340 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
20374 m_type = value_t::array;
20375 m_value.array = create<array_t>();
20376 assert_invariant();
20380 if (JSON_HEDLEY_LIKELY(
is_array()))
20383 if (idx >=
m_value.array->size())
20385 #if JSON_DIAGNOSTICS
20387 const auto previous_size =
m_value.array->size();
20389 m_value.array->resize(idx + 1);
20391 #if JSON_DIAGNOSTICS
20393 set_parents(
begin() +
static_cast<typename iterator::difference_type
>(previous_size),
static_cast<typename iterator::difference_type
>(idx + 1 - previous_size));
20397 return m_value.array->operator[](idx);
20400 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(
type_name()), *
this));
20425 if (JSON_HEDLEY_LIKELY(
is_array()))
20427 return m_value.array->operator[](idx);
20430 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(
type_name()), *
this));
20465 m_type = value_t::object;
20466 m_value.object = create<object_t>();
20467 assert_invariant();
20473 return set_parent(
m_value.object->operator[](key));
20476 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
20514 JSON_ASSERT(
m_value.object->find(key) !=
m_value.object->end());
20515 return m_value.object->find(key)->second;
20518 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
20548 template<
typename T>
20549 JSON_HEDLEY_NON_NULL(2)
20555 m_type = value_t::object;
20557 assert_invariant();
20563 return set_parent(
m_value.object->operator[](key));
20566 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
20599 template<
typename T>
20600 JSON_HEDLEY_NON_NULL(2)
20606 JSON_ASSERT(
m_value.object->find(key) !=
m_value.object->end());
20607 return m_value.object->find(key)->second;
20610 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
20664 template <
class ValueType,
typename std::enable_if <
20665 detail::is_getable<basic_json_t, ValueType>::value
20666 && !std::is_same<value_t, ValueType>::value,
int >
::type = 0 >
20667 ValueType
value(
const typename object_t::key_type& key,
const ValueType& default_value)
const
20673 const auto it =
find(key);
20676 return it->template get<ValueType>();
20679 return default_value;
20682 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(
type_name()), *
this));
20689 string_t value(
const typename object_t::key_type& key,
const char* default_value)
const
20737 template<
class ValueType,
typename std::enable_if<
20738 detail::is_getable<basic_json_t, ValueType>::value,
int>
::type = 0>
20747 return ptr.get_checked(
this).template get<ValueType>();
20751 return default_value;
20755 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(
type_name()), *
this));
20762 JSON_HEDLEY_NON_NULL(3)
20900 template <
class IteratorType,
typename std::enable_if <
20901 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
20902 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int >
::type
20904 IteratorType
erase(IteratorType pos)
20907 if (JSON_HEDLEY_UNLIKELY(
this != pos.m_object))
20909 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
20912 IteratorType result =
end();
20916 case value_t::boolean:
20917 case value_t::number_float:
20918 case value_t::number_integer:
20919 case value_t::number_unsigned:
20920 case value_t::string:
20921 case value_t::binary:
20923 if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
20925 JSON_THROW(invalid_iterator::create(205,
"iterator out of range", *
this));
20930 AllocatorType<string_t> alloc;
20931 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.string);
20932 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.string, 1);
20937 AllocatorType<binary_t> alloc;
20938 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.binary);
20939 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.binary, 1);
20943 m_type = value_t::null;
20944 assert_invariant();
20948 case value_t::object:
20950 result.m_it.object_iterator =
m_value.object->erase(pos.m_it.object_iterator);
20954 case value_t::array:
20956 result.m_it.array_iterator =
m_value.array->erase(pos.m_it.array_iterator);
20961 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
21013 template <
class IteratorType,
typename std::enable_if <
21014 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21015 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int >
::type
21017 IteratorType
erase(IteratorType first, IteratorType last)
21020 if (JSON_HEDLEY_UNLIKELY(
this != first.m_object ||
this != last.m_object))
21022 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value", *
this));
21025 IteratorType result =
end();
21029 case value_t::boolean:
21030 case value_t::number_float:
21031 case value_t::number_integer:
21032 case value_t::number_unsigned:
21033 case value_t::string:
21034 case value_t::binary:
21036 if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
21037 || !last.m_it.primitive_iterator.is_end()))
21039 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", *
this));
21044 AllocatorType<string_t> alloc;
21045 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.string);
21046 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.string, 1);
21051 AllocatorType<binary_t> alloc;
21052 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.binary);
21053 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.binary, 1);
21057 m_type = value_t::null;
21058 assert_invariant();
21062 case value_t::object:
21064 result.m_it.object_iterator =
m_value.object->erase(first.m_it.object_iterator,
21065 last.m_it.object_iterator);
21069 case value_t::array:
21071 result.m_it.array_iterator =
m_value.array->erase(first.m_it.array_iterator,
21072 last.m_it.array_iterator);
21077 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
21117 return m_value.object->erase(key);
21120 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
21150 if (JSON_HEDLEY_LIKELY(
is_array()))
21152 if (JSON_HEDLEY_UNLIKELY(idx >=
size()))
21154 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
21161 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
21199 template<
typename KeyT>
21202 auto result =
end();
21206 result.m_it.object_iterator =
m_value.object->find(std::forward<KeyT>(key));
21216 template<
typename KeyT>
21219 auto result =
cend();
21223 result.m_it.object_iterator =
m_value.object->find(std::forward<KeyT>(key));
21250 template<
typename KeyT>
21282 template <
typename KeyT,
typename std::enable_if <
21317 return ptr.contains(
this);
21357 result.set_begin();
21397 result.set_begin();
21661 JSON_HEDLEY_DEPRECATED_FOR(3.1.0,
items())
21664 return ref.items();
21670 JSON_HEDLEY_DEPRECATED_FOR(3.1.0,
items())
21673 return ref.items();
21744 iteration_proxy<iterator>
items() noexcept
21746 return iteration_proxy<iterator>(*
this);
21752 iteration_proxy<const_iterator>
items() const noexcept
21754 return iteration_proxy<const_iterator>(*
this);
21809 bool empty() const noexcept
21813 case value_t::null:
21819 case value_t::array:
21822 return m_value.array->empty();
21825 case value_t::object:
21828 return m_value.object->empty();
21886 case value_t::null:
21892 case value_t::array:
21895 return m_value.array->size();
21898 case value_t::object:
21901 return m_value.object->size();
21957 case value_t::array:
21960 return m_value.array->max_size();
21963 case value_t::object:
21966 return m_value.object->max_size();
22024 void clear() noexcept
22028 case value_t::number_integer:
22034 case value_t::number_unsigned:
22040 case value_t::number_float:
22046 case value_t::boolean:
22052 case value_t::string:
22058 case value_t::binary:
22064 case value_t::array:
22070 case value_t::object:
22106 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
22112 m_type = value_t::array;
22114 assert_invariant();
22118 m_value.array->push_back(std::move(val));
22119 set_parent(
m_value.array->back());
22142 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
22148 m_type = value_t::array;
22150 assert_invariant();
22154 m_value.array->push_back(val);
22155 set_parent(
m_value.array->back());
22188 void push_back(
const typename object_t::value_type& val)
22193 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
22199 m_type = value_t::object;
22201 assert_invariant();
22205 auto res =
m_value.object->insert(val);
22206 set_parent(res.first->second);
22246 if (
is_object() && init.size() == 2 && (*init.begin())->is_string())
22248 basic_json&& key = init.begin()->moved_or_copied();
22249 push_back(
typename object_t::value_type(
22250 std::move(key.get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
22291 template<
class... Args>
22297 JSON_THROW(type_error::create(311,
"cannot use emplace_back() with " + std::string(
type_name()), *
this));
22303 m_type = value_t::array;
22305 assert_invariant();
22309 #ifdef JSON_HAS_CPP_17
22310 return set_parent(
m_value.array->emplace_back(std::forward<Args>(args)...));
22312 m_value.array->emplace_back(std::forward<Args>(args)...);
22313 return set_parent(
m_value.array->back());
22344 template<
class... Args>
22345 std::pair<iterator, bool>
emplace(Args&& ... args)
22350 JSON_THROW(type_error::create(311,
"cannot use emplace() with " + std::string(
type_name()), *
this));
22356 m_type = value_t::object;
22358 assert_invariant();
22362 auto res =
m_value.object->emplace(std::forward<Args>(args)...);
22363 set_parent(res.first->second);
22367 it.m_it.object_iterator = res.first;
22370 return {it, res.second};
22376 template<
typename... Args>
22380 JSON_ASSERT(
m_value.array !=
nullptr);
22382 auto insert_pos = std::distance(
m_value.array->begin(), pos.m_it.array_iterator);
22383 m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
22384 result.m_it.array_iterator =
m_value.array->begin() + insert_pos;
22418 if (JSON_HEDLEY_LIKELY(
is_array()))
22421 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22423 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
22427 return set_parents(
insert_iterator(pos, val),
static_cast<typename iterator::difference_type
>(1));
22430 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
22439 return insert(pos, val);
22469 if (JSON_HEDLEY_LIKELY(
is_array()))
22472 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22474 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
22478 return set_parents(
insert_iterator(pos, cnt, val),
static_cast<typename iterator::difference_type
>(cnt));
22481 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
22517 if (JSON_HEDLEY_UNLIKELY(!
is_array()))
22519 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
22523 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22525 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
22529 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22531 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
22534 if (JSON_HEDLEY_UNLIKELY(first.m_object ==
this))
22536 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container", *
this));
22540 return set_parents(
insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator), std::distance(first, last));
22570 if (JSON_HEDLEY_UNLIKELY(!
is_array()))
22572 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
22576 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22578 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
22582 return set_parents(
insert_iterator(pos, ilist.begin(), ilist.end()),
static_cast<typename iterator::difference_type
>(ilist.size()));
22611 if (JSON_HEDLEY_UNLIKELY(!
is_object()))
22613 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
22617 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22619 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
22623 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
22625 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects", *
this));
22628 m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
22655 m_type = value_t::object;
22656 m_value.object = create<object_t>();
22657 assert_invariant();
22662 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(
type_name()), *
this));
22664 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
22666 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(j.type_name()), *
this));
22669 for (
auto it = j.cbegin(); it != j.cend(); ++it)
22671 m_value.object->operator[](it.key()) = it.value();
22706 m_type = value_t::object;
22707 m_value.object = create<object_t>();
22708 assert_invariant();
22713 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(
type_name()), *
this));
22717 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22719 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
22723 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()
22724 || !last.m_object->is_object()))
22726 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects", *
this));
22729 for (
auto it = first; it != last; ++it)
22731 m_value.object->operator[](it.key()) = it.value();
22753 std::is_nothrow_move_constructible<value_t>::value&&
22754 std::is_nothrow_move_assignable<value_t>::value&&
22755 std::is_nothrow_move_constructible<json_value>::value&&
22756 std::is_nothrow_move_assignable<json_value>::value
22759 std::swap(m_type, other.m_type);
22760 std::swap(
m_value, other.m_value);
22763 other.set_parents();
22764 assert_invariant();
22786 std::is_nothrow_move_constructible<value_t>::value&&
22787 std::is_nothrow_move_assignable<value_t>::value&&
22788 std::is_nothrow_move_constructible<json_value>::value&&
22789 std::is_nothrow_move_assignable<json_value>::value
22818 if (JSON_HEDLEY_LIKELY(
is_array()))
22820 std::swap(*(
m_value.array), other);
22824 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
22853 std::swap(*(
m_value.object), other);
22857 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
22886 std::swap(*(
m_value.string), other);
22890 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
22919 std::swap(*(
m_value.binary), other);
22923 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
22933 std::swap(*(
m_value.binary), other);
22937 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23008 const auto lhs_type = lhs.type();
23009 const auto rhs_type = rhs.type();
23011 if (lhs_type == rhs_type)
23015 case value_t::array:
23016 return *lhs.m_value.array == *rhs.m_value.array;
23018 case value_t::object:
23019 return *lhs.m_value.object == *rhs.m_value.object;
23021 case value_t::null:
23024 case value_t::string:
23025 return *lhs.m_value.string == *rhs.m_value.string;
23027 case value_t::boolean:
23028 return lhs.m_value.boolean == rhs.m_value.boolean;
23030 case value_t::number_integer:
23031 return lhs.m_value.number_integer == rhs.m_value.number_integer;
23033 case value_t::number_unsigned:
23034 return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
23036 case value_t::number_float:
23037 return lhs.m_value.number_float == rhs.m_value.number_float;
23039 case value_t::binary:
23040 return *lhs.m_value.binary == *rhs.m_value.binary;
23046 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
23048 return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
23050 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
23052 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_integer);
23054 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
23056 return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
23058 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
23060 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_unsigned);
23062 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
23064 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
23066 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
23068 return lhs.m_value.number_integer ==
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
23078 template<
typename ScalarType,
typename std::enable_if<
23079 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23089 template<
typename ScalarType,
typename std::enable_if<
23090 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23116 return !(lhs == rhs);
23123 template<
typename ScalarType,
typename std::enable_if<
23124 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23134 template<
typename ScalarType,
typename std::enable_if<
23135 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23169 const auto lhs_type = lhs.type();
23170 const auto rhs_type = rhs.type();
23172 if (lhs_type == rhs_type)
23176 case value_t::array:
23179 return (*lhs.m_value.array) < (*rhs.m_value.array);
23181 case value_t::object:
23182 return (*lhs.m_value.object) < (*rhs.m_value.object);
23184 case value_t::null:
23187 case value_t::string:
23188 return (*lhs.m_value.string) < (*rhs.m_value.string);
23190 case value_t::boolean:
23191 return (lhs.m_value.boolean) < (rhs.m_value.boolean);
23193 case value_t::number_integer:
23194 return (lhs.m_value.number_integer) < (rhs.m_value.number_integer);
23196 case value_t::number_unsigned:
23197 return (lhs.m_value.number_unsigned) < (rhs.m_value.number_unsigned);
23199 case value_t::number_float:
23200 return (lhs.m_value.number_float) < (rhs.m_value.number_float);
23202 case value_t::binary:
23203 return (*lhs.m_value.binary) < (*rhs.m_value.binary);
23209 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
23211 return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
23213 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
23215 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_integer);
23217 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
23219 return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
23221 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
23223 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_unsigned);
23225 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
23227 return lhs.m_value.number_integer <
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
23229 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
23231 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
23244 template<
typename ScalarType,
typename std::enable_if<
23245 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23255 template<
typename ScalarType,
typename std::enable_if<
23256 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23283 return !(rhs < lhs);
23290 template<
typename ScalarType,
typename std::enable_if<
23291 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23301 template<
typename ScalarType,
typename std::enable_if<
23302 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23329 return !(lhs <= rhs);
23336 template<
typename ScalarType,
typename std::enable_if<
23337 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23347 template<
typename ScalarType,
typename std::enable_if<
23348 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23375 return !(lhs < rhs);
23382 template<
typename ScalarType,
typename std::enable_if<
23383 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23393 template<
typename ScalarType,
typename std::enable_if<
23394 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23443 const bool pretty_print = o.width() > 0;
23444 const auto indentation = pretty_print ? o.width() : 0;
23450 serializer s(detail::output_adapter<char>(o), o.fill());
23451 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
23463 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator<<(std::ostream&,
const basic_json&))
23530 template<
typename InputType>
23534 const bool allow_exceptions =
true,
23535 const bool ignore_comments =
false)
23538 parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(
true, result);
23568 template<
typename IteratorType>
23573 const bool allow_exceptions =
true,
23574 const bool ignore_comments =
false)
23577 parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(
true, result);
23582 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
parse(ptr, ptr + len))
23585 const bool allow_exceptions =
true,
23586 const bool ignore_comments =
false)
23589 parser(i.get(), cb, allow_exceptions, ignore_comments).parse(
true, result);
23623 template<
typename InputType>
23624 static bool accept(InputType&& i,
23625 const bool ignore_comments =
false)
23627 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false, ignore_comments).accept(
true);
23630 template<
typename IteratorType>
23631 static bool accept(IteratorType first, IteratorType last,
23632 const bool ignore_comments =
false)
23634 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false, ignore_comments).accept(
true);
23638 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
accept(ptr, ptr + len))
23639 static bool accept(detail::span_input_adapter&& i,
23640 const bool ignore_comments =
false)
23642 return parser(i.get(),
nullptr,
false, ignore_comments).accept(
true);
23685 template <
typename InputType,
typename SAX>
23686 JSON_HEDLEY_NON_NULL(2)
23687 static
bool sax_parse(InputType&& i, SAX* sax,
23689 const
bool strict = true,
23690 const
bool ignore_comments = false)
23692 auto ia = detail::input_adapter(std::forward<InputType>(i));
23693 return format == input_format_t::json
23694 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23695 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
23698 template<
class IteratorType,
class SAX>
23699 JSON_HEDLEY_NON_NULL(3)
23700 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
23701 input_format_t format = input_format_t::
json,
23702 const
bool strict = true,
23703 const
bool ignore_comments = false)
23705 auto ia = detail::input_adapter(std::move(first), std::move(last));
23706 return format == input_format_t::json
23707 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23708 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
23711 template <
typename SAX>
23712 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
sax_parse(ptr, ptr + len, ...))
23713 JSON_HEDLEY_NON_NULL(2)
23714 static
bool sax_parse(detail::span_input_adapter&& i, SAX* sax,
23715 input_format_t format = input_format_t::
json,
23716 const
bool strict = true,
23717 const
bool ignore_comments = false)
23720 return format == input_format_t::json
23721 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23722 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
23733 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator>>(std::istream&,
basic_json&))
23766 parser(detail::input_adapter(i)).parse(
false, j);
23813 case value_t::null:
23815 case value_t::object:
23817 case value_t::array:
23819 case value_t::string:
23821 case value_t::boolean:
23823 case value_t::binary:
23825 case value_t::discarded:
23826 return "discarded";
23834 JSON_PRIVATE_UNLESS_TESTED:
23840 value_t m_type = value_t::null;
23845 #if JSON_DIAGNOSTICS
23954 std::vector<uint8_t> result;
23961 binary_writer<uint8_t>(o).write_cbor(j);
23966 binary_writer<char>(o).write_cbor(j);
24049 std::vector<uint8_t> result;
24056 binary_writer<uint8_t>(o).write_msgpack(j);
24061 binary_writer<char>(o).write_msgpack(j);
24151 const bool use_size =
false,
24152 const bool use_type =
false)
24154 std::vector<uint8_t> result;
24155 to_ubjson(j, result, use_size, use_type);
24160 const bool use_size =
false,
const bool use_type =
false)
24162 binary_writer<uint8_t>(o).write_ubjson(j, use_size, use_type);
24166 const bool use_size =
false,
const bool use_type =
false)
24168 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
24230 std::vector<uint8_t> result;
24245 binary_writer<uint8_t>(o).write_bson(j);
24253 binary_writer<char>(o).write_bson(j);
24359 template<
typename InputType>
24362 const bool strict =
true,
24363 const bool allow_exceptions =
true,
24367 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24368 auto ia = detail::input_adapter(std::forward<InputType>(i));
24369 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24370 return res ? result :
basic_json(value_t::discarded);
24376 template<
typename IteratorType>
24379 const bool strict =
true,
24380 const bool allow_exceptions =
true,
24384 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24385 auto ia = detail::input_adapter(std::move(first), std::move(last));
24386 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24387 return res ? result :
basic_json(value_t::discarded);
24390 template<
typename T>
24392 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_cbor(ptr, ptr + len))
24394 const bool strict =
true,
24395 const bool allow_exceptions =
true,
24398 return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
24405 const bool strict =
true,
24406 const bool allow_exceptions =
true,
24407 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24410 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24412 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24413 return res ? result :
basic_json(value_t::discarded);
24502 template<
typename InputType>
24505 const bool strict =
true,
24506 const bool allow_exceptions =
true)
24509 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24510 auto ia = detail::input_adapter(std::forward<InputType>(i));
24511 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
24512 return res ? result :
basic_json(value_t::discarded);
24518 template<
typename IteratorType>
24521 const bool strict =
true,
24522 const bool allow_exceptions =
true)
24525 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24526 auto ia = detail::input_adapter(std::move(first), std::move(last));
24527 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
24528 return res ? result :
basic_json(value_t::discarded);
24532 template<
typename T>
24534 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_msgpack(ptr, ptr + len))
24536 const bool strict =
true,
24537 const bool allow_exceptions =
true)
24539 return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
24543 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_msgpack(ptr, ptr + len))
24545 const bool strict =
true,
24546 const bool allow_exceptions =
true)
24549 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24551 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
24552 return res ? result :
basic_json(value_t::discarded);
24618 template<
typename InputType>
24621 const bool strict =
true,
24622 const bool allow_exceptions =
true)
24625 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24626 auto ia = detail::input_adapter(std::forward<InputType>(i));
24627 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
24628 return res ? result :
basic_json(value_t::discarded);
24634 template<
typename IteratorType>
24637 const bool strict =
true,
24638 const bool allow_exceptions =
true)
24641 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24642 auto ia = detail::input_adapter(std::move(first), std::move(last));
24643 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
24644 return res ? result :
basic_json(value_t::discarded);
24647 template<
typename T>
24649 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_ubjson(ptr, ptr + len))
24651 const bool strict =
true,
24652 const bool allow_exceptions =
true)
24654 return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
24658 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_ubjson(ptr, ptr + len))
24660 const bool strict =
true,
24661 const bool allow_exceptions =
true)
24664 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24666 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
24667 return res ? result :
basic_json(value_t::discarded);
24731 template<
typename InputType>
24734 const bool strict =
true,
24735 const bool allow_exceptions =
true)
24738 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24739 auto ia = detail::input_adapter(std::forward<InputType>(i));
24740 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
24741 return res ? result :
basic_json(value_t::discarded);
24747 template<
typename IteratorType>
24750 const bool strict =
true,
24751 const bool allow_exceptions =
true)
24754 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24755 auto ia = detail::input_adapter(std::move(first), std::move(last));
24756 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
24757 return res ? result :
basic_json(value_t::discarded);
24760 template<
typename T>
24762 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_bson(ptr, ptr + len))
24764 const bool strict =
true,
24765 const bool allow_exceptions =
true)
24767 return from_bson(ptr, ptr + len, strict, allow_exceptions);
24771 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_bson(ptr, ptr + len))
24773 const bool strict =
true,
24774 const bool allow_exceptions =
true)
24777 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24779 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
24780 return res ? result :
basic_json(value_t::discarded);
24826 return ptr.get_unchecked(
this);
24854 return ptr.get_unchecked(
this);
24897 return ptr.get_checked(
this);
24940 return ptr.get_checked(
this);
24968 json_pointer::flatten(
"", *
this, result);
25004 return json_pointer::unflatten(*
this);
25069 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
25071 const auto get_op = [](
const std::string & op)
25075 return patch_operations::add;
25077 if (op ==
"remove")
25079 return patch_operations::remove;
25081 if (op ==
"replace")
25083 return patch_operations::replace;
25087 return patch_operations::move;
25091 return patch_operations::copy;
25095 return patch_operations::test;
25098 return patch_operations::invalid;
25113 if (top_pointer != ptr)
25115 result.
at(top_pointer);
25119 const auto last_path = ptr.
back();
25123 switch (parent.m_type)
25125 case value_t::null:
25126 case value_t::object:
25129 parent[last_path] = val;
25133 case value_t::array:
25135 if (last_path ==
"-")
25142 const auto idx = json_pointer::array_index(last_path);
25143 if (JSON_HEDLEY_UNLIKELY(idx > parent.size()))
25146 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", parent));
25150 parent.insert(parent.begin() +
static_cast<difference_type>(idx), val);
25157 JSON_ASSERT(
false);
25162 const auto operation_remove = [
this, &result](
json_pointer & ptr)
25165 const auto last_path = ptr.back();
25170 if (parent.is_object())
25173 auto it = parent.
find(last_path);
25174 if (JSON_HEDLEY_LIKELY(it != parent.end()))
25180 JSON_THROW(out_of_range::create(403,
"key '" + last_path +
"' not found", *
this));
25183 else if (parent.is_array())
25186 parent.erase(json_pointer::array_index(last_path));
25191 if (JSON_HEDLEY_UNLIKELY(!json_patch.
is_array()))
25193 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", json_patch));
25197 for (
const auto& val : json_patch)
25200 const auto get_value = [&val](
const std::string & op,
25201 const std::string & member,
25205 auto it = val.m_value.object->find(member);
25208 const auto error_msg = (op ==
"op") ?
"operation" :
"operation '" + op +
"'";
25211 if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end()))
25213 JSON_THROW(parse_error::create(105, 0, error_msg +
" must have member '" + member +
"'", val));
25217 if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
25219 JSON_THROW(parse_error::create(105, 0, error_msg +
" must have string member '" + member +
"'", val));
25227 if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
25229 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", val));
25233 const auto op = get_value(
"op",
"op",
true).template get<std::string>();
25234 const auto path = get_value(op,
"path",
true).template get<std::string>();
25237 switch (get_op(op))
25239 case patch_operations::add:
25241 operation_add(ptr, get_value(
"add",
"value",
false));
25245 case patch_operations::remove:
25247 operation_remove(ptr);
25251 case patch_operations::replace:
25254 result.
at(ptr) = get_value(
"replace",
"value",
false);
25258 case patch_operations::move:
25260 const auto from_path = get_value(
"move",
"from",
true).template get<std::string>();
25270 operation_remove(from_ptr);
25271 operation_add(ptr, v);
25275 case patch_operations::copy:
25277 const auto from_path = get_value(
"copy",
"from",
true).template get<std::string>();
25286 operation_add(ptr, v);
25290 case patch_operations::test:
25292 bool success =
false;
25297 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
25305 if (JSON_HEDLEY_UNLIKELY(!success))
25307 JSON_THROW(other_error::create(501,
"unsuccessful: " + val.dump(), val));
25317 JSON_THROW(parse_error::create(105, 0,
"operation value '" + op +
"' is invalid", val));
25360 const std::string& path =
"")
25366 if (source == target)
25371 if (source.type() != target.type())
25376 {
"op",
"replace"}, {
"path", path}, {
"value", target}
25381 switch (source.type())
25383 case value_t::array:
25387 while (i < source.size() && i < target.size())
25390 auto temp_diff =
diff(source[i], target[i], path +
"/" + std::to_string(i));
25391 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
25400 while (i < source.size())
25407 {
"path", path +
"/" + std::to_string(i)}
25413 while (i < target.size())
25418 {
"path", path +
"/-"},
25419 {
"value", target[i]}
25427 case value_t::object:
25430 for (
auto it = source.cbegin(); it != source.cend(); ++it)
25433 const auto key = detail::escape(it.key());
25435 if (target.find(it.key()) != target.end())
25438 auto temp_diff =
diff(it.value(), target[it.key()], path +
"/" + key);
25439 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
25446 {
"op",
"remove"}, {
"path", path +
"/" + key}
25452 for (
auto it = target.cbegin(); it != target.cend(); ++it)
25454 if (source.find(it.key()) == source.end())
25457 const auto key = detail::escape(it.key());
25460 {
"op",
"add"}, {
"path", path +
"/" + key},
25461 {
"value", it.value()}
25474 {
"op",
"replace"}, {
"path", path}, {
"value", target}
25536 if (apply_patch.is_object())
25542 for (
auto it = apply_patch.begin(); it != apply_patch.end(); ++it)
25544 if (it.value().is_null())
25556 *
this = apply_patch;
25572 NLOHMANN_BASIC_JSON_TPL_DECLARATION
25573 std::string
to_string(
const NLOHMANN_BASIC_JSON_TPL& j)
25598 return nlohmann::detail::hash(j);
25606 struct less<::nlohmann::detail::value_t>
25612 bool operator()(nlohmann::detail::value_t lhs,
25613 nlohmann::detail::value_t rhs)
const noexcept
25615 return nlohmann::detail::operator<(lhs, rhs);
25620 #ifndef JSON_HAS_CPP_20
25629 is_nothrow_move_constructible<nlohmann::json>::value&&
25630 is_nothrow_move_assignable<nlohmann::json>::value
25653 JSON_HEDLEY_NON_NULL(1)
25654 inline
nlohmann::json operator "" _json(const
char* s, std::
size_t n)
25672 JSON_HEDLEY_NON_NULL(1)
25673 inline
nlohmann::json::json_pointer operator "" _json_pointer(const
char* s, std::
size_t n)
25682 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
25683 #pragma GCC diagnostic pop
25685 #if defined(__clang__)
25686 #pragma GCC diagnostic pop
25691 #undef JSON_INTERNAL_CATCH
25695 #undef JSON_PRIVATE_UNLESS_TESTED
25696 #undef JSON_HAS_CPP_14
25697 #undef JSON_HAS_CPP_17
25698 #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
25699 #undef NLOHMANN_BASIC_JSON_TPL
25700 #undef JSON_EXPLICIT
25703 #undef JSON_HEDLEY_ALWAYS_INLINE
25704 #undef JSON_HEDLEY_ARM_VERSION
25705 #undef JSON_HEDLEY_ARM_VERSION_CHECK
25706 #undef JSON_HEDLEY_ARRAY_PARAM
25707 #undef JSON_HEDLEY_ASSUME
25708 #undef JSON_HEDLEY_BEGIN_C_DECLS
25709 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
25710 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
25711 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
25712 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
25713 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
25714 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
25715 #undef JSON_HEDLEY_CLANG_HAS_WARNING
25716 #undef JSON_HEDLEY_COMPCERT_VERSION
25717 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
25718 #undef JSON_HEDLEY_CONCAT
25719 #undef JSON_HEDLEY_CONCAT3
25720 #undef JSON_HEDLEY_CONCAT3_EX
25721 #undef JSON_HEDLEY_CONCAT_EX
25722 #undef JSON_HEDLEY_CONST
25723 #undef JSON_HEDLEY_CONSTEXPR
25724 #undef JSON_HEDLEY_CONST_CAST
25725 #undef JSON_HEDLEY_CPP_CAST
25726 #undef JSON_HEDLEY_CRAY_VERSION
25727 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
25728 #undef JSON_HEDLEY_C_DECL
25729 #undef JSON_HEDLEY_DEPRECATED
25730 #undef JSON_HEDLEY_DEPRECATED_FOR
25731 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
25732 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
25733 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
25734 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
25735 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
25736 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
25737 #undef JSON_HEDLEY_DIAGNOSTIC_POP
25738 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
25739 #undef JSON_HEDLEY_DMC_VERSION
25740 #undef JSON_HEDLEY_DMC_VERSION_CHECK
25741 #undef JSON_HEDLEY_EMPTY_BASES
25742 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
25743 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
25744 #undef JSON_HEDLEY_END_C_DECLS
25745 #undef JSON_HEDLEY_FLAGS
25746 #undef JSON_HEDLEY_FLAGS_CAST
25747 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
25748 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
25749 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
25750 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
25751 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
25752 #undef JSON_HEDLEY_GCC_HAS_FEATURE
25753 #undef JSON_HEDLEY_GCC_HAS_WARNING
25754 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
25755 #undef JSON_HEDLEY_GCC_VERSION
25756 #undef JSON_HEDLEY_GCC_VERSION_CHECK
25757 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
25758 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
25759 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
25760 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
25761 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
25762 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
25763 #undef JSON_HEDLEY_GNUC_HAS_WARNING
25764 #undef JSON_HEDLEY_GNUC_VERSION
25765 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
25766 #undef JSON_HEDLEY_HAS_ATTRIBUTE
25767 #undef JSON_HEDLEY_HAS_BUILTIN
25768 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
25769 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
25770 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
25771 #undef JSON_HEDLEY_HAS_EXTENSION
25772 #undef JSON_HEDLEY_HAS_FEATURE
25773 #undef JSON_HEDLEY_HAS_WARNING
25774 #undef JSON_HEDLEY_IAR_VERSION
25775 #undef JSON_HEDLEY_IAR_VERSION_CHECK
25776 #undef JSON_HEDLEY_IBM_VERSION
25777 #undef JSON_HEDLEY_IBM_VERSION_CHECK
25778 #undef JSON_HEDLEY_IMPORT
25779 #undef JSON_HEDLEY_INLINE
25780 #undef JSON_HEDLEY_INTEL_CL_VERSION
25781 #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
25782 #undef JSON_HEDLEY_INTEL_VERSION
25783 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
25784 #undef JSON_HEDLEY_IS_CONSTANT
25785 #undef JSON_HEDLEY_IS_CONSTEXPR_
25786 #undef JSON_HEDLEY_LIKELY
25787 #undef JSON_HEDLEY_MALLOC
25788 #undef JSON_HEDLEY_MCST_LCC_VERSION
25789 #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
25790 #undef JSON_HEDLEY_MESSAGE
25791 #undef JSON_HEDLEY_MSVC_VERSION
25792 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
25793 #undef JSON_HEDLEY_NEVER_INLINE
25794 #undef JSON_HEDLEY_NON_NULL
25795 #undef JSON_HEDLEY_NO_ESCAPE
25796 #undef JSON_HEDLEY_NO_RETURN
25797 #undef JSON_HEDLEY_NO_THROW
25798 #undef JSON_HEDLEY_NULL
25799 #undef JSON_HEDLEY_PELLES_VERSION
25800 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
25801 #undef JSON_HEDLEY_PGI_VERSION
25802 #undef JSON_HEDLEY_PGI_VERSION_CHECK
25803 #undef JSON_HEDLEY_PREDICT
25804 #undef JSON_HEDLEY_PRINTF_FORMAT
25805 #undef JSON_HEDLEY_PRIVATE
25806 #undef JSON_HEDLEY_PUBLIC
25807 #undef JSON_HEDLEY_PURE
25808 #undef JSON_HEDLEY_REINTERPRET_CAST
25809 #undef JSON_HEDLEY_REQUIRE
25810 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
25811 #undef JSON_HEDLEY_REQUIRE_MSG
25812 #undef JSON_HEDLEY_RESTRICT
25814 #undef JSON_HEDLEY_SENTINEL
25815 #undef JSON_HEDLEY_STATIC_ASSERT
25816 #undef JSON_HEDLEY_STATIC_CAST
25817 #undef JSON_HEDLEY_STRINGIFY
25818 #undef JSON_HEDLEY_STRINGIFY_EX
25819 #undef JSON_HEDLEY_SUNPRO_VERSION
25820 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
25821 #undef JSON_HEDLEY_TINYC_VERSION
25822 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
25823 #undef JSON_HEDLEY_TI_ARMCL_VERSION
25824 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
25825 #undef JSON_HEDLEY_TI_CL2000_VERSION
25826 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
25827 #undef JSON_HEDLEY_TI_CL430_VERSION
25828 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
25829 #undef JSON_HEDLEY_TI_CL6X_VERSION
25830 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
25831 #undef JSON_HEDLEY_TI_CL7X_VERSION
25832 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
25833 #undef JSON_HEDLEY_TI_CLPRU_VERSION
25834 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
25835 #undef JSON_HEDLEY_TI_VERSION
25836 #undef JSON_HEDLEY_TI_VERSION_CHECK
25837 #undef JSON_HEDLEY_UNAVAILABLE
25838 #undef JSON_HEDLEY_UNLIKELY
25839 #undef JSON_HEDLEY_UNPREDICTABLE
25840 #undef JSON_HEDLEY_UNREACHABLE
25841 #undef JSON_HEDLEY_UNREACHABLE_RETURN
25842 #undef JSON_HEDLEY_VERSION
25843 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
25844 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
25845 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
25846 #undef JSON_HEDLEY_VERSION_ENCODE
25847 #undef JSON_HEDLEY_WARNING
25850 #undef JSON_HEDLEY_FALL_THROUGH
static basic_json binary(typename binary_t::container_type &&init, std::uint8_t subtype)
explicitly create a binary array (with subtype)
constexpr auto get() const noexcept -> decltype(std::declval< const basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
detail::parser_callback_t< basic_json > parser_callback_t
per-element parser callback type
bool contains(KeyT &&key) const
check the existence of an element in a JSON object
const_reverse_iterator crbegin() const noexcept
returns a const reverse iterator to the last element
basic_json get() const
get special-case overload
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
constexpr bool is_number_float() const noexcept
return whether value is a floating-point number
NumberIntegerType number_integer_t
a type for a number (integer)
friend bool operator==(const_reference lhs, const_reference rhs) noexcept
comparison: equal
static bool sax_parse(InputType &&i, SAX *sax, input_format_t format=input_format_t::json, const bool strict=true, const bool ignore_comments=false)
generate SAX events
detail::exception exception
general exception of the basic_json class
ReferenceType get_ref()
get a reference value (implicit)
static basic_json parse(InputType &&i, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
deserialize from a compatible input
reference emplace_back(Args &&... args)
add an object to an array
static basic_json from_cbor(const T *ptr, std::size_t len, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
basic_json(const value_t v)
create an empty value with a given type
basic_json & operator=(basic_json other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value)
copy assignment
size_type max_size() const noexcept
returns the maximum possible number of elements
basic_json(CompatibleType &&val) noexcept(noexcept(JSONSerializer< U >::to_json(std::declval< basic_json_t & >(), std::forward< CompatibleType >(val))))
create a JSON value
static basic_json diff(const basic_json &source, const basic_json &target, const std::string &path="")
creates a diff as a JSON patch
detail::input_format_t input_format_t
value_type & reference
the type of an element reference
const_reverse_iterator crend() const noexcept
returns a const reverse iterator to one before the first
detail::out_of_range out_of_range
exception indicating access out of the defined range
static iteration_proxy< iterator > iterator_wrapper(reference ref) noexcept
wrapper to access iterator member functions in range-based for
iterator begin() noexcept
returns an iterator to the first element
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
static std::vector< uint8_t > to_ubjson(const basic_json &j, const bool use_size=false, const bool use_type=false)
create a UBJSON serialization of a given JSON value
basic_json(const JsonRef &ref)
static basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
const_iterator cend() const noexcept
returns a const iterator to one past the last element
reference back()
access the last element
static bool accept(InputType &&i, const bool ignore_comments=false)
check if the input is valid JSON
StringType string_t
a type for a string
size_type size() const noexcept
returns the number of elements
friend std::ostream & operator>>(const basic_json &j, std::ostream &o)
serialize to stream
static basic_json meta()
returns version information on the library
void update(const_reference j)
updates a JSON object from another object, overwriting existing keys
std::size_t size_type
a type to represent container sizes
std::ptrdiff_t difference_type
a type to represent differences between iterators
static basic_json binary(const typename binary_t::container_type &init)
explicitly create a binary array (without subtype)
reference operator+=(basic_json &&val)
add an object to an array
basic_json(const BasicJsonType &val)
create a JSON value from an existing one
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
the type of an element const pointer
typename std::allocator_traits< allocator_type >::pointer pointer
the type of an element pointer
static basic_json from_cbor(InputType &&i, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
create a JSON value from an input in CBOR format
BooleanType boolean_t
a type for a boolean
void push_back(initializer_list_t init)
add an object to an object
const char * type_name() const noexcept
return the type as string
string_t dump(const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
serialization
IteratorType erase(IteratorType pos)
remove element given an iterator
static basic_json from_bson(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
Create a JSON value from an input in BSON format.
constexpr bool is_structured() const noexcept
return whether type is structured
reference at(size_type idx)
access specified array element with bounds checking
reference front()
access the first element
constexpr bool is_primitive() const noexcept
return whether type is primitive
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
detail::cbor_tag_handler_t cbor_tag_handler_t
how to treat CBOR tags
detail::parse_error parse_error
exception indicating a parse error
constexpr bool is_object() const noexcept
return whether value is an object
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
NumberFloatType number_float_t
a type for a number (floating-point)
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
a reverse iterator for a basic_json container
friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
comparison: less than or equal
bool empty() const noexcept
checks whether the container is empty.
friend std::ostream & operator<<(std::ostream &o, const basic_json &j)
serialize to stream
basic_json(const basic_json &other)
copy constructor
~basic_json() noexcept
destructor
friend struct detail::external_constructor
BasicJsonType get() const
get special-case overload
basic_json(basic_json &&other) noexcept
move constructor
detail::invalid_iterator invalid_iterator
exception indicating errors with iterators
friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
comparison: not equal
detail::other_error other_error
exception indicating other library errors
json_value m_value
the value of the current element
friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
comparison: greater than or equal
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
ReferenceType get_ref() const
get a reference value (implicit)
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
auto get_ptr() noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
ArrayType< basic_json, AllocatorType< basic_json > > array_t
a type for an array
Array get_to(T(&v)[N]) const noexcept(noexcept(JSONSerializer< Array >::from_json(std::declval< const basic_json_t & >(), v)))
friend bool operator>(const_reference lhs, const_reference rhs) noexcept
comparison: greater than
ValueType get() const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), std::declval< ValueType & >())))
get a value (explicit)
constexpr bool is_boolean() const noexcept
return whether value is a boolean
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
iterator end() noexcept
returns an iterator to one past the last element
void swap(reference other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
void clear() noexcept
clears the contents
constexpr bool is_binary() const noexcept
return whether value is a binary array
static std::vector< uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
static basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
reference operator[](size_type idx)
access specified array element
ValueType & get_to(ValueType &v) const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), v)))
get a value (explicit)
iter_impl< basic_json > iterator
an iterator for a basic_json container
static std::vector< uint8_t > to_bson(const basic_json &j)
Serializes the given JSON object j to BSON and returns a vector containing the corresponding BSON-rep...
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
a const reverse iterator for a basic_json container
static basic_json from_ubjson(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in UBJSON format
::nlohmann::json_pointer< basic_json > json_pointer
JSON Pointer, see nlohmann::json_pointer.
friend bool operator<(const_reference lhs, const_reference rhs) noexcept
comparison: less than
static basic_json binary(typename binary_t::container_type &&init)
explicitly create a binary array (without subtype)
constexpr bool is_string() const noexcept
return whether value is a string
constexpr bool is_array() const noexcept
return whether value is an array
iterator insert_iterator(const_iterator pos, Args &&... args)
basic_json flatten() const
return flattened JSON value
const value_type & const_reference
the type of an element const reference
void push_back(basic_json &&val)
add an object to an array
size_type count(KeyT &&key) const
returns the number of occurrences of a key in a JSON object
const binary_t & get_binary() const
constexpr bool is_number() const noexcept
return whether value is a number
std::less< StringType > object_comparator_t
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
constexpr bool is_number_integer() const noexcept
return whether value is an integer number
std::initializer_list< detail::json_ref< basic_json > > initializer_list_t
helper type for initializer lists of basic_json values
ValueType & get_to(ValueType &v) const
static basic_json binary(const typename binary_t::container_type &init, std::uint8_t subtype)
explicitly create a binary array (with subtype)
iterator find(KeyT &&key)
find an element in a JSON object
detail::type_error type_error
exception indicating executing a member function with a wrong type
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
AllocatorType< basic_json > allocator_type
the allocator type
nlohmann::byte_container_with_subtype< BinaryType > binary_t
a type for a packed binary type
JSONSerializer< T, SFINAE > json_serializer
ValueType get() const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >())))
get a value (explicit); special case
static std::vector< uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
static basic_json from_msgpack(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in MessagePack format
basic_json patch(const basic_json &json_patch) const
applies a JSON patch
basic_json unflatten() const
unflatten a previously flattened JSON value
NumberUnsignedType number_unsigned_t
a type for a number (unsigned)
const_iterator cbegin() const noexcept
returns a const iterator to the first element
basic_json(initializer_list_t init, bool type_deduction=true, value_t manual_type=value_t::array)
create a container (array or object) from an initializer list
iterator insert(const_iterator pos, const basic_json &val)
inserts element
iter_impl< const basic_json > const_iterator
a const iterator for a basic_json container
constexpr bool is_discarded() const noexcept
return whether value is discarded
constexpr bool is_null() const noexcept
return whether value is null
ObjectType< StringType, basic_json, object_comparator_t, AllocatorType< std::pair< const StringType, basic_json > >> object_t
a type for an object
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
static allocator_type get_allocator()
returns the allocator associated with the container
constexpr auto get_ptr() const noexcept -> decltype(std::declval< const basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
a class to store JSON values
BinaryType container_type
the type of the underlying container
void set_subtype(std::uint8_t subtype_) noexcept
sets the binary subtype
byte_container_with_subtype(const container_type &b) noexcept(noexcept(container_type(b)))
byte_container_with_subtype(container_type &&b) noexcept(noexcept(container_type(std::move(b))))
bool operator!=(const byte_container_with_subtype &rhs) const
void clear_subtype() noexcept
clears the binary subtype
byte_container_with_subtype() noexcept(noexcept(container_type()))
byte_container_with_subtype(const container_type &b, std::uint8_t subtype_) noexcept(noexcept(container_type(b)))
constexpr bool has_subtype() const noexcept
return whether the value has a subtype
byte_container_with_subtype(container_type &&b, std::uint8_t subtype_) noexcept(noexcept(container_type(std::move(b))))
constexpr std::uint8_t subtype() const noexcept
return the binary subtype
bool operator==(const byte_container_with_subtype &rhs) const
an internal type for a backed binary type
const std::string & back() const
return last reference token
std::string to_string() const
return a string representation of the JSON pointer
friend bool operator==(json_pointer const &lhs, json_pointer const &rhs) noexcept
compares two JSON pointers for equality
void pop_back()
remove last reference token
bool empty() const noexcept
return whether pointer points to the root document
friend bool operator!=(json_pointer const &lhs, json_pointer const &rhs) noexcept
compares two JSON pointers for inequality
void push_back(const std::string &token)
append an unescaped token at the end of the reference pointer
json_pointer & operator/=(const json_pointer &ptr)
append another JSON pointer at the end of this JSON pointer
json_pointer & operator/=(std::size_t array_idx)
append an array index at the end of this JSON pointer
json_pointer(const std::string &s="")
create JSON pointer
friend json_pointer operator/(const json_pointer &lhs, const json_pointer &rhs)
create a new JSON pointer by appending the right JSON pointer at the end of the left JSON pointer
friend json_pointer operator/(const json_pointer &ptr, std::string token)
create a new JSON pointer by appending the unescaped token at the end of the JSON pointer
json_pointer & operator/=(std::string token)
append an unescaped reference token at the end of this JSON pointer
void push_back(std::string &&token)
append an unescaped token at the end of the reference pointer
friend json_pointer operator/(const json_pointer &ptr, std::size_t array_idx)
create a new JSON pointer by appending the array-index-token at the end of the JSON pointer
json_pointer parent_pointer() const
returns the parent of this JSON pointer
constexpr const auto & to_json
constexpr const auto & from_json
basic_json<> json
default JSON class
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
namespace for Niels Lohmann
static auto to_json(BasicJsonType &j, ValueType &&val) noexcept(noexcept(::nlohmann::to_json(j, std::forward< ValueType >(val)))) -> decltype(::nlohmann::to_json(j, std::forward< ValueType >(val)), void())
convert any value type to a JSON value
static auto from_json(BasicJsonType &&j, ValueType &val) noexcept(noexcept(::nlohmann::from_json(std::forward< BasicJsonType >(j), val))) -> decltype(::nlohmann::from_json(std::forward< BasicJsonType >(j), val), void())
convert a JSON value to any value type
default JSONSerializer template argument
virtual bool start_object(std::size_t elements)=0
the beginning of an object was read
virtual bool string(string_t &val)=0
a string was read
typename BasicJsonType::number_integer_t number_integer_t
typename BasicJsonType::binary_t binary_t
virtual bool end_array()=0
the end of an array was read
virtual bool key(string_t &val)=0
an object key was read
typename BasicJsonType::number_unsigned_t number_unsigned_t
virtual bool binary(binary_t &val)=0
a binary string was read
typename BasicJsonType::number_float_t number_float_t
virtual bool start_array(std::size_t elements)=0
the beginning of an array was read
virtual bool parse_error(std::size_t position, const std::string &last_token, const detail::exception &ex)=0
a parse error occurred
virtual bool boolean(bool val)=0
a boolean value was read
virtual bool end_object()=0
the end of an object was read
virtual bool number_unsigned(number_unsigned_t val)=0
an unsigned integer number was read
typename BasicJsonType::string_t string_t
virtual bool number_float(number_float_t val, const string_t &s)=0
an floating-point number was read
virtual ~json_sax()=default
virtual bool number_integer(number_integer_t val)=0
an integer number was read
std::pair< iterator, bool > insert(const value_type &value)
ordered_map(std::initializer_list< T > init, const Allocator &alloc=Allocator())
std::vector< std::pair< const Key, T >, Allocator > Container
iterator find(const Key &key)
iterator erase(iterator pos)
void insert(InputIt first, InputIt last)
std::pair< iterator, bool > emplace(const key_type &key, T &&t)
const_iterator find(const Key &key) const
std::pair< iterator, bool > insert(value_type &&value)
size_type erase(const Key &key)
const T & operator[](const Key &key) const
ordered_map(const Allocator &alloc=Allocator())
typename std::enable_if< std::is_convertible< typename std::iterator_traits< InputIt >::iterator_category, std::input_iterator_tag >::value >::type require_input_iter
const T & at(const Key &key) const
ordered_map(It first, It last, const Allocator &alloc=Allocator())
T & operator[](const Key &key)
size_type count(const Key &key) const