18#ifndef INCLUDE_NLOHMANN_JSON_HPP_
19#define INCLUDE_NLOHMANN_JSON_HPP_
24#include <initializer_list>
56#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
57#if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && \
58 defined(NLOHMANN_JSON_VERSION_PATCH)
59#if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || \
60 NLOHMANN_JSON_VERSION_PATCH != 3
61#warning "Already included a different version of the library!"
66#define NLOHMANN_JSON_VERSION_MAJOR 3
67#define NLOHMANN_JSON_VERSION_MINOR 11
68#define NLOHMANN_JSON_VERSION_PATCH 3
70#ifndef JSON_DIAGNOSTICS
71#define JSON_DIAGNOSTICS 0
74#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
75#define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0
79#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag
81#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS
84#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
85#define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp
87#define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON
90#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION
91#define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0
95#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi##a##b
96#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b)
98#define NLOHMANN_JSON_ABI_TAGS \
99 NLOHMANN_JSON_ABI_TAGS_CONCAT(NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \
100 NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON)
103#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) _v##major##_##minor##_##patch
104#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \
105 NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch)
107#if NLOHMANN_JSON_NAMESPACE_NO_VERSION
108#define NLOHMANN_JSON_NAMESPACE_VERSION
110#define NLOHMANN_JSON_NAMESPACE_VERSION \
111 NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT( \
112 NLOHMANN_JSON_VERSION_MAJOR, NLOHMANN_JSON_VERSION_MINOR, NLOHMANN_JSON_VERSION_PATCH)
116#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a##b
117#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b)
119#ifndef NLOHMANN_JSON_NAMESPACE
120#define NLOHMANN_JSON_NAMESPACE \
121 nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT(NLOHMANN_JSON_ABI_TAGS, \
122 NLOHMANN_JSON_NAMESPACE_VERSION)
125#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
126#define NLOHMANN_JSON_NAMESPACE_BEGIN \
127 namespace nlohmann { \
128 inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT(NLOHMANN_JSON_ABI_TAGS, \
129 NLOHMANN_JSON_NAMESPACE_VERSION) {
132#ifndef NLOHMANN_JSON_NAMESPACE_END
133#define NLOHMANN_JSON_NAMESPACE_END \
149#include <forward_list>
154#include <type_traits>
155#include <unordered_map>
210#include <type_traits>
223NLOHMANN_JSON_NAMESPACE_BEGIN
229template <
typename... Ts>
using void_t =
typename make_void<Ts...>::type;
232NLOHMANN_JSON_NAMESPACE_END
234NLOHMANN_JSON_NAMESPACE_BEGIN
240 ~nonesuch() =
delete;
241 nonesuch(nonesuch
const&) =
delete;
242 nonesuch(nonesuch
const&&) =
delete;
243 void operator=(nonesuch
const&) =
delete;
244 void operator=(nonesuch&&) =
delete;
247template <
class Default,
class AlwaysVoid,
template <
class...>
class Op,
class... Args>
249 using value_t = std::false_type;
250 using type = Default;
253template <
class Default,
template <
class...>
class Op,
class... Args>
254struct detector<Default, void_t<Op<Args...>>, Op, Args...> {
255 using value_t = std::true_type;
256 using type = Op<Args...>;
259template <
template <
class...>
class Op,
class... Args>
262template <
template <
class...>
class Op,
class... Args>
265template <
template <
class...>
class Op,
class... Args>
268template <
class Default,
template <
class...>
class Op,
class... Args>
269using detected_or =
detector<Default, void, Op, Args...>;
271template <
class Default,
template <
class...>
class Op,
class... Args>
272using detected_or_t =
typename detected_or<Default, Op, Args...>::type;
274template <
class Expected,
template <
class...>
class Op,
class... Args>
275using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
277template <
class To,
template <
class...>
class Op,
class... Args>
278using is_detected_convertible = std::is_convertible<detected_t<Op, Args...>, To>;
281NLOHMANN_JSON_NAMESPACE_END
298#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15)
299#if defined(JSON_HEDLEY_VERSION)
300#undef JSON_HEDLEY_VERSION
302#define JSON_HEDLEY_VERSION 15
304#if defined(JSON_HEDLEY_STRINGIFY_EX)
305#undef JSON_HEDLEY_STRINGIFY_EX
307#define JSON_HEDLEY_STRINGIFY_EX(x) #x
309#if defined(JSON_HEDLEY_STRINGIFY)
310#undef JSON_HEDLEY_STRINGIFY
312#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
314#if defined(JSON_HEDLEY_CONCAT_EX)
315#undef JSON_HEDLEY_CONCAT_EX
317#define JSON_HEDLEY_CONCAT_EX(a, b) a##b
319#if defined(JSON_HEDLEY_CONCAT)
320#undef JSON_HEDLEY_CONCAT
322#define JSON_HEDLEY_CONCAT(a, b) JSON_HEDLEY_CONCAT_EX(a, b)
324#if defined(JSON_HEDLEY_CONCAT3_EX)
325#undef JSON_HEDLEY_CONCAT3_EX
327#define JSON_HEDLEY_CONCAT3_EX(a, b, c) a##b##c
329#if defined(JSON_HEDLEY_CONCAT3)
330#undef JSON_HEDLEY_CONCAT3
332#define JSON_HEDLEY_CONCAT3(a, b, c) JSON_HEDLEY_CONCAT3_EX(a, b, c)
334#if defined(JSON_HEDLEY_VERSION_ENCODE)
335#undef JSON_HEDLEY_VERSION_ENCODE
337#define JSON_HEDLEY_VERSION_ENCODE(major, minor, revision) \
338 (((major) * 1000000) + ((minor) * 1000) + (revision))
340#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
341#undef JSON_HEDLEY_VERSION_DECODE_MAJOR
343#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
345#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
346#undef JSON_HEDLEY_VERSION_DECODE_MINOR
348#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
350#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
351#undef JSON_HEDLEY_VERSION_DECODE_REVISION
353#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
355#if defined(JSON_HEDLEY_GNUC_VERSION)
356#undef JSON_HEDLEY_GNUC_VERSION
358#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
359#define JSON_HEDLEY_GNUC_VERSION \
360 JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
361#elif defined(__GNUC__)
362#define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
365#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
366#undef JSON_HEDLEY_GNUC_VERSION_CHECK
368#if defined(JSON_HEDLEY_GNUC_VERSION)
369#define JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) \
370 (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
372#define JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch) (0)
375#if defined(JSON_HEDLEY_MSVC_VERSION)
376#undef JSON_HEDLEY_MSVC_VERSION
378#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL)
379#define JSON_HEDLEY_MSVC_VERSION \
380 JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, \
381 (_MSC_FULL_VER % 100000) / 100)
382#elif defined(_MSC_FULL_VER) && !defined(__ICL)
383#define JSON_HEDLEY_MSVC_VERSION \
384 JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, \
385 (_MSC_FULL_VER % 10000) / 10)
386#elif defined(_MSC_VER) && !defined(__ICL)
387#define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
390#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
391#undef JSON_HEDLEY_MSVC_VERSION_CHECK
393#if !defined(JSON_HEDLEY_MSVC_VERSION)
394#define JSON_HEDLEY_MSVC_VERSION_CHECK(major, minor, patch) (0)
395#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
396#define JSON_HEDLEY_MSVC_VERSION_CHECK(major, minor, patch) \
397 (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
398#elif defined(_MSC_VER) && (_MSC_VER >= 1200)
399#define JSON_HEDLEY_MSVC_VERSION_CHECK(major, minor, patch) \
400 (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
402#define JSON_HEDLEY_MSVC_VERSION_CHECK(major, minor, patch) (_MSC_VER >= ((major * 100) + (minor)))
405#if defined(JSON_HEDLEY_INTEL_VERSION)
406#undef JSON_HEDLEY_INTEL_VERSION
408#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL)
409#define JSON_HEDLEY_INTEL_VERSION \
410 JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, \
411 __INTEL_COMPILER_UPDATE)
412#elif defined(__INTEL_COMPILER) && !defined(__ICL)
413#define JSON_HEDLEY_INTEL_VERSION \
414 JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
417#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
418#undef JSON_HEDLEY_INTEL_VERSION_CHECK
420#if defined(JSON_HEDLEY_INTEL_VERSION)
421#define JSON_HEDLEY_INTEL_VERSION_CHECK(major, minor, patch) \
422 (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
424#define JSON_HEDLEY_INTEL_VERSION_CHECK(major, minor, patch) (0)
427#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
428#undef JSON_HEDLEY_INTEL_CL_VERSION
430#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL)
431#define JSON_HEDLEY_INTEL_CL_VERSION \
432 JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0)
435#if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK)
436#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
438#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
439#define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major, minor, patch) \
440 (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
442#define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major, minor, patch) (0)
445#if defined(JSON_HEDLEY_PGI_VERSION)
446#undef JSON_HEDLEY_PGI_VERSION
448#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
449#define JSON_HEDLEY_PGI_VERSION \
450 JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
453#if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
454#undef JSON_HEDLEY_PGI_VERSION_CHECK
456#if defined(JSON_HEDLEY_PGI_VERSION)
457#define JSON_HEDLEY_PGI_VERSION_CHECK(major, minor, patch) \
458 (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
460#define JSON_HEDLEY_PGI_VERSION_CHECK(major, minor, patch) (0)
463#if defined(JSON_HEDLEY_SUNPRO_VERSION)
464#undef JSON_HEDLEY_SUNPRO_VERSION
466#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
467#define JSON_HEDLEY_SUNPRO_VERSION \
468 JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), \
469 (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), \
470 (__SUNPRO_C & 0xf) * 10)
471#elif defined(__SUNPRO_C)
472#define JSON_HEDLEY_SUNPRO_VERSION \
473 JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
474#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
475#define JSON_HEDLEY_SUNPRO_VERSION \
476 JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), \
477 (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), \
478 (__SUNPRO_CC & 0xf) * 10)
479#elif defined(__SUNPRO_CC)
480#define JSON_HEDLEY_SUNPRO_VERSION \
481 JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, \
485#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
486#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
488#if defined(JSON_HEDLEY_SUNPRO_VERSION)
489#define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major, minor, patch) \
490 (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
492#define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major, minor, patch) (0)
495#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
496#undef JSON_HEDLEY_EMSCRIPTEN_VERSION
498#if defined(__EMSCRIPTEN__)
499#define JSON_HEDLEY_EMSCRIPTEN_VERSION \
500 JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
503#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
504#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
506#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
507#define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major, minor, patch) \
508 (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
510#define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major, minor, patch) (0)
513#if defined(JSON_HEDLEY_ARM_VERSION)
514#undef JSON_HEDLEY_ARM_VERSION
516#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
517#define JSON_HEDLEY_ARM_VERSION \
518 JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, \
519 (__ARMCOMPILER_VERSION % 1000000) / 10000, \
520 (__ARMCOMPILER_VERSION % 10000) / 100)
521#elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
522#define JSON_HEDLEY_ARM_VERSION \
523 JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, \
524 (__ARMCC_VERSION % 10000) / 100)
527#if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
528#undef JSON_HEDLEY_ARM_VERSION_CHECK
530#if defined(JSON_HEDLEY_ARM_VERSION)
531#define JSON_HEDLEY_ARM_VERSION_CHECK(major, minor, patch) \
532 (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
534#define JSON_HEDLEY_ARM_VERSION_CHECK(major, minor, patch) (0)
537#if defined(JSON_HEDLEY_IBM_VERSION)
538#undef JSON_HEDLEY_IBM_VERSION
540#if defined(__ibmxl__)
541#define JSON_HEDLEY_IBM_VERSION \
542 JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
543#elif defined(__xlC__) && defined(__xlC_ver__)
544#define JSON_HEDLEY_IBM_VERSION \
545 JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
546#elif defined(__xlC__)
547#define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
550#if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
551#undef JSON_HEDLEY_IBM_VERSION_CHECK
553#if defined(JSON_HEDLEY_IBM_VERSION)
554#define JSON_HEDLEY_IBM_VERSION_CHECK(major, minor, patch) \
555 (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
557#define JSON_HEDLEY_IBM_VERSION_CHECK(major, minor, patch) (0)
560#if defined(JSON_HEDLEY_TI_VERSION)
561#undef JSON_HEDLEY_TI_VERSION
563#if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__) || \
564 defined(__MSP430__) || defined(__TMS320C2000__))
565#if (__TI_COMPILER_VERSION__ >= 16000000)
566#define JSON_HEDLEY_TI_VERSION \
567 JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, \
568 (__TI_COMPILER_VERSION__ % 1000000) / 1000, \
569 (__TI_COMPILER_VERSION__ % 1000))
573#if defined(JSON_HEDLEY_TI_VERSION_CHECK)
574#undef JSON_HEDLEY_TI_VERSION_CHECK
576#if defined(JSON_HEDLEY_TI_VERSION)
577#define JSON_HEDLEY_TI_VERSION_CHECK(major, minor, patch) \
578 (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
580#define JSON_HEDLEY_TI_VERSION_CHECK(major, minor, patch) (0)
583#if defined(JSON_HEDLEY_TI_CL2000_VERSION)
584#undef JSON_HEDLEY_TI_CL2000_VERSION
586#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
587#define JSON_HEDLEY_TI_CL2000_VERSION \
588 JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, \
589 (__TI_COMPILER_VERSION__ % 1000000) / 1000, \
590 (__TI_COMPILER_VERSION__ % 1000))
593#if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK)
594#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
596#if defined(JSON_HEDLEY_TI_CL2000_VERSION)
597#define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major, minor, patch) \
598 (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
600#define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major, minor, patch) (0)
603#if defined(JSON_HEDLEY_TI_CL430_VERSION)
604#undef JSON_HEDLEY_TI_CL430_VERSION
606#if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__)
607#define JSON_HEDLEY_TI_CL430_VERSION \
608 JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, \
609 (__TI_COMPILER_VERSION__ % 1000000) / 1000, \
610 (__TI_COMPILER_VERSION__ % 1000))
613#if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK)
614#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
616#if defined(JSON_HEDLEY_TI_CL430_VERSION)
617#define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major, minor, patch) \
618 (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
620#define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major, minor, patch) (0)
623#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
624#undef JSON_HEDLEY_TI_ARMCL_VERSION
626#if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__))
627#define JSON_HEDLEY_TI_ARMCL_VERSION \
628 JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, \
629 (__TI_COMPILER_VERSION__ % 1000000) / 1000, \
630 (__TI_COMPILER_VERSION__ % 1000))
633#if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK)
634#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
636#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
637#define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major, minor, patch) \
638 (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
640#define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major, minor, patch) (0)
643#if defined(JSON_HEDLEY_TI_CL6X_VERSION)
644#undef JSON_HEDLEY_TI_CL6X_VERSION
646#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__)
647#define JSON_HEDLEY_TI_CL6X_VERSION \
648 JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, \
649 (__TI_COMPILER_VERSION__ % 1000000) / 1000, \
650 (__TI_COMPILER_VERSION__ % 1000))
653#if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK)
654#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
656#if defined(JSON_HEDLEY_TI_CL6X_VERSION)
657#define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major, minor, patch) \
658 (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
660#define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major, minor, patch) (0)
663#if defined(JSON_HEDLEY_TI_CL7X_VERSION)
664#undef JSON_HEDLEY_TI_CL7X_VERSION
666#if defined(__TI_COMPILER_VERSION__) && defined(__C7000__)
667#define JSON_HEDLEY_TI_CL7X_VERSION \
668 JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, \
669 (__TI_COMPILER_VERSION__ % 1000000) / 1000, \
670 (__TI_COMPILER_VERSION__ % 1000))
673#if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK)
674#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
676#if defined(JSON_HEDLEY_TI_CL7X_VERSION)
677#define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major, minor, patch) \
678 (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
680#define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major, minor, patch) (0)
683#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
684#undef JSON_HEDLEY_TI_CLPRU_VERSION
686#if defined(__TI_COMPILER_VERSION__) && defined(__PRU__)
687#define JSON_HEDLEY_TI_CLPRU_VERSION \
688 JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, \
689 (__TI_COMPILER_VERSION__ % 1000000) / 1000, \
690 (__TI_COMPILER_VERSION__ % 1000))
693#if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK)
694#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
696#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
697#define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major, minor, patch) \
698 (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
700#define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major, minor, patch) (0)
703#if defined(JSON_HEDLEY_CRAY_VERSION)
704#undef JSON_HEDLEY_CRAY_VERSION
707#if defined(_RELEASE_PATCHLEVEL)
708#define JSON_HEDLEY_CRAY_VERSION \
709 JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
711#define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
715#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
716#undef JSON_HEDLEY_CRAY_VERSION_CHECK
718#if defined(JSON_HEDLEY_CRAY_VERSION)
719#define JSON_HEDLEY_CRAY_VERSION_CHECK(major, minor, patch) \
720 (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
722#define JSON_HEDLEY_CRAY_VERSION_CHECK(major, minor, patch) (0)
725#if defined(JSON_HEDLEY_IAR_VERSION)
726#undef JSON_HEDLEY_IAR_VERSION
728#if defined(__IAR_SYSTEMS_ICC__)
730#define JSON_HEDLEY_IAR_VERSION \
731 JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
733#define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0)
737#if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
738#undef JSON_HEDLEY_IAR_VERSION_CHECK
740#if defined(JSON_HEDLEY_IAR_VERSION)
741#define JSON_HEDLEY_IAR_VERSION_CHECK(major, minor, patch) \
742 (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
744#define JSON_HEDLEY_IAR_VERSION_CHECK(major, minor, patch) (0)
747#if defined(JSON_HEDLEY_TINYC_VERSION)
748#undef JSON_HEDLEY_TINYC_VERSION
750#if defined(__TINYC__)
751#define JSON_HEDLEY_TINYC_VERSION \
752 JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
755#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
756#undef JSON_HEDLEY_TINYC_VERSION_CHECK
758#if defined(JSON_HEDLEY_TINYC_VERSION)
759#define JSON_HEDLEY_TINYC_VERSION_CHECK(major, minor, patch) \
760 (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
762#define JSON_HEDLEY_TINYC_VERSION_CHECK(major, minor, patch) (0)
765#if defined(JSON_HEDLEY_DMC_VERSION)
766#undef JSON_HEDLEY_DMC_VERSION
769#define JSON_HEDLEY_DMC_VERSION \
770 JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
773#if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
774#undef JSON_HEDLEY_DMC_VERSION_CHECK
776#if defined(JSON_HEDLEY_DMC_VERSION)
777#define JSON_HEDLEY_DMC_VERSION_CHECK(major, minor, patch) \
778 (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
780#define JSON_HEDLEY_DMC_VERSION_CHECK(major, minor, patch) (0)
783#if defined(JSON_HEDLEY_COMPCERT_VERSION)
784#undef JSON_HEDLEY_COMPCERT_VERSION
786#if defined(__COMPCERT_VERSION__)
787#define JSON_HEDLEY_COMPCERT_VERSION \
788 JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, \
789 __COMPCERT_VERSION__ % 100)
792#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
793#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
795#if defined(JSON_HEDLEY_COMPCERT_VERSION)
796#define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major, minor, patch) \
797 (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
799#define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major, minor, patch) (0)
802#if defined(JSON_HEDLEY_PELLES_VERSION)
803#undef JSON_HEDLEY_PELLES_VERSION
806#define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
809#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
810#undef JSON_HEDLEY_PELLES_VERSION_CHECK
812#if defined(JSON_HEDLEY_PELLES_VERSION)
813#define JSON_HEDLEY_PELLES_VERSION_CHECK(major, minor, patch) \
814 (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
816#define JSON_HEDLEY_PELLES_VERSION_CHECK(major, minor, patch) (0)
819#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
820#undef JSON_HEDLEY_MCST_LCC_VERSION
822#if defined(__LCC__) && defined(__LCC_MINOR__)
823#define JSON_HEDLEY_MCST_LCC_VERSION \
824 JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__)
827#if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK)
828#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
830#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
831#define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major, minor, patch) \
832 (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
834#define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major, minor, patch) (0)
837#if defined(JSON_HEDLEY_GCC_VERSION)
838#undef JSON_HEDLEY_GCC_VERSION
840#if defined(JSON_HEDLEY_GNUC_VERSION) && !defined(__clang__) && \
841 !defined(JSON_HEDLEY_INTEL_VERSION) && !defined(JSON_HEDLEY_PGI_VERSION) && \
842 !defined(JSON_HEDLEY_ARM_VERSION) && !defined(JSON_HEDLEY_CRAY_VERSION) && \
843 !defined(JSON_HEDLEY_TI_VERSION) && !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \
844 !defined(JSON_HEDLEY_TI_CL430_VERSION) && !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \
845 !defined(JSON_HEDLEY_TI_CL6X_VERSION) && !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \
846 !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && !defined(__COMPCERT__) && \
847 !defined(JSON_HEDLEY_MCST_LCC_VERSION)
848#define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
851#if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
852#undef JSON_HEDLEY_GCC_VERSION_CHECK
854#if defined(JSON_HEDLEY_GCC_VERSION)
855#define JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) \
856 (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
858#define JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch) (0)
861#if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
862#undef JSON_HEDLEY_HAS_ATTRIBUTE
864#if defined(__has_attribute) && \
865 ((!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8, 5, 9)))
866#define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
868#define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
871#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
872#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
874#if defined(__has_attribute)
875#define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute, major, minor, patch) \
876 JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
878#define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute, major, minor, patch) \
879 JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch)
882#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
883#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
885#if defined(__has_attribute)
886#define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute, major, minor, patch) \
887 JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
889#define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute, major, minor, patch) \
890 JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch)
893#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
894#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
896#if defined(__has_cpp_attribute) && defined(__cplusplus) && \
897 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0))
898#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
900#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
903#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
904#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
906#if !defined(__cplusplus) || !defined(__has_cpp_attribute)
907#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns, attribute) (0)
908#elif !defined(JSON_HEDLEY_PGI_VERSION) && !defined(JSON_HEDLEY_IAR_VERSION) && \
909 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0)) && \
910 (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19, 20, 0))
911#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns, attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)
913#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns, attribute) (0)
916#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
917#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
919#if defined(__has_cpp_attribute) && defined(__cplusplus)
920#define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute, major, minor, patch) \
921 __has_cpp_attribute(attribute)
923#define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute, major, minor, patch) \
924 JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch)
927#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
928#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
930#if defined(__has_cpp_attribute) && defined(__cplusplus)
931#define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute, major, minor, patch) \
932 __has_cpp_attribute(attribute)
934#define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute, major, minor, patch) \
935 JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch)
938#if defined(JSON_HEDLEY_HAS_BUILTIN)
939#undef JSON_HEDLEY_HAS_BUILTIN
941#if defined(__has_builtin)
942#define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
944#define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
947#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
948#undef JSON_HEDLEY_GNUC_HAS_BUILTIN
950#if defined(__has_builtin)
951#define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin, major, minor, patch) __has_builtin(builtin)
953#define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin, major, minor, patch) \
954 JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch)
957#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
958#undef JSON_HEDLEY_GCC_HAS_BUILTIN
960#if defined(__has_builtin)
961#define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin, major, minor, patch) __has_builtin(builtin)
963#define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin, major, minor, patch) \
964 JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch)
967#if defined(JSON_HEDLEY_HAS_FEATURE)
968#undef JSON_HEDLEY_HAS_FEATURE
970#if defined(__has_feature)
971#define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
973#define JSON_HEDLEY_HAS_FEATURE(feature) (0)
976#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
977#undef JSON_HEDLEY_GNUC_HAS_FEATURE
979#if defined(__has_feature)
980#define JSON_HEDLEY_GNUC_HAS_FEATURE(feature, major, minor, patch) __has_feature(feature)
982#define JSON_HEDLEY_GNUC_HAS_FEATURE(feature, major, minor, patch) \
983 JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch)
986#if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
987#undef JSON_HEDLEY_GCC_HAS_FEATURE
989#if defined(__has_feature)
990#define JSON_HEDLEY_GCC_HAS_FEATURE(feature, major, minor, patch) __has_feature(feature)
992#define JSON_HEDLEY_GCC_HAS_FEATURE(feature, major, minor, patch) \
993 JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch)
996#if defined(JSON_HEDLEY_HAS_EXTENSION)
997#undef JSON_HEDLEY_HAS_EXTENSION
999#if defined(__has_extension)
1000#define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
1002#define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
1005#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
1006#undef JSON_HEDLEY_GNUC_HAS_EXTENSION
1008#if defined(__has_extension)
1009#define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension, major, minor, patch) __has_extension(extension)
1011#define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension, major, minor, patch) \
1012 JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch)
1015#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
1016#undef JSON_HEDLEY_GCC_HAS_EXTENSION
1018#if defined(__has_extension)
1019#define JSON_HEDLEY_GCC_HAS_EXTENSION(extension, major, minor, patch) __has_extension(extension)
1021#define JSON_HEDLEY_GCC_HAS_EXTENSION(extension, major, minor, patch) \
1022 JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch)
1025#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
1026#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
1028#if defined(__has_declspec_attribute)
1029#define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
1031#define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
1034#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
1035#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
1037#if defined(__has_declspec_attribute)
1038#define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute, major, minor, patch) \
1039 __has_declspec_attribute(attribute)
1041#define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute, major, minor, patch) \
1042 JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch)
1045#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
1046#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
1048#if defined(__has_declspec_attribute)
1049#define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute, major, minor, patch) \
1050 __has_declspec_attribute(attribute)
1052#define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute, major, minor, patch) \
1053 JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch)
1056#if defined(JSON_HEDLEY_HAS_WARNING)
1057#undef JSON_HEDLEY_HAS_WARNING
1059#if defined(__has_warning)
1060#define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
1062#define JSON_HEDLEY_HAS_WARNING(warning) (0)
1065#if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
1066#undef JSON_HEDLEY_GNUC_HAS_WARNING
1068#if defined(__has_warning)
1069#define JSON_HEDLEY_GNUC_HAS_WARNING(warning, major, minor, patch) __has_warning(warning)
1071#define JSON_HEDLEY_GNUC_HAS_WARNING(warning, major, minor, patch) \
1072 JSON_HEDLEY_GNUC_VERSION_CHECK(major, minor, patch)
1075#if defined(JSON_HEDLEY_GCC_HAS_WARNING)
1076#undef JSON_HEDLEY_GCC_HAS_WARNING
1078#if defined(__has_warning)
1079#define JSON_HEDLEY_GCC_HAS_WARNING(warning, major, minor, patch) __has_warning(warning)
1081#define JSON_HEDLEY_GCC_HAS_WARNING(warning, major, minor, patch) \
1082 JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch)
1085#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || defined(__clang__) || \
1086 JSON_HEDLEY_GCC_VERSION_CHECK(3, 0, 0) || JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
1087 JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) || JSON_HEDLEY_PGI_VERSION_CHECK(18, 4, 0) || \
1088 JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \
1089 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 7, 0) || JSON_HEDLEY_TI_CL430_VERSION_CHECK(2, 0, 1) || \
1090 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 1, 0) || JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 0, 0) || \
1091 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \
1092 JSON_HEDLEY_CRAY_VERSION_CHECK(5, 0, 0) || JSON_HEDLEY_TINYC_VERSION_CHECK(0, 9, 17) || \
1093 JSON_HEDLEY_SUNPRO_VERSION_CHECK(8, 0, 0) || \
1094 (JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) && defined(__C99_PRAGMA_OPERATOR))
1095#define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
1096#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0)
1097#define JSON_HEDLEY_PRAGMA(value) __pragma(value)
1099#define JSON_HEDLEY_PRAGMA(value)
1102#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
1103#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
1105#if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
1106#undef JSON_HEDLEY_DIAGNOSTIC_POP
1108#if defined(__clang__)
1109#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
1110#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
1111#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0)
1112#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
1113#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
1114#elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 6, 0)
1115#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
1116#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
1117#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0) || JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
1118#define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
1119#define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
1120#elif JSON_HEDLEY_ARM_VERSION_CHECK(5, 6, 0)
1121#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
1122#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
1123#elif JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \
1124 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 4, 0) || JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 1, 0) || \
1125 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0)
1126#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
1127#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
1128#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2, 90, 0)
1129#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
1130#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
1132#define JSON_HEDLEY_DIAGNOSTIC_PUSH
1133#define JSON_HEDLEY_DIAGNOSTIC_POP
1138#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
1139#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
1141#if defined(__cplusplus)
1142#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
1143#if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions")
1144#if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions")
1145#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1146 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1147 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1148 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
1149 _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \
1150 xpr JSON_HEDLEY_DIAGNOSTIC_POP
1152#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1153 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1154 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1155 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") xpr JSON_HEDLEY_DIAGNOSTIC_POP
1158#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1159 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1160 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") xpr JSON_HEDLEY_DIAGNOSTIC_POP
1164#if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
1165#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
1168#if defined(JSON_HEDLEY_CONST_CAST)
1169#undef JSON_HEDLEY_CONST_CAST
1171#if defined(__cplusplus)
1172#define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
1173#elif JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || JSON_HEDLEY_GCC_VERSION_CHECK(4, 6, 0) || \
1174 JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0)
1175#define JSON_HEDLEY_CONST_CAST(T, expr) \
1177 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1178 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL((T)(expr)); \
1179 JSON_HEDLEY_DIAGNOSTIC_POP \
1182#define JSON_HEDLEY_CONST_CAST(T, expr) ((T)(expr))
1185#if defined(JSON_HEDLEY_REINTERPRET_CAST)
1186#undef JSON_HEDLEY_REINTERPRET_CAST
1188#if defined(__cplusplus)
1189#define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
1191#define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T)(expr))
1194#if defined(JSON_HEDLEY_STATIC_CAST)
1195#undef JSON_HEDLEY_STATIC_CAST
1197#if defined(__cplusplus)
1198#define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
1200#define JSON_HEDLEY_STATIC_CAST(T, expr) ((T)(expr))
1203#if defined(JSON_HEDLEY_CPP_CAST)
1204#undef JSON_HEDLEY_CPP_CAST
1206#if defined(__cplusplus)
1207#if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
1208#define JSON_HEDLEY_CPP_CAST(T, expr) \
1209 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1210 _Pragma("clang diagnostic ignored \"-Wold-style-cast\"")((T)(expr)) JSON_HEDLEY_DIAGNOSTIC_POP
1211#elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 3, 0)
1212#define JSON_HEDLEY_CPP_CAST(T, expr) \
1213 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1214 _Pragma("diag_suppress=Pe137") JSON_HEDLEY_DIAGNOSTIC_POP
1216#define JSON_HEDLEY_CPP_CAST(T, expr) ((T)(expr))
1219#define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
1222#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
1223#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1225#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
1226#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED \
1227 _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
1228#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0)
1229#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
1230#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
1231#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable : 1478 1786))
1232#elif JSON_HEDLEY_PGI_VERSION_CHECK(20, 7, 0)
1233#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445")
1234#elif JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0)
1235#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1236#elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 3, 0)
1237#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED \
1238 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1239#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0)
1240#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable : 4996))
1241#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1242#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1243#elif JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \
1244 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1245 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \
1246 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1247 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \
1248 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1249 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \
1250 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1251 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \
1252 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0)
1253#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
1254#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 13, 0) && !defined(__cplusplus)
1255#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED \
1256 _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
1257#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 13, 0) && defined(__cplusplus)
1258#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED \
1259 _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
1260#elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0)
1261#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
1262#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2, 90, 0)
1263#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
1265#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1268#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
1269#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1271#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1272#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
1273 _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
1274#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0)
1275#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
1276#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
1277#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable : 161))
1278#elif JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0)
1279#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
1280#elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 3, 0)
1281#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
1282 _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
1283#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0)
1284#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable : 4068))
1285#elif JSON_HEDLEY_TI_VERSION_CHECK(16, 9, 0) || JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 0, 0) || \
1286 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 3, 0)
1287#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1288#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 0, 0)
1289#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1290#elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0)
1291#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
1292#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1293#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161")
1295#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1298#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
1299#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1301#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
1302#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES \
1303 _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"")
1304#elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 6, 0)
1305#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES \
1306 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1307#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17, 0, 0)
1308#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
1309#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
1310#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable : 1292))
1311#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19, 0, 0)
1312#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable : 5030))
1313#elif JSON_HEDLEY_PGI_VERSION_CHECK(20, 7, 0)
1314#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098")
1315#elif JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0)
1316#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1317#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 14, 0) && defined(__cplusplus)
1318#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES \
1319 _Pragma("error_messages(off,attrskipunsup)")
1320#elif JSON_HEDLEY_TI_VERSION_CHECK(18, 1, 0) || JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 3, 0) || \
1321 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0)
1322#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
1323#elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0)
1324#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097")
1325#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1326#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1328#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1331#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
1332#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1334#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
1335#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
1336#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0)
1337#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
1338#elif JSON_HEDLEY_GCC_VERSION_CHECK(3, 0, 0)
1339#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
1341#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1344#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION)
1345#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1347#if JSON_HEDLEY_HAS_WARNING("-Wunused-function")
1348#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION \
1349 _Pragma("clang diagnostic ignored \"-Wunused-function\"")
1350#elif JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0)
1351#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION \
1352 _Pragma("GCC diagnostic ignored \"-Wunused-function\"")
1353#elif JSON_HEDLEY_MSVC_VERSION_CHECK(1, 0, 0)
1354#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable : 4505))
1355#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1356#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142")
1358#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1361#if defined(JSON_HEDLEY_DEPRECATED)
1362#undef JSON_HEDLEY_DEPRECATED
1364#if defined(JSON_HEDLEY_DEPRECATED_FOR)
1365#undef JSON_HEDLEY_DEPRECATED_FOR
1367#if JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0) || JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
1368#define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " #since))
1369#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) \
1370 __declspec(deprecated("Since " #since "; use " #replacement))
1371#elif (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && \
1372 !defined(JSON_HEDLEY_IAR_VERSION)) || \
1373 JSON_HEDLEY_GCC_VERSION_CHECK(4, 5, 0) || JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
1374 JSON_HEDLEY_ARM_VERSION_CHECK(5, 6, 0) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 13, 0) || \
1375 JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || JSON_HEDLEY_TI_VERSION_CHECK(18, 1, 0) || \
1376 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18, 1, 0) || JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 3, 0) || \
1377 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 3, 0) || \
1378 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1379#define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
1380#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) \
1381 __attribute__((__deprecated__("Since " #since "; use " #replacement)))
1382#elif defined(__cplusplus) && (__cplusplus >= 201402L)
1383#define JSON_HEDLEY_DEPRECATED(since) \
1384 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
1385#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) \
1386 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_( \
1387 [[deprecated("Since " #since "; use " #replacement)]])
1388#elif JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \
1389 JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \
1390 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1391 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \
1392 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1393 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \
1394 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1395 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \
1396 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1397 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \
1398 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \
1399 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) || JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0)
1400#define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
1401#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
1402#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) || JSON_HEDLEY_PELLES_VERSION_CHECK(6, 50, 0) || \
1403 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
1404#define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
1405#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
1406#elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0)
1407#define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
1408#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
1410#define JSON_HEDLEY_DEPRECATED(since)
1411#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
1414#if defined(JSON_HEDLEY_UNAVAILABLE)
1415#undef JSON_HEDLEY_UNAVAILABLE
1417#if JSON_HEDLEY_HAS_ATTRIBUTE(warning) || JSON_HEDLEY_GCC_VERSION_CHECK(4, 3, 0) || \
1418 JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1419#define JSON_HEDLEY_UNAVAILABLE(available_since) \
1420 __attribute__((__warning__("Not available until " #available_since)))
1422#define JSON_HEDLEY_UNAVAILABLE(available_since)
1425#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT)
1426#undef JSON_HEDLEY_WARN_UNUSED_RESULT
1428#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG)
1429#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
1431#if JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) || \
1432 JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \
1433 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1434 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \
1435 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1436 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \
1437 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1438 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \
1439 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1440 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \
1441 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \
1442 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0) && defined(__cplusplus)) || \
1443 JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1444#define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
1445#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__))
1446#elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)
1447#define JSON_HEDLEY_WARN_UNUSED_RESULT \
1448 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1449#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) \
1450 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
1451#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
1452#define JSON_HEDLEY_WARN_UNUSED_RESULT \
1453 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1454#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) \
1455 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1456#elif defined(_Check_return_)
1457#define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_
1458#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_
1460#define JSON_HEDLEY_WARN_UNUSED_RESULT
1461#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg)
1464#if defined(JSON_HEDLEY_SENTINEL)
1465#undef JSON_HEDLEY_SENTINEL
1467#if JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || JSON_HEDLEY_GCC_VERSION_CHECK(4, 0, 0) || \
1468 JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || JSON_HEDLEY_ARM_VERSION_CHECK(5, 4, 0) || \
1469 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1470#define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
1472#define JSON_HEDLEY_SENTINEL(position)
1475#if defined(JSON_HEDLEY_NO_RETURN)
1476#undef JSON_HEDLEY_NO_RETURN
1478#if JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0)
1479#define JSON_HEDLEY_NO_RETURN __noreturn
1480#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1481#define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1482#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
1483#define JSON_HEDLEY_NO_RETURN _Noreturn
1484#elif defined(__cplusplus) && (__cplusplus >= 201103L)
1485#define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
1486#elif JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || JSON_HEDLEY_GCC_VERSION_CHECK(3, 2, 0) || \
1487 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \
1488 JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \
1489 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1490 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \
1491 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1492 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \
1493 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1494 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \
1495 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1496 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \
1497 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0)
1498#define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1499#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0)
1500#define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
1501#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) || JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
1502#define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1503#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 0, 0) && defined(__cplusplus)
1504#define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
1505#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3, 2, 0)
1506#define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
1507#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9, 0, 0)
1508#define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1510#define JSON_HEDLEY_NO_RETURN
1513#if defined(JSON_HEDLEY_NO_ESCAPE)
1514#undef JSON_HEDLEY_NO_ESCAPE
1516#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
1517#define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
1519#define JSON_HEDLEY_NO_ESCAPE
1522#if defined(JSON_HEDLEY_UNREACHABLE)
1523#undef JSON_HEDLEY_UNREACHABLE
1525#if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
1526#undef JSON_HEDLEY_UNREACHABLE_RETURN
1528#if defined(JSON_HEDLEY_ASSUME)
1529#undef JSON_HEDLEY_ASSUME
1531#if JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) || JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
1532 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
1533#define JSON_HEDLEY_ASSUME(expr) __assume(expr)
1534#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
1535#define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
1536#elif JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 2, 0) || JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4, 0, 0)
1537#if defined(__cplusplus)
1538#define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
1540#define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
1543#if (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
1544 JSON_HEDLEY_GCC_VERSION_CHECK(4, 5, 0) || JSON_HEDLEY_PGI_VERSION_CHECK(18, 10, 0) || \
1545 JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 5) || \
1546 JSON_HEDLEY_CRAY_VERSION_CHECK(10, 0, 0) || JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1547#define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
1548#elif defined(JSON_HEDLEY_ASSUME)
1549#define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1551#if !defined(JSON_HEDLEY_ASSUME)
1552#if defined(JSON_HEDLEY_UNREACHABLE)
1553#define JSON_HEDLEY_ASSUME(expr) \
1554 JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1)))
1556#define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr)
1559#if defined(JSON_HEDLEY_UNREACHABLE)
1560#if JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 2, 0) || JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4, 0, 0)
1561#define JSON_HEDLEY_UNREACHABLE_RETURN(value) \
1562 return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))
1564#define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
1567#define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value)
1569#if !defined(JSON_HEDLEY_UNREACHABLE)
1570#define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1573JSON_HEDLEY_DIAGNOSTIC_PUSH
1574#if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
1575#pragma clang diagnostic ignored "-Wpedantic"
1577#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
1578#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
1580#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros", 4, 0, 0)
1581#if defined(__clang__)
1582#pragma clang diagnostic ignored "-Wvariadic-macros"
1583#elif defined(JSON_HEDLEY_GCC_VERSION)
1584#pragma GCC diagnostic ignored "-Wvariadic-macros"
1587#if defined(JSON_HEDLEY_NON_NULL)
1588#undef JSON_HEDLEY_NON_NULL
1590#if JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || JSON_HEDLEY_GCC_VERSION_CHECK(3, 3, 0) || \
1591 JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0)
1592#define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
1594#define JSON_HEDLEY_NON_NULL(...)
1596JSON_HEDLEY_DIAGNOSTIC_POP
1598#if defined(JSON_HEDLEY_PRINTF_FORMAT)
1599#undef JSON_HEDLEY_PRINTF_FORMAT
1601#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format, 4, 4, 0) && \
1602 !defined(__USE_MINGW_ANSI_STDIO)
1603#define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check) \
1604 __attribute__((__format__(ms_printf, string_idx, first_to_check)))
1605#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format, 4, 4, 0) && \
1606 defined(__USE_MINGW_ANSI_STDIO)
1607#define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check) \
1608 __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
1609#elif JSON_HEDLEY_HAS_ATTRIBUTE(format) || JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \
1610 JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || JSON_HEDLEY_ARM_VERSION_CHECK(5, 6, 0) || \
1611 JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \
1612 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1613 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \
1614 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1615 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \
1616 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1617 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \
1618 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1619 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \
1620 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1621#define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check) \
1622 __attribute__((__format__(__printf__, string_idx, first_to_check)))
1623#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6, 0, 0)
1624#define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check) \
1625 __declspec(vaformat(printf, string_idx, first_to_check))
1627#define JSON_HEDLEY_PRINTF_FORMAT(string_idx, first_to_check)
1630#if defined(JSON_HEDLEY_CONSTEXPR)
1631#undef JSON_HEDLEY_CONSTEXPR
1633#if defined(__cplusplus)
1634#if __cplusplus >= 201103L
1635#define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)
1638#if !defined(JSON_HEDLEY_CONSTEXPR)
1639#define JSON_HEDLEY_CONSTEXPR
1642#if defined(JSON_HEDLEY_PREDICT)
1643#undef JSON_HEDLEY_PREDICT
1645#if defined(JSON_HEDLEY_LIKELY)
1646#undef JSON_HEDLEY_LIKELY
1648#if defined(JSON_HEDLEY_UNLIKELY)
1649#undef JSON_HEDLEY_UNLIKELY
1651#if defined(JSON_HEDLEY_UNPREDICTABLE)
1652#undef JSON_HEDLEY_UNPREDICTABLE
1654#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
1655#define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
1657#if (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && \
1658 !defined(JSON_HEDLEY_PGI_VERSION)) || \
1659 JSON_HEDLEY_GCC_VERSION_CHECK(9, 0, 0) || JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1660#define JSON_HEDLEY_PREDICT(expr, value, probability) \
1661 __builtin_expect_with_probability((expr), (value), (probability))
1662#define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
1663 __builtin_expect_with_probability(!!(expr), 1, (probability))
1664#define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
1665 __builtin_expect_with_probability(!!(expr), 0, (probability))
1666#define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1667#define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1668#elif (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
1669 JSON_HEDLEY_GCC_VERSION_CHECK(3, 0, 0) || JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
1670 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 15, 0) && defined(__cplusplus)) || \
1671 JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \
1672 JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 7, 0) || \
1673 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3, 1, 0) || JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 1, 0) || \
1674 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 1, 0) || JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \
1675 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || JSON_HEDLEY_TINYC_VERSION_CHECK(0, 9, 27) || \
1676 JSON_HEDLEY_CRAY_VERSION_CHECK(8, 1, 0) || JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1677#define JSON_HEDLEY_PREDICT(expr, expected, probability) \
1678 (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) \
1679 : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))
1680#define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
1682 double hedley_probability_ = (probability); \
1683 ((hedley_probability_ >= 0.9) \
1684 ? __builtin_expect(!!(expr), 1) \
1685 : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
1687#define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
1689 double hedley_probability_ = (probability); \
1690 ((hedley_probability_ >= 0.9) \
1691 ? __builtin_expect(!!(expr), 0) \
1692 : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
1694#define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1695#define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1697#define JSON_HEDLEY_PREDICT(expr, expected, probability) \
1698 (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))
1699#define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
1700#define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
1701#define JSON_HEDLEY_LIKELY(expr) (!!(expr))
1702#define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
1704#if !defined(JSON_HEDLEY_UNPREDICTABLE)
1705#define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
1708#if defined(JSON_HEDLEY_MALLOC)
1709#undef JSON_HEDLEY_MALLOC
1711#if JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || \
1712 JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
1713 JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || JSON_HEDLEY_IBM_VERSION_CHECK(12, 1, 0) || \
1714 JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \
1715 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1716 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \
1717 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1718 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \
1719 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1720 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \
1721 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1722 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \
1723 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1724#define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
1725#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0)
1726#define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
1727#elif JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0) || JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
1728#define JSON_HEDLEY_MALLOC __declspec(restrict)
1730#define JSON_HEDLEY_MALLOC
1733#if defined(JSON_HEDLEY_PURE)
1734#undef JSON_HEDLEY_PURE
1736#if JSON_HEDLEY_HAS_ATTRIBUTE(pure) || JSON_HEDLEY_GCC_VERSION_CHECK(2, 96, 0) || \
1737 JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
1738 JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \
1739 JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \
1740 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1741 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \
1742 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1743 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \
1744 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1745 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \
1746 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1747 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \
1748 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || \
1749 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1750#define JSON_HEDLEY_PURE __attribute__((__pure__))
1751#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0)
1752#define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
1753#elif defined(__cplusplus) && \
1754 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(2, 0, 1) || JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4, 0, 0) || \
1755 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0))
1756#define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
1758#define JSON_HEDLEY_PURE
1761#if defined(JSON_HEDLEY_CONST)
1762#undef JSON_HEDLEY_CONST
1764#if JSON_HEDLEY_HAS_ATTRIBUTE(const) || JSON_HEDLEY_GCC_VERSION_CHECK(2, 5, 0) || \
1765 JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
1766 JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \
1767 JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \
1768 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1769 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \
1770 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1771 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \
1772 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1773 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \
1774 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1775 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \
1776 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || \
1777 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1778#define JSON_HEDLEY_CONST __attribute__((__const__))
1779#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0)
1780#define JSON_HEDLEY_CONST _Pragma("no_side_effect")
1782#define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
1785#if defined(JSON_HEDLEY_RESTRICT)
1786#undef JSON_HEDLEY_RESTRICT
1788#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
1789#define JSON_HEDLEY_RESTRICT restrict
1790#elif JSON_HEDLEY_GCC_VERSION_CHECK(3, 1, 0) || JSON_HEDLEY_MSVC_VERSION_CHECK(14, 0, 0) || \
1791 JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) || \
1792 JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \
1793 JSON_HEDLEY_PGI_VERSION_CHECK(17, 10, 0) || JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \
1794 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 2, 4) || JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 1, 0) || \
1795 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \
1796 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 14, 0) && defined(__cplusplus)) || \
1797 JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0) || defined(__clang__) || \
1798 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1799#define JSON_HEDLEY_RESTRICT __restrict
1800#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 3, 0) && !defined(__cplusplus)
1801#define JSON_HEDLEY_RESTRICT _Restrict
1803#define JSON_HEDLEY_RESTRICT
1806#if defined(JSON_HEDLEY_INLINE)
1807#undef JSON_HEDLEY_INLINE
1809#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1810 (defined(__cplusplus) && (__cplusplus >= 199711L))
1811#define JSON_HEDLEY_INLINE inline
1812#elif defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_ARM_VERSION_CHECK(6, 2, 0)
1813#define JSON_HEDLEY_INLINE __inline__
1814#elif JSON_HEDLEY_MSVC_VERSION_CHECK(12, 0, 0) || \
1815 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) || JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || \
1816 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 1, 0) || JSON_HEDLEY_TI_CL430_VERSION_CHECK(3, 1, 0) || \
1817 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 2, 0) || JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8, 0, 0) || \
1818 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \
1819 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1820#define JSON_HEDLEY_INLINE __inline
1822#define JSON_HEDLEY_INLINE
1825#if defined(JSON_HEDLEY_ALWAYS_INLINE)
1826#undef JSON_HEDLEY_ALWAYS_INLINE
1828#if JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || JSON_HEDLEY_GCC_VERSION_CHECK(4, 0, 0) || \
1829 JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
1830 JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \
1831 JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \
1832 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1833 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \
1834 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1835 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \
1836 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1837 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \
1838 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1839 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \
1840 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \
1841 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) || JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0)
1842#define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
1843#elif JSON_HEDLEY_MSVC_VERSION_CHECK(12, 0, 0) || JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
1844#define JSON_HEDLEY_ALWAYS_INLINE __forceinline
1845#elif defined(__cplusplus) && \
1846 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \
1847 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 1, 0) || \
1848 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0))
1849#define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
1850#elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0)
1851#define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
1853#define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
1856#if defined(JSON_HEDLEY_NEVER_INLINE)
1857#undef JSON_HEDLEY_NEVER_INLINE
1859#if JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || JSON_HEDLEY_GCC_VERSION_CHECK(4, 0, 0) || \
1860 JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || \
1861 JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || JSON_HEDLEY_IBM_VERSION_CHECK(10, 1, 0) || \
1862 JSON_HEDLEY_TI_VERSION_CHECK(15, 12, 0) || \
1863 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4, 8, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1864 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5, 2, 0) || \
1865 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1866 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6, 4, 0) || \
1867 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 0, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1868 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4, 3, 0) || \
1869 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1870 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0) || JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1, 2, 0) || \
1871 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2, 1, 0) || \
1872 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10) || JSON_HEDLEY_IAR_VERSION_CHECK(8, 10, 0)
1873#define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
1874#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 10, 0) || JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
1875#define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1876#elif JSON_HEDLEY_PGI_VERSION_CHECK(10, 2, 0)
1877#define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
1878#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 0, 0) && defined(__cplusplus)
1879#define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
1880#elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0)
1881#define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
1882#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3, 2, 0)
1883#define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
1884#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9, 0, 0)
1885#define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1887#define JSON_HEDLEY_NEVER_INLINE
1890#if defined(JSON_HEDLEY_PRIVATE)
1891#undef JSON_HEDLEY_PRIVATE
1893#if defined(JSON_HEDLEY_PUBLIC)
1894#undef JSON_HEDLEY_PUBLIC
1896#if defined(JSON_HEDLEY_IMPORT)
1897#undef JSON_HEDLEY_IMPORT
1899#if defined(_WIN32) || defined(__CYGWIN__)
1900#define JSON_HEDLEY_PRIVATE
1901#define JSON_HEDLEY_PUBLIC __declspec(dllexport)
1902#define JSON_HEDLEY_IMPORT __declspec(dllimport)
1904#if JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || JSON_HEDLEY_GCC_VERSION_CHECK(3, 3, 0) || \
1905 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 11, 0) || JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
1906 JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 0) || \
1907 (defined(__TI_EABI__) && \
1908 ((JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 2, 0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1909 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7, 5, 0))) || \
1910 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1911#define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
1912#define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
1914#define JSON_HEDLEY_PRIVATE
1915#define JSON_HEDLEY_PUBLIC
1917#define JSON_HEDLEY_IMPORT extern
1920#if defined(JSON_HEDLEY_NO_THROW)
1921#undef JSON_HEDLEY_NO_THROW
1923#if JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || JSON_HEDLEY_GCC_VERSION_CHECK(3, 3, 0) || \
1924 JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1925#define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
1926#elif JSON_HEDLEY_MSVC_VERSION_CHECK(13, 1, 0) || \
1927 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0) || JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0)
1928#define JSON_HEDLEY_NO_THROW __declspec(nothrow)
1930#define JSON_HEDLEY_NO_THROW
1933#if defined(JSON_HEDLEY_FALL_THROUGH)
1934#undef JSON_HEDLEY_FALL_THROUGH
1936#if JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || JSON_HEDLEY_GCC_VERSION_CHECK(7, 0, 0) || \
1937 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1938#define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
1939#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang, fallthrough)
1940#define JSON_HEDLEY_FALL_THROUGH \
1941 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
1942#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
1943#define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])
1944#elif defined(__fallthrough)
1945#define JSON_HEDLEY_FALL_THROUGH __fallthrough
1947#define JSON_HEDLEY_FALL_THROUGH
1950#if defined(JSON_HEDLEY_RETURNS_NON_NULL)
1951#undef JSON_HEDLEY_RETURNS_NON_NULL
1953#if JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0) || \
1954 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1955#define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__))
1956#elif defined(_Ret_notnull_)
1957#define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_
1959#define JSON_HEDLEY_RETURNS_NON_NULL
1962#if defined(JSON_HEDLEY_ARRAY_PARAM)
1963#undef JSON_HEDLEY_ARRAY_PARAM
1965#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__STDC_NO_VLA__) && \
1966 !defined(__cplusplus) && !defined(JSON_HEDLEY_PGI_VERSION) && \
1967 !defined(JSON_HEDLEY_TINYC_VERSION)
1968#define JSON_HEDLEY_ARRAY_PARAM(name) (name)
1970#define JSON_HEDLEY_ARRAY_PARAM(name)
1973#if defined(JSON_HEDLEY_IS_CONSTANT)
1974#undef JSON_HEDLEY_IS_CONSTANT
1976#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
1977#undef JSON_HEDLEY_REQUIRE_CONSTEXPR
1981#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1982#undef JSON_HEDLEY_IS_CONSTEXPR_
1984#if JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) || \
1985 JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || JSON_HEDLEY_TINYC_VERSION_CHECK(0, 9, 19) || \
1986 JSON_HEDLEY_ARM_VERSION_CHECK(4, 1, 0) || JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 0) || \
1987 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6, 1, 0) || \
1988 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5, 10, 0) && !defined(__cplusplus)) || \
1989 JSON_HEDLEY_CRAY_VERSION_CHECK(8, 1, 0) || JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1, 25, 10)
1990#define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
1992#if !defined(__cplusplus)
1993#if JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
1994 JSON_HEDLEY_GCC_VERSION_CHECK(3, 4, 0) || JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
1995 JSON_HEDLEY_IBM_VERSION_CHECK(13, 1, 0) || JSON_HEDLEY_CRAY_VERSION_CHECK(8, 1, 0) || \
1996 JSON_HEDLEY_ARM_VERSION_CHECK(5, 4, 0) || JSON_HEDLEY_TINYC_VERSION_CHECK(0, 9, 24)
1997#if defined(__INTPTR_TYPE__)
1998#define JSON_HEDLEY_IS_CONSTEXPR_(expr) \
1999 __builtin_types_compatible_p( \
2000 __typeof__((1 ? (void*)((__INTPTR_TYPE__)((expr) * 0)) : (int*)0)), int*)
2003#define JSON_HEDLEY_IS_CONSTEXPR_(expr) \
2004 __builtin_types_compatible_p(__typeof__((1 ? (void*)((intptr_t)((expr) * 0)) : (int*)0)), int*)
2006#elif (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
2007 !defined(JSON_HEDLEY_SUNPRO_VERSION) && !defined(JSON_HEDLEY_PGI_VERSION) && \
2008 !defined(JSON_HEDLEY_IAR_VERSION)) || \
2009 (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
2010 JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0) || JSON_HEDLEY_INTEL_VERSION_CHECK(17, 0, 0) || \
2011 JSON_HEDLEY_IBM_VERSION_CHECK(12, 1, 0) || JSON_HEDLEY_ARM_VERSION_CHECK(5, 3, 0)
2012#if defined(__INTPTR_TYPE__)
2013#define JSON_HEDLEY_IS_CONSTEXPR_(expr) \
2014 _Generic((1 ? (void*)((__INTPTR_TYPE__)((expr) * 0)) : (int*)0), int*: 1, void*: 0)
2017#define JSON_HEDLEY_IS_CONSTEXPR_(expr) \
2018 _Generic((1 ? (void*)((intptr_t)*0) : (int*)0), int*: 1, void*: 0)
2020#elif defined(JSON_HEDLEY_GCC_VERSION) || defined(JSON_HEDLEY_INTEL_VERSION) || \
2021 defined(JSON_HEDLEY_TINYC_VERSION) || defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
2022 JSON_HEDLEY_TI_CL430_VERSION_CHECK(18, 12, 0) || defined(JSON_HEDLEY_TI_CL2000_VERSION) || \
2023 defined(JSON_HEDLEY_TI_CL6X_VERSION) || defined(JSON_HEDLEY_TI_CL7X_VERSION) || \
2024 defined(JSON_HEDLEY_TI_CLPRU_VERSION) || defined(__clang__)
2025#define JSON_HEDLEY_IS_CONSTEXPR_(expr) \
2027 sizeof(*(1 ? ((void*)((expr) * 0L)) : ((struct { char v[sizeof(void) * 2]; }*)1))))
2030#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
2031#if !defined(JSON_HEDLEY_IS_CONSTANT)
2032#define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
2034#define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))
2036#if !defined(JSON_HEDLEY_IS_CONSTANT)
2037#define JSON_HEDLEY_IS_CONSTANT(expr) (0)
2039#define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
2042#if defined(JSON_HEDLEY_BEGIN_C_DECLS)
2043#undef JSON_HEDLEY_BEGIN_C_DECLS
2045#if defined(JSON_HEDLEY_END_C_DECLS)
2046#undef JSON_HEDLEY_END_C_DECLS
2048#if defined(JSON_HEDLEY_C_DECL)
2049#undef JSON_HEDLEY_C_DECL
2051#if defined(__cplusplus)
2052#define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
2053#define JSON_HEDLEY_END_C_DECLS }
2054#define JSON_HEDLEY_C_DECL extern "C"
2056#define JSON_HEDLEY_BEGIN_C_DECLS
2057#define JSON_HEDLEY_END_C_DECLS
2058#define JSON_HEDLEY_C_DECL
2061#if defined(JSON_HEDLEY_STATIC_ASSERT)
2062#undef JSON_HEDLEY_STATIC_ASSERT
2064#if !defined(__cplusplus) && \
2065 ((defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
2066 (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
2067 JSON_HEDLEY_GCC_VERSION_CHECK(6, 0, 0) || JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0) || \
2068 defined(_Static_assert))
2069#define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
2070#elif (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
2071 JSON_HEDLEY_MSVC_VERSION_CHECK(16, 0, 0) || JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
2072#define JSON_HEDLEY_STATIC_ASSERT(expr, message) \
2073 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
2075#define JSON_HEDLEY_STATIC_ASSERT(expr, message)
2078#if defined(JSON_HEDLEY_NULL)
2079#undef JSON_HEDLEY_NULL
2081#if defined(__cplusplus)
2082#if __cplusplus >= 201103L
2083#define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)
2085#define JSON_HEDLEY_NULL NULL
2087#define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
2090#define JSON_HEDLEY_NULL NULL
2092#define JSON_HEDLEY_NULL ((void*)0)
2095#if defined(JSON_HEDLEY_MESSAGE)
2096#undef JSON_HEDLEY_MESSAGE
2098#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2099#define JSON_HEDLEY_MESSAGE(msg) \
2100 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2101 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2102 JSON_HEDLEY_PRAGMA(message msg) \
2103 JSON_HEDLEY_DIAGNOSTIC_POP
2104#elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 4, 0) || JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0)
2105#define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
2106#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5, 0, 0)
2107#define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
2108#elif JSON_HEDLEY_IAR_VERSION_CHECK(8, 0, 0)
2109#define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2110#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2, 0, 0)
2111#define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2113#define JSON_HEDLEY_MESSAGE(msg)
2116#if defined(JSON_HEDLEY_WARNING)
2117#undef JSON_HEDLEY_WARNING
2119#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2120#define JSON_HEDLEY_WARNING(msg) \
2121 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2122 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2123 JSON_HEDLEY_PRAGMA(clang warning msg) \
2124 JSON_HEDLEY_DIAGNOSTIC_POP
2125#elif JSON_HEDLEY_GCC_VERSION_CHECK(4, 8, 0) || JSON_HEDLEY_PGI_VERSION_CHECK(18, 4, 0) || \
2126 JSON_HEDLEY_INTEL_VERSION_CHECK(13, 0, 0)
2127#define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
2128#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15, 0, 0) || JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
2129#define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
2131#define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
2134#if defined(JSON_HEDLEY_REQUIRE)
2135#undef JSON_HEDLEY_REQUIRE
2137#if defined(JSON_HEDLEY_REQUIRE_MSG)
2138#undef JSON_HEDLEY_REQUIRE_MSG
2140#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
2141#if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
2142#define JSON_HEDLEY_REQUIRE(expr) \
2143 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2144 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2145 __attribute__((diagnose_if(!(expr), #expr, "error"))) JSON_HEDLEY_DIAGNOSTIC_POP
2146#define JSON_HEDLEY_REQUIRE_MSG(expr, msg) \
2147 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2148 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2149 __attribute__((diagnose_if(!(expr), msg, "error"))) JSON_HEDLEY_DIAGNOSTIC_POP
2151#define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error")))
2152#define JSON_HEDLEY_REQUIRE_MSG(expr, msg) __attribute__((diagnose_if(!(expr), msg, "error")))
2155#define JSON_HEDLEY_REQUIRE(expr)
2156#define JSON_HEDLEY_REQUIRE_MSG(expr, msg)
2159#if defined(JSON_HEDLEY_FLAGS)
2160#undef JSON_HEDLEY_FLAGS
2162#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && \
2163 (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion"))
2164#define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
2166#define JSON_HEDLEY_FLAGS
2169#if defined(JSON_HEDLEY_FLAGS_CAST)
2170#undef JSON_HEDLEY_FLAGS_CAST
2172#if JSON_HEDLEY_INTEL_VERSION_CHECK(19, 0, 0)
2173#define JSON_HEDLEY_FLAGS_CAST(T, expr) \
2175 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2176 _Pragma("warning(disable:188)")((T)(expr)); \
2177 JSON_HEDLEY_DIAGNOSTIC_POP \
2180#define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
2183#if defined(JSON_HEDLEY_EMPTY_BASES)
2184#undef JSON_HEDLEY_EMPTY_BASES
2186#if (JSON_HEDLEY_MSVC_VERSION_CHECK(19, 0, 23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20, 0, 0)) || \
2187 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021, 1, 0)
2188#define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
2190#define JSON_HEDLEY_EMPTY_BASES
2195#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
2196#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
2198#if defined(__clang__)
2199#define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major, minor, patch) (0)
2201#define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major, minor, patch) \
2202 JSON_HEDLEY_GCC_VERSION_CHECK(major, minor, patch)
2205#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
2206#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
2208#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
2210#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
2211#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
2213#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
2215#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
2216#undef JSON_HEDLEY_CLANG_HAS_BUILTIN
2218#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
2220#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
2221#undef JSON_HEDLEY_CLANG_HAS_FEATURE
2223#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
2225#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
2226#undef JSON_HEDLEY_CLANG_HAS_EXTENSION
2228#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
2230#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
2231#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
2233#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) \
2234 JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
2236#if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
2237#undef JSON_HEDLEY_CLANG_HAS_WARNING
2239#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
2250#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
2251#if defined(__clang__)
2252#if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
2253#error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
2255#elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
2256#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
2257#error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
2264#if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && \
2265 !defined(JSON_HAS_CPP_11)
2266#if (defined(__cplusplus) && __cplusplus >= 202002L) || \
2267 (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
2268#define JSON_HAS_CPP_20
2269#define JSON_HAS_CPP_17
2270#define JSON_HAS_CPP_14
2271#elif (defined(__cplusplus) && __cplusplus >= 201703L) || \
2272 (defined(_HAS_CXX17) && _HAS_CXX17 == 1)
2273#define JSON_HAS_CPP_17
2274#define JSON_HAS_CPP_14
2275#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
2276#define JSON_HAS_CPP_14
2280#define JSON_HAS_CPP_11
2284#if __has_include(<version>)
2289#if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM)
2290#ifdef JSON_HAS_CPP_17
2291#if defined(__cpp_lib_filesystem)
2292#define JSON_HAS_FILESYSTEM 1
2293#elif defined(__cpp_lib_experimental_filesystem)
2294#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2295#elif !defined(__has_include)
2296#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2297#elif __has_include(<filesystem>)
2298#define JSON_HAS_FILESYSTEM 1
2299#elif __has_include(<experimental/filesystem>)
2300#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2305#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8
2306#undef JSON_HAS_FILESYSTEM
2307#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2312#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 8
2313#undef JSON_HAS_FILESYSTEM
2314#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2319#if defined(__clang_major__) && __clang_major__ < 7
2320#undef JSON_HAS_FILESYSTEM
2321#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2326#if defined(_MSC_VER) && _MSC_VER < 1914
2327#undef JSON_HAS_FILESYSTEM
2328#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2332#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000
2333#undef JSON_HAS_FILESYSTEM
2334#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2338#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
2339#undef JSON_HAS_FILESYSTEM
2340#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2345#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2346#define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0
2349#ifndef JSON_HAS_FILESYSTEM
2350#define JSON_HAS_FILESYSTEM 0
2353#ifndef JSON_HAS_THREE_WAY_COMPARISON
2354#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L && \
2355 defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L
2356#define JSON_HAS_THREE_WAY_COMPARISON 1
2358#define JSON_HAS_THREE_WAY_COMPARISON 0
2362#ifndef JSON_HAS_RANGES
2364#if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427
2365#define JSON_HAS_RANGES 0
2366#elif defined(__cpp_lib_ranges)
2367#define JSON_HAS_RANGES 1
2369#define JSON_HAS_RANGES 0
2373#ifndef JSON_HAS_STATIC_RTTI
2374#if !defined(_HAS_STATIC_RTTI) || _HAS_STATIC_RTTI != 0
2375#define JSON_HAS_STATIC_RTTI 1
2377#define JSON_HAS_STATIC_RTTI 0
2381#ifdef JSON_HAS_CPP_17
2382#define JSON_INLINE_VARIABLE inline
2384#define JSON_INLINE_VARIABLE
2387#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address)
2388#define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]]
2390#define JSON_NO_UNIQUE_ADDRESS
2394#if defined(__clang__)
2395#pragma clang diagnostic push
2396#pragma clang diagnostic ignored "-Wdocumentation"
2397#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
2401#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && \
2402 !defined(JSON_NOEXCEPTION)
2403#define JSON_THROW(exception) throw exception
2405#define JSON_CATCH(exception) catch (exception)
2406#define JSON_INTERNAL_CATCH(exception) catch (exception)
2409#define JSON_THROW(exception) std::abort()
2410#define JSON_TRY if (true)
2411#define JSON_CATCH(exception) if (false)
2412#define JSON_INTERNAL_CATCH(exception) if (false)
2416#if defined(JSON_THROW_USER)
2418#define JSON_THROW JSON_THROW_USER
2420#if defined(JSON_TRY_USER)
2422#define JSON_TRY JSON_TRY_USER
2424#if defined(JSON_CATCH_USER)
2426#define JSON_CATCH JSON_CATCH_USER
2427#undef JSON_INTERNAL_CATCH
2428#define JSON_INTERNAL_CATCH JSON_CATCH_USER
2430#if defined(JSON_INTERNAL_CATCH_USER)
2431#undef JSON_INTERNAL_CATCH
2432#define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2436#if !defined(JSON_ASSERT)
2438#define JSON_ASSERT(x) assert(x)
2442#if defined(JSON_TESTS_PRIVATE)
2443#define JSON_PRIVATE_UNLESS_TESTED public
2445#define JSON_PRIVATE_UNLESS_TESTED private
2453#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2454 template <typename BasicJsonType> inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) { \
2455 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2456 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2457 auto it = std::find_if(std::begin(m), std::end(m), \
2458 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool { \
2459 return ej_pair.first == e; \
2461 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2463 template <typename BasicJsonType> \
2464 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) { \
2465 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2466 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2467 auto it = std::find_if(std::begin(m), std::end(m), \
2468 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool { \
2469 return ej_pair.second == j; \
2471 e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2477#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2478 template <template <typename, typename, typename...> class ObjectType, \
2479 template <typename, typename...> class ArrayType, class StringType, \
2480 class BooleanType, class NumberIntegerType, class NumberUnsignedType, \
2481 class NumberFloatType, template <typename> class AllocatorType, \
2482 template <typename, typename = void> class JSONSerializer, class BinaryType, \
2483 class CustomBaseClass>
2485#define NLOHMANN_BASIC_JSON_TPL \
2486 basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, \
2487 NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, \
2492#define NLOHMANN_JSON_EXPAND(x) x
2493#define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, \
2494 _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, \
2495 _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, \
2496 _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, \
2497 _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME, ...) \
2499#define NLOHMANN_JSON_PASTE(...) \
2500 NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO( \
2501 __VA_ARGS__, NLOHMANN_JSON_PASTE64, NLOHMANN_JSON_PASTE63, NLOHMANN_JSON_PASTE62, \
2502 NLOHMANN_JSON_PASTE61, NLOHMANN_JSON_PASTE60, NLOHMANN_JSON_PASTE59, \
2503 NLOHMANN_JSON_PASTE58, NLOHMANN_JSON_PASTE57, NLOHMANN_JSON_PASTE56, \
2504 NLOHMANN_JSON_PASTE55, NLOHMANN_JSON_PASTE54, NLOHMANN_JSON_PASTE53, \
2505 NLOHMANN_JSON_PASTE52, NLOHMANN_JSON_PASTE51, NLOHMANN_JSON_PASTE50, \
2506 NLOHMANN_JSON_PASTE49, NLOHMANN_JSON_PASTE48, NLOHMANN_JSON_PASTE47, \
2507 NLOHMANN_JSON_PASTE46, NLOHMANN_JSON_PASTE45, NLOHMANN_JSON_PASTE44, \
2508 NLOHMANN_JSON_PASTE43, NLOHMANN_JSON_PASTE42, NLOHMANN_JSON_PASTE41, \
2509 NLOHMANN_JSON_PASTE40, NLOHMANN_JSON_PASTE39, NLOHMANN_JSON_PASTE38, \
2510 NLOHMANN_JSON_PASTE37, NLOHMANN_JSON_PASTE36, NLOHMANN_JSON_PASTE35, \
2511 NLOHMANN_JSON_PASTE34, NLOHMANN_JSON_PASTE33, NLOHMANN_JSON_PASTE32, \
2512 NLOHMANN_JSON_PASTE31, NLOHMANN_JSON_PASTE30, NLOHMANN_JSON_PASTE29, \
2513 NLOHMANN_JSON_PASTE28, NLOHMANN_JSON_PASTE27, NLOHMANN_JSON_PASTE26, \
2514 NLOHMANN_JSON_PASTE25, NLOHMANN_JSON_PASTE24, NLOHMANN_JSON_PASTE23, \
2515 NLOHMANN_JSON_PASTE22, NLOHMANN_JSON_PASTE21, NLOHMANN_JSON_PASTE20, \
2516 NLOHMANN_JSON_PASTE19, NLOHMANN_JSON_PASTE18, NLOHMANN_JSON_PASTE17, \
2517 NLOHMANN_JSON_PASTE16, NLOHMANN_JSON_PASTE15, NLOHMANN_JSON_PASTE14, \
2518 NLOHMANN_JSON_PASTE13, NLOHMANN_JSON_PASTE12, NLOHMANN_JSON_PASTE11, \
2519 NLOHMANN_JSON_PASTE10, NLOHMANN_JSON_PASTE9, NLOHMANN_JSON_PASTE8, NLOHMANN_JSON_PASTE7, \
2520 NLOHMANN_JSON_PASTE6, NLOHMANN_JSON_PASTE5, NLOHMANN_JSON_PASTE4, NLOHMANN_JSON_PASTE3, \
2521 NLOHMANN_JSON_PASTE2, NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
2522#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
2523#define NLOHMANN_JSON_PASTE3(func, v1, v2) \
2524 NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
2525#define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) \
2526 NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
2527#define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) \
2528 NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
2529#define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) \
2530 NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
2531#define NLOHMANN_JSON_PASTE7(func, v1, v2, v3, v4, v5, v6) \
2532 NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE6(func, v2, v3, v4, v5, v6)
2533#define NLOHMANN_JSON_PASTE8(func, v1, v2, v3, v4, v5, v6, v7) \
2534 NLOHMANN_JSON_PASTE2(func, v1) \
2535 NLOHMANN_JSON_PASTE7(func, v2, v3, v4, v5, v6, v7)
2536#define NLOHMANN_JSON_PASTE9(func, v1, v2, v3, v4, v5, v6, v7, v8) \
2537 NLOHMANN_JSON_PASTE2(func, v1) \
2538 NLOHMANN_JSON_PASTE8(func, v2, v3, v4, v5, v6, v7, v8)
2539#define NLOHMANN_JSON_PASTE10(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) \
2540 NLOHMANN_JSON_PASTE2(func, v1) \
2541 NLOHMANN_JSON_PASTE9(func, v2, v3, v4, v5, v6, v7, v8, v9)
2542#define NLOHMANN_JSON_PASTE11(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) \
2543 NLOHMANN_JSON_PASTE2(func, v1) \
2544 NLOHMANN_JSON_PASTE10(func, v2, v3, v4, v5, v6, v7, v8, v9, v10)
2545#define NLOHMANN_JSON_PASTE12(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) \
2546 NLOHMANN_JSON_PASTE2(func, v1) \
2547 NLOHMANN_JSON_PASTE11(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11)
2548#define NLOHMANN_JSON_PASTE13(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) \
2549 NLOHMANN_JSON_PASTE2(func, v1) \
2550 NLOHMANN_JSON_PASTE12(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)
2551#define NLOHMANN_JSON_PASTE14(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) \
2552 NLOHMANN_JSON_PASTE2(func, v1) \
2553 NLOHMANN_JSON_PASTE13(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)
2554#define NLOHMANN_JSON_PASTE15(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) \
2555 NLOHMANN_JSON_PASTE2(func, v1) \
2556 NLOHMANN_JSON_PASTE14(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)
2557#define NLOHMANN_JSON_PASTE16(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2559 NLOHMANN_JSON_PASTE2(func, v1) \
2560 NLOHMANN_JSON_PASTE15(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)
2561#define NLOHMANN_JSON_PASTE17(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2563 NLOHMANN_JSON_PASTE2(func, v1) \
2564 NLOHMANN_JSON_PASTE16(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16)
2565#define NLOHMANN_JSON_PASTE18(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2567 NLOHMANN_JSON_PASTE2(func, v1) \
2568 NLOHMANN_JSON_PASTE17(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2570#define NLOHMANN_JSON_PASTE19(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2571 v15, v16, v17, v18) \
2572 NLOHMANN_JSON_PASTE2(func, v1) \
2573 NLOHMANN_JSON_PASTE18(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2575#define NLOHMANN_JSON_PASTE20(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2576 v15, v16, v17, v18, v19) \
2577 NLOHMANN_JSON_PASTE2(func, v1) \
2578 NLOHMANN_JSON_PASTE19(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2580#define NLOHMANN_JSON_PASTE21(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2581 v15, v16, v17, v18, v19, v20) \
2582 NLOHMANN_JSON_PASTE2(func, v1) \
2583 NLOHMANN_JSON_PASTE20(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2585#define NLOHMANN_JSON_PASTE22(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2586 v15, v16, v17, v18, v19, v20, v21) \
2587 NLOHMANN_JSON_PASTE2(func, v1) \
2588 NLOHMANN_JSON_PASTE21(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2589 v17, v18, v19, v20, v21)
2590#define NLOHMANN_JSON_PASTE23(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2591 v15, v16, v17, v18, v19, v20, v21, v22) \
2592 NLOHMANN_JSON_PASTE2(func, v1) \
2593 NLOHMANN_JSON_PASTE22(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2594 v17, v18, v19, v20, v21, v22)
2595#define NLOHMANN_JSON_PASTE24(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2596 v15, v16, v17, v18, v19, v20, v21, v22, v23) \
2597 NLOHMANN_JSON_PASTE2(func, v1) \
2598 NLOHMANN_JSON_PASTE23(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2599 v17, v18, v19, v20, v21, v22, v23)
2600#define NLOHMANN_JSON_PASTE25(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2601 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) \
2602 NLOHMANN_JSON_PASTE2(func, v1) \
2603 NLOHMANN_JSON_PASTE24(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2604 v17, v18, v19, v20, v21, v22, v23, v24)
2605#define NLOHMANN_JSON_PASTE26(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2606 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) \
2607 NLOHMANN_JSON_PASTE2(func, v1) \
2608 NLOHMANN_JSON_PASTE25(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2609 v17, v18, v19, v20, v21, v22, v23, v24, v25)
2610#define NLOHMANN_JSON_PASTE27(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2611 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) \
2612 NLOHMANN_JSON_PASTE2(func, v1) \
2613 NLOHMANN_JSON_PASTE26(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2614 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26)
2615#define NLOHMANN_JSON_PASTE28(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2616 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) \
2617 NLOHMANN_JSON_PASTE2(func, v1) \
2618 NLOHMANN_JSON_PASTE27(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2619 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27)
2620#define NLOHMANN_JSON_PASTE29(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2621 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2623 NLOHMANN_JSON_PASTE2(func, v1) \
2624 NLOHMANN_JSON_PASTE28(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2625 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28)
2626#define NLOHMANN_JSON_PASTE30(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2627 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2629 NLOHMANN_JSON_PASTE2(func, v1) \
2630 NLOHMANN_JSON_PASTE29(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2631 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29)
2632#define NLOHMANN_JSON_PASTE31(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2633 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2635 NLOHMANN_JSON_PASTE2(func, v1) \
2636 NLOHMANN_JSON_PASTE30(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2637 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30)
2638#define NLOHMANN_JSON_PASTE32(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2639 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2640 v28, v29, v30, v31) \
2641 NLOHMANN_JSON_PASTE2(func, v1) \
2642 NLOHMANN_JSON_PASTE31(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2643 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2645#define NLOHMANN_JSON_PASTE33(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2646 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2647 v28, v29, v30, v31, v32) \
2648 NLOHMANN_JSON_PASTE2(func, v1) \
2649 NLOHMANN_JSON_PASTE32(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2650 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2652#define NLOHMANN_JSON_PASTE34(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2653 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2654 v28, v29, v30, v31, v32, v33) \
2655 NLOHMANN_JSON_PASTE2(func, v1) \
2656 NLOHMANN_JSON_PASTE33(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2657 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2659#define NLOHMANN_JSON_PASTE35(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2660 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2661 v28, v29, v30, v31, v32, v33, v34) \
2662 NLOHMANN_JSON_PASTE2(func, v1) \
2663 NLOHMANN_JSON_PASTE34(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2664 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2666#define NLOHMANN_JSON_PASTE36(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2667 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2668 v28, v29, v30, v31, v32, v33, v34, v35) \
2669 NLOHMANN_JSON_PASTE2(func, v1) \
2670 NLOHMANN_JSON_PASTE35(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2671 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2672 v31, v32, v33, v34, v35)
2673#define NLOHMANN_JSON_PASTE37(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2674 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2675 v28, v29, v30, v31, v32, v33, v34, v35, v36) \
2676 NLOHMANN_JSON_PASTE2(func, v1) \
2677 NLOHMANN_JSON_PASTE36(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2678 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2679 v31, v32, v33, v34, v35, v36)
2680#define NLOHMANN_JSON_PASTE38(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2681 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2682 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) \
2683 NLOHMANN_JSON_PASTE2(func, v1) \
2684 NLOHMANN_JSON_PASTE37(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2685 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2686 v31, v32, v33, v34, v35, v36, v37)
2687#define NLOHMANN_JSON_PASTE39(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2688 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2689 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) \
2690 NLOHMANN_JSON_PASTE2(func, v1) \
2691 NLOHMANN_JSON_PASTE38(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2692 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2693 v31, v32, v33, v34, v35, v36, v37, v38)
2694#define NLOHMANN_JSON_PASTE40(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2695 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2696 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) \
2697 NLOHMANN_JSON_PASTE2(func, v1) \
2698 NLOHMANN_JSON_PASTE39(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2699 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2700 v31, v32, v33, v34, v35, v36, v37, v38, v39)
2701#define NLOHMANN_JSON_PASTE41(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2702 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2703 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) \
2704 NLOHMANN_JSON_PASTE2(func, v1) \
2705 NLOHMANN_JSON_PASTE40(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2706 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2707 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40)
2708#define NLOHMANN_JSON_PASTE42(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2709 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2710 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2712 NLOHMANN_JSON_PASTE2(func, v1) \
2713 NLOHMANN_JSON_PASTE41(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2714 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2715 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41)
2716#define NLOHMANN_JSON_PASTE43(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2717 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2718 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2720 NLOHMANN_JSON_PASTE2(func, v1) \
2721 NLOHMANN_JSON_PASTE42(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2722 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2723 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42)
2724#define NLOHMANN_JSON_PASTE44(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2725 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2726 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2728 NLOHMANN_JSON_PASTE2(func, v1) \
2729 NLOHMANN_JSON_PASTE43(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2730 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2731 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43)
2732#define NLOHMANN_JSON_PASTE45(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2733 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2734 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2735 v41, v42, v43, v44) \
2736 NLOHMANN_JSON_PASTE2(func, v1) \
2737 NLOHMANN_JSON_PASTE44(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2738 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2739 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44)
2740#define NLOHMANN_JSON_PASTE46(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2741 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2742 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2743 v41, v42, v43, v44, v45) \
2744 NLOHMANN_JSON_PASTE2(func, v1) \
2745 NLOHMANN_JSON_PASTE45(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2746 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2747 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2749#define NLOHMANN_JSON_PASTE47(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2750 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2751 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2752 v41, v42, v43, v44, v45, v46) \
2753 NLOHMANN_JSON_PASTE2(func, v1) \
2754 NLOHMANN_JSON_PASTE46(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2755 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2756 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2758#define NLOHMANN_JSON_PASTE48(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2759 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2760 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2761 v41, v42, v43, v44, v45, v46, v47) \
2762 NLOHMANN_JSON_PASTE2(func, v1) \
2763 NLOHMANN_JSON_PASTE47(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2764 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2765 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2767#define NLOHMANN_JSON_PASTE49(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2768 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2769 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2770 v41, v42, v43, v44, v45, v46, v47, v48) \
2771 NLOHMANN_JSON_PASTE2(func, v1) \
2772 NLOHMANN_JSON_PASTE48(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2773 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2774 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2776#define NLOHMANN_JSON_PASTE50(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2777 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2778 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2779 v41, v42, v43, v44, v45, v46, v47, v48, v49) \
2780 NLOHMANN_JSON_PASTE2(func, v1) \
2781 NLOHMANN_JSON_PASTE49(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2782 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2783 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2784 v45, v46, v47, v48, v49)
2785#define NLOHMANN_JSON_PASTE51(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2786 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2787 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2788 v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) \
2789 NLOHMANN_JSON_PASTE2(func, v1) \
2790 NLOHMANN_JSON_PASTE50(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2791 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2792 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2793 v45, v46, v47, v48, v49, v50)
2794#define NLOHMANN_JSON_PASTE52(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2795 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2796 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2797 v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) \
2798 NLOHMANN_JSON_PASTE2(func, v1) \
2799 NLOHMANN_JSON_PASTE51(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2800 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2801 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2802 v45, v46, v47, v48, v49, v50, v51)
2803#define NLOHMANN_JSON_PASTE53(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2804 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2805 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2806 v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) \
2807 NLOHMANN_JSON_PASTE2(func, v1) \
2808 NLOHMANN_JSON_PASTE52(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2809 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2810 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2811 v45, v46, v47, v48, v49, v50, v51, v52)
2812#define NLOHMANN_JSON_PASTE54(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2813 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2814 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2815 v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) \
2816 NLOHMANN_JSON_PASTE2(func, v1) \
2817 NLOHMANN_JSON_PASTE53(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2818 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2819 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2820 v45, v46, v47, v48, v49, v50, v51, v52, v53)
2821#define NLOHMANN_JSON_PASTE55( \
2822 func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, \
2823 v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, \
2824 v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) \
2825 NLOHMANN_JSON_PASTE2(func, v1) \
2826 NLOHMANN_JSON_PASTE54(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2827 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2828 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2829 v45, v46, v47, v48, v49, v50, v51, v52, v53, v54)
2830#define NLOHMANN_JSON_PASTE56( \
2831 func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, \
2832 v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, \
2833 v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) \
2834 NLOHMANN_JSON_PASTE2(func, v1) \
2835 NLOHMANN_JSON_PASTE55(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2836 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2837 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2838 v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55)
2839#define NLOHMANN_JSON_PASTE57( \
2840 func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, \
2841 v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, \
2842 v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) \
2843 NLOHMANN_JSON_PASTE2(func, v1) \
2844 NLOHMANN_JSON_PASTE56(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2845 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2846 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2847 v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56)
2848#define NLOHMANN_JSON_PASTE58( \
2849 func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, \
2850 v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, \
2851 v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) \
2852 NLOHMANN_JSON_PASTE2(func, v1) \
2853 NLOHMANN_JSON_PASTE57(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2854 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2855 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2856 v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57)
2857#define NLOHMANN_JSON_PASTE59(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2858 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2859 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2860 v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, \
2861 v54, v55, v56, v57, v58) \
2862 NLOHMANN_JSON_PASTE2(func, v1) \
2863 NLOHMANN_JSON_PASTE58(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2864 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2865 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2866 v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58)
2867#define NLOHMANN_JSON_PASTE60(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2868 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2869 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2870 v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, \
2871 v54, v55, v56, v57, v58, v59) \
2872 NLOHMANN_JSON_PASTE2(func, v1) \
2873 NLOHMANN_JSON_PASTE59(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2874 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2875 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2876 v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, \
2878#define NLOHMANN_JSON_PASTE61(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2879 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2880 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2881 v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, \
2882 v54, v55, v56, v57, v58, v59, v60) \
2883 NLOHMANN_JSON_PASTE2(func, v1) \
2884 NLOHMANN_JSON_PASTE60(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2885 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2886 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2887 v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, \
2889#define NLOHMANN_JSON_PASTE62(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2890 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2891 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2892 v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, \
2893 v54, v55, v56, v57, v58, v59, v60, v61) \
2894 NLOHMANN_JSON_PASTE2(func, v1) \
2895 NLOHMANN_JSON_PASTE61(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2896 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2897 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2898 v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, \
2900#define NLOHMANN_JSON_PASTE63(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2901 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2902 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2903 v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, \
2904 v54, v55, v56, v57, v58, v59, v60, v61, v62) \
2905 NLOHMANN_JSON_PASTE2(func, v1) \
2906 NLOHMANN_JSON_PASTE62(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2907 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2908 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2909 v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, \
2911#define NLOHMANN_JSON_PASTE64(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, \
2912 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, \
2913 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, \
2914 v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, \
2915 v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) \
2916 NLOHMANN_JSON_PASTE2(func, v1) \
2917 NLOHMANN_JSON_PASTE63(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, \
2918 v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
2919 v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, \
2920 v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, \
2921 v59, v60, v61, v62, v63)
2923#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2924#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2925#define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) \
2926 nlohmann_json_t.v1 = nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1);
2933#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
2934 friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { \
2935 NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \
2937 friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { \
2938 NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) \
2941#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \
2942 friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { \
2943 NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \
2945 friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { \
2946 const Type nlohmann_json_default_obj{}; \
2947 NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) \
2950#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \
2951 friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { \
2952 NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \
2960#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
2961 inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { \
2962 NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \
2964 inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { \
2965 NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) \
2968#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \
2969 inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { \
2970 NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \
2973#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \
2974 inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { \
2975 NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \
2977 inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { \
2978 const Type nlohmann_json_default_obj{}; \
2979 NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) \
2988#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \
2989 namespace detail { \
2990 using std::std_name; \
2992 template <typename... T> \
2993 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2996 namespace detail2 { \
2997 struct std_name##_tag {}; \
2999 template <typename... T> std_name##_tag std_name(T&&...); \
3001 template <typename... T> \
3002 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
3004 template <typename... T> struct would_call_std_##std_name { \
3005 static constexpr auto const value = \
3006 ::nlohmann::detail::is_detected_exact<std_name##_tag, result_of_##std_name, \
3011 template <typename... T> \
3012 struct would_call_std_##std_name : detail2::would_call_std_##std_name<T...> {}
3014#ifndef JSON_USE_IMPLICIT_CONVERSIONS
3015#define JSON_USE_IMPLICIT_CONVERSIONS 1
3018#if JSON_USE_IMPLICIT_CONVERSIONS
3019#define JSON_EXPLICIT
3021#define JSON_EXPLICIT explicit
3024#ifndef JSON_DISABLE_ENUM_SERIALIZATION
3025#define JSON_DISABLE_ENUM_SERIALIZATION 0
3028#ifndef JSON_USE_GLOBAL_UDLS
3029#define JSON_USE_GLOBAL_UDLS 1
3032#if JSON_HAS_THREE_WAY_COMPARISON
3036NLOHMANN_JSON_NAMESPACE_BEGIN
3093#if JSON_HAS_THREE_WAY_COMPARISON
3094inline std::partial_ordering operator<=>(
const value_t lhs,
3100 static constexpr std::array<std::uint8_t, 9> order = {{
3105 const auto l_index =
static_cast<std::size_t
>(lhs);
3106 const auto r_index =
static_cast<std::size_t
>(rhs);
3107#if JSON_HAS_THREE_WAY_COMPARISON
3108 if (l_index < order.size() && r_index < order.size()) {
3109 return order[l_index] <=> order[r_index];
3111 return std::partial_ordering::unordered;
3113 return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
3121#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__)
3123 return std::is_lt(lhs <=> rhs);
3128NLOHMANN_JSON_NAMESPACE_END
3141NLOHMANN_JSON_NAMESPACE_BEGIN
3157template <
typename StringType>
3159 JSON_ASSERT(!f.empty());
3160 for (
auto pos = s.find(f);
3161 pos != StringType::npos;
3162 s.replace(pos, f.size(), t),
3163 pos = s.find(f, pos + t.size()))
3175template <
typename StringType>
inline StringType
escape(StringType s) {
3188template <
typename StringType>
static void unescape(StringType& s) {
3194NLOHMANN_JSON_NAMESPACE_END
3209NLOHMANN_JSON_NAMESPACE_BEGIN
3226NLOHMANN_JSON_NAMESPACE_END
3242#include <type_traits>
3247NLOHMANN_JSON_NAMESPACE_BEGIN
3250template <
typename T>
3251using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
3253#ifdef JSON_HAS_CPP_14
3256using std::enable_if_t;
3257using std::index_sequence;
3258using std::index_sequence_for;
3259using std::make_index_sequence;
3264template <
bool B,
typename T =
void>
using enable_if_t =
typename std::enable_if<B, T>::type;
3293 using value_type = T;
3294 static constexpr std::size_t size()
noexcept {
return sizeof...(Ints); }
3302template <
size_t... Ints>
using index_sequence =
integer_sequence<size_t, Ints...>;
3304namespace utility_internal {
3306template <
typename Seq,
size_t SeqSize,
size_t Rem>
struct Extend;
3309template <
typename T, T... Ints,
size_t SeqSize>
3314template <
typename T, T... Ints,
size_t SeqSize>
3316 using type =
integer_sequence<T, Ints..., (Ints + SeqSize)..., 2 * SeqSize>;
3321template <
typename T,
size_t N>
struct Gen {
3322 using type =
typename Extend<
typename Gen<T, N / 2>::type, N / 2, N % 2>::type;
3325template <
typename T>
struct Gen<T, 0> {
3338template <
typename T, T N>
using make_integer_sequence =
typename utility_internal::Gen<T, N>::type;
3345template <
size_t N>
using make_index_sequence = make_integer_sequence<size_t, N>;
3352template <
typename... Ts>
using index_sequence_for = make_index_sequence<
sizeof...(Ts)>;
3364 static JSON_INLINE_VARIABLE
constexpr T value{};
3367#ifndef JSON_HAS_CPP_17
3368template <
typename T>
constexpr T static_const<T>::value;
3371template <
typename T,
typename... Args>
3372inline constexpr std::array<T,
sizeof...(Args)> make_array(Args&&... args) {
3373 return std::array<T,
sizeof...(Args)>{{
static_cast<T
>(std::forward<Args>(args))...}};
3377NLOHMANN_JSON_NAMESPACE_END
3391#include <type_traits>
3411NLOHMANN_JSON_NAMESPACE_BEGIN
3416template <
typename It>
3418 It, void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
3419 typename It::reference, typename It::iterator_category>> {
3420 using difference_type =
typename It::difference_type;
3421 using value_type =
typename It::value_type;
3422 using pointer =
typename It::pointer;
3423 using reference =
typename It::reference;
3424 using iterator_category =
typename It::iterator_category;
3432template <
typename T>
3436 using iterator_category = std::random_access_iterator_tag;
3437 using value_type = T;
3438 using difference_type = ptrdiff_t;
3440 using reference = T&;
3444NLOHMANN_JSON_NAMESPACE_END
3459NLOHMANN_JSON_NAMESPACE_BEGIN
3461NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin);
3463NLOHMANN_JSON_NAMESPACE_END
3476NLOHMANN_JSON_NAMESPACE_BEGIN
3478NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end);
3480NLOHMANN_JSON_NAMESPACE_END
3495#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
3496#define INCLUDE_NLOHMANN_JSON_FWD_HPP_
3511NLOHMANN_JSON_NAMESPACE_BEGIN
3520template <
typename T =
void,
typename SFINAE =
void>
struct adl_serializer;
3524template <
template <
typename U,
typename V,
typename... Args>
class ObjectType = std::map,
3525 template <
typename U,
typename... Args>
class ArrayType = std::vector,
3526 class StringType = std::string,
class BooleanType = bool,
3527 class NumberIntegerType = std::int64_t,
class NumberUnsignedType = std::uint64_t,
3528 class NumberFloatType = double,
3529 template <
typename U>
class AllocatorType = std::allocator,
3530 template <
typename T,
typename SFINAE =
void>
class JSONSerializer =
adl_serializer,
3531 class BinaryType = std::vector<std::uint8_t>,
3532 class CustomBaseClass =
void>
3548template <
class Key,
class T,
class IgnoredLess,
class Allocator>
struct ordered_map;
3554NLOHMANN_JSON_NAMESPACE_END
3558NLOHMANN_JSON_NAMESPACE_BEGIN
3584NLOHMANN_BASIC_JSON_TPL_DECLARATION
3590template <
typename BasicJsonContext>
3592 : std::integral_constant<
3593 bool, is_basic_json<typename std::remove_cv<
3594 typename std::remove_pointer<BasicJsonContext>::type>::type>::value ||
3595 std::is_same<BasicJsonContext, std::nullptr_t>::value> {};
3611template <
typename T>
using mapped_type_t =
typename T::mapped_type;
3613template <
typename T>
using key_type_t =
typename T::key_type;
3615template <
typename T>
using value_type_t =
typename T::value_type;
3617template <
typename T>
using difference_type_t =
typename T::difference_type;
3619template <
typename T>
using pointer_t =
typename T::pointer;
3621template <
typename T>
using reference_t =
typename T::reference;
3623template <
typename T>
using iterator_category_t =
typename T::iterator_category;
3625template <
typename T,
typename... Args>
3626using to_json_function =
decltype(T::to_json(std::declval<Args>()...));
3628template <
typename T,
typename... Args>
3629using from_json_function =
decltype(T::from_json(std::declval<Args>()...));
3631template <
typename T,
typename U>
3632using get_template_function =
decltype(std::declval<T>().template get<U>());
3635template <
typename BasicJsonType,
typename T,
typename =
void>
3644 static constexpr bool value =
3645 is_detected<get_template_function, const BasicJsonType&, T>::value;
3648template <
typename BasicJsonType,
typename T>
3650 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3652 static constexpr bool value =
3653 is_detected_exact<void, from_json_function, serializer, const BasicJsonType&, T&>::value;
3658template <
typename BasicJsonType,
typename T,
typename =
void>
3661template <
typename BasicJsonType,
typename T>
3663 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3665 static constexpr bool value =
3666 is_detected_exact<T, from_json_function, serializer, const BasicJsonType&>::value;
3672template <
typename BasicJsonType,
typename T,
typename =
void>
3675template <
typename BasicJsonType,
typename T>
3677 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3679 static constexpr bool value =
3680 is_detected_exact<void, to_json_function, serializer, BasicJsonType&, T>::value;
3683template <
typename T>
using detect_key_compare =
typename T::key_compare;
3685template <
typename T>
3686struct has_key_compare : std::integral_constant<bool, is_detected<detect_key_compare, T>::value> {};
3690 using object_t =
typename BasicJsonType::object_t;
3691 using object_comparator_t =
typename BasicJsonType::default_object_comparator_t;
3693 typename std::conditional<has_key_compare<object_t>::value,
typename object_t::key_compare,
3694 object_comparator_t>::type;
3697template <
typename BasicJsonType>
3698using actual_object_comparator_t =
typename actual_object_comparator<BasicJsonType>::type;
3708template <>
struct char_traits<unsigned char> : std::char_traits<char> {
3709 using char_type =
unsigned char;
3710 using int_type = uint64_t;
3713 static int_type to_int_type(char_type c)
noexcept {
return static_cast<int_type
>(c); }
3715 static char_type to_char_type(int_type i)
noexcept {
return static_cast<char_type
>(i); }
3717 static constexpr int_type eof()
noexcept {
return static_cast<int_type
>(EOF); }
3722 using char_type =
signed char;
3723 using int_type = uint64_t;
3726 static int_type to_int_type(char_type c)
noexcept {
return static_cast<int_type
>(c); }
3728 static char_type to_char_type(int_type i)
noexcept {
return static_cast<char_type
>(i); }
3730 static constexpr int_type eof()
noexcept {
return static_cast<int_type
>(EOF); }
3740template <
class B,
class... Bn>
3742 : std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {};
3745template <
class B>
struct negation : std::integral_constant<bool, !B::value> {};
3753template <
typename T1,
typename T2>
3755 :
conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3757template <
typename T1,
typename T2>
3759 :
conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3761template <
typename... Ts>
3765template <
typename... Ts>
3767 :
conjunction<is_default_constructible<Ts>...> {};
3769template <
typename T,
typename... Args>
3772template <
typename T1,
typename T2>
3775template <
typename T1,
typename T2>
3779template <
typename... Ts>
3782template <
typename... Ts>
3793 static constexpr auto value =
3794 is_detected<value_type_t, traits>::value && is_detected<difference_type_t, traits>::value &&
3795 is_detected<pointer_t, traits>::value && is_detected<iterator_category_t, traits>::value &&
3796 is_detected<reference_t, traits>::value;
3801 using t_ref =
typename std::add_lvalue_reference<T>::type;
3803 using iterator = detected_t<result_of_begin, t_ref>;
3804 using sentinel = detected_t<result_of_end, t_ref>;
3814 static constexpr bool value = !std::is_same<iterator, nonesuch>::value &&
3815 !std::is_same<sentinel, nonesuch>::value && is_iterator_begin;
3818template <
typename R>
3819using iterator_t = enable_if_t<is_range<R>::value, result_of_begin<decltype(std::declval<R&>())>>;
3821template <
typename T>
using range_value_t = value_type_t<iterator_traits<iterator_t<T>>>;
3829template <
typename T>
struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {};
3831template <
typename BasicJsonType,
typename CompatibleObjectType,
typename =
void>
3834template <
typename BasicJsonType,
typename CompatibleObjectType>
3836 BasicJsonType, CompatibleObjectType,
3837 enable_if_t<is_detected<mapped_type_t, CompatibleObjectType>::value &&
3838 is_detected<key_type_t, CompatibleObjectType>::value>> {
3839 using object_t =
typename BasicJsonType::object_t;
3842 static constexpr bool value =
3844 typename CompatibleObjectType::key_type>::value &&
3846 typename CompatibleObjectType::mapped_type>::value;
3849template <
typename BasicJsonType,
typename CompatibleObjectType>
3853template <
typename BasicJsonType,
typename ConstructibleObjectType,
typename =
void>
3856template <
typename BasicJsonType,
typename ConstructibleObjectType>
3858 BasicJsonType, ConstructibleObjectType,
3859 enable_if_t<is_detected<mapped_type_t, ConstructibleObjectType>::value &&
3860 is_detected<key_type_t, ConstructibleObjectType>::value>> {
3861 using object_t =
typename BasicJsonType::object_t;
3863 static constexpr bool value =
3865 (std::is_move_assignable<ConstructibleObjectType>::value ||
3866 std::is_copy_assignable<ConstructibleObjectType>::value) &&
3868 typename object_t::key_type>::value &&
3869 std::is_same<
typename object_t::mapped_type,
3870 typename ConstructibleObjectType::mapped_type>::value)) ||
3873 typename ConstructibleObjectType::mapped_type>::value);
3876template <
typename BasicJsonType,
typename ConstructibleObjectType>
3881 static constexpr auto value =
3885template <
typename BasicJsonType,
typename ConstructibleStringType>
3888#ifdef __INTEL_COMPILER
3889 using laundered_type =
decltype(std::declval<ConstructibleStringType>());
3891 using laundered_type = ConstructibleStringType;
3894 static constexpr auto value =
3896 is_detected_exact<
typename BasicJsonType::string_t::value_type, value_type_t,
3897 laundered_type>>::value;
3900template <
typename BasicJsonType,
typename CompatibleArrayType,
typename =
void>
3903template <
typename BasicJsonType,
typename CompatibleArrayType>
3905 BasicJsonType, CompatibleArrayType,
3907 is_detected<iterator_t, CompatibleArrayType>::value &&
3908 is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value &&
3912 !std::is_same<CompatibleArrayType,
3913 detected_t<range_value_t, CompatibleArrayType>>::value>> {
3914 static constexpr bool value =
3918template <
typename BasicJsonType,
typename CompatibleArrayType>
3922template <
typename BasicJsonType,
typename ConstructibleArrayType,
typename =
void>
3925template <
typename BasicJsonType,
typename ConstructibleArrayType>
3927 BasicJsonType, ConstructibleArrayType,
3928 enable_if_t<std::is_same<ConstructibleArrayType, typename BasicJsonType::value_type>::value>>
3929 : std::true_type {};
3931template <
typename BasicJsonType,
typename ConstructibleArrayType>
3933 BasicJsonType, ConstructibleArrayType,
3934 enable_if_t<!std::is_same<ConstructibleArrayType, typename BasicJsonType::value_type>::value &&
3937 (std::is_move_assignable<ConstructibleArrayType>::value ||
3938 std::is_copy_assignable<ConstructibleArrayType>::value) &&
3939 is_detected<iterator_t, ConstructibleArrayType>::value &&
3941 iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value &&
3942 is_detected<range_value_t, ConstructibleArrayType>::value &&
3946 !std::is_same<ConstructibleArrayType,
3947 detected_t<range_value_t, ConstructibleArrayType>>::value &&
3948 is_complete_type<detected_t<range_value_t, ConstructibleArrayType>>::value>> {
3949 using value_type = range_value_t<ConstructibleArrayType>;
3951 static constexpr bool value =
3952 std::is_same<value_type, typename BasicJsonType::array_t::value_type>::value ||
3957template <
typename BasicJsonType,
typename ConstructibleArrayType>
3961template <
typename RealIntegerType,
typename CompatibleNumberIntegerType,
typename =
void>
3964template <
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3966 RealIntegerType, CompatibleNumberIntegerType,
3967 enable_if_t<std::is_integral<RealIntegerType>::value &&
3968 std::is_integral<CompatibleNumberIntegerType>::value &&
3969 !std::is_same<bool, CompatibleNumberIntegerType>::value>> {
3971 using RealLimits = std::numeric_limits<RealIntegerType>;
3972 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
3974 static constexpr auto value =
3976 CompatibleLimits::is_integer && RealLimits::is_signed == CompatibleLimits::is_signed;
3979template <
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3983template <
typename BasicJsonType,
typename CompatibleType,
typename =
void>
3986template <
typename BasicJsonType,
typename CompatibleType>
3992template <
typename BasicJsonType,
typename CompatibleType>
3997template <
typename T1,
typename... Args>
4003template <
typename BasicJsonType>
4006template <
typename BasicJsonType>
4011template <
template <
typename...>
class Primary,
typename T>
4014template <
template <
typename...>
class Primary,
typename... Args>
4017template <
typename T>
4021template <
typename Compare,
typename A,
typename B,
typename =
void>
4024template <
typename Compare,
typename A,
typename B>
4027 void_t<decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())),
4028 decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))>>
4029 : std::true_type {};
4031template <
typename T>
using detect_is_transparent =
typename T::is_transparent;
4035template <
typename Comparator,
typename ObjectKeyType,
typename KeyTypeCVRef,
4036 bool RequireTransparentComparator =
true,
4037 bool ExcludeObjectKeyType = RequireTransparentComparator,
4038 typename KeyType = uncvref_t<KeyTypeCVRef>>
4039using is_usable_as_key_type =
typename std::conditional<
4041 !(ExcludeObjectKeyType && std::is_same<KeyType, ObjectKeyType>::value) &&
4042 (!RequireTransparentComparator || is_detected<detect_is_transparent, Comparator>::value) &&
4043 !is_json_pointer<KeyType>::value,
4044 std::true_type, std::false_type>::type;
4053template <
typename BasicJsonType,
typename KeyTypeCVRef,
bool RequireTransparentComparator =
true,
4054 bool ExcludeObjectKeyType = RequireTransparentComparator,
4055 typename KeyType = uncvref_t<KeyTypeCVRef>>
4056using is_usable_as_basic_json_key_type =
typename std::conditional<
4057 is_usable_as_key_type<
typename BasicJsonType::object_comparator_t,
4058 typename BasicJsonType::object_t::key_type, KeyTypeCVRef,
4059 RequireTransparentComparator, ExcludeObjectKeyType>::value &&
4061 std::true_type, std::false_type>::type;
4063template <
typename ObjectType,
typename KeyType>
4064using detect_erase_with_key_type =
4065 decltype(std::declval<ObjectType&>().erase(std::declval<KeyType>()));
4069template <
typename BasicJsonType,
typename KeyType>
4070using has_erase_with_key_type =
typename std::conditional<
4071 is_detected<detect_erase_with_key_type, typename BasicJsonType::object_t, KeyType>::value,
4072 std::true_type, std::false_type>::type;
4084 template <
typename C>
static one test(
decltype(&C::capacity));
4085 template <
typename C>
static two test(...);
4088 value =
sizeof(test<T>(
nullptr)) ==
sizeof(
char)
4094template <typename T, typename U, enable_if_t<!std::is_same<T, U>::value,
int> = 0>
4095T conditional_static_cast(U value) {
4096 return static_cast<T
>(value);
4099template <typename T, typename U, enable_if_t<std::is_same<T, U>::value,
int> = 0>
4100T conditional_static_cast(U value) {
4111template <
typename... Types>
4113 std::integral_constant<bool, all_signed<Types...>::value || all_unsigned<Types...>::value>;
4115template <
typename OfType,
typename T>
4116using never_out_of_range =
4117 std::integral_constant<bool, (std::is_signed<OfType>::value && (
sizeof(T) <
sizeof(OfType))) ||
4118 (same_sign<OfType, T>::value &&
sizeof(OfType) ==
sizeof(T))>;
4120template <typename OfType, typename T, bool OfTypeSigned = std::is_signed<OfType>::value,
4121 bool TSigned = std::is_signed<T>::value>
4125 static constexpr bool test(T val) {
4126 using CommonType =
typename std::common_type<OfType, T>::type;
4127 return static_cast<CommonType
>(val) <=
4128 static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4133 static constexpr bool test(T val) {
4134 using CommonType =
typename std::common_type<OfType, T>::type;
4135 return static_cast<CommonType
>(val) <=
4136 static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4141 static constexpr bool test(T val) {
4142 using CommonType =
typename std::common_type<OfType, T>::type;
4143 return val >= 0 &&
static_cast<CommonType
>(val) <=
4144 static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4149 static constexpr bool test(T val) {
4150 using CommonType =
typename std::common_type<OfType, T>::type;
4151 return static_cast<CommonType
>(val) >=
4152 static_cast<CommonType
>((std::numeric_limits<OfType>::min)()) &&
4153 static_cast<CommonType
>(val) <=
4154 static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4158template <typename OfType, typename T, bool NeverOutOfRange = never_out_of_range<OfType, T>::value,
4159 typename = detail::enable_if_t<all_integral<OfType, T>::value>>
4167 static constexpr bool test(T ) {
return true; }
4170template <
typename OfType,
typename T>
inline constexpr bool value_in_range_of(T val) {
4174template <
bool Value>
using bool_constant = std::integral_constant<bool, Value>;
4182template <
typename T>
inline constexpr bool is_c_string() {
4183 using TUnExt =
typename std::remove_extent<T>::type;
4184 using TUnCVExt =
typename std::remove_cv<TUnExt>::type;
4185 using TUnPtr =
typename std::remove_pointer<T>::type;
4186 using TUnCVPtr =
typename std::remove_cv<TUnPtr>::type;
4187 return (std::is_array<T>::value && std::is_same<TUnCVExt, char>::value) ||
4188 (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value);
4194template <
typename T>
struct is_c_string : bool_constant<impl::is_c_string<T>()> {};
4205 return is_detected<detect_is_transparent, T>::value;
4211template <
typename T>
struct is_transparent : bool_constant<impl::is_transparent<T>()> {};
4216NLOHMANN_JSON_NAMESPACE_END
4235NLOHMANN_JSON_NAMESPACE_BEGIN
4238inline std::size_t concat_length() {
4242template <
typename... Args>
inline std::size_t concat_length(
const char* cstr,
const Args&... rest);
4244template <
typename StringType,
typename... Args>
4245inline std::size_t concat_length(
const StringType& str,
const Args&... rest);
4247template <
typename... Args>
4248inline std::size_t concat_length(
const char ,
const Args&... rest) {
4249 return 1 + concat_length(rest...);
4252template <
typename... Args>
4253inline std::size_t concat_length(
const char* cstr,
const Args&... rest) {
4255 return ::strlen(cstr) + concat_length(rest...);
4258template <
typename StringType,
typename... Args>
4259inline std::size_t concat_length(
const StringType& str,
const Args&... rest) {
4260 return str.size() + concat_length(rest...);
4263template <
typename OutStringType>
inline void concat_into(OutStringType& ) {}
4265template <
typename StringType,
typename Arg>
4266using string_can_append =
decltype(std::declval<StringType&>().append(std::declval<Arg&&>()));
4268template <
typename StringType,
typename Arg>
4269using detect_string_can_append = is_detected<string_can_append, StringType, Arg>;
4271template <
typename StringType,
typename Arg>
4272using string_can_append_op =
decltype(std::declval<StringType&>() += std::declval<Arg&&>());
4274template <
typename StringType,
typename Arg>
4275using detect_string_can_append_op = is_detected<string_can_append_op, StringType, Arg>;
4277template <
typename StringType,
typename Arg>
4278using string_can_append_iter =
decltype(std::declval<StringType&>().append(
4279 std::declval<const Arg&>().begin(), std::declval<const Arg&>().end()));
4281template <
typename StringType,
typename Arg>
4282using detect_string_can_append_iter = is_detected<string_can_append_iter, StringType, Arg>;
4284template <
typename StringType,
typename Arg>
4285using string_can_append_data =
decltype(std::declval<StringType&>().append(
4286 std::declval<const Arg&>().data(), std::declval<const Arg&>().size()));
4288template <
typename StringType,
typename Arg>
4289using detect_string_can_append_data = is_detected<string_can_append_data, StringType, Arg>;
4291template <
typename OutStringType,
typename Arg,
typename... Args,
4292 enable_if_t<!detect_string_can_append<OutStringType, Arg>::value &&
4293 detect_string_can_append_op<OutStringType, Arg>::value,
4295inline void concat_into(OutStringType& out, Arg&& arg, Args&&... rest);
4297template <
typename OutStringType,
typename Arg,
typename... Args,
4298 enable_if_t<!detect_string_can_append<OutStringType, Arg>::value &&
4299 !detect_string_can_append_op<OutStringType, Arg>::value &&
4300 detect_string_can_append_iter<OutStringType, Arg>::value,
4302inline void concat_into(OutStringType& out,
const Arg& arg, Args&&... rest);
4304template <
typename OutStringType,
typename Arg,
typename... Args,
4305 enable_if_t<!detect_string_can_append<OutStringType, Arg>::value &&
4306 !detect_string_can_append_op<OutStringType, Arg>::value &&
4307 !detect_string_can_append_iter<OutStringType, Arg>::value &&
4308 detect_string_can_append_data<OutStringType, Arg>::value,
4310inline void concat_into(OutStringType& out,
const Arg& arg, Args&&... rest);
4312template <
typename OutStringType,
typename Arg,
typename... Args,
4313 enable_if_t<detect_string_can_append<OutStringType, Arg>::value,
int> = 0>
4314inline void concat_into(OutStringType& out, Arg&& arg, Args&&... rest) {
4315 out.append(std::forward<Arg>(arg));
4316 concat_into(out, std::forward<Args>(rest)...);
4319template <
typename OutStringType,
typename Arg,
typename... Args,
4320 enable_if_t<!detect_string_can_append<OutStringType, Arg>::value &&
4321 detect_string_can_append_op<OutStringType, Arg>::value,
4323inline void concat_into(OutStringType& out, Arg&& arg, Args&&... rest) {
4324 out += std::forward<Arg>(arg);
4325 concat_into(out, std::forward<Args>(rest)...);
4328template <
typename OutStringType,
typename Arg,
typename... Args,
4329 enable_if_t<!detect_string_can_append<OutStringType, Arg>::value &&
4330 !detect_string_can_append_op<OutStringType, Arg>::value &&
4331 detect_string_can_append_iter<OutStringType, Arg>::value,
4333inline void concat_into(OutStringType& out,
const Arg& arg, Args&&... rest) {
4334 out.append(arg.begin(), arg.end());
4335 concat_into(out, std::forward<Args>(rest)...);
4338template <
typename OutStringType,
typename Arg,
typename... Args,
4339 enable_if_t<!detect_string_can_append<OutStringType, Arg>::value &&
4340 !detect_string_can_append_op<OutStringType, Arg>::value &&
4341 !detect_string_can_append_iter<OutStringType, Arg>::value &&
4342 detect_string_can_append_data<OutStringType, Arg>::value,
4344inline void concat_into(OutStringType& out,
const Arg& arg, Args&&... rest) {
4345 out.append(arg.data(), arg.size());
4346 concat_into(out, std::forward<Args>(rest)...);
4349template <
typename OutStringType = std::string,
typename... Args>
4350inline OutStringType concat(Args&&... args) {
4352 str.reserve(concat_length(args...));
4353 concat_into(str, std::forward<Args>(args)...);
4358NLOHMANN_JSON_NAMESPACE_END
4360NLOHMANN_JSON_NAMESPACE_BEGIN
4369class exception :
public std::exception {
4372 const char*
what() const noexcept
override {
return m.what(); }
4378 JSON_HEDLEY_NON_NULL(3)
4379 exception(
int id_, const
char* what_arg)
4380 :
id(id_), m(what_arg) {}
4382 static std::string name(
const std::string& ename,
int id_) {
4383 return concat(
"[json.exception.", ename,
'.', std::to_string(id_),
"] ");
4386 static std::string diagnostics(std::nullptr_t ) {
return ""; }
4388 template <
typename BasicJsonType>
4389 static std::string diagnostics(
const BasicJsonType* leaf_element) {
4391 std::vector<std::string> tokens;
4392 for (
const auto* current = leaf_element; current !=
nullptr && current->m_parent !=
nullptr;
4393 current = current->m_parent) {
4394 switch (current->m_parent->type()) {
4396 for (std::size_t i = 0; i < current->m_parent->m_data.m_value.array->size();
4398 if (¤t->m_parent->m_data.m_value.array->operator[](i) == current) {
4399 tokens.emplace_back(std::to_string(i));
4407 for (
const auto& element : *current->m_parent->m_data.m_value.object) {
4408 if (&element.second == current) {
4409 tokens.emplace_back(element.first.c_str());
4429 if (tokens.empty()) {
4433 auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
4434 [](
const std::string& a,
const std::string& b) {
4435 return concat(a,
'/', detail::escape(b));
4437 return concat(
'(', str,
") ");
4439 static_cast<void>(leaf_element);
4446 std::runtime_error m;
4451class parse_error :
public exception {
4462 template <
typename BasicJsonContext,
4463 enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4465 BasicJsonContext context) {
4466 const std::string w =
4467 concat(exception::name(
"parse_error", id_),
"parse error", position_string(pos),
": ",
4468 exception::diagnostics(context), what_arg);
4472 template <
typename BasicJsonContext,
4473 enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4474 static parse_error create(
int id_, std::size_t byte_,
const std::string& what_arg,
4475 BasicJsonContext context) {
4476 const std::string w =
4477 concat(exception::name(
"parse_error", id_),
"parse error",
4478 (byte_ != 0 ? (concat(
" at byte ", std::to_string(byte_))) :
""),
": ",
4479 exception::diagnostics(context), what_arg);
4480 return {id_, byte_, w.c_str()};
4495 parse_error(
int id_, std::size_t byte_,
const char* what_arg)
4496 : exception(id_, what_arg),
byte(byte_) {}
4498 static std::string position_string(
const position_t& pos) {
4499 return concat(
" at line ", std::to_string(pos.
lines_read + 1),
", column ",
4506class invalid_iterator :
public exception {
4508 template <
typename BasicJsonContext,
4509 enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4510 static invalid_iterator create(
int id_,
const std::string& what_arg, BasicJsonContext context) {
4511 const std::string w = concat(exception::name(
"invalid_iterator", id_),
4512 exception::diagnostics(context), what_arg);
4513 return {id_, w.c_str()};
4517 JSON_HEDLEY_NON_NULL(3)
4518 invalid_iterator(
int id_,
const char* what_arg) : exception(id_, what_arg) {}
4523class type_error :
public exception {
4525 template <
typename BasicJsonContext,
4526 enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4527 static type_error create(
int id_,
const std::string& what_arg, BasicJsonContext context) {
4528 const std::string w =
4529 concat(exception::name(
"type_error", id_), exception::diagnostics(context), what_arg);
4530 return {id_, w.c_str()};
4534 JSON_HEDLEY_NON_NULL(3)
4535 type_error(
int id_,
const char* what_arg) : exception(id_, what_arg) {}
4540class out_of_range :
public exception {
4542 template <
typename BasicJsonContext,
4543 enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4544 static out_of_range create(
int id_,
const std::string& what_arg, BasicJsonContext context) {
4545 const std::string w =
4546 concat(exception::name(
"out_of_range", id_), exception::diagnostics(context), what_arg);
4547 return {id_, w.c_str()};
4551 JSON_HEDLEY_NON_NULL(3)
4552 out_of_range(
int id_,
const char* what_arg) : exception(id_, what_arg) {}
4557class other_error :
public exception {
4559 template <
typename BasicJsonContext,
4560 enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4561 static other_error create(
int id_,
const std::string& what_arg, BasicJsonContext context) {
4562 const std::string w =
4563 concat(exception::name(
"other_error", id_), exception::diagnostics(context), what_arg);
4564 return {id_, w.c_str()};
4568 JSON_HEDLEY_NON_NULL(3)
4569 other_error(
int id_,
const char* what_arg) : exception(id_, what_arg) {}
4573NLOHMANN_JSON_NAMESPACE_END
4590NLOHMANN_JSON_NAMESPACE_BEGIN
4597NLOHMANN_JSON_NAMESPACE_END
4610#if JSON_HAS_EXPERIMENTAL_FILESYSTEM
4611#include <experimental/filesystem>
4612NLOHMANN_JSON_NAMESPACE_BEGIN
4614namespace std_fs = std::experimental::filesystem;
4616NLOHMANN_JSON_NAMESPACE_END
4617#elif JSON_HAS_FILESYSTEM
4618#include <filesystem>
4619NLOHMANN_JSON_NAMESPACE_BEGIN
4621namespace std_fs = std::filesystem;
4623NLOHMANN_JSON_NAMESPACE_END
4632NLOHMANN_JSON_NAMESPACE_BEGIN
4635template <
typename BasicJsonType>
4636inline void from_json(
const BasicJsonType& j,
typename std::nullptr_t& n) {
4637 if (JSON_HEDLEY_UNLIKELY(!j.is_null())) {
4639 type_error::create(302, concat(
"type must be null, but is ", j.type_name()), &j));
4645template <
typename BasicJsonType,
typename ArithmeticType,
4646 enable_if_t<std::is_arithmetic<ArithmeticType>::value &&
4647 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4649void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val) {
4650 switch (
static_cast<value_t>(j)) {
4652 val =
static_cast<ArithmeticType
>(
4653 *j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4657 val =
static_cast<ArithmeticType
>(
4658 *j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4662 val =
static_cast<ArithmeticType
>(
4663 *j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4676 type_error::create(302, concat(
"type must be number, but is ", j.type_name()), &j));
4680template <
typename BasicJsonType>
4681inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::boolean_t& b) {
4682 if (JSON_HEDLEY_UNLIKELY(!j.is_boolean())) {
4684 type_error::create(302, concat(
"type must be boolean, but is ", j.type_name()), &j));
4686 b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
4689template <
typename BasicJsonType>
4690inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::string_t& s) {
4691 if (JSON_HEDLEY_UNLIKELY(!j.is_string())) {
4693 type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
4695 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4699 typename BasicJsonType,
typename StringType,
4700 enable_if_t<std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value &&
4701 is_detected_exact<
typename BasicJsonType::string_t::value_type, value_type_t,
4702 StringType>::value &&
4703 !std::is_same<typename BasicJsonType::string_t, StringType>::value &&
4706inline void from_json(
const BasicJsonType& j, StringType& s) {
4707 if (JSON_HEDLEY_UNLIKELY(!j.is_string())) {
4709 type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
4712 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4715template <
typename BasicJsonType>
4716inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_float_t& val) {
4717 get_arithmetic_value(j, val);
4720template <
typename BasicJsonType>
4721inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_unsigned_t& val) {
4722 get_arithmetic_value(j, val);
4725template <
typename BasicJsonType>
4726inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_integer_t& val) {
4727 get_arithmetic_value(j, val);
4730#if !JSON_DISABLE_ENUM_SERIALIZATION
4731template <
typename BasicJsonType,
typename EnumType,
4732 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
4733inline void from_json(
const BasicJsonType& j, EnumType& e) {
4734 typename std::underlying_type<EnumType>::type val;
4735 get_arithmetic_value(j, val);
4736 e =
static_cast<EnumType
>(val);
4741template <
typename BasicJsonType,
typename T,
typename Allocator,
4742 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4743inline void from_json(
const BasicJsonType& j, std::forward_list<T, Allocator>& l) {
4744 if (JSON_HEDLEY_UNLIKELY(!j.is_array())) {
4746 type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4749 std::transform(j.rbegin(), j.rend(), std::front_inserter(l),
4750 [](
const BasicJsonType& i) { return i.template get<T>(); });
4754template <
typename BasicJsonType,
typename T,
4755 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4756inline void from_json(
const BasicJsonType& j, std::valarray<T>& l) {
4757 if (JSON_HEDLEY_UNLIKELY(!j.is_array())) {
4759 type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4762 std::transform(j.begin(), j.end(), std::begin(l),
4763 [](
const BasicJsonType& elem) { return elem.template get<T>(); });
4766template <
typename BasicJsonType,
typename T, std::
size_t N>
4768 const BasicJsonType& j,
4771 ->
decltype(j.template get<T>(), void()) {
4772 for (std::size_t i = 0; i < N; ++i) {
4773 arr[i] = j.at(i).template get<T>();
4777template <
typename BasicJsonType>
4778inline void from_json_array_impl(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr,
4780 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
4783template <
typename BasicJsonType,
typename T, std::
size_t N>
4784auto from_json_array_impl(
const BasicJsonType& j, std::array<T, N>& arr,
priority_tag<2> )
4785 ->
decltype(j.template get<T>(), void()) {
4786 for (std::size_t i = 0; i < N; ++i) {
4787 arr[i] = j.at(i).template get<T>();
4791template <
typename BasicJsonType,
typename ConstructibleArrayType,
4792 enable_if_t<std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4794auto from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
4796 ->
decltype(arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
4797 j.template get<typename ConstructibleArrayType::value_type>(),
void()) {
4800 ConstructibleArrayType ret;
4801 ret.reserve(j.size());
4802 std::transform(j.begin(), j.end(), std::inserter(ret, end(ret)), [](
const BasicJsonType& i) {
4805 return i.template get<typename ConstructibleArrayType::value_type>();
4807 arr = std::move(ret);
4810template <
typename BasicJsonType,
typename ConstructibleArrayType,
4811 enable_if_t<std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4813inline void from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
4817 ConstructibleArrayType ret;
4818 std::transform(j.begin(), j.end(), std::inserter(ret, end(ret)), [](
const BasicJsonType& i) {
4821 return i.template get<typename ConstructibleArrayType::value_type>();
4823 arr = std::move(ret);
4826template <
typename BasicJsonType,
typename ConstructibleArrayType,
4830 !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value &&
4831 !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value &&
4834auto from_json(
const BasicJsonType& j, ConstructibleArrayType& arr)
4836 j.template get<typename ConstructibleArrayType::value_type>(), void()) {
4837 if (JSON_HEDLEY_UNLIKELY(!j.is_array())) {
4839 type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4845template <
typename BasicJsonType,
typename T, std::size_t... Idx>
4846std::array<T,
sizeof...(Idx)>
4847from_json_inplace_array_impl(BasicJsonType&& j,
4849 index_sequence<Idx...> ) {
4850 return {{std::forward<BasicJsonType>(j).at(Idx).template get<T>()...}};
4853template <
typename BasicJsonType,
typename T, std::
size_t N>
4854auto from_json(BasicJsonType&& j,
identity_tag<std::array<T, N>> tag)
4855 ->
decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag,
4856 make_index_sequence<N>{})) {
4857 if (JSON_HEDLEY_UNLIKELY(!j.is_array())) {
4859 type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4862 return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag,
4863 make_index_sequence<N>{});
4866template <
typename BasicJsonType>
4867inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::binary_t& bin) {
4868 if (JSON_HEDLEY_UNLIKELY(!j.is_binary())) {
4870 type_error::create(302, concat(
"type must be binary, but is ", j.type_name()), &j));
4873 bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
4876template <
typename BasicJsonType,
typename ConstructibleObjectType,
4877 enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value,
4879inline void from_json(
const BasicJsonType& j, ConstructibleObjectType& obj) {
4880 if (JSON_HEDLEY_UNLIKELY(!j.is_object())) {
4882 type_error::create(302, concat(
"type must be object, but is ", j.type_name()), &j));
4885 ConstructibleObjectType ret;
4886 const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
4887 using value_type =
typename ConstructibleObjectType::value_type;
4888 std::transform(inner_object->begin(), inner_object->end(), std::inserter(ret, ret.begin()),
4889 [](
typename BasicJsonType::object_t::value_type
const& p) {
4892 p.second.template get<typename ConstructibleObjectType::mapped_type>());
4894 obj = std::move(ret);
4901template <
typename BasicJsonType,
typename ArithmeticType,
4903 std::is_arithmetic<ArithmeticType>::value &&
4904 !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value &&
4905 !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value &&
4906 !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value &&
4907 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4909inline void from_json(
const BasicJsonType& j, ArithmeticType& val) {
4910 switch (
static_cast<value_t>(j)) {
4912 val =
static_cast<ArithmeticType
>(
4913 *j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4917 val =
static_cast<ArithmeticType
>(
4918 *j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4922 val =
static_cast<ArithmeticType
>(
4923 *j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4927 val =
static_cast<ArithmeticType
>(
4928 *j.template get_ptr<const typename BasicJsonType::boolean_t*>());
4940 type_error::create(302, concat(
"type must be number, but is ", j.type_name()), &j));
4944template <
typename BasicJsonType,
typename... Args, std::size_t... Idx>
4945std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j,
4946 index_sequence<Idx...> ) {
4947 return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).
template get<Args>()...);
4950template <
typename BasicJsonType,
class A1,
class A2>
4951std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j,
4954 return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
4955 std::forward<BasicJsonType>(j).at(1).template get<A2>()};
4958template <
typename BasicJsonType,
typename A1,
typename A2>
4959inline void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p,
4961 p = from_json_tuple_impl(std::forward<BasicJsonType>(j),
identity_tag<std::pair<A1, A2>>{},
4965template <
typename BasicJsonType,
typename... Args>
4966std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j,
4969 return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j),
4970 index_sequence_for<Args...>{});
4973template <
typename BasicJsonType,
typename... Args>
4974inline void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t,
4976 t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j),
4977 index_sequence_for<Args...>{});
4980template <
typename BasicJsonType,
typename TupleRelated>
4981auto from_json(BasicJsonType&& j, TupleRelated&& t)
4982 ->
decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t),
4984 if (JSON_HEDLEY_UNLIKELY(!j.is_array())) {
4986 type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4989 return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t),
4994 typename BasicJsonType,
typename Key,
typename Value,
typename Compare,
typename Allocator,
4995 typename = enable_if_t<!std::is_constructible<typename BasicJsonType::string_t, Key>::value>>
4996inline void from_json(
const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m) {
4997 if (JSON_HEDLEY_UNLIKELY(!j.is_array())) {
4999 type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5002 for (
const auto& p : j) {
5003 if (JSON_HEDLEY_UNLIKELY(!p.is_array())) {
5005 type_error::create(302, concat(
"type must be array, but is ", p.type_name()), &j));
5007 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
5012 typename BasicJsonType,
typename Key,
typename Value,
typename Hash,
typename KeyEqual,
5014 typename = enable_if_t<!std::is_constructible<typename BasicJsonType::string_t, Key>::value>>
5015inline void from_json(
const BasicJsonType& j,
5016 std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m) {
5017 if (JSON_HEDLEY_UNLIKELY(!j.is_array())) {
5019 type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5022 for (
const auto& p : j) {
5023 if (JSON_HEDLEY_UNLIKELY(!p.is_array())) {
5025 type_error::create(302, concat(
"type must be array, but is ", p.type_name()), &j));
5027 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
5031#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
5032template <
typename BasicJsonType>
inline void from_json(
const BasicJsonType& j, std_fs::path& p) {
5033 if (JSON_HEDLEY_UNLIKELY(!j.is_string())) {
5035 type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
5037 p = *j.template get_ptr<const typename BasicJsonType::string_t*>();
5042 template <
typename BasicJsonType,
typename T>
5043 auto operator()(
const BasicJsonType& j, T&& val)
const
5044 noexcept(
noexcept(from_json(j, std::forward<T>(val))))
5045 ->
decltype(from_json(j, std::forward<T>(val))) {
5046 return from_json(j, std::forward<T>(val));
5052#ifndef JSON_HAS_CPP_17
5059JSON_INLINE_VARIABLE
constexpr const auto& from_json =
5060 detail::static_const<detail::from_json_fn>::value;
5061#ifndef JSON_HAS_CPP_17
5065NLOHMANN_JSON_NAMESPACE_END
5080#include <type_traits>
5110NLOHMANN_JSON_NAMESPACE_BEGIN
5113template <
typename string_type>
void int_to_string(string_type& target, std::size_t value) {
5115 using std::to_string;
5116 target = to_string(value);
5118template <
typename IteratorType>
class iteration_proxy_value {
5120 using difference_type = std::ptrdiff_t;
5121 using value_type = iteration_proxy_value;
5122 using pointer = value_type*;
5123 using reference = value_type&;
5124 using iterator_category = std::input_iterator_tag;
5125 using string_type =
typename std::remove_cv<
5126 typename std::remove_reference<decltype(std::declval<IteratorType>().key())>::type>::type;
5130 IteratorType anchor{};
5132 std::size_t array_index = 0;
5134 mutable std::size_t array_index_last = 0;
5136 mutable string_type array_index_str =
"0";
5138 string_type empty_str{};
5141 explicit iteration_proxy_value() =
default;
5142 explicit iteration_proxy_value(IteratorType it, std::size_t array_index_ = 0)
noexcept(
5143 std::is_nothrow_move_constructible<IteratorType>::value &&
5144 std::is_nothrow_default_constructible<string_type>::value)
5145 : anchor(std::move(it)), array_index(array_index_) {}
5147 iteration_proxy_value(iteration_proxy_value
const&) =
default;
5148 iteration_proxy_value& operator=(iteration_proxy_value
const&) =
default;
5151 iteration_proxy_value(iteration_proxy_value&&)
noexcept(
5152 std::is_nothrow_move_constructible<IteratorType>::value &&
5153 std::is_nothrow_move_constructible<string_type>::value) =
5155 iteration_proxy_value& operator=(iteration_proxy_value&&)
noexcept(
5156 std::is_nothrow_move_assignable<IteratorType>::value &&
5157 std::is_nothrow_move_assignable<string_type>::value) =
5159 ~iteration_proxy_value() =
default;
5162 const iteration_proxy_value&
operator*()
const {
return *
this; }
5181 bool operator==(
const iteration_proxy_value& o)
const {
return anchor == o.anchor; }
5184 bool operator!=(
const iteration_proxy_value& o)
const {
return anchor != o.anchor; }
5187 const string_type&
key()
const {
5188 JSON_ASSERT(anchor.m_object !=
nullptr);
5190 switch (anchor.m_object->type()) {
5193 if (array_index != array_index_last) {
5194 int_to_string(array_index_str, array_index);
5195 array_index_last = array_index;
5197 return array_index_str;
5202 return anchor.key();
5219 typename IteratorType::reference
value()
const {
return anchor.value(); }
5223template <
typename IteratorType>
class iteration_proxy {
5226 typename IteratorType::pointer container =
nullptr;
5229 explicit iteration_proxy() =
default;
5232 explicit iteration_proxy(
typename IteratorType::reference cont) noexcept : container(&cont) {}
5254template <std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
5255auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.key()) {
5261template <std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
5262auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.value()) {
5267NLOHMANN_JSON_NAMESPACE_END
5275#if defined(__clang__)
5277#pragma clang diagnostic push
5278#pragma clang diagnostic ignored "-Wmismatched-tags"
5280template <
typename IteratorType>
5281class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
5282 :
public std::integral_constant<std::size_t, 2> {};
5284template <std::
size_t N,
typename IteratorType>
5286 N, ::nlohmann::detail::iteration_proxy_value<IteratorType>>
5290 decltype(get<N>(std::declval<::nlohmann::detail::iteration_proxy_value<IteratorType>>()));
5292#if defined(__clang__)
5293#pragma clang diagnostic pop
5299template <
typename IteratorType>
5300inline constexpr bool ::std::ranges::enable_borrowed_range<
5301 ::nlohmann::detail::iteration_proxy<IteratorType>> =
true;
5314NLOHMANN_JSON_NAMESPACE_BEGIN
5331 template <
typename BasicJsonType>
5332 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t b)
noexcept {
5333 j.m_data.m_value.destroy(j.m_data.m_type);
5335 j.m_data.m_value = b;
5336 j.assert_invariant();
5341 template <
typename BasicJsonType>
5342 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t& s) {
5343 j.m_data.m_value.destroy(j.m_data.m_type);
5345 j.m_data.m_value = s;
5346 j.assert_invariant();
5349 template <
typename BasicJsonType>
5350 static void construct(BasicJsonType& j,
typename BasicJsonType::string_t&& s) {
5351 j.m_data.m_value.destroy(j.m_data.m_type);
5353 j.m_data.m_value = std::move(s);
5354 j.assert_invariant();
5358 typename BasicJsonType,
typename CompatibleStringType,
5359 enable_if_t<!std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
5361 static void construct(BasicJsonType& j,
const CompatibleStringType& str) {
5362 j.m_data.m_value.destroy(j.m_data.m_type);
5364 j.m_data.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
5365 j.assert_invariant();
5370 template <
typename BasicJsonType>
5371 static void construct(BasicJsonType& j,
const typename BasicJsonType::binary_t& b) {
5372 j.m_data.m_value.destroy(j.m_data.m_type);
5374 j.m_data.m_value =
typename BasicJsonType::binary_t(b);
5375 j.assert_invariant();
5378 template <
typename BasicJsonType>
5379 static void construct(BasicJsonType& j,
typename BasicJsonType::binary_t&& b) {
5380 j.m_data.m_value.destroy(j.m_data.m_type);
5382 j.m_data.m_value =
typename BasicJsonType::binary_t(std::move(b));
5383 j.assert_invariant();
5388 template <
typename BasicJsonType>
5389 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val)
noexcept {
5390 j.m_data.m_value.destroy(j.m_data.m_type);
5392 j.m_data.m_value = val;
5393 j.assert_invariant();
5398 template <
typename BasicJsonType>
5399 static void construct(BasicJsonType& j,
5400 typename BasicJsonType::number_unsigned_t val)
noexcept {
5401 j.m_data.m_value.destroy(j.m_data.m_type);
5403 j.m_data.m_value = val;
5404 j.assert_invariant();
5409 template <
typename BasicJsonType>
5410 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val)
noexcept {
5411 j.m_data.m_value.destroy(j.m_data.m_type);
5413 j.m_data.m_value = val;
5414 j.assert_invariant();
5419 template <
typename BasicJsonType>
5420 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr) {
5421 j.m_data.m_value.destroy(j.m_data.m_type);
5423 j.m_data.m_value = arr;
5425 j.assert_invariant();
5428 template <
typename BasicJsonType>
5429 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr) {
5430 j.m_data.m_value.destroy(j.m_data.m_type);
5432 j.m_data.m_value = std::move(arr);
5434 j.assert_invariant();
5438 typename BasicJsonType,
typename CompatibleArrayType,
5439 enable_if_t<!std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
5441 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr) {
5445 j.m_data.m_value.destroy(j.m_data.m_type);
5447 j.m_data.m_value.array =
5448 j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
5450 j.assert_invariant();
5453 template <
typename BasicJsonType>
5454 static void construct(BasicJsonType& j,
const std::vector<bool>& arr) {
5455 j.m_data.m_value.destroy(j.m_data.m_type);
5458 j.m_data.m_value.array->reserve(arr.size());
5459 for (
const bool x : arr) {
5460 j.m_data.m_value.array->push_back(x);
5461 j.set_parent(j.m_data.m_value.array->back());
5463 j.assert_invariant();
5466 template <
typename BasicJsonType,
typename T,
5467 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
5468 static void construct(BasicJsonType& j,
const std::valarray<T>& arr) {
5469 j.m_data.m_value.destroy(j.m_data.m_type);
5472 j.m_data.m_value.array->resize(arr.size());
5473 if (arr.size() > 0) {
5474 std::copy(std::begin(arr), std::end(arr), j.m_data.m_value.array->begin());
5477 j.assert_invariant();
5482 template <
typename BasicJsonType>
5483 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj) {
5484 j.m_data.m_value.destroy(j.m_data.m_type);
5486 j.m_data.m_value = obj;
5488 j.assert_invariant();
5491 template <
typename BasicJsonType>
5492 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj) {
5493 j.m_data.m_value.destroy(j.m_data.m_type);
5495 j.m_data.m_value = std::move(obj);
5497 j.assert_invariant();
5501 typename BasicJsonType,
typename CompatibleObjectType,
5502 enable_if_t<!std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
5504 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj) {
5508 j.m_data.m_value.destroy(j.m_data.m_type);
5510 j.m_data.m_value.object =
5511 j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
5513 j.assert_invariant();
5521template <
typename BasicJsonType,
typename T,
5522 enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value,
int> = 0>
5523inline void to_json(BasicJsonType& j, T b)
noexcept {
5528 typename BasicJsonType,
typename BoolRef,
5530 ((std::is_same<std::vector<bool>::reference, BoolRef>::value &&
5531 !std::is_same<std::vector<bool>::reference,
typename BasicJsonType::boolean_t&>::value) ||
5532 (std::is_same<std::vector<bool>::const_reference, BoolRef>::value &&
5533 !std::is_same<detail::uncvref_t<std::vector<bool>::const_reference>,
5534 typename BasicJsonType::boolean_t>::value)) &&
5535 std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value,
5537inline void to_json(BasicJsonType& j,
const BoolRef& b)
noexcept {
5538 external_constructor<value_t::boolean>::construct(
5539 j,
static_cast<typename BasicJsonType::boolean_t
>(b));
5543 typename BasicJsonType,
typename CompatibleString,
5544 enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value,
5546inline void to_json(BasicJsonType& j,
const CompatibleString& s) {
5550template <
typename BasicJsonType>
5551inline void to_json(BasicJsonType& j,
typename BasicJsonType::string_t&& s) {
5555template <
typename BasicJsonType,
typename FloatType,
5556 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
5557inline void to_json(BasicJsonType& j, FloatType val)
noexcept {
5559 j,
static_cast<typename BasicJsonType::number_float_t
>(val));
5562template <
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
5564 CompatibleNumberUnsignedType>::value,
5566inline void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val)
noexcept {
5568 j,
static_cast<typename BasicJsonType::number_unsigned_t
>(val));
5571template <
typename BasicJsonType,
typename CompatibleNumberIntegerType,
5573 CompatibleNumberIntegerType>::value,
5575inline void to_json(BasicJsonType& j, CompatibleNumberIntegerType val)
noexcept {
5577 j,
static_cast<typename BasicJsonType::number_integer_t
>(val));
5580#if !JSON_DISABLE_ENUM_SERIALIZATION
5581template <
typename BasicJsonType,
typename EnumType,
5582 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
5583inline void to_json(BasicJsonType& j, EnumType e)
noexcept {
5584 using underlying_type =
typename std::underlying_type<EnumType>::type;
5585 static constexpr value_t integral_value_t = std::is_unsigned<underlying_type>::value
5592template <
typename BasicJsonType>
5593inline void to_json(BasicJsonType& j,
const std::vector<bool>& e) {
5598 typename BasicJsonType,
typename CompatibleArrayType,
5599 enable_if_t<is_compatible_array_type<BasicJsonType, CompatibleArrayType>::value &&
5601 !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value &&
5602 !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value &&
5605inline void to_json(BasicJsonType& j,
const CompatibleArrayType& arr) {
5609template <
typename BasicJsonType>
5610inline void to_json(BasicJsonType& j,
const typename BasicJsonType::binary_t& bin) {
5614template <
typename BasicJsonType,
typename T,
5615 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
5616inline void to_json(BasicJsonType& j,
const std::valarray<T>& arr) {
5620template <
typename BasicJsonType>
5621inline void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr) {
5625template <
typename BasicJsonType,
typename CompatibleObjectType,
5626 enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value &&
5629inline void to_json(BasicJsonType& j,
const CompatibleObjectType& obj) {
5633template <
typename BasicJsonType>
5634inline void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj) {
5639 typename BasicJsonType,
typename T, std::size_t N,
5641 !std::is_constructible<
typename BasicJsonType::string_t,
5653template <
typename BasicJsonType,
typename T1,
typename T2,
5654 enable_if_t<std::is_constructible<BasicJsonType, T1>::value &&
5655 std::is_constructible<BasicJsonType, T2>::value,
5657inline void to_json(BasicJsonType& j,
const std::pair<T1, T2>& p) {
5658 j = {p.first, p.second};
5663 typename BasicJsonType,
typename T,
5664 enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value,
5666inline void to_json(BasicJsonType& j,
const T& b) {
5667 j = {{b.key(), b.value()}};
5670template <
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
5671inline void to_json_tuple_impl(BasicJsonType& j,
const Tuple& t,
5672 index_sequence<Idx...> ) {
5673 j = {std::get<Idx>(t)...};
5676template <
typename BasicJsonType,
typename T,
5677 enable_if_t<is_constructible_tuple<BasicJsonType, T>::value,
int> = 0>
5678inline void to_json(BasicJsonType& j,
const T& t) {
5679 to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value>{});
5682#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
5683template <
typename BasicJsonType>
inline void to_json(BasicJsonType& j,
const std_fs::path& p) {
5689 template <
typename BasicJsonType,
typename T>
5690 auto operator()(BasicJsonType& j, T&& val)
const
5691 noexcept(
noexcept(to_json(j, std::forward<T>(val))))
5692 ->
decltype(to_json(j, std::forward<T>(val)),
void()) {
5693 return to_json(j, std::forward<T>(val));
5698#ifndef JSON_HAS_CPP_17
5705JSON_INLINE_VARIABLE
constexpr const auto& to_json =
5706 detail::static_const<detail::to_json_fn>::value;
5707#ifndef JSON_HAS_CPP_17
5711NLOHMANN_JSON_NAMESPACE_END
5715NLOHMANN_JSON_NAMESPACE_BEGIN
5721 template <
typename BasicJsonType,
typename TargetType = ValueType>
5722 static auto from_json(BasicJsonType&& j, TargetType& val)
noexcept(
5723 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
5724 ->
decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val),
void()) {
5725 ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
5730 template <
typename BasicJsonType,
typename TargetType = ValueType>
5733 ->
decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j),
5735 return ::nlohmann::from_json(std::forward<BasicJsonType>(j),
5736 detail::identity_tag<TargetType>{});
5741 template <
typename BasicJsonType,
typename TargetType = ValueType>
5742 static auto to_json(BasicJsonType& j, TargetType&& val)
noexcept(
5743 noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
5744 ->
decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)),
void()) {
5745 ::nlohmann::to_json(j, std::forward<TargetType>(val));
5749NLOHMANN_JSON_NAMESPACE_END
5766NLOHMANN_JSON_NAMESPACE_BEGIN
5772 using container_type = BinaryType;
5773 using subtype_type = std::uint64_t;
5782 : container_type(b) {}
5787 : container_type(std::move(b)) {}
5792 subtype_type subtype_)
noexcept(
noexcept(container_type(b)))
5793 : container_type(b), m_subtype(subtype_), m_has_subtype(true) {}
5798 noexcept(container_type(std::move(b))))
5799 : container_type(std::move(b)), m_subtype(subtype_), m_has_subtype(true) {}
5802 return std::tie(
static_cast<const BinaryType&
>(*
this), m_subtype, m_has_subtype) ==
5803 std::tie(
static_cast<const BinaryType&
>(rhs), rhs.m_subtype, rhs.m_has_subtype);
5811 m_subtype = subtype_;
5812 m_has_subtype =
true;
5818 return m_has_subtype ? m_subtype :
static_cast<subtype_type
>(-1);
5830 m_has_subtype =
false;
5834 subtype_type m_subtype = 0;
5835 bool m_has_subtype =
false;
5838NLOHMANN_JSON_NAMESPACE_END
5857#include <functional>
5863NLOHMANN_JSON_NAMESPACE_BEGIN
5867inline std::size_t combine(std::size_t seed, std::size_t h)
noexcept {
5868 seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
5883template <
typename BasicJsonType> std::size_t
hash(
const BasicJsonType& j) {
5884 using string_t =
typename BasicJsonType::string_t;
5885 using number_integer_t =
typename BasicJsonType::number_integer_t;
5886 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5887 using number_float_t =
typename BasicJsonType::number_float_t;
5889 const auto type =
static_cast<std::size_t
>(j.type());
5891 case BasicJsonType::value_t::null:
5892 case BasicJsonType::value_t::discarded: {
5893 return combine(type, 0);
5896 case BasicJsonType::value_t::object: {
5897 auto seed = combine(type, j.size());
5898 for (
const auto& element : j.items()) {
5899 const auto h = std::hash<string_t>{}(element.key());
5900 seed = combine(seed, h);
5901 seed = combine(seed,
hash(element.value()));
5906 case BasicJsonType::value_t::array: {
5907 auto seed = combine(type, j.size());
5908 for (
const auto& element : j) {
5909 seed = combine(seed,
hash(element));
5914 case BasicJsonType::value_t::string: {
5915 const auto h = std::hash<string_t>{}(j.template get_ref<const string_t&>());
5916 return combine(type, h);
5919 case BasicJsonType::value_t::boolean: {
5920 const auto h = std::hash<bool>{}(j.template get<bool>());
5921 return combine(type, h);
5924 case BasicJsonType::value_t::number_integer: {
5925 const auto h = std::hash<number_integer_t>{}(j.template get<number_integer_t>());
5926 return combine(type, h);
5929 case BasicJsonType::value_t::number_unsigned: {
5930 const auto h = std::hash<number_unsigned_t>{}(j.template get<number_unsigned_t>());
5931 return combine(type, h);
5934 case BasicJsonType::value_t::number_float: {
5935 const auto h = std::hash<number_float_t>{}(j.template get<number_float_t>());
5936 return combine(type, h);
5939 case BasicJsonType::value_t::binary: {
5940 auto seed = combine(type, j.get_binary().size());
5941 const auto h = std::hash<bool>{}(j.get_binary().has_subtype());
5942 seed = combine(seed, h);
5943 seed = combine(seed,
static_cast<std::size_t
>(j.get_binary().subtype()));
5944 for (
const auto byte : j.get_binary()) {
5945 seed = combine(seed, std::hash<std::uint8_t>{}(byte));
5958NLOHMANN_JSON_NAMESPACE_END
6000#include <type_traits>
6014NLOHMANN_JSON_NAMESPACE_BEGIN
6029class file_input_adapter {
6031 using char_type = char;
6033 JSON_HEDLEY_NON_NULL(2)
6034 explicit file_input_adapter(std::FILE* f) noexcept : m_file(f) {
6035 JSON_ASSERT(m_file !=
nullptr);
6039 file_input_adapter(
const file_input_adapter&) =
delete;
6040 file_input_adapter(file_input_adapter&&)
noexcept =
default;
6041 file_input_adapter& operator=(
const file_input_adapter&) =
delete;
6042 file_input_adapter& operator=(file_input_adapter&&) =
delete;
6043 ~file_input_adapter() =
default;
6045 std::char_traits<char>::int_type get_character()
noexcept {
return std::fgetc(m_file); }
6061class input_stream_adapter {
6063 using char_type = char;
6065 ~input_stream_adapter() {
6068 if (is !=
nullptr) {
6069 is->clear(is->rdstate() & std::ios::eofbit);
6073 explicit input_stream_adapter(std::istream& i) : is(&i), sb(i.rdbuf()) {}
6076 input_stream_adapter(
const input_stream_adapter&) =
delete;
6077 input_stream_adapter& operator=(input_stream_adapter&) =
delete;
6078 input_stream_adapter& operator=(input_stream_adapter&&) =
delete;
6080 input_stream_adapter(input_stream_adapter&& rhs) noexcept : is(rhs.is), sb(rhs.sb) {
6088 std::char_traits<char>::int_type get_character() {
6089 auto res = sb->sbumpc();
6091 if (JSON_HEDLEY_UNLIKELY(res == std::char_traits<char>::eof())) {
6092 is->clear(is->rdstate() | std::ios::eofbit);
6099 std::istream* is =
nullptr;
6100 std::streambuf* sb =
nullptr;
6106template <
typename IteratorType>
class iterator_input_adapter {
6108 using char_type =
typename std::iterator_traits<IteratorType>::value_type;
6110 iterator_input_adapter(IteratorType first, IteratorType last)
6111 : current(std::move(first)), end(std::move(last)) {}
6114 if (JSON_HEDLEY_LIKELY(current != end)) {
6116 std::advance(current, 1);
6124 IteratorType current;
6127 template <
typename BaseInputAdapter,
size_t T>
friend struct wide_string_input_helper;
6129 bool empty()
const {
return current == end; }
6136 static void fill_buffer(BaseInputAdapter& input,
6137 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
6138 size_t& utf8_bytes_index,
size_t& utf8_bytes_filled) {
6139 utf8_bytes_index = 0;
6141 if (JSON_HEDLEY_UNLIKELY(input.empty())) {
6142 utf8_bytes[0] = std::char_traits<char>::eof();
6143 utf8_bytes_filled = 1;
6146 const auto wc = input.get_character();
6150 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6151 utf8_bytes_filled = 1;
6152 }
else if (wc <= 0x7FF) {
6153 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(
6154 0xC0u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
6155 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(
6156 0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6157 utf8_bytes_filled = 2;
6158 }
else if (wc <= 0xFFFF) {
6159 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(
6160 0xE0u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
6161 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(
6162 0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6163 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(
6164 0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6165 utf8_bytes_filled = 3;
6166 }
else if (wc <= 0x10FFFF) {
6167 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(
6168 0xF0u | ((
static_cast<unsigned int>(wc) >> 18u) & 0x07u));
6169 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(
6170 0x80u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
6171 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(
6172 0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6173 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(
6174 0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6175 utf8_bytes_filled = 4;
6178 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6179 utf8_bytes_filled = 1;
6187 static void fill_buffer(BaseInputAdapter& input,
6188 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
6189 size_t& utf8_bytes_index,
size_t& utf8_bytes_filled) {
6190 utf8_bytes_index = 0;
6192 if (JSON_HEDLEY_UNLIKELY(input.empty())) {
6193 utf8_bytes[0] = std::char_traits<char>::eof();
6194 utf8_bytes_filled = 1;
6197 const auto wc = input.get_character();
6201 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6202 utf8_bytes_filled = 1;
6203 }
else if (wc <= 0x7FF) {
6204 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(
6205 0xC0u | ((
static_cast<unsigned int>(wc) >> 6u)));
6206 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(
6207 0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6208 utf8_bytes_filled = 2;
6209 }
else if (0xD800 > wc || wc >= 0xE000) {
6210 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(
6211 0xE0u | ((
static_cast<unsigned int>(wc) >> 12u)));
6212 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(
6213 0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6214 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(
6215 0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6216 utf8_bytes_filled = 3;
6218 if (JSON_HEDLEY_UNLIKELY(!input.empty())) {
6219 const auto wc2 =
static_cast<unsigned int>(input.get_character());
6220 const auto charcode =
6222 (((
static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
6224 static_cast<std::char_traits<char>::int_type
>(0xF0u | (charcode >> 18u));
6225 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(
6226 0x80u | ((charcode >> 12u) & 0x3Fu));
6227 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(
6228 0x80u | ((charcode >> 6u) & 0x3Fu));
6230 static_cast<std::char_traits<char>::int_type
>(0x80u | (charcode & 0x3Fu));
6231 utf8_bytes_filled = 4;
6233 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6234 utf8_bytes_filled = 1;
6243template <
typename BaseInputAdapter,
typename W
ideCharType>
class wide_string_input_adapter {
6245 using char_type = char;
6247 wide_string_input_adapter(BaseInputAdapter base) : base_adapter(base) {}
6249 typename std::char_traits<char>::int_type get_character()
noexcept {
6251 if (utf8_bytes_index == utf8_bytes_filled) {
6252 fill_buffer<sizeof(WideCharType)>();
6254 JSON_ASSERT(utf8_bytes_filled > 0);
6255 JSON_ASSERT(utf8_bytes_index == 0);
6259 JSON_ASSERT(utf8_bytes_filled > 0);
6260 JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);
6261 return utf8_bytes[utf8_bytes_index++];
6265 BaseInputAdapter base_adapter;
6267 template <
size_t T>
void fill_buffer() {
6269 base_adapter, utf8_bytes, utf8_bytes_index, utf8_bytes_filled);
6273 std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
6276 std::size_t utf8_bytes_index = 0;
6278 std::size_t utf8_bytes_filled = 0;
6282 using iterator_type = IteratorType;
6283 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
6286 static adapter_type create(IteratorType first, IteratorType last) {
6287 return adapter_type(std::move(first), std::move(last));
6292 using value_type =
typename std::iterator_traits<T>::value_type;
6293 enum { value =
sizeof(value_type) > 1 };
6296template <
typename IteratorType>
6299 using iterator_type = IteratorType;
6300 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
6304 static adapter_type create(IteratorType first, IteratorType last) {
6305 return adapter_type(base_adapter_type(std::move(first), std::move(last)));
6310template <
typename IteratorType>
6311typename iterator_input_adapter_factory<IteratorType>::adapter_type
6312input_adapter(IteratorType first, IteratorType last) {
6314 return factory_type::create(first, last);
6322namespace container_input_adapter_factory_impl {
6329template <
typename ContainerType>
6332 void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>> {
6333 using adapter_type =
decltype(input_adapter(begin(std::declval<ContainerType>()),
6334 end(std::declval<ContainerType>())));
6336 static adapter_type create(
const ContainerType& container) {
6337 return input_adapter(begin(container), end(container));
6343template <
typename ContainerType>
6345 ContainerType>::adapter_type
6346input_adapter(
const ContainerType& container) {
6348 ContainerType>::create(container);
6353inline file_input_adapter input_adapter(std::FILE* file) {
6354 return file_input_adapter(file);
6366using contiguous_bytes_input_adapter =
6367 decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
6370template <
typename CharT,
6371 typename std::enable_if<
6372 std::is_pointer<CharT>::value && !std::is_array<CharT>::value &&
6373 std::is_integral<typename std::remove_pointer<CharT>::type>::value &&
6374 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
6376contiguous_bytes_input_adapter input_adapter(CharT b) {
6377 auto length = std::strlen(
reinterpret_cast<const char*
>(b));
6378 const auto* ptr =
reinterpret_cast<const char*
>(b);
6379 return input_adapter(ptr, ptr + length);
6382template <
typename T, std::
size_t N>
6383auto input_adapter(T (&
array)[N]) ->
decltype(input_adapter(
6394class span_input_adapter {
6396 template <
typename CharT,
6397 typename std::enable_if<
6398 std::is_pointer<CharT>::value &&
6399 std::is_integral<typename std::remove_pointer<CharT>::type>::value &&
6400 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
6402 span_input_adapter(CharT b, std::size_t l)
6403 : ia(
reinterpret_cast<const char*
>(b),
reinterpret_cast<const char*
>(b) + l) {}
6405 template <
class IteratorType,
6406 typename std::enable_if<
6407 std::is_same<typename iterator_traits<IteratorType>::iterator_category,
6408 std::random_access_iterator_tag>::value,
6410 span_input_adapter(IteratorType first, IteratorType last) : ia(input_adapter(first, last)) {}
6412 contiguous_bytes_input_adapter&& get() {
6413 return std::move(ia);
6417 contiguous_bytes_input_adapter ia;
6421NLOHMANN_JSON_NAMESPACE_END
6443NLOHMANN_JSON_NAMESPACE_BEGIN
6453template <
typename BasicJsonType>
struct json_sax {
6454 using number_integer_t =
typename BasicJsonType::number_integer_t;
6455 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6456 using number_float_t =
typename BasicJsonType::number_float_t;
6457 using string_t =
typename BasicJsonType::string_t;
6458 using binary_t =
typename BasicJsonType::binary_t;
6525 virtual bool key(string_t& val) = 0;
6554 virtual bool parse_error(std::size_t position,
const std::string& last_token,
6557 json_sax() =
default;
6558 json_sax(
const json_sax&) =
default;
6559 json_sax(json_sax&&) noexcept = default;
6560 json_sax& operator=(const json_sax&) = default;
6561 json_sax& operator=(json_sax&&) noexcept = default;
6562 virtual ~json_sax() = default;
6581 using number_integer_t =
typename BasicJsonType::number_integer_t;
6582 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6583 using number_float_t =
typename BasicJsonType::number_float_t;
6584 using string_t =
typename BasicJsonType::string_t;
6585 using binary_t =
typename BasicJsonType::binary_t;
6593 : root(r), allow_exceptions(allow_exceptions_) {}
6605 handle_value(
nullptr);
6609 bool boolean(
bool val) {
6624 bool number_float(number_float_t val,
const string_t& ) {
6629 bool string(string_t& val) {
6634 bool binary(binary_t& val) {
6635 handle_value(std::move(val));
6639 bool start_object(std::size_t len) {
6640 ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
6642 if (JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) &&
6643 len > ref_stack.back()->max_size())) {
6644 JSON_THROW(out_of_range::create(
6645 408, concat(
"excessive object size: ", std::to_string(len)), ref_stack.back()));
6651 bool key(string_t& val) {
6652 JSON_ASSERT(!ref_stack.empty());
6653 JSON_ASSERT(ref_stack.back()->is_object());
6656 object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val));
6661 JSON_ASSERT(!ref_stack.empty());
6662 JSON_ASSERT(ref_stack.back()->is_object());
6664 ref_stack.back()->set_parents();
6665 ref_stack.pop_back();
6669 bool start_array(std::size_t len) {
6670 ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
6672 if (JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) &&
6673 len > ref_stack.back()->max_size())) {
6674 JSON_THROW(out_of_range::create(
6675 408, concat(
"excessive array size: ", std::to_string(len)), ref_stack.back()));
6682 JSON_ASSERT(!ref_stack.empty());
6683 JSON_ASSERT(ref_stack.back()->is_array());
6685 ref_stack.back()->set_parents();
6686 ref_stack.pop_back();
6690 template <
class Exception>
6691 bool parse_error(std::size_t ,
const std::string& ,
const Exception& ex) {
6693 static_cast<void>(ex);
6694 if (allow_exceptions) {
6700 constexpr bool is_errored()
const {
return errored; }
6709 template <
typename Value> JSON_HEDLEY_RETURNS_NON_NULL BasicJsonType* handle_value(Value&& v) {
6710 if (ref_stack.empty()) {
6711 root = BasicJsonType(std::forward<Value>(v));
6715 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6717 if (ref_stack.back()->is_array()) {
6718 ref_stack.back()->m_data.m_value.array->emplace_back(std::forward<Value>(v));
6719 return &(ref_stack.back()->m_data.m_value.array->back());
6722 JSON_ASSERT(ref_stack.back()->is_object());
6723 JSON_ASSERT(object_element);
6724 *object_element = BasicJsonType(std::forward<Value>(v));
6725 return object_element;
6729 BasicJsonType& root;
6731 std::vector<BasicJsonType*> ref_stack{};
6733 BasicJsonType* object_element =
nullptr;
6735 bool errored =
false;
6737 const bool allow_exceptions =
true;
6740template <
typename BasicJsonType>
class json_sax_dom_callback_parser {
6742 using number_integer_t =
typename BasicJsonType::number_integer_t;
6743 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6744 using number_float_t =
typename BasicJsonType::number_float_t;
6745 using string_t =
typename BasicJsonType::string_t;
6746 using binary_t =
typename BasicJsonType::binary_t;
6747 using parser_callback_t =
typename BasicJsonType::parser_callback_t;
6748 using parse_event_t =
typename BasicJsonType::parse_event_t;
6750 json_sax_dom_callback_parser(BasicJsonType& r,
const parser_callback_t cb,
6751 const bool allow_exceptions_ =
true)
6752 : root(r), callback(cb), allow_exceptions(allow_exceptions_) {
6753 keep_stack.push_back(
true);
6757 json_sax_dom_callback_parser(
const json_sax_dom_callback_parser&) =
delete;
6758 json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) =
6760 json_sax_dom_callback_parser& operator=(
const json_sax_dom_callback_parser&) =
delete;
6761 json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) =
6763 ~json_sax_dom_callback_parser() =
default;
6766 handle_value(
nullptr);
6770 bool boolean(
bool val) {
6775 bool number_integer(number_integer_t val) {
6780 bool number_unsigned(number_unsigned_t val) {
6785 bool number_float(number_float_t val,
const string_t& ) {
6790 bool string(string_t& val) {
6795 bool binary(binary_t& val) {
6796 handle_value(std::move(val));
6800 bool start_object(std::size_t len) {
6804 keep_stack.push_back(keep);
6806 auto val = handle_value(BasicJsonType::value_t::object,
true);
6807 ref_stack.push_back(val.second);
6810 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) &&
6811 len > ref_stack.back()->max_size())) {
6812 JSON_THROW(out_of_range::create(
6813 408, concat(
"excessive object size: ", std::to_string(len)), ref_stack.back()));
6819 bool key(string_t& val) {
6820 BasicJsonType k = BasicJsonType(val);
6823 const bool keep = callback(
static_cast<int>(ref_stack.size()),
parse_event_t::key, k);
6824 key_keep_stack.push_back(keep);
6827 if (keep && ref_stack.back()) {
6829 &(ref_stack.back()->m_data.m_value.object->operator[](val) = discarded);
6836 if (ref_stack.back()) {
6838 *ref_stack.back())) {
6840 *ref_stack.back() = discarded;
6842 ref_stack.back()->set_parents();
6846 JSON_ASSERT(!ref_stack.empty());
6847 JSON_ASSERT(!keep_stack.empty());
6848 ref_stack.pop_back();
6849 keep_stack.pop_back();
6851 if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured()) {
6853 for (
auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it) {
6854 if (it->is_discarded()) {
6855 ref_stack.back()->erase(it);
6864 bool start_array(std::size_t len) {
6867 keep_stack.push_back(keep);
6869 auto val = handle_value(BasicJsonType::value_t::array,
true);
6870 ref_stack.push_back(val.second);
6873 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) &&
6874 len > ref_stack.back()->max_size())) {
6875 JSON_THROW(out_of_range::create(
6876 408, concat(
"excessive array size: ", std::to_string(len)), ref_stack.back()));
6885 if (ref_stack.back()) {
6889 ref_stack.back()->set_parents();
6892 *ref_stack.back() = discarded;
6896 JSON_ASSERT(!ref_stack.empty());
6897 JSON_ASSERT(!keep_stack.empty());
6898 ref_stack.pop_back();
6899 keep_stack.pop_back();
6902 if (!keep && !ref_stack.empty() && ref_stack.back()->is_array()) {
6903 ref_stack.back()->m_data.m_value.array->pop_back();
6909 template <
class Exception>
6910 bool parse_error(std::size_t ,
const std::string& ,
const Exception& ex) {
6912 static_cast<void>(ex);
6913 if (allow_exceptions) {
6919 constexpr bool is_errored()
const {
return errored; }
6937 template <
typename Value>
6938 std::pair<bool, BasicJsonType*> handle_value(Value&& v,
const bool skip_callback =
false) {
6939 JSON_ASSERT(!keep_stack.empty());
6943 if (!keep_stack.back()) {
6944 return {
false,
nullptr};
6948 auto value = BasicJsonType(std::forward<Value>(v));
6951 const bool keep = skip_callback ||
6956 return {
false,
nullptr};
6959 if (ref_stack.empty()) {
6960 root = std::move(value);
6961 return {
true, &root};
6966 if (!ref_stack.back()) {
6967 return {
false,
nullptr};
6971 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6974 if (ref_stack.back()->is_array()) {
6975 ref_stack.back()->m_data.m_value.array->emplace_back(std::move(value));
6976 return {
true, &(ref_stack.back()->m_data.m_value.array->back())};
6980 JSON_ASSERT(ref_stack.back()->is_object());
6982 JSON_ASSERT(!key_keep_stack.empty());
6983 const bool store_element = key_keep_stack.back();
6984 key_keep_stack.pop_back();
6986 if (!store_element) {
6987 return {
false,
nullptr};
6990 JSON_ASSERT(object_element);
6991 *object_element = std::move(value);
6992 return {
true, object_element};
6996 BasicJsonType& root;
6998 std::vector<BasicJsonType*> ref_stack{};
7000 std::vector<bool> keep_stack{};
7002 std::vector<bool> key_keep_stack{};
7004 BasicJsonType* object_element =
nullptr;
7006 bool errored =
false;
7008 const parser_callback_t callback =
nullptr;
7010 const bool allow_exceptions =
true;
7012 BasicJsonType discarded = BasicJsonType::value_t::discarded;
7017 using number_integer_t =
typename BasicJsonType::number_integer_t;
7018 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7019 using number_float_t =
typename BasicJsonType::number_float_t;
7020 using string_t =
typename BasicJsonType::string_t;
7021 using binary_t =
typename BasicJsonType::binary_t;
7023 bool null() {
return true; }
7025 bool boolean(
bool ) {
return true; }
7027 bool number_integer(number_integer_t ) {
return true; }
7029 bool number_unsigned(number_unsigned_t ) {
return true; }
7031 bool number_float(number_float_t ,
const string_t& ) {
return true; }
7033 bool string(string_t& ) {
return true; }
7035 bool binary(binary_t& ) {
return true; }
7037 bool start_object(std::size_t =
static_cast<std::size_t
>(-1)) {
return true; }
7039 bool key(string_t& ) {
return true; }
7041 bool end_object() {
return true; }
7043 bool start_array(std::size_t =
static_cast<std::size_t
>(-1)) {
return true; }
7045 bool end_array() {
return true; }
7047 bool parse_error(std::size_t ,
const std::string& ,
7054NLOHMANN_JSON_NAMESPACE_END
7070#include <initializer_list>
7083NLOHMANN_JSON_NAMESPACE_BEGIN
7118 JSON_HEDLEY_RETURNS_NON_NULL
7123 return "<uninitialized>";
7125 return "true literal";
7127 return "false literal";
7129 return "null literal";
7131 return "string literal";
7135 return "number literal";
7149 return "<parse error>";
7151 return "end of input";
7153 return "'[', '{', or a literal";
7156 return "unknown token";
7166template <
typename BasicJsonType,
typename InputAdapterType>
7168 using number_integer_t =
typename BasicJsonType::number_integer_t;
7169 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7170 using number_float_t =
typename BasicJsonType::number_float_t;
7171 using string_t =
typename BasicJsonType::string_t;
7172 using char_type =
typename InputAdapterType::char_type;
7178 explicit lexer(InputAdapterType&& adapter,
bool ignore_comments_ =
false) noexcept
7179 : ia(std::move(adapter)), ignore_comments(ignore_comments_),
7180 decimal_point_char(
static_cast<char_int_type
>(get_decimal_point())) {}
7183 lexer(
const lexer&) =
delete;
7184 lexer(lexer&&) =
default;
7185 lexer& operator=(lexer&) =
delete;
7186 lexer& operator=(lexer&&) =
7197 static char get_decimal_point()
noexcept {
7198 const auto* loc = localeconv();
7199 JSON_ASSERT(loc !=
nullptr);
7200 return (loc->decimal_point ==
nullptr) ?
'.' : *(loc->decimal_point);
7222 int get_codepoint() {
7224 JSON_ASSERT(current ==
'u');
7227 const auto factors = {12u, 8u, 4u, 0u};
7228 for (
const auto factor : factors) {
7231 if (current >=
'0' && current <=
'9') {
7233 static_cast<int>((
static_cast<unsigned int>(current) - 0x30u) << factor);
7234 }
else if (current >=
'A' && current <=
'F') {
7236 static_cast<int>((
static_cast<unsigned int>(current) - 0x37u) << factor);
7237 }
else if (current >=
'a' && current <=
'f') {
7239 static_cast<int>((
static_cast<unsigned int>(current) - 0x57u) << factor);
7245 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
7264 bool next_byte_in_range(std::initializer_list<char_int_type> ranges) {
7265 JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
7268 for (
auto range = ranges.begin(); range != ranges.end(); ++range) {
7270 if (JSON_HEDLEY_LIKELY(*range <= current &&
7271 current <= *(++range)))
7275 error_message =
"invalid string: ill-formed UTF-8 byte";
7298 token_type scan_string() {
7303 JSON_ASSERT(current ==
'\"');
7310 error_message =
"invalid string: missing closing quote";
7311 return token_type::parse_error;
7316 return token_type::value_string;
7357 const int codepoint1 = get_codepoint();
7358 int codepoint = codepoint1;
7360 if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1)) {
7362 "invalid string: '\\u' must be followed by 4 hex digits";
7363 return token_type::parse_error;
7367 if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF) {
7369 if (JSON_HEDLEY_LIKELY(get() ==
'\\' && get() ==
'u')) {
7370 const int codepoint2 = get_codepoint();
7372 if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1)) {
7373 error_message =
"invalid string: '\\u' must be followed by "
7375 return token_type::parse_error;
7379 if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 &&
7380 codepoint2 <= 0xDFFF)) {
7382 codepoint =
static_cast<int>(
7384 (
static_cast<unsigned int>(codepoint1) << 10u)
7386 +
static_cast<unsigned int>(codepoint2)
7393 "invalid string: surrogate U+D800..U+DBFF must "
7394 "be followed by U+DC00..U+DFFF";
7395 return token_type::parse_error;
7398 error_message =
"invalid string: surrogate U+D800..U+DBFF must "
7399 "be followed by U+DC00..U+DFFF";
7400 return token_type::parse_error;
7403 if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 &&
7404 codepoint1 <= 0xDFFF)) {
7405 error_message =
"invalid string: surrogate U+DC00..U+DFFF must "
7406 "follow U+D800..U+DBFF";
7407 return token_type::parse_error;
7412 JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
7415 if (codepoint < 0x80) {
7417 add(
static_cast<char_int_type
>(codepoint));
7418 }
else if (codepoint <= 0x7FF) {
7420 add(
static_cast<char_int_type
>(
7421 0xC0u | (
static_cast<unsigned int>(codepoint) >> 6u)));
7422 add(
static_cast<char_int_type
>(
7423 0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7424 }
else if (codepoint <= 0xFFFF) {
7426 add(
static_cast<char_int_type
>(
7427 0xE0u | (
static_cast<unsigned int>(codepoint) >> 12u)));
7428 add(
static_cast<char_int_type
>(
7430 ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7431 add(
static_cast<char_int_type
>(
7432 0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7435 add(
static_cast<char_int_type
>(
7436 0xF0u | (
static_cast<unsigned int>(codepoint) >> 18u)));
7437 add(
static_cast<char_int_type
>(
7439 ((
static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
7440 add(
static_cast<char_int_type
>(
7442 ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7443 add(
static_cast<char_int_type
>(
7444 0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7452 error_message =
"invalid string: forbidden character after backslash";
7453 return token_type::parse_error;
7461 error_message =
"invalid string: control character U+0000 (NUL) must "
7462 "be escaped to \\u0000";
7463 return token_type::parse_error;
7467 error_message =
"invalid string: control character U+0001 (SOH) must "
7468 "be escaped to \\u0001";
7469 return token_type::parse_error;
7473 error_message =
"invalid string: control character U+0002 (STX) must "
7474 "be escaped to \\u0002";
7475 return token_type::parse_error;
7479 error_message =
"invalid string: control character U+0003 (ETX) must "
7480 "be escaped to \\u0003";
7481 return token_type::parse_error;
7485 error_message =
"invalid string: control character U+0004 (EOT) must "
7486 "be escaped to \\u0004";
7487 return token_type::parse_error;
7491 error_message =
"invalid string: control character U+0005 (ENQ) must "
7492 "be escaped to \\u0005";
7493 return token_type::parse_error;
7497 error_message =
"invalid string: control character U+0006 (ACK) must "
7498 "be escaped to \\u0006";
7499 return token_type::parse_error;
7503 error_message =
"invalid string: control character U+0007 (BEL) must "
7504 "be escaped to \\u0007";
7505 return token_type::parse_error;
7509 error_message =
"invalid string: control character U+0008 (BS) must be "
7510 "escaped to \\u0008 or \\b";
7511 return token_type::parse_error;
7515 error_message =
"invalid string: control character U+0009 (HT) must be "
7516 "escaped to \\u0009 or \\t";
7517 return token_type::parse_error;
7521 error_message =
"invalid string: control character U+000A (LF) must be "
7522 "escaped to \\u000A or \\n";
7523 return token_type::parse_error;
7527 error_message =
"invalid string: control character U+000B (VT) must be "
7528 "escaped to \\u000B";
7529 return token_type::parse_error;
7533 error_message =
"invalid string: control character U+000C (FF) must be "
7534 "escaped to \\u000C or \\f";
7535 return token_type::parse_error;
7539 error_message =
"invalid string: control character U+000D (CR) must be "
7540 "escaped to \\u000D or \\r";
7541 return token_type::parse_error;
7545 error_message =
"invalid string: control character U+000E (SO) must be "
7546 "escaped to \\u000E";
7547 return token_type::parse_error;
7551 error_message =
"invalid string: control character U+000F (SI) must be "
7552 "escaped to \\u000F";
7553 return token_type::parse_error;
7557 error_message =
"invalid string: control character U+0010 (DLE) must "
7558 "be escaped to \\u0010";
7559 return token_type::parse_error;
7563 error_message =
"invalid string: control character U+0011 (DC1) must "
7564 "be escaped to \\u0011";
7565 return token_type::parse_error;
7569 error_message =
"invalid string: control character U+0012 (DC2) must "
7570 "be escaped to \\u0012";
7571 return token_type::parse_error;
7575 error_message =
"invalid string: control character U+0013 (DC3) must "
7576 "be escaped to \\u0013";
7577 return token_type::parse_error;
7581 error_message =
"invalid string: control character U+0014 (DC4) must "
7582 "be escaped to \\u0014";
7583 return token_type::parse_error;
7587 error_message =
"invalid string: control character U+0015 (NAK) must "
7588 "be escaped to \\u0015";
7589 return token_type::parse_error;
7593 error_message =
"invalid string: control character U+0016 (SYN) must "
7594 "be escaped to \\u0016";
7595 return token_type::parse_error;
7599 error_message =
"invalid string: control character U+0017 (ETB) must "
7600 "be escaped to \\u0017";
7601 return token_type::parse_error;
7605 error_message =
"invalid string: control character U+0018 (CAN) must "
7606 "be escaped to \\u0018";
7607 return token_type::parse_error;
7611 error_message =
"invalid string: control character U+0019 (EM) must be "
7612 "escaped to \\u0019";
7613 return token_type::parse_error;
7617 error_message =
"invalid string: control character U+001A (SUB) must "
7618 "be escaped to \\u001A";
7619 return token_type::parse_error;
7623 error_message =
"invalid string: control character U+001B (ESC) must "
7624 "be escaped to \\u001B";
7625 return token_type::parse_error;
7629 error_message =
"invalid string: control character U+001C (FS) must be "
7630 "escaped to \\u001C";
7631 return token_type::parse_error;
7635 error_message =
"invalid string: control character U+001D (GS) must be "
7636 "escaped to \\u001D";
7637 return token_type::parse_error;
7641 error_message =
"invalid string: control character U+001E (RS) must be "
7642 "escaped to \\u001E";
7643 return token_type::parse_error;
7647 error_message =
"invalid string: control character U+001F (US) must be "
7648 "escaped to \\u001F";
7649 return token_type::parse_error;
7782 if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF}))) {
7783 return token_type::parse_error;
7790 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF})))) {
7791 return token_type::parse_error;
7812 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF})))) {
7813 return token_type::parse_error;
7820 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF})))) {
7821 return token_type::parse_error;
7828 if (JSON_HEDLEY_UNLIKELY(
7829 !(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF})))) {
7830 return token_type::parse_error;
7839 if (JSON_HEDLEY_UNLIKELY(
7840 !(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF})))) {
7841 return token_type::parse_error;
7848 if (JSON_HEDLEY_UNLIKELY(
7849 !(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF})))) {
7850 return token_type::parse_error;
7857 error_message =
"invalid string: ill-formed UTF-8 byte";
7858 return token_type::parse_error;
7868 bool scan_comment() {
7892 error_message =
"invalid comment; missing closing '*/'";
7916 error_message =
"invalid comment; expecting '/' or '*' after '/'";
7922 JSON_HEDLEY_NON_NULL(2)
7923 static void strtof(
float& f,
const char* str,
char** endptr)
noexcept {
7924 f = std::strtof(str, endptr);
7927 JSON_HEDLEY_NON_NULL(2)
7928 static void strtof(
double& f,
const char* str,
char** endptr)
noexcept {
7929 f = std::strtod(str, endptr);
7932 JSON_HEDLEY_NON_NULL(2)
7933 static void strtof(
long double& f,
const char* str,
char** endptr)
noexcept {
7934 f = std::strtold(str, endptr);
7979 token_type scan_number()
7986 token_type number_type = token_type::value_unsigned;
7992 goto scan_number_minus;
7997 goto scan_number_zero;
8010 goto scan_number_any1;
8021 number_type = token_type::value_integer;
8025 goto scan_number_zero;
8038 goto scan_number_any1;
8042 error_message =
"invalid number; expected digit after '-'";
8043 return token_type::parse_error;
8051 add(decimal_point_char);
8052 goto scan_number_decimal1;
8058 goto scan_number_exponent;
8062 goto scan_number_done;
8079 goto scan_number_any1;
8083 add(decimal_point_char);
8084 goto scan_number_decimal1;
8090 goto scan_number_exponent;
8094 goto scan_number_done;
8097 scan_number_decimal1:
8099 number_type = token_type::value_float;
8112 goto scan_number_decimal2;
8116 error_message =
"invalid number; expected digit after '.'";
8117 return token_type::parse_error;
8121 scan_number_decimal2:
8135 goto scan_number_decimal2;
8141 goto scan_number_exponent;
8145 goto scan_number_done;
8148 scan_number_exponent:
8150 number_type = token_type::value_float;
8155 goto scan_number_sign;
8169 goto scan_number_any2;
8173 error_message =
"invalid number; expected '+', '-', or digit after exponent";
8174 return token_type::parse_error;
8192 goto scan_number_any2;
8196 error_message =
"invalid number; expected digit after exponent sign";
8197 return token_type::parse_error;
8215 goto scan_number_any2;
8219 goto scan_number_done;
8227 char* endptr =
nullptr;
8231 if (number_type == token_type::value_unsigned) {
8232 const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
8235 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8238 value_unsigned =
static_cast<number_unsigned_t
>(x);
8239 if (value_unsigned == x) {
8240 return token_type::value_unsigned;
8243 }
else if (number_type == token_type::value_integer) {
8244 const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
8247 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8250 value_integer =
static_cast<number_integer_t
>(x);
8251 if (value_integer == x) {
8252 return token_type::value_integer;
8259 strtof(value_float, token_buffer.data(), &endptr);
8262 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8264 return token_type::value_float;
8272 JSON_HEDLEY_NON_NULL(2)
8273 token_type scan_literal(
const char_type* literal_text,
const std::size_t length,
8274 token_type return_type) {
8276 for (std::size_t i = 1; i < length; ++i) {
8279 error_message =
"invalid literal";
8280 return token_type::parse_error;
8291 void reset()
noexcept {
8292 token_buffer.clear();
8293 token_string.clear();
8307 char_int_type get() {
8308 ++position.chars_read_total;
8309 ++position.chars_read_current_line;
8315 current = ia.get_character();
8322 if (current ==
'\n') {
8323 ++position.lines_read;
8324 position.chars_read_current_line = 0;
8341 --position.chars_read_total;
8344 if (position.chars_read_current_line == 0) {
8345 if (position.lines_read > 0) {
8346 --position.lines_read;
8349 --position.chars_read_current_line;
8353 JSON_ASSERT(!token_string.empty());
8354 token_string.pop_back();
8359 void add(char_int_type c) {
8360 token_buffer.push_back(
static_cast<typename string_t::value_type
>(c));
8394 for (
const auto c : token_string) {
8395 if (
static_cast<unsigned char>(c) <=
'\x1F') {
8397 std::array<char, 9> cs{{}};
8398 static_cast<void>((std::snprintf)(
8399 cs.data(), cs.size(),
"<U+%.4X>",
8400 static_cast<unsigned char>(
8402 result += cs.data();
8405 result.push_back(
static_cast<std::string::value_type
>(c));
8413 JSON_HEDLEY_RETURNS_NON_NULL
8425 if (get() == 0xEF) {
8427 return get() == 0xBB && get() == 0xBF;
8436 void skip_whitespace() {
8439 }
while (current ==
' ' || current ==
'\t' || current ==
'\n' || current ==
'\r');
8444 if (position.chars_read_total == 0 && !skip_bom()) {
8445 error_message =
"invalid BOM; must be 0xEF 0xBB 0xBF if given";
8446 return token_type::parse_error;
8453 while (ignore_comments && current ==
'/') {
8454 if (!scan_comment()) {
8455 return token_type::parse_error;
8465 return token_type::begin_array;
8467 return token_type::end_array;
8469 return token_type::begin_object;
8471 return token_type::end_object;
8473 return token_type::name_separator;
8475 return token_type::value_separator;
8479 std::array<char_type, 4> true_literal = {
8480 {
static_cast<char_type
>(
't'),
static_cast<char_type
>(
'r'),
8481 static_cast<char_type
>(
'u'),
static_cast<char_type
>(
'e')}};
8482 return scan_literal(true_literal.data(), true_literal.size(),
8483 token_type::literal_true);
8486 std::array<char_type, 5> false_literal = {
8487 {
static_cast<char_type
>(
'f'),
static_cast<char_type
>(
'a'),
8488 static_cast<char_type
>(
'l'),
static_cast<char_type
>(
's'),
8489 static_cast<char_type
>(
'e')}};
8490 return scan_literal(false_literal.data(), false_literal.size(),
8491 token_type::literal_false);
8494 std::array<char_type, 4> null_literal = {
8495 {
static_cast<char_type
>(
'n'),
static_cast<char_type
>(
'u'),
8496 static_cast<char_type
>(
'l'),
static_cast<char_type
>(
'l')}};
8497 return scan_literal(null_literal.data(), null_literal.size(),
8498 token_type::literal_null);
8503 return scan_string();
8517 return scan_number();
8522 case char_traits<char_type>::eof():
8523 return token_type::end_of_input;
8527 error_message =
"invalid literal";
8528 return token_type::parse_error;
8534 InputAdapterType ia;
8537 const bool ignore_comments =
false;
8540 char_int_type current = char_traits<char_type>::eof();
8543 bool next_unget =
false;
8546 position_t position{};
8549 std::vector<char_type> token_string{};
8552 string_t token_buffer{};
8555 const char* error_message =
"";
8558 number_integer_t value_integer = 0;
8559 number_unsigned_t value_unsigned = 0;
8560 number_float_t value_float = 0;
8563 const char_int_type decimal_point_char =
'.';
8567NLOHMANN_JSON_NAMESPACE_END
8590NLOHMANN_JSON_NAMESPACE_BEGIN
8593template <
typename T>
using null_function_t =
decltype(std::declval<T&>().null());
8595template <
typename T>
8596using boolean_function_t =
decltype(std::declval<T&>().boolean(std::declval<bool>()));
8598template <
typename T,
typename Integer>
8599using number_integer_function_t =
8600 decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
8602template <
typename T,
typename Un
signed>
8603using number_unsigned_function_t =
8604 decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
8606template <
typename T,
typename Float,
typename String>
8607using number_float_function_t =
8608 decltype(std::declval<T&>().number_float(std::declval<Float>(), std::declval<const String&>()));
8610template <
typename T,
typename String>
8611using string_function_t =
decltype(std::declval<T&>().string(std::declval<String&>()));
8613template <
typename T,
typename Binary>
8614using binary_function_t =
decltype(std::declval<T&>().binary(std::declval<Binary&>()));
8616template <
typename T>
8617using start_object_function_t =
8618 decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
8620template <
typename T,
typename String>
8621using key_function_t =
decltype(std::declval<T&>().key(std::declval<String&>()));
8623template <
typename T>
using end_object_function_t =
decltype(std::declval<T&>().end_object());
8625template <
typename T>
8626using start_array_function_t =
8627 decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
8629template <
typename T>
using end_array_function_t =
decltype(std::declval<T&>().end_array());
8631template <
typename T,
typename Exception>
8632using parse_error_function_t =
8633 decltype(std::declval<T&>().parse_error(std::declval<std::size_t>(),
8634 std::declval<const std::string&>(),
8635 std::declval<const Exception&>()));
8637template <
typename SAX,
typename BasicJsonType>
struct is_sax {
8640 "BasicJsonType must be of type basic_json<...>");
8642 using number_integer_t =
typename BasicJsonType::number_integer_t;
8643 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8644 using number_float_t =
typename BasicJsonType::number_float_t;
8645 using string_t =
typename BasicJsonType::string_t;
8646 using binary_t =
typename BasicJsonType::binary_t;
8647 using exception_t =
typename BasicJsonType::exception;
8650 static constexpr bool value =
8651 is_detected_exact<bool, null_function_t, SAX>::value &&
8652 is_detected_exact<bool, boolean_function_t, SAX>::value &&
8653 is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
8654 is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
8655 is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
8656 is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
8657 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
8658 is_detected_exact<bool, start_object_function_t, SAX>::value &&
8659 is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
8660 is_detected_exact<bool, end_object_function_t, SAX>::value &&
8661 is_detected_exact<bool, start_array_function_t, SAX>::value &&
8662 is_detected_exact<bool, end_array_function_t, SAX>::value &&
8663 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
8669 "BasicJsonType must be of type basic_json<...>");
8671 using number_integer_t =
typename BasicJsonType::number_integer_t;
8672 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8673 using number_float_t =
typename BasicJsonType::number_float_t;
8674 using string_t =
typename BasicJsonType::string_t;
8675 using binary_t =
typename BasicJsonType::binary_t;
8676 using exception_t =
typename BasicJsonType::exception;
8679 static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
8680 "Missing/invalid function: bool null()");
8681 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
8682 "Missing/invalid function: bool boolean(bool)");
8683 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
8684 "Missing/invalid function: bool boolean(bool)");
8685 static_assert(is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value,
8686 "Missing/invalid function: bool number_integer(number_integer_t)");
8688 is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value,
8689 "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
8691 is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value,
8692 "Missing/invalid function: bool number_float(number_float_t, "
8693 "const string_t&)");
8694 static_assert(is_detected_exact<bool, string_function_t, SAX, string_t>::value,
8695 "Missing/invalid function: bool string(string_t&)");
8696 static_assert(is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
8697 "Missing/invalid function: bool binary(binary_t&)");
8698 static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
8699 "Missing/invalid function: bool start_object(std::size_t)");
8700 static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
8701 "Missing/invalid function: bool key(string_t&)");
8702 static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
8703 "Missing/invalid function: bool end_object()");
8704 static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
8705 "Missing/invalid function: bool start_array(std::size_t)");
8706 static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
8707 "Missing/invalid function: bool end_array()");
8708 static_assert(is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
8709 "Missing/invalid function: bool parse_error(std::size_t, const "
8710 "std::string&, const exception&)");
8714NLOHMANN_JSON_NAMESPACE_END
8722NLOHMANN_JSON_NAMESPACE_BEGIN
8739static inline bool little_endianness(
int num = 1) noexcept {
8740 return *
reinterpret_cast<char*
>(&num) == 1;
8750template <
typename BasicJsonType,
typename InputAdapterType,
8751 typename SAX = json_sax_dom_parser<BasicJsonType>>
8753 using number_integer_t =
typename BasicJsonType::number_integer_t;
8754 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8755 using number_float_t =
typename BasicJsonType::number_float_t;
8756 using string_t =
typename BasicJsonType::string_t;
8757 using binary_t =
typename BasicJsonType::binary_t;
8758 using json_sax_t = SAX;
8759 using char_type =
typename InputAdapterType::char_type;
8770 : ia(std::move(adapter)), input_format(format) {
8791 JSON_HEDLEY_NON_NULL(3)
8795 bool result =
false;
8798 case input_format_t::bson:
8799 result = parse_bson_internal();
8802 case input_format_t::cbor:
8803 result = parse_cbor_internal(
true, tag_handler);
8806 case input_format_t::msgpack:
8807 result = parse_msgpack_internal();
8810 case input_format_t::ubjson:
8811 case input_format_t::bjdata:
8812 result = parse_ubjson_internal();
8815 case input_format_t::json:
8823 if (input_format == input_format_t::ubjson || input_format == input_format_t::bjdata) {
8830 return sax->parse_error(
8831 chars_read, get_token_string(),
8836 concat(
"expected end of input; last byte: 0x", get_token_string()),
8854 bool parse_bson_internal() {
8855 std::int32_t document_size{};
8856 get_number<std::int32_t, true>(input_format_t::bson, document_size);
8858 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(
static_cast<std::size_t
>(-1)))) {
8862 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
false))) {
8866 return sax->end_object();
8876 bool get_bson_cstr(string_t& result) {
8877 auto out = std::back_inserter(result);
8880 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"cstring"))) {
8883 if (current == 0x00) {
8886 *out++ =
static_cast<typename string_t::value_type
>(current);
8901 template <
typename NumberType>
bool get_bson_string(
const NumberType len, string_t& result) {
8902 if (JSON_HEDLEY_UNLIKELY(len < 1)) {
8903 auto last_token = get_token_string();
8904 return sax->parse_error(
8905 chars_read, last_token,
8906 parse_error::create(
8909 input_format_t::bson,
8910 concat(
"string length must be at least 1, is ", std::to_string(len)),
8915 return get_string(input_format_t::bson, len -
static_cast<NumberType
>(1), result) &&
8916 get() != char_traits<char_type>::eof();
8928 template <
typename NumberType>
bool get_bson_binary(
const NumberType len, binary_t& result) {
8929 if (JSON_HEDLEY_UNLIKELY(len < 0)) {
8930 auto last_token = get_token_string();
8931 return sax->parse_error(
8932 chars_read, last_token,
8933 parse_error::create(
8936 input_format_t::bson,
8937 concat(
"byte array length cannot be negative, is ", std::to_string(len)),
8943 std::uint8_t subtype{};
8944 get_number<std::uint8_t>(input_format_t::bson, subtype);
8945 result.set_subtype(subtype);
8947 return get_binary(input_format_t::bson, len, result);
8961 bool parse_bson_element_internal(
const char_int_type element_type,
8962 const std::size_t element_type_parse_position) {
8963 switch (element_type) {
8967 return get_number<double, true>(input_format_t::bson, number) &&
8968 sax->number_float(
static_cast<number_float_t
>(number),
"");
8975 return get_number<std::int32_t, true>(input_format_t::bson, len) &&
8976 get_bson_string(len, value) && sax->string(value);
8981 return parse_bson_internal();
8986 return parse_bson_array();
8993 return get_number<std::int32_t, true>(input_format_t::bson, len) &&
8994 get_bson_binary(len, value) && sax->binary(value);
8999 return sax->boolean(get() != 0);
9009 std::int32_t value{};
9010 return get_number<std::int32_t, true>(input_format_t::bson, value) &&
9011 sax->number_integer(value);
9016 std::int64_t value{};
9017 return get_number<std::int64_t, true>(input_format_t::bson, value) &&
9018 sax->number_integer(value);
9023 std::array<char, 3> cr{{}};
9024 static_cast<void>((std::snprintf)(
9025 cr.data(), cr.size(),
"%.2hhX",
9026 static_cast<unsigned char>(
9028 const std::string cr_str{cr.data()};
9029 return sax->parse_error(
9030 element_type_parse_position, cr_str,
9031 parse_error::create(114, element_type_parse_position,
9032 concat(
"Unsupported BSON record type 0x", cr_str),
9050 bool parse_bson_element_list(
const bool is_array) {
9053 while (
auto element_type = get()) {
9054 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"element list"))) {
9058 const std::size_t element_type_parse_position = chars_read;
9059 if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key))) {
9063 if (!is_array && !sax->key(key)) {
9067 if (JSON_HEDLEY_UNLIKELY(
9068 !parse_bson_element_internal(element_type, element_type_parse_position))) {
9083 bool parse_bson_array() {
9084 std::int32_t document_size{};
9085 get_number<std::int32_t, true>(input_format_t::bson, document_size);
9087 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(
static_cast<std::size_t
>(-1)))) {
9091 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
true))) {
9095 return sax->end_array();
9110 bool parse_cbor_internal(
const bool get_char,
const cbor_tag_handler_t tag_handler) {
9111 switch (get_char ? get() : current) {
9113 case char_traits<char_type>::eof():
9141 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
9145 std::uint8_t number{};
9146 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9151 std::uint16_t number{};
9152 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9157 std::uint32_t number{};
9158 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9163 std::uint64_t number{};
9164 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9192 return sax->number_integer(
static_cast<std::int8_t
>(0x20 - 1 - current));
9196 std::uint8_t number{};
9197 return get_number(input_format_t::cbor, number) &&
9198 sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
9203 std::uint16_t number{};
9204 return get_number(input_format_t::cbor, number) &&
9205 sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
9210 std::uint32_t number{};
9211 return get_number(input_format_t::cbor, number) &&
9212 sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
9217 std::uint64_t number{};
9218 return get_number(input_format_t::cbor, number) &&
9219 sax->number_integer(
static_cast<number_integer_t
>(-1) -
9220 static_cast<number_integer_t
>(number));
9255 return get_cbor_binary(b) && sax->binary(b);
9290 return get_cbor_string(s) && sax->string(s);
9318 return get_cbor_array(conditional_static_cast<std::size_t>(
9319 static_cast<unsigned int>(current) & 0x1Fu),
9325 return get_number(input_format_t::cbor, len) &&
9326 get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
9331 std::uint16_t len{};
9332 return get_number(input_format_t::cbor, len) &&
9333 get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
9338 std::uint32_t len{};
9339 return get_number(input_format_t::cbor, len) &&
9340 get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
9345 std::uint64_t len{};
9346 return get_number(input_format_t::cbor, len) &&
9347 get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
9351 return get_cbor_array(
static_cast<std::size_t
>(-1), tag_handler);
9378 return get_cbor_object(conditional_static_cast<std::size_t>(
9379 static_cast<unsigned int>(current) & 0x1Fu),
9385 return get_number(input_format_t::cbor, len) &&
9386 get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
9391 std::uint16_t len{};
9392 return get_number(input_format_t::cbor, len) &&
9393 get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
9398 std::uint32_t len{};
9399 return get_number(input_format_t::cbor, len) &&
9400 get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
9405 std::uint64_t len{};
9406 return get_number(input_format_t::cbor, len) &&
9407 get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
9411 return get_cbor_object(
static_cast<std::size_t
>(-1), tag_handler);
9433 switch (tag_handler) {
9434 case cbor_tag_handler_t::error: {
9435 auto last_token = get_token_string();
9436 return sax->parse_error(
9437 chars_read, last_token,
9438 parse_error::create(
9440 exception_message(input_format_t::cbor,
9441 concat(
"invalid byte: 0x", last_token),
"value"),
9445 case cbor_tag_handler_t::ignore: {
9449 std::uint8_t subtype_to_ignore{};
9450 get_number(input_format_t::cbor, subtype_to_ignore);
9454 std::uint16_t subtype_to_ignore{};
9455 get_number(input_format_t::cbor, subtype_to_ignore);
9459 std::uint32_t subtype_to_ignore{};
9460 get_number(input_format_t::cbor, subtype_to_ignore);
9464 std::uint64_t subtype_to_ignore{};
9465 get_number(input_format_t::cbor, subtype_to_ignore);
9471 return parse_cbor_internal(
true, tag_handler);
9474 case cbor_tag_handler_t::store: {
9479 std::uint8_t subtype{};
9480 get_number(input_format_t::cbor, subtype);
9481 b.set_subtype(detail::conditional_static_cast<
9482 typename binary_t::subtype_type>(subtype));
9486 std::uint16_t subtype{};
9487 get_number(input_format_t::cbor, subtype);
9488 b.set_subtype(detail::conditional_static_cast<
9489 typename binary_t::subtype_type>(subtype));
9493 std::uint32_t subtype{};
9494 get_number(input_format_t::cbor, subtype);
9495 b.set_subtype(detail::conditional_static_cast<
9496 typename binary_t::subtype_type>(subtype));
9500 std::uint64_t subtype{};
9501 get_number(input_format_t::cbor, subtype);
9502 b.set_subtype(detail::conditional_static_cast<
9503 typename binary_t::subtype_type>(subtype));
9507 return parse_cbor_internal(
true, tag_handler);
9510 return get_cbor_binary(b) && sax->binary(b);
9522 return sax->boolean(
false);
9525 return sax->boolean(
true);
9532 const auto byte1_raw = get();
9533 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number"))) {
9536 const auto byte2_raw = get();
9537 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number"))) {
9541 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
9542 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
9552 const auto half =
static_cast<unsigned int>((byte1 << 8u) + byte2);
9553 const double val = [&half] {
9554 const int exp = (half >> 10u) & 0x1Fu;
9555 const unsigned int mant = half & 0x3FFu;
9556 JSON_ASSERT(0 <= exp && exp <= 32);
9557 JSON_ASSERT(mant <= 1024);
9560 return std::ldexp(mant, -24);
9562 return (mant == 0) ? std::numeric_limits<double>::infinity()
9563 : std::numeric_limits<double>::quiet_NaN();
9565 return std::ldexp(mant + 1024, exp - 25);
9568 return sax->number_float((half & 0x8000u) != 0 ?
static_cast<number_float_t
>(-val)
9569 :
static_cast<number_float_t
>(val),
9576 return get_number(input_format_t::cbor, number) &&
9577 sax->number_float(
static_cast<number_float_t
>(number),
"");
9583 return get_number(input_format_t::cbor, number) &&
9584 sax->number_float(
static_cast<number_float_t
>(number),
"");
9589 auto last_token = get_token_string();
9590 return sax->parse_error(
9591 chars_read, last_token,
9592 parse_error::create(112, chars_read,
9593 exception_message(input_format_t::cbor,
9594 concat(
"invalid byte: 0x", last_token),
9612 bool get_cbor_string(string_t& result) {
9613 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"string"))) {
9643 return get_string(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu,
9650 return get_number(input_format_t::cbor, len) &&
9651 get_string(input_format_t::cbor, len, result);
9656 std::uint16_t len{};
9657 return get_number(input_format_t::cbor, len) &&
9658 get_string(input_format_t::cbor, len, result);
9663 std::uint32_t len{};
9664 return get_number(input_format_t::cbor, len) &&
9665 get_string(input_format_t::cbor, len, result);
9670 std::uint64_t len{};
9671 return get_number(input_format_t::cbor, len) &&
9672 get_string(input_format_t::cbor, len, result);
9677 while (get() != 0xFF) {
9679 if (!get_cbor_string(chunk)) {
9682 result.append(chunk);
9688 auto last_token = get_token_string();
9689 return sax->parse_error(
9690 chars_read, last_token,
9691 parse_error::create(
9693 exception_message(input_format_t::cbor,
9694 concat(
"expected length specification (0x60-0x7B) or "
9695 "indefinite string type (0x7F); last byte: 0x",
9714 bool get_cbor_binary(binary_t& result) {
9715 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"binary"))) {
9745 return get_binary(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu,
9752 return get_number(input_format_t::cbor, len) &&
9753 get_binary(input_format_t::cbor, len, result);
9758 std::uint16_t len{};
9759 return get_number(input_format_t::cbor, len) &&
9760 get_binary(input_format_t::cbor, len, result);
9765 std::uint32_t len{};
9766 return get_number(input_format_t::cbor, len) &&
9767 get_binary(input_format_t::cbor, len, result);
9772 std::uint64_t len{};
9773 return get_number(input_format_t::cbor, len) &&
9774 get_binary(input_format_t::cbor, len, result);
9779 while (get() != 0xFF) {
9781 if (!get_cbor_binary(chunk)) {
9784 result.insert(result.end(), chunk.begin(), chunk.end());
9790 auto last_token = get_token_string();
9791 return sax->parse_error(
9792 chars_read, last_token,
9793 parse_error::create(
9796 input_format_t::cbor,
9797 concat(
"expected length specification (0x40-0x5B) or "
9798 "indefinite binary array type (0x5F); last byte: 0x",
9812 bool get_cbor_array(
const std::size_t len,
const cbor_tag_handler_t tag_handler) {
9813 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len))) {
9817 if (len !=
static_cast<std::size_t
>(-1)) {
9818 for (std::size_t i = 0; i < len; ++i) {
9819 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler))) {
9824 while (get() != 0xFF) {
9825 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
false, tag_handler))) {
9831 return sax->end_array();
9840 bool get_cbor_object(
const std::size_t len,
const cbor_tag_handler_t tag_handler) {
9841 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len))) {
9847 if (len !=
static_cast<std::size_t
>(-1)) {
9848 for (std::size_t i = 0; i < len; ++i) {
9850 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key))) {
9854 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler))) {
9860 while (get() != 0xFF) {
9861 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key))) {
9865 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler))) {
9873 return sax->end_object();
9883 bool parse_msgpack_internal() {
9886 case char_traits<char_type>::eof():
10018 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
10037 return get_msgpack_object(conditional_static_cast<std::size_t>(
10038 static_cast<unsigned int>(current) & 0x0Fu));
10057 return get_msgpack_array(conditional_static_cast<std::size_t>(
10058 static_cast<unsigned int>(current) & 0x0Fu));
10098 return get_msgpack_string(s) && sax->string(s);
10102 return sax->null();
10105 return sax->boolean(
false);
10108 return sax->boolean(
true);
10123 return get_msgpack_binary(b) && sax->binary(b);
10129 return get_number(input_format_t::msgpack, number) &&
10130 sax->number_float(
static_cast<number_float_t
>(number),
"");
10136 return get_number(input_format_t::msgpack, number) &&
10137 sax->number_float(
static_cast<number_float_t
>(number),
"");
10142 std::uint8_t number{};
10143 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10148 std::uint16_t number{};
10149 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10154 std::uint32_t number{};
10155 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10160 std::uint64_t number{};
10161 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10166 std::int8_t number{};
10167 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10172 std::int16_t number{};
10173 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10178 std::int32_t number{};
10179 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10184 std::int64_t number{};
10185 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10190 std::uint16_t len{};
10191 return get_number(input_format_t::msgpack, len) &&
10192 get_msgpack_array(
static_cast<std::size_t
>(len));
10197 std::uint32_t len{};
10198 return get_number(input_format_t::msgpack, len) &&
10199 get_msgpack_array(conditional_static_cast<std::size_t>(len));
10204 std::uint16_t len{};
10205 return get_number(input_format_t::msgpack, len) &&
10206 get_msgpack_object(
static_cast<std::size_t
>(len));
10211 std::uint32_t len{};
10212 return get_number(input_format_t::msgpack, len) &&
10213 get_msgpack_object(conditional_static_cast<std::size_t>(len));
10249 return sax->number_integer(
static_cast<std::int8_t
>(current));
10253 auto last_token = get_token_string();
10254 return sax->parse_error(
10255 chars_read, last_token,
10256 parse_error::create(112, chars_read,
10257 exception_message(input_format_t::msgpack,
10258 concat(
"invalid byte: 0x", last_token),
10275 bool get_msgpack_string(string_t& result) {
10276 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack,
"string"))) {
10314 return get_string(input_format_t::msgpack,
10315 static_cast<unsigned int>(current) & 0x1Fu, result);
10320 std::uint8_t len{};
10321 return get_number(input_format_t::msgpack, len) &&
10322 get_string(input_format_t::msgpack, len, result);
10327 std::uint16_t len{};
10328 return get_number(input_format_t::msgpack, len) &&
10329 get_string(input_format_t::msgpack, len, result);
10334 std::uint32_t len{};
10335 return get_number(input_format_t::msgpack, len) &&
10336 get_string(input_format_t::msgpack, len, result);
10340 auto last_token = get_token_string();
10341 return sax->parse_error(
10342 chars_read, last_token,
10343 parse_error::create(
10345 exception_message(input_format_t::msgpack,
10346 concat(
"expected length specification "
10347 "(0xA0-0xBF, 0xD9-0xDB); last byte: 0x",
10365 bool get_msgpack_binary(binary_t& result) {
10367 auto assign_and_return_true = [&result](std::int8_t subtype) {
10368 result.set_subtype(
static_cast<std::uint8_t
>(subtype));
10375 std::uint8_t len{};
10376 return get_number(input_format_t::msgpack, len) &&
10377 get_binary(input_format_t::msgpack, len, result);
10382 std::uint16_t len{};
10383 return get_number(input_format_t::msgpack, len) &&
10384 get_binary(input_format_t::msgpack, len, result);
10389 std::uint32_t len{};
10390 return get_number(input_format_t::msgpack, len) &&
10391 get_binary(input_format_t::msgpack, len, result);
10396 std::uint8_t len{};
10397 std::int8_t subtype{};
10398 return get_number(input_format_t::msgpack, len) &&
10399 get_number(input_format_t::msgpack, subtype) &&
10400 get_binary(input_format_t::msgpack, len, result) &&
10401 assign_and_return_true(subtype);
10406 std::uint16_t len{};
10407 std::int8_t subtype{};
10408 return get_number(input_format_t::msgpack, len) &&
10409 get_number(input_format_t::msgpack, subtype) &&
10410 get_binary(input_format_t::msgpack, len, result) &&
10411 assign_and_return_true(subtype);
10416 std::uint32_t len{};
10417 std::int8_t subtype{};
10418 return get_number(input_format_t::msgpack, len) &&
10419 get_number(input_format_t::msgpack, subtype) &&
10420 get_binary(input_format_t::msgpack, len, result) &&
10421 assign_and_return_true(subtype);
10426 std::int8_t subtype{};
10427 return get_number(input_format_t::msgpack, subtype) &&
10428 get_binary(input_format_t::msgpack, 1, result) &&
10429 assign_and_return_true(subtype);
10434 std::int8_t subtype{};
10435 return get_number(input_format_t::msgpack, subtype) &&
10436 get_binary(input_format_t::msgpack, 2, result) &&
10437 assign_and_return_true(subtype);
10442 std::int8_t subtype{};
10443 return get_number(input_format_t::msgpack, subtype) &&
10444 get_binary(input_format_t::msgpack, 4, result) &&
10445 assign_and_return_true(subtype);
10450 std::int8_t subtype{};
10451 return get_number(input_format_t::msgpack, subtype) &&
10452 get_binary(input_format_t::msgpack, 8, result) &&
10453 assign_and_return_true(subtype);
10458 std::int8_t subtype{};
10459 return get_number(input_format_t::msgpack, subtype) &&
10460 get_binary(input_format_t::msgpack, 16, result) &&
10461 assign_and_return_true(subtype);
10473 bool get_msgpack_array(
const std::size_t len) {
10474 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len))) {
10478 for (std::size_t i = 0; i < len; ++i) {
10479 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal())) {
10484 return sax->end_array();
10491 bool get_msgpack_object(
const std::size_t len) {
10492 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len))) {
10497 for (std::size_t i = 0; i < len; ++i) {
10499 if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key))) {
10503 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal())) {
10509 return sax->end_object();
10523 bool parse_ubjson_internal(
const bool get_char =
true) {
10524 return get_ubjson_value(get_char ? get_ignore_noop() : current);
10541 bool get_ubjson_string(string_t& result,
const bool get_char =
true) {
10546 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"value"))) {
10552 std::uint8_t len{};
10553 return get_number(input_format, len) && get_string(input_format, len, result);
10558 return get_number(input_format, len) && get_string(input_format, len, result);
10562 std::int16_t len{};
10563 return get_number(input_format, len) && get_string(input_format, len, result);
10567 std::int32_t len{};
10568 return get_number(input_format, len) && get_string(input_format, len, result);
10572 std::int64_t len{};
10573 return get_number(input_format, len) && get_string(input_format, len, result);
10577 if (input_format != input_format_t::bjdata) {
10580 std::uint16_t len{};
10581 return get_number(input_format, len) && get_string(input_format, len, result);
10585 if (input_format != input_format_t::bjdata) {
10588 std::uint32_t len{};
10589 return get_number(input_format, len) && get_string(input_format, len, result);
10593 if (input_format != input_format_t::bjdata) {
10596 std::uint64_t len{};
10597 return get_number(input_format, len) && get_string(input_format, len, result);
10603 auto last_token = get_token_string();
10604 std::string message;
10606 if (input_format != input_format_t::bjdata) {
10608 "expected length type specification (U, i, I, l, L); last byte: 0x" + last_token;
10610 message =
"expected length type specification (U, i, u, I, m, l, M, L); "
10614 return sax->parse_error(
10615 chars_read, last_token,
10616 parse_error::create(113, chars_read, exception_message(input_format, message,
"string"),
10624 bool get_ubjson_ndarray_size(std::vector<size_t>& dim) {
10625 std::pair<std::size_t, char_int_type> size_and_type;
10627 bool no_ndarray =
true;
10629 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type, no_ndarray))) {
10633 if (size_and_type.first != npos) {
10634 if (size_and_type.second != 0) {
10635 if (size_and_type.second !=
'N') {
10636 for (std::size_t i = 0; i < size_and_type.first; ++i) {
10637 if (JSON_HEDLEY_UNLIKELY(
10638 !get_ubjson_size_value(dimlen, no_ndarray, size_and_type.second))) {
10641 dim.push_back(dimlen);
10645 for (std::size_t i = 0; i < size_and_type.first; ++i) {
10646 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray))) {
10649 dim.push_back(dimlen);
10653 while (current !=
']') {
10654 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, current))) {
10657 dim.push_back(dimlen);
10674 bool get_ubjson_size_value(std::size_t& result,
bool& is_ndarray, char_int_type prefix = 0) {
10676 prefix = get_ignore_noop();
10681 std::uint8_t number{};
10682 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number))) {
10685 result =
static_cast<std::size_t
>(number);
10690 std::int8_t number{};
10691 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number))) {
10695 return sax->parse_error(
10696 chars_read, get_token_string(),
10697 parse_error::create(
10699 exception_message(input_format,
10700 "count in an optimized container must be positive",
10704 result =
static_cast<std::size_t
>(
10711 std::int16_t number{};
10712 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number))) {
10716 return sax->parse_error(
10717 chars_read, get_token_string(),
10718 parse_error::create(
10720 exception_message(input_format,
10721 "count in an optimized container must be positive",
10725 result =
static_cast<std::size_t
>(number);
10730 std::int32_t number{};
10731 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number))) {
10735 return sax->parse_error(
10736 chars_read, get_token_string(),
10737 parse_error::create(
10739 exception_message(input_format,
10740 "count in an optimized container must be positive",
10744 result =
static_cast<std::size_t
>(number);
10749 std::int64_t number{};
10750 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number))) {
10754 return sax->parse_error(
10755 chars_read, get_token_string(),
10756 parse_error::create(
10758 exception_message(input_format,
10759 "count in an optimized container must be positive",
10763 if (!value_in_range_of<std::size_t>(number)) {
10764 return sax->parse_error(
10765 chars_read, get_token_string(),
10766 out_of_range::create(
10767 408, exception_message(input_format,
"integer value overflow",
"size"),
10770 result =
static_cast<std::size_t
>(number);
10775 if (input_format != input_format_t::bjdata) {
10778 std::uint16_t number{};
10779 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number))) {
10782 result =
static_cast<std::size_t
>(number);
10787 if (input_format != input_format_t::bjdata) {
10790 std::uint32_t number{};
10791 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number))) {
10794 result = conditional_static_cast<std::size_t>(number);
10799 if (input_format != input_format_t::bjdata) {
10802 std::uint64_t number{};
10803 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number))) {
10806 if (!value_in_range_of<std::size_t>(number)) {
10807 return sax->parse_error(
10808 chars_read, get_token_string(),
10809 out_of_range::create(
10810 408, exception_message(input_format,
"integer value overflow",
"size"),
10813 result = detail::conditional_static_cast<std::size_t>(number);
10818 if (input_format != input_format_t::bjdata) {
10824 return sax->parse_error(
10825 chars_read, get_token_string(),
10826 parse_error::create(
10828 exception_message(input_format,
10829 "ndarray dimensional vector is not allowed",
"size"),
10832 std::vector<size_t> dim;
10833 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_ndarray_size(dim))) {
10836 if (dim.size() == 1 ||
10837 (dim.size() == 2 &&
10840 result = dim.at(dim.size() - 1);
10855 string_t
key =
"_ArraySize_";
10856 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(3) || !sax->key(key) ||
10857 !sax->start_array(dim.size()))) {
10861 for (
auto i : dim) {
10868 return sax->parse_error(
10869 chars_read, get_token_string(),
10870 out_of_range::create(
10872 exception_message(input_format,
10873 "excessive ndarray size caused overflow",
10877 if (JSON_HEDLEY_UNLIKELY(
10878 !sax->number_unsigned(
static_cast<number_unsigned_t
>(i)))) {
10883 return sax->end_array();
10892 auto last_token = get_token_string();
10893 std::string message;
10895 if (input_format != input_format_t::bjdata) {
10896 message =
"expected length type specification (U, i, I, l, L) after '#'; "
10900 message =
"expected length type specification (U, i, u, I, m, l, M, L) "
10901 "after '#'; last byte: 0x" +
10904 return sax->parse_error(
10905 chars_read, last_token,
10906 parse_error::create(113, chars_read, exception_message(input_format, message,
"size"),
10922 bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result,
10923 bool inside_ndarray =
false) {
10924 result.first = npos;
10926 bool is_ndarray =
false;
10930 if (current ==
'$') {
10931 result.second = get();
10932 if (input_format == input_format_t::bjdata &&
10933 JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(),
10934 bjd_optimized_type_markers.end(),
10936 auto last_token = get_token_string();
10937 return sax->parse_error(
10938 chars_read, last_token,
10939 parse_error::create(
10941 exception_message(input_format,
10942 concat(
"marker 0x", last_token,
10943 " is not a permitted optimized array type"),
10948 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"type"))) {
10953 if (JSON_HEDLEY_UNLIKELY(current !=
'#')) {
10954 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"value"))) {
10957 auto last_token = get_token_string();
10958 return sax->parse_error(
10959 chars_read, last_token,
10960 parse_error::create(
10964 concat(
"expected '#' after type information; last byte: 0x",
10970 const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
10971 if (input_format == input_format_t::bjdata && is_ndarray) {
10972 if (inside_ndarray) {
10973 return sax->parse_error(
10974 chars_read, get_token_string(),
10975 parse_error::create(
10977 exception_message(input_format,
"ndarray can not be recursive",
"size"),
10980 result.second |= (1 << 8);
10986 if (current ==
'#') {
10987 const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
10988 if (input_format == input_format_t::bjdata && is_ndarray) {
10989 return sax->parse_error(
10990 chars_read, get_token_string(),
10991 parse_error::create(112, chars_read,
10992 exception_message(input_format,
10993 "ndarray requires both type and size",
11007 bool get_ubjson_value(
const char_int_type prefix) {
11009 case char_traits<char_type>::eof():
11010 return unexpect_eof(input_format,
"value");
11013 return sax->boolean(
true);
11015 return sax->boolean(
false);
11018 return sax->null();
11021 std::uint8_t number{};
11022 return get_number(input_format, number) && sax->number_unsigned(number);
11026 std::int8_t number{};
11027 return get_number(input_format, number) && sax->number_integer(number);
11031 std::int16_t number{};
11032 return get_number(input_format, number) && sax->number_integer(number);
11036 std::int32_t number{};
11037 return get_number(input_format, number) && sax->number_integer(number);
11041 std::int64_t number{};
11042 return get_number(input_format, number) && sax->number_integer(number);
11046 if (input_format != input_format_t::bjdata) {
11049 std::uint16_t number{};
11050 return get_number(input_format, number) && sax->number_unsigned(number);
11054 if (input_format != input_format_t::bjdata) {
11057 std::uint32_t number{};
11058 return get_number(input_format, number) && sax->number_unsigned(number);
11062 if (input_format != input_format_t::bjdata) {
11065 std::uint64_t number{};
11066 return get_number(input_format, number) && sax->number_unsigned(number);
11070 if (input_format != input_format_t::bjdata) {
11073 const auto byte1_raw = get();
11074 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number"))) {
11077 const auto byte2_raw = get();
11078 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number"))) {
11082 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
11083 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
11093 const auto half =
static_cast<unsigned int>((byte2 << 8u) + byte1);
11094 const double val = [&half] {
11095 const int exp = (half >> 10u) & 0x1Fu;
11096 const unsigned int mant = half & 0x3FFu;
11097 JSON_ASSERT(0 <= exp && exp <= 32);
11098 JSON_ASSERT(mant <= 1024);
11101 return std::ldexp(mant, -24);
11103 return (mant == 0) ? std::numeric_limits<double>::infinity()
11104 : std::numeric_limits<double>::quiet_NaN();
11106 return std::ldexp(mant + 1024, exp - 25);
11109 return sax->number_float((half & 0x8000u) != 0 ?
static_cast<number_float_t
>(-val)
11110 :
static_cast<number_float_t
>(val),
11116 return get_number(input_format, number) &&
11117 sax->number_float(
static_cast<number_float_t
>(number),
"");
11122 return get_number(input_format, number) &&
11123 sax->number_float(
static_cast<number_float_t
>(number),
"");
11127 return get_ubjson_high_precision_number();
11133 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"char"))) {
11136 if (JSON_HEDLEY_UNLIKELY(current > 127)) {
11137 auto last_token = get_token_string();
11138 return sax->parse_error(
11139 chars_read, last_token,
11140 parse_error::create(
11142 exception_message(input_format,
11143 concat(
"byte after 'C' must be in range "
11144 "0x00..0x7F; last byte: 0x",
11149 string_t s(1,
static_cast<typename string_t::value_type
>(current));
11150 return sax->string(s);
11156 return get_ubjson_string(s) && sax->string(s);
11160 return get_ubjson_array();
11163 return get_ubjson_object();
11168 auto last_token = get_token_string();
11169 return sax->parse_error(
11170 chars_read, last_token,
11171 parse_error::create(
11173 exception_message(input_format,
"invalid byte: 0x" + last_token,
"value"),
11180 bool get_ubjson_array() {
11181 std::pair<std::size_t, char_int_type> size_and_type;
11182 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type))) {
11192 if (input_format == input_format_t::bjdata && size_and_type.first != npos &&
11193 (size_and_type.second & (1 << 8)) != 0) {
11194 size_and_type.second &=
11195 ~(
static_cast<char_int_type
>(1) << 8);
11198 std::lower_bound(bjd_types_map.begin(), bjd_types_map.end(), size_and_type.second,
11199 [](
const bjd_type& p, char_int_type t) { return p.first < t; });
11200 string_t
key =
"_ArrayType_";
11201 if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() ||
11202 it->first != size_and_type.second)) {
11203 auto last_token = get_token_string();
11204 return sax->parse_error(
11205 chars_read, last_token,
11206 parse_error::create(
11208 exception_message(input_format,
"invalid byte: 0x" + last_token,
"type"),
11212 string_t type = it->second;
11213 if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type))) {
11217 if (size_and_type.second ==
'C') {
11218 size_and_type.second =
'U';
11221 key =
"_ArrayData_";
11222 if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->start_array(size_and_type.first))) {
11226 for (std::size_t i = 0; i < size_and_type.first; ++i) {
11227 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second))) {
11232 return (sax->end_array() && sax->end_object());
11235 if (size_and_type.first != npos) {
11236 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first))) {
11240 if (size_and_type.second != 0) {
11241 if (size_and_type.second !=
'N') {
11242 for (std::size_t i = 0; i < size_and_type.first; ++i) {
11243 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second))) {
11249 for (std::size_t i = 0; i < size_and_type.first; ++i) {
11250 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal())) {
11256 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(
static_cast<std::size_t
>(-1)))) {
11260 while (current !=
']') {
11261 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(
false))) {
11268 return sax->end_array();
11274 bool get_ubjson_object() {
11275 std::pair<std::size_t, char_int_type> size_and_type;
11276 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type))) {
11281 if (input_format == input_format_t::bjdata && size_and_type.first != npos &&
11282 (size_and_type.second & (1 << 8)) != 0) {
11283 auto last_token = get_token_string();
11284 return sax->parse_error(
11285 chars_read, last_token,
11286 parse_error::create(
11288 exception_message(input_format,
11289 "BJData object does not support ND-array size "
11290 "in optimized format",
11296 if (size_and_type.first != npos) {
11297 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first))) {
11301 if (size_and_type.second != 0) {
11302 for (std::size_t i = 0; i < size_and_type.first; ++i) {
11303 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key))) {
11306 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second))) {
11312 for (std::size_t i = 0; i < size_and_type.first; ++i) {
11313 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key))) {
11316 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal())) {
11323 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(
static_cast<std::size_t
>(-1)))) {
11327 while (current !=
'}') {
11328 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key,
false) || !sax->key(key))) {
11331 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal())) {
11339 return sax->end_object();
11345 bool get_ubjson_high_precision_number() {
11347 std::size_t size{};
11348 bool no_ndarray =
true;
11349 auto res = get_ubjson_size_value(size, no_ndarray);
11350 if (JSON_HEDLEY_UNLIKELY(!res)) {
11355 std::vector<char> number_vector;
11356 for (std::size_t i = 0; i < size; ++i) {
11358 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number"))) {
11361 number_vector.push_back(
static_cast<char>(current));
11365 using ia_type =
decltype(detail::input_adapter(number_vector));
11366 auto number_lexer =
11367 detail::lexer<BasicJsonType, ia_type>(detail::input_adapter(number_vector),
false);
11368 const auto result_number = number_lexer.scan();
11369 const auto number_string = number_lexer.get_token_string();
11370 const auto result_remainder = number_lexer.scan();
11374 if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input)) {
11375 return sax->parse_error(
11376 chars_read, number_string,
11377 parse_error::create(115, chars_read,
11378 exception_message(input_format,
11379 concat(
"invalid number text: ",
11380 number_lexer.get_token_string()),
11381 "high-precision number"),
11385 switch (result_number) {
11386 case token_type::value_integer:
11387 return sax->number_integer(number_lexer.get_number_integer());
11388 case token_type::value_unsigned:
11389 return sax->number_unsigned(number_lexer.get_number_unsigned());
11390 case token_type::value_float:
11391 return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
11392 case token_type::uninitialized:
11393 case token_type::literal_true:
11394 case token_type::literal_false:
11395 case token_type::literal_null:
11396 case token_type::value_string:
11397 case token_type::begin_array:
11398 case token_type::begin_object:
11399 case token_type::end_array:
11400 case token_type::end_object:
11401 case token_type::name_separator:
11402 case token_type::value_separator:
11403 case token_type::parse_error:
11404 case token_type::end_of_input:
11405 case token_type::literal_or_value:
11407 return sax->parse_error(
11408 chars_read, number_string,
11409 parse_error::create(115, chars_read,
11410 exception_message(input_format,
11411 concat(
"invalid number text: ",
11412 number_lexer.get_token_string()),
11413 "high-precision number"),
11431 char_int_type get() {
11433 return current = ia.get_character();
11439 char_int_type get_ignore_noop() {
11442 }
while (current ==
'N');
11462 template <
typename NumberType,
bool InputIsLittleEndian = false>
11463 bool get_number(
const input_format_t format, NumberType& result) {
11465 std::array<std::uint8_t,
sizeof(NumberType)> vec{};
11466 for (std::size_t i = 0; i <
sizeof(NumberType); ++i) {
11468 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"number"))) {
11473 if (is_little_endian != (InputIsLittleEndian || format == input_format_t::bjdata)) {
11474 vec[
sizeof(NumberType) - i - 1] =
static_cast<std::uint8_t
>(current);
11476 vec[i] =
static_cast<std::uint8_t
>(current);
11481 std::memcpy(&result, vec.data(),
sizeof(NumberType));
11499 template <
typename NumberType>
11500 bool get_string(
const input_format_t format,
const NumberType len, string_t& result) {
11501 bool success =
true;
11502 for (NumberType i = 0; i < len; i++) {
11504 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"string"))) {
11508 result.push_back(
static_cast<typename string_t::value_type
>(current));
11527 template <
typename NumberType>
11528 bool get_binary(
const input_format_t format,
const NumberType len, binary_t& result) {
11529 bool success =
true;
11530 for (NumberType i = 0; i < len; i++) {
11532 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"binary"))) {
11536 result.push_back(
static_cast<std::uint8_t
>(current));
11546 JSON_HEDLEY_NON_NULL(3)
11547 bool unexpect_eof(const input_format_t format, const
char* context)
const {
11548 if (JSON_HEDLEY_UNLIKELY(current == char_traits<char_type>::eof())) {
11549 return sax->parse_error(
11550 chars_read,
"<end of file>",
11551 parse_error::create(110, chars_read,
11552 exception_message(format,
"unexpected end of input", context),
11561 std::string get_token_string()
const {
11562 std::array<char, 3> cr{{}};
11563 static_cast<void>((std::snprintf)(
11564 cr.data(), cr.size(),
"%.2hhX",
11565 static_cast<unsigned char>(
11567 return std::string{cr.data()};
11576 std::string exception_message(
const input_format_t format,
const std::string& detail,
11577 const std::string& context)
const {
11578 std::string error_msg =
"syntax error while parsing ";
11581 case input_format_t::cbor:
11582 error_msg +=
"CBOR";
11585 case input_format_t::msgpack:
11586 error_msg +=
"MessagePack";
11589 case input_format_t::ubjson:
11590 error_msg +=
"UBJSON";
11593 case input_format_t::bson:
11594 error_msg +=
"BSON";
11597 case input_format_t::bjdata:
11598 error_msg +=
"BJData";
11601 case input_format_t::json:
11603 JSON_ASSERT(
false);
11607 return concat(error_msg,
' ', context,
": ", detail);
11611 static JSON_INLINE_VARIABLE
constexpr std::size_t npos =
static_cast<std::size_t
>(-1);
11614 InputAdapterType ia;
11617 char_int_type current = char_traits<char_type>::eof();
11620 std::size_t chars_read = 0;
11623 const bool is_little_endian = little_endianness();
11629 json_sax_t* sax =
nullptr;
11632#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ \
11633 make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
11635#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
11636 make_array<bjd_type>(bjd_type{'C', "char"}, bjd_type{'D', "double"}, bjd_type{'I', "int16"}, \
11637 bjd_type{'L', "int64"}, bjd_type{'M', "uint64"}, bjd_type{'U', "uint8"}, \
11638 bjd_type{'d', "single"}, bjd_type{'i', "int8"}, bjd_type{'l', "int32"}, \
11639 bjd_type{'m', "uint32"}, bjd_type{'u', "uint16"})
11641 JSON_PRIVATE_UNLESS_TESTED :
11644 const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_)
11645 bjd_optimized_type_markers = JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_;
11647 using bjd_type = std::pair<char_int_type, string_t>;
11649 const decltype(JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_) bjd_types_map =
11650 JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_;
11652#undef JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_
11653#undef JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_
11656#ifndef JSON_HAS_CPP_17
11657template <
typename BasicJsonType,
typename InputAdapterType,
typename SAX>
11658constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos;
11662NLOHMANN_JSON_NAMESPACE_END
11679#include <functional>
11700NLOHMANN_JSON_NAMESPACE_BEGIN
11721template <
typename BasicJsonType>
11722using parser_callback_t =
11723 std::function<bool(
int , parse_event_t , BasicJsonType& )>;
11730template <
typename BasicJsonType,
typename InputAdapterType>
class parser {
11731 using number_integer_t =
typename BasicJsonType::number_integer_t;
11732 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
11733 using number_float_t =
typename BasicJsonType::number_float_t;
11734 using string_t =
typename BasicJsonType::string_t;
11736 using token_type =
typename lexer_t::token_type;
11740 explicit parser(InputAdapterType&& adapter,
const parser_callback_t<BasicJsonType> cb =
nullptr,
11741 const bool allow_exceptions_ =
true,
const bool skip_comments =
false)
11742 : callback(cb), m_lexer(std::move(adapter), skip_comments),
11743 allow_exceptions(allow_exceptions_) {
11761 sax_parse_internal(&sdp);
11764 if (
strict && (get_token() != token_type::end_of_input)) {
11765 sdp.parse_error(m_lexer.get_position(), m_lexer.get_token_string(),
11767 101, m_lexer.get_position(),
11768 exception_message(token_type::end_of_input,
"value"),
nullptr));
11772 if (sdp.is_errored()) {
11779 if (result.is_discarded()) {
11784 sax_parse_internal(&sdp);
11787 if (
strict && (get_token() != token_type::end_of_input)) {
11788 sdp.parse_error(m_lexer.get_position(), m_lexer.get_token_string(),
11790 101, m_lexer.get_position(),
11791 exception_message(token_type::end_of_input,
"value"),
nullptr));
11795 if (sdp.is_errored()) {
11801 result.assert_invariant();
11812 return sax_parse(&sax_acceptor,
strict);
11815 template <
typename SAX>
11816 JSON_HEDLEY_NON_NULL(2)
11817 bool sax_parse(SAX* sax, const
bool strict = true) {
11819 const bool result = sax_parse_internal(sax);
11822 if (result && strict && (get_token() != token_type::end_of_input)) {
11823 return sax->parse_error(
11824 m_lexer.get_position(), m_lexer.get_token_string(),
11825 parse_error::create(101, m_lexer.get_position(),
11826 exception_message(token_type::end_of_input,
"value"),
nullptr));
11833 template <
typename SAX> JSON_HEDLEY_NON_NULL(2) bool sax_parse_internal(SAX* sax) {
11836 std::vector<bool> states;
11838 bool skip_to_state_evaluation =
false;
11841 if (!skip_to_state_evaluation) {
11843 switch (last_token) {
11844 case token_type::begin_object: {
11845 if (JSON_HEDLEY_UNLIKELY(
11846 !sax->start_object(
static_cast<std::size_t
>(-1)))) {
11851 if (get_token() == token_type::end_object) {
11852 if (JSON_HEDLEY_UNLIKELY(!sax->end_object())) {
11859 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string)) {
11860 return sax->parse_error(
11861 m_lexer.get_position(), m_lexer.get_token_string(),
11862 parse_error::create(
11863 101, m_lexer.get_position(),
11864 exception_message(token_type::value_string,
"object key"),
11867 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) {
11872 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator)) {
11873 return sax->parse_error(
11874 m_lexer.get_position(), m_lexer.get_token_string(),
11875 parse_error::create(101, m_lexer.get_position(),
11876 exception_message(token_type::name_separator,
11877 "object separator"),
11882 states.push_back(
false);
11889 case token_type::begin_array: {
11890 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(
static_cast<std::size_t
>(-1)))) {
11895 if (get_token() == token_type::end_array) {
11896 if (JSON_HEDLEY_UNLIKELY(!sax->end_array())) {
11903 states.push_back(
true);
11909 case token_type::value_float: {
11910 const auto res = m_lexer.get_number_float();
11912 if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res))) {
11913 return sax->parse_error(
11914 m_lexer.get_position(), m_lexer.get_token_string(),
11915 out_of_range::create(406,
11916 concat(
"number overflow parsing '",
11917 m_lexer.get_token_string(),
'\''),
11921 if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string()))) {
11928 case token_type::literal_false: {
11929 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
false))) {
11935 case token_type::literal_null: {
11936 if (JSON_HEDLEY_UNLIKELY(!sax->null())) {
11942 case token_type::literal_true: {
11943 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
true))) {
11949 case token_type::value_integer: {
11950 if (JSON_HEDLEY_UNLIKELY(
11951 !sax->number_integer(m_lexer.get_number_integer()))) {
11957 case token_type::value_string: {
11958 if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string()))) {
11964 case token_type::value_unsigned: {
11965 if (JSON_HEDLEY_UNLIKELY(
11966 !sax->number_unsigned(m_lexer.get_number_unsigned()))) {
11972 case token_type::parse_error: {
11974 return sax->parse_error(
11975 m_lexer.get_position(), m_lexer.get_token_string(),
11976 parse_error::create(
11977 101, m_lexer.get_position(),
11978 exception_message(token_type::uninitialized,
"value"),
nullptr));
11980 case token_type::end_of_input: {
11981 if (JSON_HEDLEY_UNLIKELY(m_lexer.get_position().chars_read_total == 1)) {
11982 return sax->parse_error(
11983 m_lexer.get_position(), m_lexer.get_token_string(),
11984 parse_error::create(
11985 101, m_lexer.get_position(),
11986 "attempting to parse an empty input; check that your input "
11987 "string or stream contains the expected JSON",
11991 return sax->parse_error(
11992 m_lexer.get_position(), m_lexer.get_token_string(),
11993 parse_error::create(
11994 101, m_lexer.get_position(),
11995 exception_message(token_type::literal_or_value,
"value"),
nullptr));
11997 case token_type::uninitialized:
11998 case token_type::end_array:
11999 case token_type::end_object:
12000 case token_type::name_separator:
12001 case token_type::value_separator:
12002 case token_type::literal_or_value:
12005 return sax->parse_error(
12006 m_lexer.get_position(), m_lexer.get_token_string(),
12007 parse_error::create(
12008 101, m_lexer.get_position(),
12009 exception_message(token_type::literal_or_value,
"value"),
nullptr));
12013 skip_to_state_evaluation =
false;
12017 if (states.empty()) {
12025 if (get_token() == token_type::value_separator) {
12032 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array)) {
12033 if (JSON_HEDLEY_UNLIKELY(!sax->end_array())) {
12041 JSON_ASSERT(!states.empty());
12043 skip_to_state_evaluation =
true;
12047 return sax->parse_error(
12048 m_lexer.get_position(), m_lexer.get_token_string(),
12049 parse_error::create(101, m_lexer.get_position(),
12050 exception_message(token_type::end_array,
"array"),
12057 if (get_token() == token_type::value_separator) {
12059 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string)) {
12060 return sax->parse_error(
12061 m_lexer.get_position(), m_lexer.get_token_string(),
12062 parse_error::create(
12063 101, m_lexer.get_position(),
12064 exception_message(token_type::value_string,
"object key"),
nullptr));
12067 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) {
12072 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator)) {
12073 return sax->parse_error(
12074 m_lexer.get_position(), m_lexer.get_token_string(),
12075 parse_error::create(
12076 101, m_lexer.get_position(),
12077 exception_message(token_type::name_separator,
"object separator"),
12087 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object)) {
12088 if (JSON_HEDLEY_UNLIKELY(!sax->end_object())) {
12096 JSON_ASSERT(!states.empty());
12098 skip_to_state_evaluation =
true;
12102 return sax->parse_error(
12103 m_lexer.get_position(), m_lexer.get_token_string(),
12104 parse_error::create(101, m_lexer.get_position(),
12105 exception_message(token_type::end_object,
"object"),
nullptr));
12110 token_type get_token() {
return last_token = m_lexer.scan(); }
12112 std::string exception_message(
const token_type expected,
const std::string& context) {
12113 std::string error_msg =
"syntax error ";
12115 if (!context.empty()) {
12116 error_msg += concat(
"while parsing ", context,
' ');
12121 if (last_token == token_type::parse_error) {
12122 error_msg += concat(m_lexer.get_error_message(),
"; last read: '",
12123 m_lexer.get_token_string(),
'\'');
12125 error_msg += concat(
"unexpected ", lexer_t::token_type_name(last_token));
12128 if (expected != token_type::uninitialized) {
12129 error_msg += concat(
"; expected ", lexer_t::token_type_name(expected));
12137 const parser_callback_t<BasicJsonType> callback =
nullptr;
12139 token_type last_token = token_type::uninitialized;
12143 const bool allow_exceptions =
true;
12147NLOHMANN_JSON_NAMESPACE_END
12174NLOHMANN_JSON_NAMESPACE_BEGIN
12188 using difference_type = std::ptrdiff_t;
12189 static constexpr difference_type begin_value = 0;
12190 static constexpr difference_type end_value = begin_value + 1;
12192 JSON_PRIVATE_UNLESS_TESTED :
12194 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
12197 constexpr difference_type get_value()
const noexcept {
return m_it; }
12206 constexpr bool is_begin() const noexcept {
return m_it == begin_value; }
12209 constexpr bool is_end() const noexcept {
return m_it == end_value; }
12212 return lhs.m_it == rhs.m_it;
12215 friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept {
12216 return lhs.m_it < rhs.m_it;
12219 primitive_iterator_t operator+(difference_type n)
noexcept {
12220 auto result = *
this;
12225 friend constexpr difference_type operator-(primitive_iterator_t lhs,
12226 primitive_iterator_t rhs)
noexcept {
12227 return lhs.m_it - rhs.m_it;
12230 primitive_iterator_t& operator++() noexcept {
12235 primitive_iterator_t operator++(
int) &
noexcept
12237 auto result = *
this;
12242 primitive_iterator_t& operator--() noexcept {
12247 primitive_iterator_t operator--(
int) &
noexcept
12249 auto result = *
this;
12254 primitive_iterator_t& operator+=(difference_type n)
noexcept {
12259 primitive_iterator_t& operator-=(difference_type n)
noexcept {
12266NLOHMANN_JSON_NAMESPACE_END
12268NLOHMANN_JSON_NAMESPACE_BEGIN
12288NLOHMANN_JSON_NAMESPACE_END
12300#include <type_traits>
12316NLOHMANN_JSON_NAMESPACE_BEGIN
12320template <
typename IteratorType>
class iteration_proxy;
12321template <
typename IteratorType>
class iteration_proxy_value;
12341template <
typename BasicJsonType>
12345 using other_iter_impl =
12346 iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value,
12347 typename std::remove_const<BasicJsonType>::type,
12348 const BasicJsonType>::type>;
12350 friend other_iter_impl;
12351 friend BasicJsonType;
12355 using object_t =
typename BasicJsonType::object_t;
12356 using array_t =
typename BasicJsonType::array_t;
12359 "iter_impl only accepts (const) basic_json");
12362 std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value &&
12363 std::is_base_of<std::bidirectional_iterator_tag,
12364 typename std::iterator_traits<
12366 "basic_json iterator assumes array and object type iterators satisfy the "
12367 "LegacyBidirectionalIterator named requirement.");
12384 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
12385 typename BasicJsonType::const_pointer,
12386 typename BasicJsonType::pointer>::type;
12388 using reference =
typename std::conditional<std::is_const<BasicJsonType>::value,
12389 typename BasicJsonType::const_reference,
12390 typename BasicJsonType::reference>::type;
12392 iter_impl() =
default;
12393 ~iter_impl() =
default;
12394 iter_impl(iter_impl&&) noexcept = default;
12395 iter_impl& operator=(iter_impl&&) noexcept = default;
12403 explicit iter_impl(
pointer object) noexcept : m_object(
object) {
12404 JSON_ASSERT(m_object !=
nullptr);
12406 switch (m_object->m_data.m_type) {
12408 m_it.object_iterator =
typename object_t::iterator();
12413 m_it.array_iterator =
typename array_t::iterator();
12449 : m_object(other.m_object),
m_it(other.m_it) {}
12457 iter_impl&
operator=(
const iter_impl<const BasicJsonType>& other)
noexcept {
12458 if (&other !=
this) {
12459 m_object = other.m_object;
12470 iter_impl(
const iter_impl<
typename std::remove_const<BasicJsonType>::type>& other) noexcept
12471 : m_object(other.m_object),
m_it(other.m_it) {}
12479 iter_impl&
operator=(
const iter_impl<
typename std::remove_const<BasicJsonType>::type>&
12482 m_object = other.m_object;
12487 JSON_PRIVATE_UNLESS_TESTED :
12493 set_begin() noexcept {
12494 JSON_ASSERT(m_object !=
nullptr);
12496 switch (m_object->m_data.m_type) {
12498 m_it.object_iterator = m_object->m_data.m_value.object->begin();
12502 case value_t::array: {
12503 m_it.array_iterator = m_object->m_data.m_value.array->begin();
12507 case value_t::null: {
12509 m_it.primitive_iterator.set_end();
12513 case value_t::string:
12514 case value_t::boolean:
12515 case value_t::number_integer:
12516 case value_t::number_unsigned:
12517 case value_t::number_float:
12518 case value_t::binary:
12519 case value_t::discarded:
12521 m_it.primitive_iterator.set_begin();
12532 JSON_ASSERT(m_object !=
nullptr);
12534 switch (m_object->m_data.m_type) {
12536 m_it.object_iterator = m_object->m_data.m_value.object->end();
12541 m_it.array_iterator = m_object->m_data.m_value.array->end();
12554 m_it.primitive_iterator.set_end();
12566 JSON_ASSERT(m_object !=
nullptr);
12568 switch (m_object->m_data.m_type) {
12570 JSON_ASSERT(
m_it.object_iterator != m_object->m_data.m_value.object->end());
12571 return m_it.object_iterator->second;
12575 JSON_ASSERT(
m_it.array_iterator != m_object->m_data.m_value.array->end());
12576 return *
m_it.array_iterator;
12580 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
12590 if (JSON_HEDLEY_LIKELY(
m_it.primitive_iterator.is_begin())) {
12594 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
12604 JSON_ASSERT(m_object !=
nullptr);
12606 switch (m_object->m_data.m_type) {
12608 JSON_ASSERT(
m_it.object_iterator != m_object->m_data.m_value.object->end());
12609 return &(
m_it.object_iterator->second);
12613 JSON_ASSERT(
m_it.array_iterator != m_object->m_data.m_value.array->end());
12614 return &*
m_it.array_iterator;
12626 if (JSON_HEDLEY_LIKELY(
m_it.primitive_iterator.is_begin())) {
12630 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
12641 auto result = *
this;
12651 JSON_ASSERT(m_object !=
nullptr);
12653 switch (m_object->m_data.m_type) {
12655 std::advance(
m_it.object_iterator, 1);
12660 std::advance(
m_it.array_iterator, 1);
12673 ++
m_it.primitive_iterator;
12687 auto result = *
this;
12697 JSON_ASSERT(m_object !=
nullptr);
12699 switch (m_object->m_data.m_type) {
12701 std::advance(
m_it.object_iterator, -1);
12706 std::advance(
m_it.array_iterator, -1);
12719 --
m_it.primitive_iterator;
12731 template <
typename IterImpl,
12732 detail::enable_if_t<(std::is_same<IterImpl, iter_impl>::value ||
12733 std::is_same<IterImpl, other_iter_impl>::value),
12734 std::nullptr_t> =
nullptr>
12735 bool operator==(
const IterImpl& other)
const {
12737 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object)) {
12738 JSON_THROW(invalid_iterator::create(
12739 212,
"cannot compare iterators of different containers", m_object));
12742 JSON_ASSERT(m_object !=
nullptr);
12744 switch (m_object->m_data.m_type) {
12746 return (
m_it.object_iterator == other.m_it.object_iterator);
12749 return (
m_it.array_iterator == other.m_it.array_iterator);
12760 return (
m_it.primitive_iterator == other.m_it.primitive_iterator);
12768 template <
typename IterImpl,
12769 detail::enable_if_t<(std::is_same<IterImpl, iter_impl>::value ||
12770 std::is_same<IterImpl, other_iter_impl>::value),
12771 std::nullptr_t> =
nullptr>
12772 bool operator!=(
const IterImpl& other)
const {
12782 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object)) {
12783 JSON_THROW(invalid_iterator::create(
12784 212,
"cannot compare iterators of different containers", m_object));
12787 JSON_ASSERT(m_object !=
nullptr);
12789 switch (m_object->m_data.m_type) {
12791 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators",
12795 return (
m_it.array_iterator < other.
m_it.array_iterator);
12806 return (
m_it.primitive_iterator < other.
m_it.primitive_iterator);
12814 bool operator<=(
const iter_impl& other)
const {
return !other.operator<(*this); }
12833 JSON_ASSERT(m_object !=
nullptr);
12835 switch (m_object->m_data.m_type) {
12837 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators",
12841 std::advance(
m_it.array_iterator, i);
12854 m_it.primitive_iterator += i;
12873 auto result = *
this;
12893 auto result = *
this;
12903 JSON_ASSERT(m_object !=
nullptr);
12905 switch (m_object->m_data.m_type) {
12907 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators",
12911 return m_it.array_iterator - other.
m_it.array_iterator;
12922 return m_it.primitive_iterator - other.
m_it.primitive_iterator;
12931 JSON_ASSERT(m_object !=
nullptr);
12933 switch (m_object->m_data.m_type) {
12935 JSON_THROW(invalid_iterator::create(
12936 208,
"cannot use operator[] for object iterators", m_object));
12939 return *std::next(
m_it.array_iterator, n);
12942 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
12952 if (JSON_HEDLEY_LIKELY(
m_it.primitive_iterator.get_value() == -n)) {
12956 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
12965 const typename object_t::key_type&
key()
const {
12966 JSON_ASSERT(m_object !=
nullptr);
12968 if (JSON_HEDLEY_LIKELY(m_object->is_object())) {
12969 return m_it.object_iterator->first;
12973 invalid_iterator::create(207,
"cannot use key() for non-object iterators", m_object));
12982 JSON_PRIVATE_UNLESS_TESTED :
12984 pointer m_object =
nullptr;
12990NLOHMANN_JSON_NAMESPACE_END
13009NLOHMANN_JSON_NAMESPACE_BEGIN
13036 using difference_type = std::ptrdiff_t;
13095 auto key() const -> decltype(std::declval<Base>().
key()) {
13096 auto it = --this->base();
13102 auto it = --this->base();
13103 return it.operator*();
13108NLOHMANN_JSON_NAMESPACE_END
13121#include <type_traits>
13125NLOHMANN_JSON_NAMESPACE_BEGIN
13141using json_base_class =
13142 typename std::conditional<std::is_same<T, void>::value,
json_default_base, T>::type;
13145NLOHMANN_JSON_NAMESPACE_END
13156#include <algorithm>
13179NLOHMANN_JSON_NAMESPACE_BEGIN
13184template <
typename RefStringType>
class json_pointer {
13186 NLOHMANN_BASIC_JSON_TPL_DECLARATION
13187 friend class basic_json;
13189 template <
typename>
friend class json_pointer;
13191 template <
typename T>
struct string_t_helper {
13195 NLOHMANN_BASIC_JSON_TPL_DECLARATION
13196 struct string_t_helper<NLOHMANN_BASIC_JSON_TPL> {
13197 using type = StringType;
13202 using string_t =
typename string_t_helper<RefStringType>::type;
13211 return std::accumulate(reference_tokens.begin(), reference_tokens.end(), string_t{},
13212 [](
const string_t& a,
const string_t& b) {
13213 return detail::concat(a,
'/', detail::escape(b));
13219 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, to_string())
13225 friend std::ostream&
operator<<(std::ostream& o,
const json_pointer& ptr) {
13234 reference_tokens.insert(reference_tokens.end(), ptr.reference_tokens.begin(),
13235 ptr.reference_tokens.end());
13248 json_pointer&
operator/=(std::size_t array_idx) {
return *
this /= std::to_string(array_idx); }
13253 friend json_pointer
operator/(
const json_pointer& lhs,
const json_pointer& rhs) {
13254 return json_pointer(lhs) /= rhs;
13263 return json_pointer(lhs) /= std::move(token);
13269 friend json_pointer
operator/(
const json_pointer& lhs, std::size_t array_idx) {
13270 return json_pointer(lhs) /= array_idx;
13280 json_pointer res = *
this;
13288 if (JSON_HEDLEY_UNLIKELY(
empty())) {
13289 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
13292 reference_tokens.pop_back();
13298 if (JSON_HEDLEY_UNLIKELY(
empty())) {
13299 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
13302 return reference_tokens.back();
13307 void push_back(
const string_t& token) { reference_tokens.push_back(token); }
13311 void push_back(string_t&& token) { reference_tokens.push_back(std::move(token)); }
13315 bool empty() const noexcept {
return reference_tokens.empty(); }
13328 template <
typename BasicJsonType>
13329 static typename BasicJsonType::size_type array_index(
const string_t& s) {
13330 using size_type =
typename BasicJsonType::size_type;
13333 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] ==
'0')) {
13335 106, 0, detail::concat(
"array index '", s,
"' must not begin with '0'"),
nullptr));
13339 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >=
'1' && s[0] <=
'9'))) {
13341 109, 0, detail::concat(
"array index '", s,
"' is not a number"),
nullptr));
13344 const char* p = s.c_str();
13345 char* p_end =
nullptr;
13347 const unsigned long long res = std::strtoull(p, &p_end, 10);
13350 || JSON_HEDLEY_UNLIKELY(
static_cast<std::size_t
>(p_end - p) !=
13353 JSON_THROW(detail::out_of_range::create(
13354 404, detail::concat(
"unresolved reference token '", s,
"'"),
nullptr));
13359 if (res >=
static_cast<unsigned long long>(
13360 (std::numeric_limits<size_type>::max)()))
13362 JSON_THROW(detail::out_of_range::create(
13363 410, detail::concat(
"array index ", s,
" exceeds size_type"),
13367 return static_cast<size_type
>(res);
13370 JSON_PRIVATE_UNLESS_TESTED : json_pointer top()
const {
13371 if (JSON_HEDLEY_UNLIKELY(empty())) {
13372 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
13375 json_pointer result = *
this;
13376 result.reference_tokens = {reference_tokens[0]};
13389 template <
typename BasicJsonType> BasicJsonType& get_and_create(BasicJsonType& j)
const {
13394 for (
const auto& reference_token : reference_tokens) {
13395 switch (result->type()) {
13397 if (reference_token ==
"0") {
13399 result = &result->operator[](0);
13402 result = &result->operator[](reference_token);
13409 result = &result->operator[](reference_token);
13415 result = &result->operator[](array_index<BasicJsonType>(reference_token));
13433 JSON_THROW(detail::type_error::create(313,
"invalid value to unflatten", &j));
13459 template <
typename BasicJsonType> BasicJsonType& get_unchecked(BasicJsonType* ptr)
const {
13460 for (
const auto& reference_token : reference_tokens) {
13462 if (ptr->is_null()) {
13465 std::all_of(reference_token.begin(), reference_token.end(),
13466 [](
const unsigned char x) { return std::isdigit(x); });
13473 switch (ptr->type()) {
13476 ptr = &ptr->operator[](reference_token);
13481 if (reference_token ==
"-") {
13483 ptr = &ptr->operator[](ptr->m_data.m_value.array->size());
13486 ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));
13500 JSON_THROW(detail::out_of_range::create(
13501 404, detail::concat(
"unresolved reference token '", reference_token,
"'"),
13515 template <
typename BasicJsonType> BasicJsonType& get_checked(BasicJsonType* ptr)
const {
13516 for (
const auto& reference_token : reference_tokens) {
13517 switch (ptr->type()) {
13520 ptr = &ptr->at(reference_token);
13525 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-")) {
13527 JSON_THROW(detail::out_of_range::create(
13529 detail::concat(
"array index '-' (",
13530 std::to_string(ptr->m_data.m_value.array->size()),
13531 ") is out of range"),
13536 ptr = &ptr->at(array_index<BasicJsonType>(reference_token));
13549 JSON_THROW(detail::out_of_range::create(
13550 404, detail::concat(
"unresolved reference token '", reference_token,
"'"),
13571 template <
typename BasicJsonType>
13572 const BasicJsonType& get_unchecked(
const BasicJsonType* ptr)
const {
13573 for (
const auto& reference_token : reference_tokens) {
13574 switch (ptr->type()) {
13577 ptr = &ptr->operator[](reference_token);
13582 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-")) {
13584 JSON_THROW(detail::out_of_range::create(
13586 detail::concat(
"array index '-' (",
13587 std::to_string(ptr->m_data.m_value.array->size()),
13588 ") is out of range"),
13593 ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));
13606 JSON_THROW(detail::out_of_range::create(
13607 404, detail::concat(
"unresolved reference token '", reference_token,
"'"),
13621 template <
typename BasicJsonType>
13622 const BasicJsonType& get_checked(
const BasicJsonType* ptr)
const {
13623 for (
const auto& reference_token : reference_tokens) {
13624 switch (ptr->type()) {
13627 ptr = &ptr->at(reference_token);
13632 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-")) {
13634 JSON_THROW(detail::out_of_range::create(
13636 detail::concat(
"array index '-' (",
13637 std::to_string(ptr->m_data.m_value.array->size()),
13638 ") is out of range"),
13643 ptr = &ptr->at(array_index<BasicJsonType>(reference_token));
13656 JSON_THROW(detail::out_of_range::create(
13657 404, detail::concat(
"unresolved reference token '", reference_token,
"'"),
13669 template <
typename BasicJsonType>
bool contains(
const BasicJsonType* ptr)
const {
13670 for (
const auto& reference_token : reference_tokens) {
13671 switch (ptr->type()) {
13673 if (!ptr->contains(reference_token)) {
13678 ptr = &ptr->operator[](reference_token);
13683 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-")) {
13687 if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 &&
13688 !(
"0" <= reference_token && reference_token <=
"9"))) {
13692 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1)) {
13693 if (JSON_HEDLEY_UNLIKELY(
13694 !(
'1' <= reference_token[0] && reference_token[0] <=
'9'))) {
13698 for (std::size_t i = 1; i < reference_token.size(); i++) {
13699 if (JSON_HEDLEY_UNLIKELY(
13700 !(
'0' <= reference_token[i] && reference_token[i] <=
'9'))) {
13707 const auto idx = array_index<BasicJsonType>(reference_token);
13708 if (idx >= ptr->size()) {
13713 ptr = &ptr->operator[](idx);
13746 static std::vector<string_t> split(
const string_t& reference_string) {
13747 std::vector<string_t> result;
13750 if (reference_string.empty()) {
13755 if (JSON_HEDLEY_UNLIKELY(reference_string[0] !=
'/')) {
13758 detail::concat(
"JSON pointer must be empty or begin with '/' - was: '",
13759 reference_string,
"'"),
13768 std::size_t slash = reference_string.find_first_of(
'/', 1),
13775 start = (slash == string_t::npos) ? 0 : slash + 1,
13777 slash = reference_string.find_first_of(
'/', start)) {
13780 auto reference_token = reference_string.substr(start, slash - start);
13783 for (std::size_t pos = reference_token.find_first_of(
'~'); pos != string_t::npos;
13784 pos = reference_token.find_first_of(
'~', pos + 1)) {
13785 JSON_ASSERT(reference_token[pos] ==
'~');
13788 if (JSON_HEDLEY_UNLIKELY(
13789 pos == reference_token.size() - 1 ||
13790 (reference_token[pos + 1] !=
'0' && reference_token[pos + 1] !=
'1'))) {
13792 108, 0,
"escape character '~' must be followed with '0' or '1'",
nullptr));
13797 detail::unescape(reference_token);
13798 result.push_back(reference_token);
13812 template <
typename BasicJsonType>
13813 static void flatten(
const string_t& reference_string,
const BasicJsonType& value,
13814 BasicJsonType& result) {
13815 switch (value.type()) {
13817 if (value.m_data.m_value.array->empty()) {
13819 result[reference_string] =
nullptr;
13822 for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i) {
13823 flatten(detail::concat(reference_string,
'/', std::to_string(i)),
13824 value.m_data.m_value.array->operator[](i), result);
13831 if (value.m_data.m_value.object->empty()) {
13833 result[reference_string] =
nullptr;
13836 for (
const auto& element : *value.m_data.m_value.object) {
13838 detail::concat(reference_string,
'/',
detail::escape(element.first)),
13839 element.second, result);
13855 result[reference_string] = value;
13871 template <
typename BasicJsonType>
static BasicJsonType unflatten(
const BasicJsonType& value) {
13872 if (JSON_HEDLEY_UNLIKELY(!value.is_object())) {
13873 JSON_THROW(detail::type_error::create(314,
"only objects can be unflattened", &value));
13876 BasicJsonType result;
13879 for (
const auto& element : *value.m_data.m_value.object) {
13880 if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive())) {
13881 JSON_THROW(detail::type_error::create(315,
"values in object must be primitive",
13889 json_pointer(element.first).get_and_create(result) = element.second;
13896 json_pointer<string_t> convert() const& {
13897 json_pointer<string_t> result;
13898 result.reference_tokens = reference_tokens;
13902 json_pointer<string_t> convert() && {
13903 json_pointer<string_t> result;
13904 result.reference_tokens = std::move(reference_tokens);
13909#if JSON_HAS_THREE_WAY_COMPARISON
13912 template <
typename RefStringTypeRhs>
13913 bool operator==(
const json_pointer<RefStringTypeRhs>& rhs)
const noexcept {
13914 return reference_tokens == rhs.reference_tokens;
13919 JSON_HEDLEY_DEPRECATED_FOR(3.11.2,
operator==(json_pointer))
13920 bool operator==(
const string_t& rhs)
const {
return *
this == json_pointer(rhs); }
13923 template <
typename RefStringTypeRhs>
13924 std::strong_ordering
13925 operator<=>(
const json_pointer<RefStringTypeRhs>& rhs)
const noexcept
13927 return reference_tokens <=> rhs.reference_tokens;
13932 template <
typename RefStringTypeLhs,
typename RefStringTypeRhs>
13934 friend bool operator==(
const json_pointer<RefStringTypeLhs>& lhs,
13935 const json_pointer<RefStringTypeRhs>& rhs)
noexcept;
13939 template <
typename RefStringTypeLhs,
typename StringType>
13941 friend bool operator==(
const json_pointer<RefStringTypeLhs>& lhs,
const StringType& rhs);
13945 template <
typename RefStringTypeRhs,
typename StringType>
13947 friend bool operator==(
const StringType& lhs,
const json_pointer<RefStringTypeRhs>& rhs);
13951 template <
typename RefStringTypeLhs,
typename RefStringTypeRhs>
13953 friend bool operator!=(
const json_pointer<RefStringTypeLhs>& lhs,
13954 const json_pointer<RefStringTypeRhs>& rhs)
noexcept;
13958 template <
typename RefStringTypeLhs,
typename StringType>
13960 friend bool operator!=(
const json_pointer<RefStringTypeLhs>& lhs,
const StringType& rhs);
13964 template <
typename RefStringTypeRhs,
typename StringType>
13966 friend bool operator!=(
const StringType& lhs,
const json_pointer<RefStringTypeRhs>& rhs);
13969 template <
typename RefStringTypeLhs,
typename RefStringTypeRhs>
13971 friend bool operator<(
const json_pointer<RefStringTypeLhs>& lhs,
13972 const json_pointer<RefStringTypeRhs>& rhs)
noexcept;
13977 std::vector<string_t> reference_tokens;
13980#if !JSON_HAS_THREE_WAY_COMPARISON
13982template <
typename RefStringTypeLhs,
typename RefStringTypeRhs>
13984 const json_pointer<RefStringTypeRhs>& rhs)
noexcept {
13985 return lhs.reference_tokens == rhs.reference_tokens;
13988template <
typename RefStringTypeLhs,
13989 typename StringType =
typename json_pointer<RefStringTypeLhs>::string_t>
13991inline
bool operator==(const json_pointer<RefStringTypeLhs>& lhs, const StringType& rhs) {
13992 return lhs == json_pointer<RefStringTypeLhs>(rhs);
13995template <
typename RefStringTypeRhs,
13996 typename StringType =
typename json_pointer<RefStringTypeRhs>::string_t>
13998inline
bool operator==(const StringType& lhs, const json_pointer<RefStringTypeRhs>& rhs) {
13999 return json_pointer<RefStringTypeRhs>(lhs) == rhs;
14002template <
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14004 const json_pointer<RefStringTypeRhs>& rhs)
noexcept {
14005 return !(lhs == rhs);
14008template <
typename RefStringTypeLhs,
14009 typename StringType =
typename json_pointer<RefStringTypeLhs>::string_t>
14011inline
bool operator!=(const json_pointer<RefStringTypeLhs>& lhs, const StringType& rhs) {
14012 return !(lhs == rhs);
14015template <
typename RefStringTypeRhs,
14016 typename StringType =
typename json_pointer<RefStringTypeRhs>::string_t>
14018inline
bool operator!=(const StringType& lhs, const json_pointer<RefStringTypeRhs>& rhs) {
14019 return !(lhs == rhs);
14022template <
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14024 const json_pointer<RefStringTypeRhs>& rhs)
noexcept {
14025 return lhs.reference_tokens < rhs.reference_tokens;
14029NLOHMANN_JSON_NAMESPACE_END
14040#include <initializer_list>
14047NLOHMANN_JSON_NAMESPACE_BEGIN
14050template <
typename BasicJsonType>
class json_ref {
14052 using value_type = BasicJsonType;
14054 json_ref(value_type&& value) : owned_value(std::move(value)) {}
14056 json_ref(
const value_type& value) : value_ref(&value) {}
14058 json_ref(std::initializer_list<json_ref> init) : owned_value(init) {}
14060 template <
class... Args,
14061 enable_if_t<std::is_constructible<value_type, Args...>::value,
int> = 0>
14062 json_ref(Args&&... args) : owned_value(std::forward<Args>(args)...) {}
14065 json_ref(json_ref&&)
noexcept =
default;
14066 json_ref(
const json_ref&) =
delete;
14067 json_ref& operator=(
const json_ref&) =
delete;
14068 json_ref& operator=(json_ref&&) =
delete;
14069 ~json_ref() =
default;
14071 value_type moved_or_copied()
const {
14072 if (value_ref ==
nullptr) {
14073 return std::move(owned_value);
14078 value_type
const& operator*()
const {
return value_ref ? *value_ref : owned_value; }
14080 value_type
const* operator->()
const {
return &**
this; }
14083 mutable value_type owned_value =
nullptr;
14084 value_type
const* value_ref =
nullptr;
14088NLOHMANN_JSON_NAMESPACE_END
14109#include <algorithm>
14133#include <algorithm>
14147NLOHMANN_JSON_NAMESPACE_BEGIN
14151template <
typename CharType>
struct output_adapter_protocol {
14152 virtual void write_character(CharType c) = 0;
14153 virtual void write_characters(
const CharType* s, std::size_t length) = 0;
14154 virtual ~output_adapter_protocol() =
default;
14156 output_adapter_protocol() =
default;
14157 output_adapter_protocol(
const output_adapter_protocol&) =
default;
14158 output_adapter_protocol(output_adapter_protocol&&)
noexcept =
default;
14159 output_adapter_protocol& operator=(
const output_adapter_protocol&) =
default;
14160 output_adapter_protocol& operator=(output_adapter_protocol&&)
noexcept =
default;
14164template <
typename CharType>
14168template <
typename CharType,
typename AllocatorType = std::allocator<CharType>>
14169class output_vector_adapter :
public output_adapter_protocol<CharType> {
14171 explicit output_vector_adapter(std::vector<CharType, AllocatorType>& vec) noexcept : v(vec) {}
14173 void write_character(CharType c)
override { v.push_back(c); }
14175 JSON_HEDLEY_NON_NULL(2)
14176 void write_characters(
const CharType* s, std::size_t length)
override {
14177 v.insert(v.end(), s, s + length);
14181 std::vector<CharType, AllocatorType>& v;
14186template <
typename CharType>
14187class output_stream_adapter :
public output_adapter_protocol<CharType> {
14189 explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept : stream(s) {}
14191 void write_character(CharType c)
override { stream.put(c); }
14193 JSON_HEDLEY_NON_NULL(2)
14194 void write_characters(
const CharType* s, std::size_t length)
override {
14195 stream.write(s,
static_cast<std::streamsize
>(length));
14199 std::basic_ostream<CharType>& stream;
14204template <
typename CharType,
typename StringType = std::basic_
string<CharType>>
14205class output_string_adapter :
public output_adapter_protocol<CharType> {
14207 explicit output_string_adapter(StringType& s) noexcept : str(s) {}
14209 void write_character(CharType c)
override { str.push_back(c); }
14211 JSON_HEDLEY_NON_NULL(2)
14212 void write_characters(
const CharType* s, std::size_t length)
override { str.append(s, length); }
14218template <
typename CharType,
typename StringType = std::basic_
string<CharType>>
14219class output_adapter {
14221 template <
typename AllocatorType = std::allocator<CharType>>
14222 output_adapter(std::vector<CharType, AllocatorType>& vec)
14226 output_adapter(std::basic_ostream<CharType>& s)
14230 output_adapter(StringType& s)
14240NLOHMANN_JSON_NAMESPACE_END
14244NLOHMANN_JSON_NAMESPACE_BEGIN
14255 using string_t =
typename BasicJsonType::string_t;
14256 using binary_t =
typename BasicJsonType::binary_t;
14257 using number_float_t =
typename BasicJsonType::number_float_t;
14274 switch (j.type()) {
14276 write_bson_object(*j.m_data.m_value.object);
14290 JSON_THROW(type_error::create(
14292 concat(
"to serialize to BSON, top-level type must be object, but is ",
14303 switch (j.type()) {
14305 oa->write_character(to_char_type(0xF6));
14310 oa->write_character(j.m_data.m_value.boolean ? to_char_type(0xF5)
14311 : to_char_type(0xF4));
14316 if (j.m_data.m_value.number_integer >= 0) {
14320 if (j.m_data.m_value.number_integer <= 0x17) {
14321 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
14322 }
else if (j.m_data.m_value.number_integer <=
14323 (std::numeric_limits<std::uint8_t>::max)()) {
14324 oa->write_character(to_char_type(0x18));
14325 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
14326 }
else if (j.m_data.m_value.number_integer <=
14327 (std::numeric_limits<std::uint16_t>::max)()) {
14328 oa->write_character(to_char_type(0x19));
14329 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
14330 }
else if (j.m_data.m_value.number_integer <=
14331 (std::numeric_limits<std::uint32_t>::max)()) {
14332 oa->write_character(to_char_type(0x1A));
14333 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
14335 oa->write_character(to_char_type(0x1B));
14336 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
14341 const auto positive_number = -1 - j.m_data.m_value.number_integer;
14342 if (j.m_data.m_value.number_integer >= -24) {
14343 write_number(
static_cast<std::uint8_t
>(0x20 + positive_number));
14344 }
else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)()) {
14345 oa->write_character(to_char_type(0x38));
14346 write_number(
static_cast<std::uint8_t
>(positive_number));
14347 }
else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)()) {
14348 oa->write_character(to_char_type(0x39));
14349 write_number(
static_cast<std::uint16_t
>(positive_number));
14350 }
else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)()) {
14351 oa->write_character(to_char_type(0x3A));
14352 write_number(
static_cast<std::uint32_t
>(positive_number));
14354 oa->write_character(to_char_type(0x3B));
14355 write_number(
static_cast<std::uint64_t
>(positive_number));
14362 if (j.m_data.m_value.number_unsigned <= 0x17) {
14363 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_unsigned));
14364 }
else if (j.m_data.m_value.number_unsigned <=
14365 (std::numeric_limits<std::uint8_t>::max)()) {
14366 oa->write_character(to_char_type(0x18));
14367 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_unsigned));
14368 }
else if (j.m_data.m_value.number_unsigned <=
14369 (std::numeric_limits<std::uint16_t>::max)()) {
14370 oa->write_character(to_char_type(0x19));
14371 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_unsigned));
14372 }
else if (j.m_data.m_value.number_unsigned <=
14373 (std::numeric_limits<std::uint32_t>::max)()) {
14374 oa->write_character(to_char_type(0x1A));
14375 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_unsigned));
14377 oa->write_character(to_char_type(0x1B));
14378 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_unsigned));
14384 if (std::isnan(j.m_data.m_value.number_float)) {
14386 oa->write_character(to_char_type(0xF9));
14387 oa->write_character(to_char_type(0x7E));
14388 oa->write_character(to_char_type(0x00));
14389 }
else if (std::isinf(j.m_data.m_value.number_float)) {
14391 oa->write_character(to_char_type(0xf9));
14392 oa->write_character(j.m_data.m_value.number_float > 0 ? to_char_type(0x7C)
14393 : to_char_type(0xFC));
14394 oa->write_character(to_char_type(0x00));
14396 write_compact_float(j.m_data.m_value.number_float,
14397 detail::input_format_t::cbor);
14404 const auto N = j.m_data.m_value.string->size();
14406 write_number(
static_cast<std::uint8_t
>(0x60 + N));
14407 }
else if (N <= (std::numeric_limits<std::uint8_t>::max)()) {
14408 oa->write_character(to_char_type(0x78));
14409 write_number(
static_cast<std::uint8_t
>(N));
14410 }
else if (N <= (std::numeric_limits<std::uint16_t>::max)()) {
14411 oa->write_character(to_char_type(0x79));
14412 write_number(
static_cast<std::uint16_t
>(N));
14413 }
else if (N <= (std::numeric_limits<std::uint32_t>::max)()) {
14414 oa->write_character(to_char_type(0x7A));
14415 write_number(
static_cast<std::uint32_t
>(N));
14418 else if (N <= (std::numeric_limits<std::uint64_t>::max)()) {
14419 oa->write_character(to_char_type(0x7B));
14420 write_number(
static_cast<std::uint64_t
>(N));
14425 oa->write_characters(
14426 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
14427 j.m_data.m_value.string->size());
14433 const auto N = j.m_data.m_value.array->size();
14435 write_number(
static_cast<std::uint8_t
>(0x80 + N));
14436 }
else if (N <= (std::numeric_limits<std::uint8_t>::max)()) {
14437 oa->write_character(to_char_type(0x98));
14438 write_number(
static_cast<std::uint8_t
>(N));
14439 }
else if (N <= (std::numeric_limits<std::uint16_t>::max)()) {
14440 oa->write_character(to_char_type(0x99));
14441 write_number(
static_cast<std::uint16_t
>(N));
14442 }
else if (N <= (std::numeric_limits<std::uint32_t>::max)()) {
14443 oa->write_character(to_char_type(0x9A));
14444 write_number(
static_cast<std::uint32_t
>(N));
14447 else if (N <= (std::numeric_limits<std::uint64_t>::max)()) {
14448 oa->write_character(to_char_type(0x9B));
14449 write_number(
static_cast<std::uint64_t
>(N));
14454 for (
const auto& el : *j.m_data.m_value.array) {
14461 if (j.m_data.m_value.binary->has_subtype()) {
14462 if (j.m_data.m_value.binary->subtype() <=
14463 (std::numeric_limits<std::uint8_t>::max)()) {
14464 write_number(
static_cast<std::uint8_t
>(0xd8));
14465 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.binary->subtype()));
14466 }
else if (j.m_data.m_value.binary->subtype() <=
14467 (std::numeric_limits<std::uint16_t>::max)()) {
14468 write_number(
static_cast<std::uint8_t
>(0xd9));
14470 static_cast<std::uint16_t
>(j.m_data.m_value.binary->subtype()));
14471 }
else if (j.m_data.m_value.binary->subtype() <=
14472 (std::numeric_limits<std::uint32_t>::max)()) {
14473 write_number(
static_cast<std::uint8_t
>(0xda));
14475 static_cast<std::uint32_t
>(j.m_data.m_value.binary->subtype()));
14476 }
else if (j.m_data.m_value.binary->subtype() <=
14477 (std::numeric_limits<std::uint64_t>::max)()) {
14478 write_number(
static_cast<std::uint8_t
>(0xdb));
14480 static_cast<std::uint64_t
>(j.m_data.m_value.binary->subtype()));
14485 const auto N = j.m_data.m_value.binary->size();
14487 write_number(
static_cast<std::uint8_t
>(0x40 + N));
14488 }
else if (N <= (std::numeric_limits<std::uint8_t>::max)()) {
14489 oa->write_character(to_char_type(0x58));
14490 write_number(
static_cast<std::uint8_t
>(N));
14491 }
else if (N <= (std::numeric_limits<std::uint16_t>::max)()) {
14492 oa->write_character(to_char_type(0x59));
14493 write_number(
static_cast<std::uint16_t
>(N));
14494 }
else if (N <= (std::numeric_limits<std::uint32_t>::max)()) {
14495 oa->write_character(to_char_type(0x5A));
14496 write_number(
static_cast<std::uint32_t
>(N));
14499 else if (N <= (std::numeric_limits<std::uint64_t>::max)()) {
14500 oa->write_character(to_char_type(0x5B));
14501 write_number(
static_cast<std::uint64_t
>(N));
14506 oa->write_characters(
14507 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()), N);
14514 const auto N = j.m_data.m_value.object->size();
14516 write_number(
static_cast<std::uint8_t
>(0xA0 + N));
14517 }
else if (N <= (std::numeric_limits<std::uint8_t>::max)()) {
14518 oa->write_character(to_char_type(0xB8));
14519 write_number(
static_cast<std::uint8_t
>(N));
14520 }
else if (N <= (std::numeric_limits<std::uint16_t>::max)()) {
14521 oa->write_character(to_char_type(0xB9));
14522 write_number(
static_cast<std::uint16_t
>(N));
14523 }
else if (N <= (std::numeric_limits<std::uint32_t>::max)()) {
14524 oa->write_character(to_char_type(0xBA));
14525 write_number(
static_cast<std::uint32_t
>(N));
14528 else if (N <= (std::numeric_limits<std::uint64_t>::max)()) {
14529 oa->write_character(to_char_type(0xBB));
14530 write_number(
static_cast<std::uint64_t
>(N));
14535 for (
const auto& el : *j.m_data.m_value.object) {
14552 switch (j.type()) {
14555 oa->write_character(to_char_type(0xC0));
14561 oa->write_character(j.m_data.m_value.boolean ? to_char_type(0xC3)
14562 : to_char_type(0xC2));
14567 if (j.m_data.m_value.number_integer >= 0) {
14571 if (j.m_data.m_value.number_unsigned < 128) {
14573 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
14574 }
else if (j.m_data.m_value.number_unsigned <=
14575 (std::numeric_limits<std::uint8_t>::max)()) {
14577 oa->write_character(to_char_type(0xCC));
14578 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
14579 }
else if (j.m_data.m_value.number_unsigned <=
14580 (std::numeric_limits<std::uint16_t>::max)()) {
14582 oa->write_character(to_char_type(0xCD));
14583 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
14584 }
else if (j.m_data.m_value.number_unsigned <=
14585 (std::numeric_limits<std::uint32_t>::max)()) {
14587 oa->write_character(to_char_type(0xCE));
14588 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
14589 }
else if (j.m_data.m_value.number_unsigned <=
14590 (std::numeric_limits<std::uint64_t>::max)()) {
14592 oa->write_character(to_char_type(0xCF));
14593 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
14596 if (j.m_data.m_value.number_integer >= -32) {
14598 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.number_integer));
14599 }
else if (j.m_data.m_value.number_integer >=
14600 (std::numeric_limits<std::int8_t>::min)() &&
14601 j.m_data.m_value.number_integer <=
14602 (std::numeric_limits<std::int8_t>::max)()) {
14604 oa->write_character(to_char_type(0xD0));
14605 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.number_integer));
14606 }
else if (j.m_data.m_value.number_integer >=
14607 (std::numeric_limits<std::int16_t>::min)() &&
14608 j.m_data.m_value.number_integer <=
14609 (std::numeric_limits<std::int16_t>::max)()) {
14611 oa->write_character(to_char_type(0xD1));
14612 write_number(
static_cast<std::int16_t
>(j.m_data.m_value.number_integer));
14613 }
else if (j.m_data.m_value.number_integer >=
14614 (std::numeric_limits<std::int32_t>::min)() &&
14615 j.m_data.m_value.number_integer <=
14616 (std::numeric_limits<std::int32_t>::max)()) {
14618 oa->write_character(to_char_type(0xD2));
14619 write_number(
static_cast<std::int32_t
>(j.m_data.m_value.number_integer));
14620 }
else if (j.m_data.m_value.number_integer >=
14621 (std::numeric_limits<std::int64_t>::min)() &&
14622 j.m_data.m_value.number_integer <=
14623 (std::numeric_limits<std::int64_t>::max)()) {
14625 oa->write_character(to_char_type(0xD3));
14626 write_number(
static_cast<std::int64_t
>(j.m_data.m_value.number_integer));
14633 if (j.m_data.m_value.number_unsigned < 128) {
14635 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
14636 }
else if (j.m_data.m_value.number_unsigned <=
14637 (std::numeric_limits<std::uint8_t>::max)()) {
14639 oa->write_character(to_char_type(0xCC));
14640 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
14641 }
else if (j.m_data.m_value.number_unsigned <=
14642 (std::numeric_limits<std::uint16_t>::max)()) {
14644 oa->write_character(to_char_type(0xCD));
14645 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
14646 }
else if (j.m_data.m_value.number_unsigned <=
14647 (std::numeric_limits<std::uint32_t>::max)()) {
14649 oa->write_character(to_char_type(0xCE));
14650 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
14651 }
else if (j.m_data.m_value.number_unsigned <=
14652 (std::numeric_limits<std::uint64_t>::max)()) {
14654 oa->write_character(to_char_type(0xCF));
14655 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
14661 write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::msgpack);
14667 const auto N = j.m_data.m_value.string->size();
14670 write_number(
static_cast<std::uint8_t
>(0xA0 | N));
14671 }
else if (N <= (std::numeric_limits<std::uint8_t>::max)()) {
14673 oa->write_character(to_char_type(0xD9));
14674 write_number(
static_cast<std::uint8_t
>(N));
14675 }
else if (N <= (std::numeric_limits<std::uint16_t>::max)()) {
14677 oa->write_character(to_char_type(0xDA));
14678 write_number(
static_cast<std::uint16_t
>(N));
14679 }
else if (N <= (std::numeric_limits<std::uint32_t>::max)()) {
14681 oa->write_character(to_char_type(0xDB));
14682 write_number(
static_cast<std::uint32_t
>(N));
14686 oa->write_characters(
14687 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
14688 j.m_data.m_value.string->size());
14694 const auto N = j.m_data.m_value.array->size();
14697 write_number(
static_cast<std::uint8_t
>(0x90 | N));
14698 }
else if (N <= (std::numeric_limits<std::uint16_t>::max)()) {
14700 oa->write_character(to_char_type(0xDC));
14701 write_number(
static_cast<std::uint16_t
>(N));
14702 }
else if (N <= (std::numeric_limits<std::uint32_t>::max)()) {
14704 oa->write_character(to_char_type(0xDD));
14705 write_number(
static_cast<std::uint32_t
>(N));
14709 for (
const auto& el : *j.m_data.m_value.array) {
14718 const bool use_ext = j.m_data.m_value.binary->has_subtype();
14721 const auto N = j.m_data.m_value.binary->size();
14722 if (N <= (std::numeric_limits<std::uint8_t>::max)()) {
14723 std::uint8_t output_type{};
14728 output_type = 0xD4;
14731 output_type = 0xD5;
14734 output_type = 0xD6;
14737 output_type = 0xD7;
14740 output_type = 0xD8;
14743 output_type = 0xC7;
14749 output_type = 0xC4;
14753 oa->write_character(to_char_type(output_type));
14755 write_number(
static_cast<std::uint8_t
>(N));
14757 }
else if (N <= (std::numeric_limits<std::uint16_t>::max)()) {
14758 const std::uint8_t output_type = use_ext ? 0xC8
14761 oa->write_character(to_char_type(output_type));
14762 write_number(
static_cast<std::uint16_t
>(N));
14763 }
else if (N <= (std::numeric_limits<std::uint32_t>::max)()) {
14764 const std::uint8_t output_type = use_ext ? 0xC9
14767 oa->write_character(to_char_type(output_type));
14768 write_number(
static_cast<std::uint32_t
>(N));
14773 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.binary->subtype()));
14777 oa->write_characters(
14778 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()), N);
14785 const auto N = j.m_data.m_value.object->size();
14788 write_number(
static_cast<std::uint8_t
>(0x80 | (N & 0xF)));
14789 }
else if (N <= (std::numeric_limits<std::uint16_t>::max)()) {
14791 oa->write_character(to_char_type(0xDE));
14792 write_number(
static_cast<std::uint16_t
>(N));
14793 }
else if (N <= (std::numeric_limits<std::uint32_t>::max)()) {
14795 oa->write_character(to_char_type(0xDF));
14796 write_number(
static_cast<std::uint32_t
>(N));
14800 for (
const auto& el : *j.m_data.m_value.object) {
14820 void write_ubjson(
const BasicJsonType& j,
const bool use_count,
const bool use_type,
14821 const bool add_prefix =
true,
const bool use_bjdata =
false) {
14822 switch (j.type()) {
14825 oa->write_character(to_char_type(
'Z'));
14832 oa->write_character(j.m_data.m_value.boolean ? to_char_type(
'T')
14833 : to_char_type(
'F'));
14839 write_number_with_ubjson_prefix(j.m_data.m_value.number_integer, add_prefix,
14845 write_number_with_ubjson_prefix(j.m_data.m_value.number_unsigned, add_prefix,
14851 write_number_with_ubjson_prefix(j.m_data.m_value.number_float, add_prefix,
14858 oa->write_character(to_char_type(
'S'));
14860 write_number_with_ubjson_prefix(j.m_data.m_value.string->size(),
true, use_bjdata);
14861 oa->write_characters(
14862 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
14863 j.m_data.m_value.string->size());
14869 oa->write_character(to_char_type(
'['));
14872 bool prefix_required =
true;
14873 if (use_type && !j.m_data.m_value.array->empty()) {
14874 JSON_ASSERT(use_count);
14875 const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
14876 const bool same_prefix =
14877 std::all_of(j.begin() + 1, j.end(),
14878 [
this, first_prefix, use_bjdata](
const BasicJsonType& v) {
14879 return ubjson_prefix(v, use_bjdata) == first_prefix;
14882 std::vector<CharType> bjdx = {
14883 '[',
'{',
'S',
'H',
14884 'T',
'F',
'N',
'Z'};
14886 if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(),
14887 first_prefix) != bjdx.end())) {
14888 prefix_required =
false;
14889 oa->write_character(to_char_type(
'$'));
14890 oa->write_character(first_prefix);
14895 oa->write_character(to_char_type(
'#'));
14896 write_number_with_ubjson_prefix(j.m_data.m_value.array->size(),
true,
14900 for (
const auto& el : *j.m_data.m_value.array) {
14901 write_ubjson(el, use_count, use_type, prefix_required, use_bjdata);
14905 oa->write_character(to_char_type(
']'));
14913 oa->write_character(to_char_type(
'['));
14916 if (use_type && !j.m_data.m_value.binary->empty()) {
14917 JSON_ASSERT(use_count);
14918 oa->write_character(to_char_type(
'$'));
14919 oa->write_character(
'U');
14923 oa->write_character(to_char_type(
'#'));
14924 write_number_with_ubjson_prefix(j.m_data.m_value.binary->size(),
true,
14929 oa->write_characters(
14930 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
14931 j.m_data.m_value.binary->size());
14933 for (
size_t i = 0; i < j.m_data.m_value.binary->size(); ++i) {
14934 oa->write_character(to_char_type(
'U'));
14935 oa->write_character(j.m_data.m_value.binary->data()[i]);
14940 oa->write_character(to_char_type(
']'));
14947 if (use_bjdata && j.m_data.m_value.object->size() == 3 &&
14948 j.m_data.m_value.object->find(
"_ArrayType_") !=
14949 j.m_data.m_value.object->end() &&
14950 j.m_data.m_value.object->find(
"_ArraySize_") !=
14951 j.m_data.m_value.object->end() &&
14952 j.m_data.m_value.object->find(
"_ArrayData_") !=
14953 j.m_data.m_value.object->end()) {
14954 if (!write_bjdata_ndarray(
14955 *j.m_data.m_value.object, use_count,
14964 oa->write_character(to_char_type(
'{'));
14967 bool prefix_required =
true;
14968 if (use_type && !j.m_data.m_value.object->empty()) {
14969 JSON_ASSERT(use_count);
14970 const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
14971 const bool same_prefix =
14972 std::all_of(j.begin(), j.end(),
14973 [
this, first_prefix, use_bjdata](
const BasicJsonType& v) {
14974 return ubjson_prefix(v, use_bjdata) == first_prefix;
14977 std::vector<CharType> bjdx = {
14978 '[',
'{',
'S',
'H',
14979 'T',
'F',
'N',
'Z'};
14981 if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(),
14982 first_prefix) != bjdx.end())) {
14983 prefix_required =
false;
14984 oa->write_character(to_char_type(
'$'));
14985 oa->write_character(first_prefix);
14990 oa->write_character(to_char_type(
'#'));
14991 write_number_with_ubjson_prefix(j.m_data.m_value.object->size(),
true,
14995 for (
const auto& el : *j.m_data.m_value.object) {
14996 write_number_with_ubjson_prefix(el.first.size(),
true, use_bjdata);
14997 oa->write_characters(
reinterpret_cast<const CharType*
>(el.first.c_str()),
14999 write_ubjson(el.second, use_count, use_type, prefix_required, use_bjdata);
15003 oa->write_character(to_char_type(
'}'));
15024 static std::size_t calc_bson_entry_header_size(
const string_t& name,
const BasicJsonType& j) {
15025 const auto it = name.find(
static_cast<typename string_t::value_type
>(0));
15026 if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos)) {
15028 out_of_range::create(409,
15029 concat(
"BSON key cannot contain code point U+0000 (at byte ",
15030 std::to_string(it),
")"),
15032 static_cast<void>(j);
15035 return 1ul + name.size() + 1u;
15041 void write_bson_entry_header(
const string_t& name,
const std::uint8_t element_type) {
15042 oa->write_character(to_char_type(element_type));
15043 oa->write_characters(
reinterpret_cast<const CharType*
>(name.c_str()), name.size() + 1u);
15049 void write_bson_boolean(
const string_t& name,
const bool value) {
15050 write_bson_entry_header(name, 0x08);
15051 oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
15057 void write_bson_double(
const string_t& name,
const double value) {
15058 write_bson_entry_header(name, 0x01);
15059 write_number<double>(value,
true);
15065 static std::size_t calc_bson_string_size(
const string_t& value) {
15066 return sizeof(std::int32_t) + value.size() + 1ul;
15072 void write_bson_string(
const string_t& name,
const string_t& value) {
15073 write_bson_entry_header(name, 0x02);
15075 write_number<std::int32_t>(
static_cast<std::int32_t
>(value.size() + 1ul),
true);
15076 oa->write_characters(
reinterpret_cast<const CharType*
>(value.c_str()), value.size() + 1);
15082 void write_bson_null(
const string_t& name) { write_bson_entry_header(name, 0x0A); }
15087 static std::size_t calc_bson_integer_size(
const std::int64_t value) {
15088 return (std::numeric_limits<std::int32_t>::min)() <= value &&
15089 value <= (std::numeric_limits<std::int32_t>::max)()
15090 ?
sizeof(std::int32_t)
15091 :
sizeof(std::int64_t);
15097 void write_bson_integer(
const string_t& name,
const std::int64_t value) {
15098 if ((std::numeric_limits<std::int32_t>::min)() <= value &&
15099 value <= (std::numeric_limits<std::int32_t>::max)()) {
15100 write_bson_entry_header(name, 0x10);
15101 write_number<std::int32_t>(
static_cast<std::int32_t
>(value),
true);
15103 write_bson_entry_header(name, 0x12);
15104 write_number<std::int64_t>(
static_cast<std::int64_t
>(value),
true);
15111 static constexpr std::size_t calc_bson_unsigned_size(
const std::uint64_t value)
noexcept {
15112 return (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
15113 ?
sizeof(std::int32_t)
15114 : sizeof(std::int64_t);
15120 void write_bson_unsigned(
const string_t& name,
const BasicJsonType& j) {
15121 if (j.m_data.m_value.number_unsigned <=
15122 static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)())) {
15123 write_bson_entry_header(name, 0x10 );
15124 write_number<std::int32_t>(
static_cast<std::int32_t
>(j.m_data.m_value.number_unsigned),
15126 }
else if (j.m_data.m_value.number_unsigned <=
15127 static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)())) {
15128 write_bson_entry_header(name, 0x12 );
15129 write_number<std::int64_t>(
static_cast<std::int64_t
>(j.m_data.m_value.number_unsigned),
15132 JSON_THROW(out_of_range::create(
15134 concat(
"integer number ", std::to_string(j.m_data.m_value.number_unsigned),
15135 " cannot be represented by BSON as it does not fit int64"),
15143 void write_bson_object_entry(
const string_t& name,
15144 const typename BasicJsonType::object_t& value) {
15145 write_bson_entry_header(name, 0x03);
15146 write_bson_object(value);
15152 static std::size_t calc_bson_array_size(
const typename BasicJsonType::array_t& value) {
15153 std::size_t array_index = 0ul;
15155 const std::size_t embedded_document_size = std::accumulate(
15156 std::begin(value), std::end(value),
static_cast<std::size_t
>(0),
15157 [&array_index](std::size_t result,
15158 const typename BasicJsonType::array_t::value_type& el) {
15159 return result + calc_bson_element_size(std::to_string(array_index++), el);
15162 return sizeof(std::int32_t) + embedded_document_size + 1ul;
15168 static std::size_t calc_bson_binary_size(
const typename BasicJsonType::binary_t& value) {
15169 return sizeof(std::int32_t) + value.size() + 1ul;
15175 void write_bson_array(
const string_t& name,
const typename BasicJsonType::array_t& value) {
15176 write_bson_entry_header(name, 0x04);
15177 write_number<std::int32_t>(
static_cast<std::int32_t
>(calc_bson_array_size(value)),
true);
15179 std::size_t array_index = 0ul;
15181 for (
const auto& el : value) {
15182 write_bson_element(std::to_string(array_index++), el);
15185 oa->write_character(to_char_type(0x00));
15191 void write_bson_binary(
const string_t& name,
const binary_t& value) {
15192 write_bson_entry_header(name, 0x05);
15194 write_number<std::int32_t>(
static_cast<std::int32_t
>(value.size()),
true);
15195 write_number(value.has_subtype() ?
static_cast<std::uint8_t
>(value.subtype())
15196 :
static_cast<std::uint8_t
>(0x00));
15198 oa->write_characters(
reinterpret_cast<const CharType*
>(value.data()), value.size());
15207 static std::size_t calc_bson_element_size(
const string_t& name,
const BasicJsonType& j) {
15208 const auto header_size = calc_bson_entry_header_size(name, j);
15209 switch (j.type()) {
15210 case value_t::object:
15211 return header_size + calc_bson_object_size(*j.m_data.m_value.object);
15213 case value_t::array:
15214 return header_size + calc_bson_array_size(*j.m_data.m_value.array);
15216 case value_t::binary:
15217 return header_size + calc_bson_binary_size(*j.m_data.m_value.binary);
15219 case value_t::boolean:
15220 return header_size + 1ul;
15222 case value_t::number_float:
15223 return header_size + 8ul;
15225 case value_t::number_integer:
15226 return header_size + calc_bson_integer_size(j.m_data.m_value.number_integer);
15228 case value_t::number_unsigned:
15229 return header_size + calc_bson_unsigned_size(j.m_data.m_value.number_unsigned);
15231 case value_t::string:
15232 return header_size + calc_bson_string_size(*j.m_data.m_value.string);
15234 case value_t::null:
15235 return header_size + 0ul;
15238 case value_t::discarded:
15240 JSON_ASSERT(
false);
15252 void write_bson_element(
const string_t& name,
const BasicJsonType& j) {
15253 switch (j.type()) {
15254 case value_t::object:
15255 return write_bson_object_entry(name, *j.m_data.m_value.object);
15257 case value_t::array:
15258 return write_bson_array(name, *j.m_data.m_value.array);
15260 case value_t::binary:
15261 return write_bson_binary(name, *j.m_data.m_value.binary);
15263 case value_t::boolean:
15264 return write_bson_boolean(name, j.m_data.m_value.boolean);
15266 case value_t::number_float:
15267 return write_bson_double(name, j.m_data.m_value.number_float);
15269 case value_t::number_integer:
15270 return write_bson_integer(name, j.m_data.m_value.number_integer);
15272 case value_t::number_unsigned:
15273 return write_bson_unsigned(name, j);
15275 case value_t::string:
15276 return write_bson_string(name, *j.m_data.m_value.string);
15278 case value_t::null:
15279 return write_bson_null(name);
15282 case value_t::discarded:
15284 JSON_ASSERT(
false);
15296 static std::size_t calc_bson_object_size(
const typename BasicJsonType::object_t& value) {
15297 const std::size_t document_size = std::accumulate(
15298 value.begin(), value.end(),
static_cast<std::size_t
>(0),
15299 [](
size_t result,
const typename BasicJsonType::object_t::value_type& el) {
15300 return result += calc_bson_element_size(el.first, el.second);
15303 return sizeof(std::int32_t) + document_size + 1ul;
15310 void write_bson_object(
const typename BasicJsonType::object_t& value) {
15311 write_number<std::int32_t>(
static_cast<std::int32_t
>(calc_bson_object_size(value)),
true);
15313 for (
const auto& el : value) {
15314 write_bson_element(el.first, el.second);
15317 oa->write_character(to_char_type(0x00));
15324 static constexpr CharType get_cbor_float_prefix(
float ) {
15325 return to_char_type(0xFA);
15328 static constexpr CharType get_cbor_float_prefix(
double ) {
15329 return to_char_type(0xFB);
15336 static constexpr CharType get_msgpack_float_prefix(
float ) {
15337 return to_char_type(0xCA);
15340 static constexpr CharType get_msgpack_float_prefix(
double ) {
15341 return to_char_type(0xCB);
15349 template <
typename NumberType,
15350 typename std::enable_if<std::is_floating_point<NumberType>::value,
int>::type = 0>
15351 void write_number_with_ubjson_prefix(
const NumberType n,
const bool add_prefix,
15352 const bool use_bjdata) {
15354 oa->write_character(get_ubjson_float_prefix(n));
15356 write_number(n, use_bjdata);
15360 template <
typename NumberType,
15361 typename std::enable_if<std::is_unsigned<NumberType>::value,
int>::type = 0>
15362 void write_number_with_ubjson_prefix(
const NumberType n,
const bool add_prefix,
15363 const bool use_bjdata) {
15364 if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)())) {
15366 oa->write_character(to_char_type(
'i'));
15368 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
15369 }
else if (n <= (std::numeric_limits<std::uint8_t>::max)()) {
15371 oa->write_character(to_char_type(
'U'));
15373 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
15374 }
else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)())) {
15376 oa->write_character(to_char_type(
'I'));
15378 write_number(
static_cast<std::int16_t
>(n), use_bjdata);
15379 }
else if (use_bjdata &&
15380 n <=
static_cast<uint64_t
>((std::numeric_limits<uint16_t>::max)())) {
15382 oa->write_character(to_char_type(
'u'));
15384 write_number(
static_cast<std::uint16_t
>(n), use_bjdata);
15385 }
else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)())) {
15387 oa->write_character(to_char_type(
'l'));
15389 write_number(
static_cast<std::int32_t
>(n), use_bjdata);
15390 }
else if (use_bjdata &&
15391 n <=
static_cast<uint64_t
>((std::numeric_limits<uint32_t>::max)())) {
15393 oa->write_character(to_char_type(
'm'));
15395 write_number(
static_cast<std::uint32_t
>(n), use_bjdata);
15396 }
else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)())) {
15398 oa->write_character(to_char_type(
'L'));
15400 write_number(
static_cast<std::int64_t
>(n), use_bjdata);
15401 }
else if (use_bjdata && n <= (std::numeric_limits<uint64_t>::max)()) {
15403 oa->write_character(to_char_type(
'M'));
15405 write_number(
static_cast<std::uint64_t
>(n), use_bjdata);
15408 oa->write_character(to_char_type(
'H'));
15411 const auto number = BasicJsonType(n).dump();
15412 write_number_with_ubjson_prefix(number.size(),
true, use_bjdata);
15413 for (std::size_t i = 0; i < number.size(); ++i) {
15414 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
15420 template <
typename NumberType,
15421 typename std::enable_if<std::is_signed<NumberType>::value &&
15422 !std::is_floating_point<NumberType>::value,
15424 void write_number_with_ubjson_prefix(
const NumberType n,
const bool add_prefix,
15425 const bool use_bjdata) {
15426 if ((std::numeric_limits<std::int8_t>::min)() <= n &&
15427 n <= (std::numeric_limits<std::int8_t>::max)()) {
15429 oa->write_character(to_char_type(
'i'));
15431 write_number(
static_cast<std::int8_t
>(n), use_bjdata);
15432 }
else if (
static_cast<std::int64_t
>((std::numeric_limits<std::uint8_t>::min)()) <= n &&
15433 n <=
static_cast<std::int64_t
>((std::numeric_limits<std::uint8_t>::max)())) {
15435 oa->write_character(to_char_type(
'U'));
15437 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
15438 }
else if ((std::numeric_limits<std::int16_t>::min)() <= n &&
15439 n <= (std::numeric_limits<std::int16_t>::max)()) {
15441 oa->write_character(to_char_type(
'I'));
15443 write_number(
static_cast<std::int16_t
>(n), use_bjdata);
15444 }
else if (use_bjdata &&
15445 (
static_cast<std::int64_t
>((std::numeric_limits<std::uint16_t>::min)()) <= n &&
15446 n <=
static_cast<std::int64_t
>((std::numeric_limits<std::uint16_t>::max)()))) {
15448 oa->write_character(to_char_type(
'u'));
15450 write_number(
static_cast<uint16_t
>(n), use_bjdata);
15451 }
else if ((std::numeric_limits<std::int32_t>::min)() <= n &&
15452 n <= (std::numeric_limits<std::int32_t>::max)()) {
15454 oa->write_character(to_char_type(
'l'));
15456 write_number(
static_cast<std::int32_t
>(n), use_bjdata);
15457 }
else if (use_bjdata &&
15458 (
static_cast<std::int64_t
>((std::numeric_limits<std::uint32_t>::min)()) <= n &&
15459 n <=
static_cast<std::int64_t
>((std::numeric_limits<std::uint32_t>::max)()))) {
15461 oa->write_character(to_char_type(
'm'));
15463 write_number(
static_cast<uint32_t
>(n), use_bjdata);
15464 }
else if ((std::numeric_limits<std::int64_t>::min)() <= n &&
15465 n <= (std::numeric_limits<std::int64_t>::max)()) {
15467 oa->write_character(to_char_type(
'L'));
15469 write_number(
static_cast<std::int64_t
>(n), use_bjdata);
15474 oa->write_character(to_char_type(
'H'));
15477 const auto number = BasicJsonType(n).dump();
15478 write_number_with_ubjson_prefix(number.size(),
true, use_bjdata);
15479 for (std::size_t i = 0; i < number.size(); ++i) {
15480 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
15489 CharType ubjson_prefix(
const BasicJsonType& j,
const bool use_bjdata)
const noexcept {
15490 switch (j.type()) {
15491 case value_t::null:
15494 case value_t::boolean:
15495 return j.m_data.m_value.boolean ?
'T' :
'F';
15497 case value_t::number_integer: {
15498 if ((std::numeric_limits<std::int8_t>::min)() <= j.m_data.m_value.number_integer &&
15499 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)()) {
15502 if ((std::numeric_limits<std::uint8_t>::min)() <= j.m_data.m_value.number_integer &&
15503 j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)()) {
15506 if ((std::numeric_limits<std::int16_t>::min)() <= j.m_data.m_value.number_integer &&
15507 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)()) {
15510 if (use_bjdata && ((std::numeric_limits<std::uint16_t>::min)() <=
15511 j.m_data.m_value.number_integer &&
15512 j.m_data.m_value.number_integer <=
15513 (std::numeric_limits<std::uint16_t>::max)())) {
15516 if ((std::numeric_limits<std::int32_t>::min)() <= j.m_data.m_value.number_integer &&
15517 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)()) {
15520 if (use_bjdata && ((std::numeric_limits<std::uint32_t>::min)() <=
15521 j.m_data.m_value.number_integer &&
15522 j.m_data.m_value.number_integer <=
15523 (std::numeric_limits<std::uint32_t>::max)())) {
15526 if ((std::numeric_limits<std::int64_t>::min)() <= j.m_data.m_value.number_integer &&
15527 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)()) {
15534 case value_t::number_unsigned: {
15535 if (j.m_data.m_value.number_unsigned <=
15536 static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)())) {
15539 if (j.m_data.m_value.number_unsigned <=
15540 static_cast<std::uint64_t
>((std::numeric_limits<std::uint8_t>::max)())) {
15543 if (j.m_data.m_value.number_unsigned <=
15544 static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)())) {
15548 j.m_data.m_value.number_unsigned <=
15549 static_cast<std::uint64_t
>((std::numeric_limits<std::uint16_t>::max)())) {
15552 if (j.m_data.m_value.number_unsigned <=
15553 static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)())) {
15557 j.m_data.m_value.number_unsigned <=
15558 static_cast<std::uint64_t
>((std::numeric_limits<std::uint32_t>::max)())) {
15561 if (j.m_data.m_value.number_unsigned <=
15562 static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)())) {
15565 if (use_bjdata && j.m_data.m_value.number_unsigned <=
15566 (std::numeric_limits<std::uint64_t>::max)()) {
15573 case value_t::number_float:
15574 return get_ubjson_float_prefix(j.m_data.m_value.number_float);
15576 case value_t::string:
15579 case value_t::array:
15580 case value_t::binary:
15583 case value_t::object:
15586 case value_t::discarded:
15592 static constexpr CharType get_ubjson_float_prefix(
float ) {
15596 static constexpr CharType get_ubjson_float_prefix(
double ) {
15604 bool write_bjdata_ndarray(
const typename BasicJsonType::object_t& value,
const bool use_count,
15605 const bool use_type) {
15606 std::map<string_t, CharType> bjdtype = {{
"uint8",
'U'}, {
"int8",
'i'}, {
"uint16",
'u'},
15607 {
"int16",
'I'}, {
"uint32",
'm'}, {
"int32",
'l'},
15608 {
"uint64",
'M'}, {
"int64",
'L'}, {
"single",
'd'},
15609 {
"double",
'D'}, {
"char",
'C'}};
15611 string_t
key =
"_ArrayType_";
15612 auto it = bjdtype.find(
static_cast<string_t
>(value.at(key)));
15613 if (it == bjdtype.end()) {
15616 CharType dtype = it->second;
15618 key =
"_ArraySize_";
15619 std::size_t len = (value.at(key).empty() ? 0 : 1);
15620 for (
const auto& el : value.at(key)) {
15621 len *=
static_cast<std::size_t
>(el.m_data.m_value.number_unsigned);
15624 key =
"_ArrayData_";
15625 if (value.at(key).size() != len) {
15629 oa->write_character(
'[');
15630 oa->write_character(
'$');
15631 oa->write_character(dtype);
15632 oa->write_character(
'#');
15634 key =
"_ArraySize_";
15635 write_ubjson(value.at(key), use_count, use_type,
true,
true);
15637 key =
"_ArrayData_";
15638 if (dtype ==
'U' || dtype ==
'C') {
15639 for (
const auto& el : value.at(key)) {
15640 write_number(
static_cast<std::uint8_t
>(el.m_data.m_value.number_unsigned),
true);
15642 }
else if (dtype ==
'i') {
15643 for (
const auto& el : value.at(key)) {
15644 write_number(
static_cast<std::int8_t
>(el.m_data.m_value.number_integer),
true);
15646 }
else if (dtype ==
'u') {
15647 for (
const auto& el : value.at(key)) {
15648 write_number(
static_cast<std::uint16_t
>(el.m_data.m_value.number_unsigned),
true);
15650 }
else if (dtype ==
'I') {
15651 for (
const auto& el : value.at(key)) {
15652 write_number(
static_cast<std::int16_t
>(el.m_data.m_value.number_integer),
true);
15654 }
else if (dtype ==
'm') {
15655 for (
const auto& el : value.at(key)) {
15656 write_number(
static_cast<std::uint32_t
>(el.m_data.m_value.number_unsigned),
true);
15658 }
else if (dtype ==
'l') {
15659 for (
const auto& el : value.at(key)) {
15660 write_number(
static_cast<std::int32_t
>(el.m_data.m_value.number_integer),
true);
15662 }
else if (dtype ==
'M') {
15663 for (
const auto& el : value.at(key)) {
15664 write_number(
static_cast<std::uint64_t
>(el.m_data.m_value.number_unsigned),
true);
15666 }
else if (dtype ==
'L') {
15667 for (
const auto& el : value.at(key)) {
15668 write_number(
static_cast<std::int64_t
>(el.m_data.m_value.number_integer),
true);
15670 }
else if (dtype ==
'd') {
15671 for (
const auto& el : value.at(key)) {
15672 write_number(
static_cast<float>(el.m_data.m_value.number_float),
true);
15674 }
else if (dtype ==
'D') {
15675 for (
const auto& el : value.at(key)) {
15676 write_number(
static_cast<double>(el.m_data.m_value.number_float),
true);
15699 template <
typename NumberType>
15700 void write_number(
const NumberType n,
const bool OutputIsLittleEndian =
false) {
15702 std::array<CharType,
sizeof(NumberType)> vec{};
15703 std::memcpy(vec.data(), &n,
sizeof(NumberType));
15706 if (is_little_endian != OutputIsLittleEndian) {
15708 std::reverse(vec.begin(), vec.end());
15711 oa->write_characters(vec.data(),
sizeof(NumberType));
15716#pragma GCC diagnostic push
15717#pragma GCC diagnostic ignored "-Wfloat-equal"
15719 if (
static_cast<double>(n) >=
static_cast<double>(std::numeric_limits<float>::lowest()) &&
15720 static_cast<double>(n) <=
static_cast<double>((std::numeric_limits<float>::max)()) &&
15721 static_cast<double>(
static_cast<float>(n)) ==
static_cast<double>(n)) {
15722 oa->write_character(format == detail::input_format_t::cbor
15723 ? get_cbor_float_prefix(
static_cast<float>(n))
15724 : get_msgpack_float_prefix(
static_cast<float>(n)));
15725 write_number(
static_cast<float>(n));
15727 oa->write_character(format == detail::input_format_t::cbor
15728 ? get_cbor_float_prefix(n)
15729 : get_msgpack_float_prefix(n));
15733#pragma GCC diagnostic pop
15742 template <
typename C = CharType,
15743 enable_if_t<std::is_signed<C>::value && std::is_signed<char>::value>* =
nullptr>
15744 static constexpr CharType to_char_type(std::uint8_t x)
noexcept {
15745 return *
reinterpret_cast<char*
>(&x);
15748 template <
typename C = CharType,
15749 enable_if_t<std::is_signed<C>::value && std::is_unsigned<char>::value>* =
nullptr>
15750 static CharType to_char_type(std::uint8_t x)
noexcept {
15751 static_assert(
sizeof(std::uint8_t) ==
sizeof(CharType),
15752 "size of CharType must be equal to std::uint8_t");
15753 static_assert(std::is_trivial<CharType>::value,
"CharType must be trivial");
15755 std::memcpy(&result, &x,
sizeof(x));
15759 template <typename C = CharType, enable_if_t<std::is_unsigned<C>::value>* =
nullptr>
15760 static constexpr CharType to_char_type(std::uint8_t x)
noexcept {
15765 typename InputCharType,
typename C = CharType,
15766 enable_if_t<std::is_signed<C>::value && std::is_signed<char>::value &&
15767 std::is_same<char, typename std::remove_cv<InputCharType>::type>::value>* =
15769 static constexpr CharType to_char_type(InputCharType x)
noexcept {
15775 const bool is_little_endian = little_endianness();
15778 output_adapter_t<CharType> oa =
nullptr;
15782NLOHMANN_JSON_NAMESPACE_END
15796#include <algorithm>
15806#include <type_traits>
15824#include <type_traits>
15828NLOHMANN_JSON_NAMESPACE_BEGIN
15853template <
typename Target,
typename Source> Target reinterpret_bits(
const Source source) {
15854 static_assert(
sizeof(Target) ==
sizeof(Source),
"size mismatch");
15857 std::memcpy(&target, &source,
sizeof(Source));
15863 static constexpr int kPrecision = 64;
15865 std::uint64_t f = 0;
15868 constexpr diyfp(std::uint64_t f_,
int e_) noexcept : f(f_), e(e_) {}
15874 static diyfp
sub(
const diyfp& x,
const diyfp& y)
noexcept {
15875 JSON_ASSERT(x.e == y.e);
15876 JSON_ASSERT(x.f >= y.f);
15878 return {x.f - y.f, x.e};
15885 static diyfp
mul(
const diyfp& x,
const diyfp& y)
noexcept {
15886 static_assert(kPrecision == 64,
"internal error");
15912 const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
15913 const std::uint64_t u_hi = x.f >> 32u;
15914 const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
15915 const std::uint64_t v_hi = y.f >> 32u;
15917 const std::uint64_t p0 = u_lo * v_lo;
15918 const std::uint64_t p1 = u_lo * v_hi;
15919 const std::uint64_t p2 = u_hi * v_lo;
15920 const std::uint64_t p3 = u_hi * v_hi;
15922 const std::uint64_t p0_hi = p0 >> 32u;
15923 const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
15924 const std::uint64_t p1_hi = p1 >> 32u;
15925 const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
15926 const std::uint64_t p2_hi = p2 >> 32u;
15928 std::uint64_t Q = p0_hi + p1_lo + p2_lo;
15939 Q += std::uint64_t{1} << (64u - 32u - 1u);
15941 const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
15943 return {h, x.e + y.e + 64};
15951 JSON_ASSERT(x.f != 0);
15953 while ((x.f >> 63u) == 0) {
15965 static diyfp
normalize_to(
const diyfp& x,
const int target_exponent)
noexcept {
15966 const int delta = x.e - target_exponent;
15968 JSON_ASSERT(delta >= 0);
15969 JSON_ASSERT(((x.f << delta) >> delta) == x.f);
15971 return {x.f << delta, target_exponent};
15988 JSON_ASSERT(std::isfinite(value));
15989 JSON_ASSERT(value > 0);
15998 static_assert(std::numeric_limits<FloatType>::is_iec559,
15999 "internal error: dtoa_short requires an IEEE-754 "
16000 "floating-point implementation");
16002 constexpr int kPrecision =
16003 std::numeric_limits<FloatType>::digits;
16004 constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
16005 constexpr int kMinExp = 1 - kBias;
16006 constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
16009 typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t>::type;
16011 const auto bits =
static_cast<std::uint64_t
>(reinterpret_bits<bits_type>(value));
16012 const std::uint64_t E = bits >> (kPrecision - 1);
16013 const std::uint64_t F = bits & (kHiddenBit - 1);
16015 const bool is_denormal = E == 0;
16017 is_denormal ?
diyfp(F, kMinExp) :
diyfp(F + kHiddenBit,
static_cast<int>(E) - kBias);
16040 const bool lower_boundary_is_closer = F == 0 && E > 1;
16041 const diyfp m_plus =
diyfp(2 * v.f + 1, v.e - 1);
16042 const diyfp m_minus = lower_boundary_is_closer ?
diyfp(4 * v.f - 1, v.e - 2)
16043 :
diyfp(2 * v.f - 1, v.e - 1);
16109constexpr int kAlpha = -60;
16110constexpr int kGamma = -32;
16177 constexpr int kCachedPowersMinDecExp = -300;
16178 constexpr int kCachedPowersDecStep = 8;
16180 static constexpr std::array<cached_power, 79> kCachedPowers = {{
16181 {0xAB70FE17C79AC6CA, -1060, -300}, {0xFF77B1FCBEBCDC4F, -1034, -292},
16182 {0xBE5691EF416BD60C, -1007, -284}, {0x8DD01FAD907FFC3C, -980, -276},
16183 {0xD3515C2831559A83, -954, -268}, {0x9D71AC8FADA6C9B5, -927, -260},
16184 {0xEA9C227723EE8BCB, -901, -252}, {0xAECC49914078536D, -874, -244},
16185 {0x823C12795DB6CE57, -847, -236}, {0xC21094364DFB5637, -821, -228},
16186 {0x9096EA6F3848984F, -794, -220}, {0xD77485CB25823AC7, -768, -212},
16187 {0xA086CFCD97BF97F4, -741, -204}, {0xEF340A98172AACE5, -715, -196},
16188 {0xB23867FB2A35B28E, -688, -188}, {0x84C8D4DFD2C63F3B, -661, -180},
16189 {0xC5DD44271AD3CDBA, -635, -172}, {0x936B9FCEBB25C996, -608, -164},
16190 {0xDBAC6C247D62A584, -582, -156}, {0xA3AB66580D5FDAF6, -555, -148},
16191 {0xF3E2F893DEC3F126, -529, -140}, {0xB5B5ADA8AAFF80B8, -502, -132},
16192 {0x87625F056C7C4A8B, -475, -124}, {0xC9BCFF6034C13053, -449, -116},
16193 {0x964E858C91BA2655, -422, -108}, {0xDFF9772470297EBD, -396, -100},
16194 {0xA6DFBD9FB8E5B88F, -369, -92}, {0xF8A95FCF88747D94, -343, -84},
16195 {0xB94470938FA89BCF, -316, -76}, {0x8A08F0F8BF0F156B, -289, -68},
16196 {0xCDB02555653131B6, -263, -60}, {0x993FE2C6D07B7FAC, -236, -52},
16197 {0xE45C10C42A2B3B06, -210, -44}, {0xAA242499697392D3, -183, -36},
16198 {0xFD87B5F28300CA0E, -157, -28}, {0xBCE5086492111AEB, -130, -20},
16199 {0x8CBCCC096F5088CC, -103, -12}, {0xD1B71758E219652C, -77, -4},
16200 {0x9C40000000000000, -50, 4}, {0xE8D4A51000000000, -24, 12},
16201 {0xAD78EBC5AC620000, 3, 20}, {0x813F3978F8940984, 30, 28},
16202 {0xC097CE7BC90715B3, 56, 36}, {0x8F7E32CE7BEA5C70, 83, 44},
16203 {0xD5D238A4ABE98068, 109, 52}, {0x9F4F2726179A2245, 136, 60},
16204 {0xED63A231D4C4FB27, 162, 68}, {0xB0DE65388CC8ADA8, 189, 76},
16205 {0x83C7088E1AAB65DB, 216, 84}, {0xC45D1DF942711D9A, 242, 92},
16206 {0x924D692CA61BE758, 269, 100}, {0xDA01EE641A708DEA, 295, 108},
16207 {0xA26DA3999AEF774A, 322, 116}, {0xF209787BB47D6B85, 348, 124},
16208 {0xB454E4A179DD1877, 375, 132}, {0x865B86925B9BC5C2, 402, 140},
16209 {0xC83553C5C8965D3D, 428, 148}, {0x952AB45CFA97A0B3, 455, 156},
16210 {0xDE469FBD99A05FE3, 481, 164}, {0xA59BC234DB398C25, 508, 172},
16211 {0xF6C69A72A3989F5C, 534, 180}, {0xB7DCBF5354E9BECE, 561, 188},
16212 {0x88FCF317F22241E2, 588, 196}, {0xCC20CE9BD35C78A5, 614, 204},
16213 {0x98165AF37B2153DF, 641, 212}, {0xE2A0B5DC971F303A, 667, 220},
16214 {0xA8D9D1535CE3B396, 694, 228}, {0xFB9B7CD9A4A7443C, 720, 236},
16215 {0xBB764C4CA7A44410, 747, 244}, {0x8BAB8EEFB6409C1A, 774, 252},
16216 {0xD01FEF10A657842C, 800, 260}, {0x9B10A4E5E9913129, 827, 268},
16217 {0xE7109BFBA19C0C9D, 853, 276}, {0xAC2820D9623BF429, 880, 284},
16218 {0x80444B5E7AA7CF85, 907, 292}, {0xBF21E44003ACDD2D, 933, 300},
16219 {0x8E679C2F5E44FF8F, 960, 308}, {0xD433179D9C8CB841, 986, 316},
16220 {0x9E19DB92B4E31BA9, 1013, 324},
16227 JSON_ASSERT(e >= -1500);
16228 JSON_ASSERT(e <= 1500);
16229 const int f = kAlpha - e - 1;
16230 const int k = (f * 78913) / (1 << 18) +
static_cast<int>(f > 0);
16233 (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
16234 JSON_ASSERT(index >= 0);
16235 JSON_ASSERT(
static_cast<std::size_t
>(index) < kCachedPowers.size());
16237 const cached_power cached = kCachedPowers[
static_cast<std::size_t
>(index)];
16238 JSON_ASSERT(kAlpha <= cached.e + e + 64);
16239 JSON_ASSERT(kGamma >= cached.e + e + 64);
16250 if (n >= 1000000000) {
16251 pow10 = 1000000000;
16255 if (n >= 100000000) {
16259 if (n >= 10000000) {
16263 if (n >= 1000000) {
16292inline void grisu2_round(
char* buf,
int len, std::uint64_t dist, std::uint64_t delta,
16293 std::uint64_t rest, std::uint64_t ten_k) {
16294 JSON_ASSERT(len >= 1);
16295 JSON_ASSERT(dist <= delta);
16296 JSON_ASSERT(rest <= delta);
16297 JSON_ASSERT(ten_k > 0);
16318 while (rest < dist && delta - rest >= ten_k &&
16319 (rest + ten_k < dist || dist - rest > rest + ten_k - dist)) {
16320 JSON_ASSERT(buf[len - 1] !=
'0');
16332 static_assert(kAlpha >= -60,
"internal error");
16333 static_assert(kGamma <= -32,
"internal error");
16348 JSON_ASSERT(M_plus.e >= kAlpha);
16349 JSON_ASSERT(M_plus.e <= kGamma);
16351 std::uint64_t delta =
16353 std::uint64_t dist =
16363 const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
16365 auto p1 =
static_cast<std::uint32_t
>(
16366 M_plus.f >> -one.e);
16367 std::uint64_t p2 = M_plus.f & (one.f - 1);
16373 JSON_ASSERT(p1 > 0);
16375 std::uint32_t pow10{};
16402 const std::uint32_t d = p1 / pow10;
16403 const std::uint32_t r = p1 % pow10;
16408 JSON_ASSERT(d <= 9);
16409 buffer[length++] =
static_cast<char>(
'0' + d);
16428 const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
16429 if (rest <= delta) {
16432 decimal_exponent += n;
16443 const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
16444 grisu2_round(buffer, length, dist, delta, rest, ten_n);
16494 JSON_ASSERT(p2 > delta);
16506 JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
16508 const std::uint64_t d = p2 >> -one.e;
16509 const std::uint64_t r = p2 & (one.f - 1);
16515 JSON_ASSERT(d <= 9);
16516 buffer[length++] =
static_cast<char>(
'0' + d);
16540 decimal_exponent -= m;
16548 const std::uint64_t ten_m = one.f;
16549 grisu2_round(buffer, length, dist, delta, p2, ten_m);
16571JSON_HEDLEY_NON_NULL(1)
16574 JSON_ASSERT(m_plus.e == m_minus.e);
16575 JSON_ASSERT(m_plus.e == v.e);
16588 const diyfp c_minus_k(cached.f, cached.e);
16617 const diyfp M_minus(w_minus.f + 1, w_minus.e);
16618 const diyfp M_plus(w_plus.f - 1, w_plus.e);
16620 decimal_exponent = -cached.k;
16630template <
typename FloatType>
16631JSON_HEDLEY_NON_NULL(1)
16632void
grisu2(
char* buf,
int& len,
int& decimal_exponent, FloatType value) {
16633 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
16634 "internal error: not enough precision");
16636 JSON_ASSERT(std::isfinite(value));
16637 JSON_ASSERT(value > 0);
16664 grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
16672JSON_HEDLEY_NON_NULL(1)
16673JSON_HEDLEY_RETURNS_NON_NULL
16675 JSON_ASSERT(e > -1000);
16676 JSON_ASSERT(e < 1000);
16685 auto k =
static_cast<std::uint32_t
>(e);
16690 *buf++ =
static_cast<char>(
'0' + k);
16691 }
else if (k < 100) {
16692 *buf++ =
static_cast<char>(
'0' + k / 10);
16694 *buf++ =
static_cast<char>(
'0' + k);
16696 *buf++ =
static_cast<char>(
'0' + k / 100);
16698 *buf++ =
static_cast<char>(
'0' + k / 10);
16700 *buf++ =
static_cast<char>(
'0' + k);
16715JSON_HEDLEY_NON_NULL(1)
16716JSON_HEDLEY_RETURNS_NON_NULL
16717inline
char*
format_buffer(
char* buf,
int len,
int decimal_exponent,
int min_exp,
int max_exp) {
16718 JSON_ASSERT(min_exp < 0);
16719 JSON_ASSERT(max_exp > 0);
16722 const int n = len + decimal_exponent;
16728 if (k <= n && n <= max_exp) {
16732 std::memset(buf + k,
'0',
static_cast<size_t>(n) -
static_cast<size_t>(k));
16736 return buf + (
static_cast<size_t>(n) + 2);
16739 if (0 < n && n <= max_exp) {
16743 JSON_ASSERT(k > n);
16745 std::memmove(buf + (
static_cast<size_t>(n) + 1), buf + n,
16746 static_cast<size_t>(k) -
static_cast<size_t>(n));
16748 return buf + (
static_cast<size_t>(k) + 1U);
16751 if (min_exp < n && n <= 0) {
16755 std::memmove(buf + (2 +
static_cast<size_t>(-n)), buf,
static_cast<size_t>(k));
16758 std::memset(buf + 2,
'0',
static_cast<size_t>(-n));
16759 return buf + (2U +
static_cast<size_t>(-n) +
static_cast<size_t>(k));
16771 std::memmove(buf + 2, buf + 1,
static_cast<size_t>(k) - 1);
16773 buf += 1 +
static_cast<size_t>(k);
16793template <
typename FloatType>
16794JSON_HEDLEY_NON_NULL(1, 2)
16795JSON_HEDLEY_RETURNS_NON_NULL
char*
to_chars(
char* first, const
char* last, FloatType value) {
16796 static_cast<void>(last);
16797 JSON_ASSERT(std::isfinite(value));
16800 if (std::signbit(value)) {
16806#pragma GCC diagnostic push
16807#pragma GCC diagnostic ignored "-Wfloat-equal"
16818#pragma GCC diagnostic pop
16821 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
16828 int decimal_exponent = 0;
16831 JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
16834 constexpr int kMinExp = -4;
16836 constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10;
16838 JSON_ASSERT(last - first >= kMaxExp + 2);
16839 JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
16840 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
16846NLOHMANN_JSON_NAMESPACE_END
16862NLOHMANN_JSON_NAMESPACE_BEGIN
16877 using string_t =
typename BasicJsonType::string_t;
16878 using number_float_t =
typename BasicJsonType::number_float_t;
16879 using number_integer_t =
typename BasicJsonType::number_integer_t;
16880 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
16881 using binary_char_t =
typename BasicJsonType::binary_t::value_type;
16882 static constexpr std::uint8_t UTF8_ACCEPT = 0;
16883 static constexpr std::uint8_t UTF8_REJECT = 1;
16893 : o(std::move(s)),
loc(std::localeconv()),
16931 void dump(
const BasicJsonType& val,
const bool pretty_print,
const bool ensure_ascii,
16932 const unsigned int indent_step,
const unsigned int current_indent = 0) {
16933 switch (val.m_data.m_type) {
16935 if (val.m_data.m_value.object->empty()) {
16936 o->write_characters(
"{}", 2);
16940 if (pretty_print) {
16941 o->write_characters(
"{\n", 2);
16944 const auto new_indent = current_indent + indent_step;
16945 if (JSON_HEDLEY_UNLIKELY(
indent_string.size() < new_indent)) {
16950 auto i = val.m_data.m_value.object->cbegin();
16951 for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1;
16954 o->write_character(
'\"');
16955 dump_escaped(i->first, ensure_ascii);
16956 o->write_characters(
"\": ", 3);
16957 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
16958 o->write_characters(
",\n", 2);
16962 JSON_ASSERT(i != val.m_data.m_value.object->cend());
16963 JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
16965 o->write_character(
'\"');
16966 dump_escaped(i->first, ensure_ascii);
16967 o->write_characters(
"\": ", 3);
16968 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
16970 o->write_character(
'\n');
16971 o->write_characters(
indent_string.c_str(), current_indent);
16972 o->write_character(
'}');
16974 o->write_character(
'{');
16977 auto i = val.m_data.m_value.object->cbegin();
16978 for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1;
16980 o->write_character(
'\"');
16981 dump_escaped(i->first, ensure_ascii);
16982 o->write_characters(
"\":", 2);
16983 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
16984 o->write_character(
',');
16988 JSON_ASSERT(i != val.m_data.m_value.object->cend());
16989 JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
16990 o->write_character(
'\"');
16991 dump_escaped(i->first, ensure_ascii);
16992 o->write_characters(
"\":", 2);
16993 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
16995 o->write_character(
'}');
17002 if (val.m_data.m_value.array->empty()) {
17003 o->write_characters(
"[]", 2);
17007 if (pretty_print) {
17008 o->write_characters(
"[\n", 2);
17011 const auto new_indent = current_indent + indent_step;
17012 if (JSON_HEDLEY_UNLIKELY(
indent_string.size() < new_indent)) {
17017 for (
auto i = val.m_data.m_value.array->cbegin();
17018 i != val.m_data.m_value.array->cend() - 1; ++i) {
17020 dump(*i,
true, ensure_ascii, indent_step, new_indent);
17021 o->write_characters(
",\n", 2);
17025 JSON_ASSERT(!val.m_data.m_value.array->empty());
17027 dump(val.m_data.m_value.array->back(),
true, ensure_ascii, indent_step,
17030 o->write_character(
'\n');
17031 o->write_characters(
indent_string.c_str(), current_indent);
17032 o->write_character(
']');
17034 o->write_character(
'[');
17037 for (
auto i = val.m_data.m_value.array->cbegin();
17038 i != val.m_data.m_value.array->cend() - 1; ++i) {
17039 dump(*i,
false, ensure_ascii, indent_step, current_indent);
17040 o->write_character(
',');
17044 JSON_ASSERT(!val.m_data.m_value.array->empty());
17045 dump(val.m_data.m_value.array->back(),
false, ensure_ascii, indent_step,
17048 o->write_character(
']');
17055 o->write_character(
'\"');
17056 dump_escaped(*val.m_data.m_value.string, ensure_ascii);
17057 o->write_character(
'\"');
17062 if (pretty_print) {
17063 o->write_characters(
"{\n", 2);
17066 const auto new_indent = current_indent + indent_step;
17067 if (JSON_HEDLEY_UNLIKELY(
indent_string.size() < new_indent)) {
17073 o->write_characters(
"\"bytes\": [", 10);
17075 if (!val.m_data.m_value.binary->empty()) {
17076 for (
auto i = val.m_data.m_value.binary->cbegin();
17077 i != val.m_data.m_value.binary->cend() - 1; ++i) {
17079 o->write_characters(
", ", 2);
17081 dump_integer(val.m_data.m_value.binary->back());
17084 o->write_characters(
"],\n", 3);
17087 o->write_characters(
"\"subtype\": ", 11);
17088 if (val.m_data.m_value.binary->has_subtype()) {
17089 dump_integer(val.m_data.m_value.binary->subtype());
17091 o->write_characters(
"null", 4);
17093 o->write_character(
'\n');
17094 o->write_characters(
indent_string.c_str(), current_indent);
17095 o->write_character(
'}');
17097 o->write_characters(
"{\"bytes\":[", 10);
17099 if (!val.m_data.m_value.binary->empty()) {
17100 for (
auto i = val.m_data.m_value.binary->cbegin();
17101 i != val.m_data.m_value.binary->cend() - 1; ++i) {
17103 o->write_character(
',');
17105 dump_integer(val.m_data.m_value.binary->back());
17108 o->write_characters(
"],\"subtype\":", 12);
17109 if (val.m_data.m_value.binary->has_subtype()) {
17110 dump_integer(val.m_data.m_value.binary->subtype());
17111 o->write_character(
'}');
17113 o->write_characters(
"null}", 5);
17120 if (val.m_data.m_value.boolean) {
17121 o->write_characters(
"true", 4);
17123 o->write_characters(
"false", 5);
17129 dump_integer(val.m_data.m_value.number_integer);
17134 dump_integer(val.m_data.m_value.number_unsigned);
17139 dump_float(val.m_data.m_value.number_float);
17144 o->write_characters(
"<discarded>", 11);
17149 o->write_characters(
"null", 4);
17154 JSON_ASSERT(
false);
17159 JSON_PRIVATE_UNLESS_TESTED :
17175 dump_escaped(
const string_t& s,
const bool ensure_ascii) {
17176 std::uint32_t codepoint{};
17177 std::uint8_t state = UTF8_ACCEPT;
17178 std::size_t bytes = 0;
17181 std::size_t bytes_after_last_accept = 0;
17182 std::size_t undumped_chars = 0;
17184 for (std::size_t i = 0; i < s.size(); ++i) {
17185 const auto byte =
static_cast<std::uint8_t
>(s[i]);
17187 switch (decode(state, codepoint,
byte)) {
17190 switch (codepoint) {
17193 string_buffer[bytes++] =
'\\';
17194 string_buffer[bytes++] =
'b';
17200 string_buffer[bytes++] =
'\\';
17201 string_buffer[bytes++] =
't';
17207 string_buffer[bytes++] =
'\\';
17208 string_buffer[bytes++] =
'n';
17214 string_buffer[bytes++] =
'\\';
17215 string_buffer[bytes++] =
'f';
17221 string_buffer[bytes++] =
'\\';
17222 string_buffer[bytes++] =
'r';
17228 string_buffer[bytes++] =
'\\';
17229 string_buffer[bytes++] =
'\"';
17235 string_buffer[bytes++] =
'\\';
17236 string_buffer[bytes++] =
'\\';
17243 if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F))) {
17244 if (codepoint <= 0xFFFF) {
17247 (std::snprintf)(string_buffer.data() + bytes, 7,
"\\u%04x",
17248 static_cast<std::uint16_t
>(codepoint)));
17252 static_cast<void>((std::snprintf)(
17253 string_buffer.data() + bytes, 13,
"\\u%04x\\u%04x",
17254 static_cast<std::uint16_t
>(0xD7C0u + (codepoint >> 10u)),
17255 static_cast<std::uint16_t
>(0xDC00u +
17256 (codepoint & 0x3FFu))));
17262 string_buffer[bytes++] = s[i];
17271 if (string_buffer.size() - bytes < 13) {
17272 o->write_characters(string_buffer.data(), bytes);
17277 bytes_after_last_accept = bytes;
17278 undumped_chars = 0;
17284 switch (error_handler) {
17285 case error_handler_t::strict: {
17286 JSON_THROW(type_error::create(316,
17287 concat(
"invalid UTF-8 byte at index ",
17288 std::to_string(i),
": 0x",
17289 hex_bytes(
byte | 0)),
17293 case error_handler_t::ignore:
17294 case error_handler_t::replace: {
17299 if (undumped_chars > 0) {
17305 bytes = bytes_after_last_accept;
17307 if (error_handler == error_handler_t::replace) {
17309 if (ensure_ascii) {
17310 string_buffer[bytes++] =
'\\';
17311 string_buffer[bytes++] =
'u';
17312 string_buffer[bytes++] =
'f';
17313 string_buffer[bytes++] =
'f';
17314 string_buffer[bytes++] =
'f';
17315 string_buffer[bytes++] =
'd';
17317 string_buffer[bytes++] =
17318 detail::binary_writer<BasicJsonType, char>::to_char_type(
17320 string_buffer[bytes++] =
17321 detail::binary_writer<BasicJsonType, char>::to_char_type(
17323 string_buffer[bytes++] =
17324 detail::binary_writer<BasicJsonType, char>::to_char_type(
17331 if (string_buffer.size() - bytes < 13) {
17332 o->write_characters(string_buffer.data(), bytes);
17336 bytes_after_last_accept = bytes;
17339 undumped_chars = 0;
17342 state = UTF8_ACCEPT;
17356 if (!ensure_ascii) {
17358 string_buffer[bytes++] = s[i];
17367 if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT)) {
17370 o->write_characters(string_buffer.data(), bytes);
17374 switch (error_handler) {
17375 case error_handler_t::strict: {
17376 JSON_THROW(type_error::create(
17378 concat(
"incomplete UTF-8 string; last byte: 0x",
17379 hex_bytes(
static_cast<std::uint8_t
>(s.back() | 0))),
17383 case error_handler_t::ignore: {
17385 o->write_characters(string_buffer.data(), bytes_after_last_accept);
17389 case error_handler_t::replace: {
17391 o->write_characters(string_buffer.data(), bytes_after_last_accept);
17393 if (ensure_ascii) {
17394 o->write_characters(
"\\ufffd", 6);
17396 o->write_characters(
"\xEF\xBF\xBD", 3);
17418 inline unsigned int count_digits(number_unsigned_t x)
noexcept {
17419 unsigned int n_digits = 1;
17425 return n_digits + 1;
17428 return n_digits + 2;
17431 return n_digits + 3;
17443 static std::string hex_bytes(std::uint8_t
byte) {
17444 std::string result =
"FF";
17445 constexpr const char* nibble_to_hex =
"0123456789ABCDEF";
17446 result[0] = nibble_to_hex[
byte / 16];
17447 result[1] = nibble_to_hex[
byte % 16];
17452 template <typename NumberType, enable_if_t<std::is_signed<NumberType>::value,
int> = 0>
17453 bool is_negative_number(NumberType x) {
17457 template <typename NumberType, enable_if_t<std::is_unsigned<NumberType>::value,
int> = 0>
17458 bool is_negative_number(NumberType ) {
17471 template <
typename NumberType,
17472 detail::enable_if_t<std::is_integral<NumberType>::value ||
17473 std::is_same<NumberType, number_unsigned_t>::value ||
17474 std::is_same<NumberType, number_integer_t>::value ||
17475 std::is_same<NumberType, binary_char_t>::value,
17477 void dump_integer(NumberType x) {
17478 static constexpr std::array<std::array<char, 2>, 100> digits_to_99{{
17479 {{
'0',
'0'}}, {{
'0',
'1'}}, {{
'0',
'2'}}, {{
'0',
'3'}}, {{
'0',
'4'}}, {{
'0',
'5'}},
17480 {{
'0',
'6'}}, {{
'0',
'7'}}, {{
'0',
'8'}}, {{
'0',
'9'}}, {{
'1',
'0'}}, {{
'1',
'1'}},
17481 {{
'1',
'2'}}, {{
'1',
'3'}}, {{
'1',
'4'}}, {{
'1',
'5'}}, {{
'1',
'6'}}, {{
'1',
'7'}},
17482 {{
'1',
'8'}}, {{
'1',
'9'}}, {{
'2',
'0'}}, {{
'2',
'1'}}, {{
'2',
'2'}}, {{
'2',
'3'}},
17483 {{
'2',
'4'}}, {{
'2',
'5'}}, {{
'2',
'6'}}, {{
'2',
'7'}}, {{
'2',
'8'}}, {{
'2',
'9'}},
17484 {{
'3',
'0'}}, {{
'3',
'1'}}, {{
'3',
'2'}}, {{
'3',
'3'}}, {{
'3',
'4'}}, {{
'3',
'5'}},
17485 {{
'3',
'6'}}, {{
'3',
'7'}}, {{
'3',
'8'}}, {{
'3',
'9'}}, {{
'4',
'0'}}, {{
'4',
'1'}},
17486 {{
'4',
'2'}}, {{
'4',
'3'}}, {{
'4',
'4'}}, {{
'4',
'5'}}, {{
'4',
'6'}}, {{
'4',
'7'}},
17487 {{
'4',
'8'}}, {{
'4',
'9'}}, {{
'5',
'0'}}, {{
'5',
'1'}}, {{
'5',
'2'}}, {{
'5',
'3'}},
17488 {{
'5',
'4'}}, {{
'5',
'5'}}, {{
'5',
'6'}}, {{
'5',
'7'}}, {{
'5',
'8'}}, {{
'5',
'9'}},
17489 {{
'6',
'0'}}, {{
'6',
'1'}}, {{
'6',
'2'}}, {{
'6',
'3'}}, {{
'6',
'4'}}, {{
'6',
'5'}},
17490 {{
'6',
'6'}}, {{
'6',
'7'}}, {{
'6',
'8'}}, {{
'6',
'9'}}, {{
'7',
'0'}}, {{
'7',
'1'}},
17491 {{
'7',
'2'}}, {{
'7',
'3'}}, {{
'7',
'4'}}, {{
'7',
'5'}}, {{
'7',
'6'}}, {{
'7',
'7'}},
17492 {{
'7',
'8'}}, {{
'7',
'9'}}, {{
'8',
'0'}}, {{
'8',
'1'}}, {{
'8',
'2'}}, {{
'8',
'3'}},
17493 {{
'8',
'4'}}, {{
'8',
'5'}}, {{
'8',
'6'}}, {{
'8',
'7'}}, {{
'8',
'8'}}, {{
'8',
'9'}},
17494 {{
'9',
'0'}}, {{
'9',
'1'}}, {{
'9',
'2'}}, {{
'9',
'3'}}, {{
'9',
'4'}}, {{
'9',
'5'}},
17495 {{
'9',
'6'}}, {{
'9',
'7'}}, {{
'9',
'8'}}, {{
'9',
'9'}},
17500 o->write_character(
'0');
17509 number_unsigned_t abs_value;
17511 unsigned int n_chars{};
17513 if (is_negative_number(x)) {
17515 abs_value = remove_sign(
static_cast<number_integer_t
>(x));
17518 n_chars = 1 + count_digits(abs_value);
17520 abs_value =
static_cast<number_unsigned_t
>(x);
17521 n_chars = count_digits(abs_value);
17525 JSON_ASSERT(n_chars < number_buffer.size() - 1);
17529 buffer_ptr += n_chars;
17533 while (abs_value >= 100) {
17534 const auto digits_index =
static_cast<unsigned>((abs_value % 100));
17536 *(--buffer_ptr) = digits_to_99[digits_index][1];
17537 *(--buffer_ptr) = digits_to_99[digits_index][0];
17540 if (abs_value >= 10) {
17541 const auto digits_index =
static_cast<unsigned>(abs_value);
17542 *(--buffer_ptr) = digits_to_99[digits_index][1];
17543 *(--buffer_ptr) = digits_to_99[digits_index][0];
17545 *(--buffer_ptr) =
static_cast<char>(
'0' + abs_value);
17548 o->write_characters(number_buffer.data(), n_chars);
17559 void dump_float(number_float_t x) {
17561 if (!std::isfinite(x)) {
17562 o->write_characters(
"null", 4);
17571 static constexpr bool is_ieee_single_or_double =
17572 (std::numeric_limits<number_float_t>::is_iec559 &&
17573 std::numeric_limits<number_float_t>::digits == 24 &&
17574 std::numeric_limits<number_float_t>::max_exponent == 128) ||
17575 (std::numeric_limits<number_float_t>::is_iec559 &&
17576 std::numeric_limits<number_float_t>::digits == 53 &&
17577 std::numeric_limits<number_float_t>::max_exponent == 1024);
17579 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
17582 void dump_float(number_float_t x, std::true_type ) {
17583 auto* begin = number_buffer.data();
17584 auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
17586 o->write_characters(begin,
static_cast<size_t>(end - begin));
17589 void dump_float(number_float_t x, std::false_type ) {
17591 static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
17595 std::ptrdiff_t len =
17596 (std::snprintf)(number_buffer.data(), number_buffer.size(),
"%.*g", d, x);
17599 JSON_ASSERT(len > 0);
17601 JSON_ASSERT(
static_cast<std::size_t
>(len) < number_buffer.size());
17604 if (thousands_sep !=
'\0') {
17609 std::remove(number_buffer.begin(), number_buffer.begin() + len, thousands_sep);
17610 std::fill(end, number_buffer.end(),
'\0');
17611 JSON_ASSERT((end - number_buffer.begin()) <= len);
17612 len = (end - number_buffer.begin());
17616 if (decimal_point !=
'\0' && decimal_point !=
'.') {
17620 const auto dec_pos =
17621 std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
17622 if (dec_pos != number_buffer.end()) {
17627 o->write_characters(number_buffer.data(),
static_cast<std::size_t
>(len));
17630 const bool value_is_int_like =
17631 std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
17632 [](
char c) { return c ==
'.' || c ==
'e'; });
17634 if (value_is_int_like) {
17635 o->write_characters(
".0", 2);
17660 static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep,
17661 const std::uint8_t
byte)
noexcept {
17662 static const std::array<std::uint8_t, 400> utf8d =
17665 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17666 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17667 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17668 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17669 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17670 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17671 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17672 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17673 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17674 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17675 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17676 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17677 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
17678 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9,
17679 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
17680 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
17681 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
17682 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
17683 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2,
17684 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
17685 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
17686 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3,
17687 0x3, 0x3, 0x4, 0x3, 0x3,
17688 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
17689 0x8, 0x8, 0x8, 0x8, 0x8,
17690 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4,
17691 0x6, 0x1, 0x1, 0x1, 0x1,
17692 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
17693 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
17694 1, 0, 1, 0, 1, 1, 1, 1, 1, 1,
17695 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1,
17696 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
17697 1, 2, 1, 1, 1, 1, 1, 1, 1, 1,
17698 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1,
17699 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
17700 1, 3, 1, 3, 1, 1, 1, 1, 1, 1,
17701 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1,
17702 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1,
17703 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
17706 JSON_ASSERT(
byte < utf8d.size());
17707 const std::uint8_t type = utf8d[byte];
17709 codep = (state != UTF8_ACCEPT) ? (
byte & 0x3fu) | (codep << 6u) : (0xFFu >> type) & (byte);
17711 const std::size_t index =
17712 256u +
static_cast<size_t>(state) * 16u +
static_cast<size_t>(type);
17713 JSON_ASSERT(index < utf8d.size());
17714 state = utf8d[index];
17723 number_unsigned_t remove_sign(number_unsigned_t x) {
17724 JSON_ASSERT(
false);
17738 inline number_unsigned_t remove_sign(number_integer_t x)
noexcept {
17739 JSON_ASSERT(x < 0 &&
17740 x < (std::numeric_limits<
17741 number_integer_t>::max)());
17742 return static_cast<number_unsigned_t
>(-(x + 1)) + 1;
17747 output_adapter_t<char> o =
nullptr;
17772NLOHMANN_JSON_NAMESPACE_END
17787#include <functional>
17788#include <initializer_list>
17791#include <stdexcept>
17792#include <type_traits>
17800NLOHMANN_JSON_NAMESPACE_BEGIN
17804template <
class Key,
class T,
class IgnoredLess = std::less<Key>,
17805 class Allocator = std::allocator<std::pair<const Key, T>>>
17806struct ordered_map : std::vector<std::pair<const Key, T>, Allocator> {
17807 using key_type = Key;
17808 using mapped_type = T;
17809 using Container = std::vector<std::pair<const Key, T>, Allocator>;
17810 using iterator =
typename Container::iterator;
17811 using const_iterator =
typename Container::const_iterator;
17812 using size_type =
typename Container::size_type;
17813 using value_type =
typename Container::value_type;
17814#ifdef JSON_HAS_CPP_14
17815 using key_compare = std::equal_to<>;
17817 using key_compare = std::equal_to<Key>;
17822 ordered_map()
noexcept(
noexcept(Container())) : Container{} {}
17823 explicit ordered_map(
const Allocator& alloc)
noexcept(
noexcept(Container(alloc)))
17824 : Container{alloc} {}
17825 template <
class It>
17826 ordered_map(It first, It last,
const Allocator& alloc = Allocator())
17827 : Container{first, last, alloc} {}
17828 ordered_map(std::initializer_list<value_type> init,
const Allocator& alloc = Allocator())
17829 : Container{init, alloc} {}
17831 std::pair<iterator, bool> emplace(
const key_type& key, T&& t) {
17832 for (
auto it = this->begin(); it != this->end(); ++it) {
17833 if (m_compare(it->first, key)) {
17834 return {it,
false};
17837 Container::emplace_back(key, std::forward<T>(t));
17838 return {std::prev(this->end()),
true};
17841 template <
class KeyType,
17842 detail::enable_if_t<
17843 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
17844 std::pair<iterator, bool> emplace(KeyType&& key, T&& t) {
17845 for (
auto it = this->begin(); it != this->end(); ++it) {
17846 if (m_compare(it->first, key)) {
17847 return {it,
false};
17850 Container::emplace_back(std::forward<KeyType>(key), std::forward<T>(t));
17851 return {std::prev(this->end()),
true};
17854 T& operator[](
const key_type& key) {
return emplace(key, T{}).first->second; }
17856 template <
class KeyType,
17857 detail::enable_if_t<
17858 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
17859 T& operator[](KeyType&& key) {
17860 return emplace(std::forward<KeyType>(key), T{}).first->second;
17863 const T& operator[](
const key_type& key)
const {
return at(key); }
17865 template <
class KeyType,
17866 detail::enable_if_t<
17867 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
17868 const T& operator[](KeyType&& key)
const {
17869 return at(std::forward<KeyType>(key));
17872 T& at(
const key_type& key) {
17873 for (
auto it = this->begin(); it != this->end(); ++it) {
17874 if (m_compare(it->first, key)) {
17879 JSON_THROW(std::out_of_range(
"key not found"));
17884 detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
17886 T& at(KeyType&& key)
17888 for (
auto it = this->begin(); it != this->end(); ++it) {
17889 if (m_compare(it->first, key)) {
17894 JSON_THROW(std::out_of_range(
"key not found"));
17897 const T& at(
const key_type& key)
const {
17898 for (
auto it = this->begin(); it != this->end(); ++it) {
17899 if (m_compare(it->first, key)) {
17904 JSON_THROW(std::out_of_range(
"key not found"));
17909 detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
17911 const T& at(KeyType&& key)
const
17913 for (
auto it = this->begin(); it != this->end(); ++it) {
17914 if (m_compare(it->first, key)) {
17919 JSON_THROW(std::out_of_range(
"key not found"));
17922 size_type erase(
const key_type& key) {
17923 for (
auto it = this->begin(); it != this->end(); ++it) {
17924 if (m_compare(it->first, key)) {
17926 for (
auto next = it; ++next != this->end(); ++it) {
17928 new (&*it) value_type{std::move(*next)};
17930 Container::pop_back();
17939 detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
17941 size_type erase(KeyType&& key)
17943 for (
auto it = this->begin(); it != this->end(); ++it) {
17944 if (m_compare(it->first, key)) {
17946 for (
auto next = it; ++next != this->end(); ++it) {
17948 new (&*it) value_type{std::move(*next)};
17950 Container::pop_back();
17957 iterator erase(iterator pos) {
return erase(pos, std::next(pos)); }
17959 iterator erase(iterator first, iterator last) {
17960 if (first == last) {
17964 const auto elements_affected = std::distance(first, last);
17965 const auto offset = std::distance(Container::begin(), first);
17987 for (
auto it = first; std::next(it, elements_affected) != Container::end(); ++it) {
17989 new (&*it) value_type{
17990 std::move(*std::next(it, elements_affected))};
17998 Container::resize(this->size() -
static_cast<size_type
>(elements_affected));
18007 return Container::begin() + offset;
18010 size_type count(
const key_type& key)
const {
18011 for (
auto it = this->begin(); it != this->end(); ++it) {
18012 if (m_compare(it->first, key)) {
18021 detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
18023 size_type count(KeyType&& key)
const
18025 for (
auto it = this->begin(); it != this->end(); ++it) {
18026 if (m_compare(it->first, key)) {
18033 iterator find(
const key_type& key) {
18034 for (
auto it = this->begin(); it != this->end(); ++it) {
18035 if (m_compare(it->first, key)) {
18039 return Container::end();
18044 detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
18046 iterator find(KeyType&& key)
18048 for (
auto it = this->begin(); it != this->end(); ++it) {
18049 if (m_compare(it->first, key)) {
18053 return Container::end();
18056 const_iterator find(
const key_type& key)
const {
18057 for (
auto it = this->begin(); it != this->end(); ++it) {
18058 if (m_compare(it->first, key)) {
18062 return Container::end();
18065 std::pair<iterator, bool> insert(value_type&& value) {
18066 return emplace(value.first, std::move(value.second));
18069 std::pair<iterator, bool> insert(
const value_type& value) {
18070 for (
auto it = this->begin(); it != this->end(); ++it) {
18071 if (m_compare(it->first, value.first)) {
18072 return {it,
false};
18075 Container::push_back(value);
18076 return {--this->end(),
true};
18079 template <
typename InputIt>
18080 using require_input_iter =
typename std::enable_if<
18081 std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
18082 std::input_iterator_tag>::value>::type;
18084 template <
typename InputIt,
typename = require_input_iter<InputIt>>
18085 void insert(InputIt first, InputIt last) {
18086 for (
auto it = first; it != last; ++it) {
18092 JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare();
18095NLOHMANN_JSON_NAMESPACE_END
18097#if defined(JSON_HAS_CPP_17)
18098#if JSON_HAS_STATIC_RTTI
18101#include <string_view>
18109NLOHMANN_JSON_NAMESPACE_BEGIN
18129NLOHMANN_BASIC_JSON_TPL_DECLARATION
18132 : public ::nlohmann::detail::json_base_class<CustomBaseClass> {
18136 template <
typename>
friend class ::nlohmann::json_pointer;
18140 template <
typename BasicJsonType,
typename InputType>
friend class ::nlohmann::detail::parser;
18141 friend ::nlohmann::detail::serializer<basic_json>;
18142 template <
typename BasicJsonType>
friend class ::nlohmann::detail::iter_impl;
18143 template <
typename BasicJsonType,
typename CharType>
18144 friend class ::nlohmann::detail::binary_writer;
18145 template <
typename BasicJsonType,
typename InputType,
typename SAX>
18146 friend class ::nlohmann::detail::binary_reader;
18147 template <
typename BasicJsonType>
friend class ::nlohmann::detail::json_sax_dom_parser;
18148 template <
typename BasicJsonType>
friend class ::nlohmann::detail::json_sax_dom_callback_parser;
18149 friend class ::nlohmann::detail::exception;
18152 using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
18153 using json_base_class_t = ::nlohmann::detail::json_base_class<CustomBaseClass>;
18155 JSON_PRIVATE_UNLESS_TESTED :
18157 using lexer = ::nlohmann::detail::lexer_base<basic_json>;
18159 template <
typename InputAdapterType>
18160 static ::nlohmann::detail::parser<basic_json, InputAdapterType>
18161 parser(InputAdapterType adapter, detail::parser_callback_t<basic_json> cb =
nullptr,
18162 const bool allow_exceptions =
true,
const bool ignore_comments =
false) {
18163 return ::nlohmann::detail::parser<basic_json, InputAdapterType>(
18164 std::move(adapter), std::move(cb), allow_exceptions, ignore_comments);
18168 using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
18169 template <
typename BasicJsonType>
18170 using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
18171 template <
typename BasicJsonType>
18172 using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>;
18173 template <
typename Iterator>
18174 using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>;
18175 template <
typename Base>
18176 using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>;
18178 template <
typename CharType>
18179 using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>;
18181 template <
typename InputType>
18182 using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
18183 template <
typename CharType>
18184 using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
18186 JSON_PRIVATE_UNLESS_TESTED :
using serializer = ::nlohmann::detail::serializer<basic_json>;
18192 template <
typename T,
typename SFINAE>
using json_serializer = JSONSerializer<T, SFINAE>;
18247 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
18249 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
18268 JSON_HEDLEY_WARN_UNUSED_RESULT
18272 result[
"copyright"] =
"(C) 2013-2023 Niels Lohmann";
18273 result[
"name"] =
"JSON for Modern C++";
18274 result[
"url"] =
"https://github.com/nlohmann/json";
18275 result[
"version"][
"string"] =
18276 detail::concat(std::to_string(NLOHMANN_JSON_VERSION_MAJOR),
'.',
18277 std::to_string(NLOHMANN_JSON_VERSION_MINOR),
'.',
18278 std::to_string(NLOHMANN_JSON_VERSION_PATCH));
18279 result[
"version"][
"major"] = NLOHMANN_JSON_VERSION_MAJOR;
18280 result[
"version"][
"minor"] = NLOHMANN_JSON_VERSION_MINOR;
18281 result[
"version"][
"patch"] = NLOHMANN_JSON_VERSION_PATCH;
18284 result[
"platform"] =
"win32";
18285#elif defined __linux__
18286 result[
"platform"] =
"linux";
18287#elif defined __APPLE__
18288 result[
"platform"] =
"apple";
18289#elif defined __unix__
18290 result[
"platform"] =
"unix";
18292 result[
"platform"] =
"unknown";
18295#if defined(__ICC) || defined(__INTEL_COMPILER)
18296 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER }};
18297#elif defined(__clang__)
18298 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__ }};
18299#elif defined(__GNUC__) || defined(__GNUG__)
18300 result[
"compiler"] = {
18303 detail::concat(std::to_string(__GNUC__),
'.', std::to_string(__GNUC_MINOR__),
'.',
18304 std::to_string(__GNUC_PATCHLEVEL__)) }};
18305#elif defined(__HP_cc) || defined(__HP_aCC)
18306 result[
"compiler"] =
"hp"
18307#elif defined(__IBMCPP__)
18308 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__ }};
18309#elif defined(_MSC_VER)
18310 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER }};
18311#elif defined(__PGI)
18312 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI }};
18313#elif defined(__SUNPRO_CC)
18314 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC }};
18316 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
18319#if defined(_MSVC_LANG)
18320 result[
"compiler"][
"c++"] = std::to_string(_MSVC_LANG);
18321#elif defined(__cplusplus)
18322 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
18324 result[
"compiler"][
"c++"] =
"unknown";
18342#if defined(JSON_HAS_CPP_14)
18346 using default_object_comparator_t = std::less<>;
18354 AllocatorType<std::pair<const StringType, basic_json>>>;
18358 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
18382 using binary_t = nlohmann::byte_container_with_subtype<BinaryType>;
18392 template <
typename T,
typename... Args>
18393 JSON_HEDLEY_RETURNS_NON_NULL
static T* create(Args&&... args) {
18394 AllocatorType<T> alloc;
18395 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
18397 auto deleter = [&](T* obj) { AllocatorTraits::deallocate(alloc, obj, 1); };
18398 std::unique_ptr<T,
decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
18399 AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
18400 JSON_ASSERT(obj !=
nullptr);
18401 return obj.release();
18408 JSON_PRIVATE_UNLESS_TESTED :
18446 number_integer_t number_integer;
18448 number_unsigned_t number_unsigned;
18450 number_float_t number_float;
18453 json_value() =
default;
18455 json_value(boolean_t v) noexcept : boolean(v) {}
18461 json_value(number_float_t v) noexcept :
number_float(v) {}
18463 json_value(value_t t) {
18465 case value_t::object: {
18466 object = create<object_t>();
18470 case value_t::array: {
18471 array = create<array_t>();
18475 case value_t::string: {
18476 string = create<string_t>(
"");
18480 case value_t::binary: {
18481 binary = create<binary_t>();
18485 case value_t::boolean: {
18486 boolean =
static_cast<boolean_t
>(
false);
18490 case value_t::number_integer: {
18495 case value_t::number_unsigned: {
18500 case value_t::number_float: {
18505 case value_t::null: {
18510 case value_t::discarded:
18513 if (JSON_HEDLEY_UNLIKELY(t == value_t::null)) {
18514 JSON_THROW(other_error::create(
18515 500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.11.3",
18524 json_value(
const string_t& value) :
string(create<string_t>(value)) {}
18527 json_value(string_t&& value) :
string(create<string_t>(std::move(value))) {}
18530 json_value(
const object_t& value) :
object(create<object_t>(value)) {}
18533 json_value(object_t&& value) :
object(create<object_t>(std::move(value))) {}
18536 json_value(
const array_t& value) :
array(create<array_t>(value)) {}
18539 json_value(array_t&& value) :
array(create<array_t>(std::move(value))) {}
18542 json_value(
const typename binary_t::container_type& value)
18543 :
binary(create<binary_t>(value)) {}
18546 json_value(
typename binary_t::container_type&& value)
18547 :
binary(create<binary_t>(std::move(value))) {}
18550 json_value(
const binary_t& value) :
binary(create<binary_t>(value)) {}
18553 json_value(binary_t&& value) :
binary(create<binary_t>(std::move(value))) {}
18555 void destroy(value_t t) {
18556 if ((t == value_t::object &&
object ==
nullptr) ||
18557 (t == value_t::array && array ==
nullptr) ||
18558 (t == value_t::string &&
string ==
nullptr) ||
18559 (t == value_t::binary && binary ==
nullptr)) {
18563 if (t == value_t::array || t == value_t::object) {
18565 std::vector<basic_json> stack;
18568 if (t == value_t::array) {
18569 stack.reserve(
array->size());
18570 std::move(
array->begin(),
array->end(), std::back_inserter(stack));
18572 stack.reserve(
object->size());
18573 for (
auto&& it : *
object) {
18574 stack.push_back(std::move(it.second));
18578 while (!stack.empty()) {
18580 basic_json current_item(std::move(stack.back()));
18585 if (current_item.is_array()) {
18586 std::move(current_item.m_data.m_value.array->begin(),
18587 current_item.m_data.m_value.array->end(),
18588 std::back_inserter(stack));
18590 current_item.m_data.m_value.array->clear();
18591 }
else if (current_item.is_object()) {
18592 for (
auto&& it : *current_item.m_data.m_value.object) {
18593 stack.push_back(std::move(it.second));
18596 current_item.m_data.m_value.object->clear();
18605 case value_t::object: {
18606 AllocatorType<object_t> alloc;
18607 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
object);
18608 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
object, 1);
18612 case value_t::array: {
18613 AllocatorType<array_t> alloc;
18614 std::allocator_traits<
decltype(alloc)>::destroy(alloc, array);
18615 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, array, 1);
18619 case value_t::string: {
18620 AllocatorType<string_t> alloc;
18621 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
string);
18622 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
string, 1);
18626 case value_t::binary: {
18627 AllocatorType<binary_t> alloc;
18628 std::allocator_traits<
decltype(alloc)>::destroy(alloc, binary);
18629 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, binary, 1);
18633 case value_t::null:
18634 case value_t::boolean:
18635 case value_t::number_integer:
18636 case value_t::number_unsigned:
18637 case value_t::number_float:
18638 case value_t::discarded:
18665 void assert_invariant(
bool check_parents =
true) const noexcept {
18666 JSON_ASSERT(m_data.m_type != value_t::object || m_data.m_value.object !=
nullptr);
18667 JSON_ASSERT(m_data.m_type != value_t::array || m_data.m_value.array !=
nullptr);
18668 JSON_ASSERT(m_data.m_type != value_t::string || m_data.m_value.string !=
nullptr);
18669 JSON_ASSERT(m_data.m_type != value_t::binary || m_data.m_value.binary !=
nullptr);
18671#if JSON_DIAGNOSTICS
18674 JSON_ASSERT(!check_parents || !is_structured() ||
18675 std::all_of(begin(), end(),
18676 [
this](
const basic_json& j) {
return j.m_parent ==
this; }));
18680 static_cast<void>(check_parents);
18683 void set_parents() {
18684#if JSON_DIAGNOSTICS
18685 switch (m_data.m_type) {
18686 case value_t::array: {
18687 for (
auto& element : *m_data.m_value.array) {
18688 element.m_parent =
this;
18693 case value_t::object: {
18694 for (
auto& element : *m_data.m_value.object) {
18695 element.second.m_parent =
this;
18700 case value_t::null:
18701 case value_t::string:
18702 case value_t::boolean:
18703 case value_t::number_integer:
18704 case value_t::number_unsigned:
18705 case value_t::number_float:
18706 case value_t::binary:
18707 case value_t::discarded:
18714 iterator set_parents(iterator it,
typename iterator::difference_type count_set_parents) {
18715#if JSON_DIAGNOSTICS
18716 for (
typename iterator::difference_type i = 0; i < count_set_parents; ++i) {
18717 (it + i)->m_parent =
this;
18720 static_cast<void>(count_set_parents);
18725 reference set_parent(reference j, std::size_t old_capacity =
static_cast<std::size_t
>(-1)) {
18726#if JSON_DIAGNOSTICS
18727 if (old_capacity !=
static_cast<std::size_t
>(-1)) {
18729 JSON_ASSERT(type() == value_t::array);
18730 if (JSON_HEDLEY_UNLIKELY(m_data.m_value.array->capacity() != old_capacity)) {
18739#ifdef JSON_HEDLEY_MSVC_VERSION
18740#pragma warning(push)
18741#pragma warning(disable : 4127)
18743 if (detail::is_ordered_map<object_t>::value) {
18747#ifdef JSON_HEDLEY_MSVC_VERSION
18748#pragma warning(pop)
18753 static_cast<void>(j);
18754 static_cast<void>(old_capacity);
18789 assert_invariant();
18794 template <
typename CompatibleType,
typename U = detail::uncvref_t<CompatibleType>,
18795 detail::enable_if_t<!detail::is_basic_json<U>::value &&
18796 detail::is_compatible_type<basic_json_t, U>::value,
18800 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
18801 std::forward<CompatibleType>(val)))) {
18802 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
18804 assert_invariant();
18809 template <
typename BasicJsonType,
18810 detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value &&
18811 !std::is_same<basic_json, BasicJsonType>::value,
18814 using other_boolean_t =
typename BasicJsonType::boolean_t;
18815 using other_number_float_t =
typename BasicJsonType::number_float_t;
18816 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
18817 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
18818 using other_string_t =
typename BasicJsonType::string_t;
18819 using other_object_t =
typename BasicJsonType::object_t;
18820 using other_array_t =
typename BasicJsonType::array_t;
18821 using other_binary_t =
typename BasicJsonType::binary_t;
18823 switch (val.type()) {
18824 case value_t::boolean:
18825 JSONSerializer<other_boolean_t>::to_json(*
this,
18828 case value_t::number_float:
18829 JSONSerializer<other_number_float_t>::to_json(
18832 case value_t::number_integer:
18833 JSONSerializer<other_number_integer_t>::to_json(
18836 case value_t::number_unsigned:
18837 JSONSerializer<other_number_unsigned_t>::to_json(
18840 case value_t::string:
18841 JSONSerializer<other_string_t>::to_json(
18844 case value_t::object:
18845 JSONSerializer<other_object_t>::to_json(
18848 case value_t::array:
18849 JSONSerializer<other_array_t>::to_json(
18852 case value_t::binary:
18853 JSONSerializer<other_binary_t>::to_json(
18856 case value_t::null:
18859 case value_t::discarded:
18860 m_data.m_type = value_t::discarded;
18863 JSON_ASSERT(
false);
18866 JSON_ASSERT(m_data.m_type == val.type());
18868 assert_invariant();
18874 value_t manual_type = value_t::array) {
18877 bool is_an_object = std::all_of(
18883 return element_ref->is_array() && element_ref->size() == 2 &&
18884 (*element_ref)[static_cast<size_type>(0)].is_string();
18888 if (!type_deduction) {
18890 if (manual_type == value_t::array) {
18891 is_an_object =
false;
18895 if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object)) {
18897 type_error::create(301,
"cannot create object from initializer list",
nullptr));
18901 if (is_an_object) {
18903 m_data.m_type = value_t::object;
18904 m_data.m_value = value_t::object;
18906 for (
auto& element_ref : init) {
18907 auto element = element_ref.moved_or_copied();
18908 m_data.m_value.object->emplace(
18909 std::move(*((*element.m_data.m_value.array)[0].m_data.m_value.string)),
18910 std::move((*element.m_data.m_value.array)[1]));
18914 m_data.m_type = value_t::array;
18915 m_data.m_value.array = create<array_t>(init.begin(), init.end());
18919 assert_invariant();
18924 JSON_HEDLEY_WARN_UNUSED_RESULT
18927 res.m_data.m_type = value_t::binary;
18928 res.m_data.m_value = init;
18934 JSON_HEDLEY_WARN_UNUSED_RESULT
18936 typename binary_t::subtype_type subtype) {
18938 res.m_data.m_type = value_t::binary;
18939 res.m_data.m_value =
binary_t(init, subtype);
18945 JSON_HEDLEY_WARN_UNUSED_RESULT
18948 res.m_data.m_type = value_t::binary;
18949 res.m_data.m_value = std::move(init);
18955 JSON_HEDLEY_WARN_UNUSED_RESULT
18957 typename binary_t::subtype_type subtype) {
18959 res.m_data.m_type = value_t::binary;
18960 res.m_data.m_value =
binary_t(std::move(init), subtype);
18966 JSON_HEDLEY_WARN_UNUSED_RESULT
18968 return basic_json(init,
false, value_t::array);
18973 JSON_HEDLEY_WARN_UNUSED_RESULT
18975 return basic_json(init,
false, value_t::object);
18982 assert_invariant();
18987 template <
class InputIT,
18988 typename std::enable_if<
18989 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
18990 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
18993 JSON_ASSERT(first.m_object !=
nullptr);
18994 JSON_ASSERT(last.m_object !=
nullptr);
18997 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) {
18998 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible",
nullptr));
19002 m_data.m_type = first.m_object->m_data.m_type;
19005 switch (m_data.m_type) {
19006 case value_t::boolean:
19007 case value_t::number_float:
19008 case value_t::number_integer:
19009 case value_t::number_unsigned:
19010 case value_t::string: {
19011 if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin() ||
19012 !last.m_it.primitive_iterator.is_end())) {
19014 invalid_iterator::create(204,
"iterators out of range", first.m_object));
19019 case value_t::null:
19020 case value_t::object:
19021 case value_t::array:
19022 case value_t::binary:
19023 case value_t::discarded:
19028 switch (m_data.m_type) {
19029 case value_t::number_integer: {
19030 m_data.m_value.number_integer = first.m_object->m_data.m_value.number_integer;
19034 case value_t::number_unsigned: {
19035 m_data.m_value.number_unsigned = first.m_object->m_data.m_value.number_unsigned;
19039 case value_t::number_float: {
19040 m_data.m_value.number_float = first.m_object->m_data.m_value.number_float;
19044 case value_t::boolean: {
19045 m_data.m_value.boolean = first.m_object->m_data.m_value.boolean;
19049 case value_t::string: {
19050 m_data.m_value = *first.m_object->m_data.m_value.string;
19054 case value_t::object: {
19055 m_data.m_value.object =
19056 create<object_t>(first.m_it.object_iterator, last.m_it.object_iterator);
19060 case value_t::array: {
19061 m_data.m_value.array =
19062 create<array_t>(first.m_it.array_iterator, last.m_it.array_iterator);
19066 case value_t::binary: {
19067 m_data.m_value = *first.m_object->m_data.m_value.binary;
19071 case value_t::null:
19072 case value_t::discarded:
19075 invalid_iterator::create(206,
19076 detail::concat(
"cannot construct with iterators from ",
19077 first.m_object->type_name()),
19082 assert_invariant();
19091 detail::enable_if_t<
19093 std::is_same<typename JsonRef::value_type, basic_json>>::value,
19100 m_data.m_type = other.m_data.m_type;
19102 other.assert_invariant();
19104 switch (m_data.m_type) {
19105 case value_t::object: {
19106 m_data.m_value = *other.m_data.m_value.object;
19110 case value_t::array: {
19111 m_data.m_value = *other.m_data.m_value.array;
19115 case value_t::string: {
19116 m_data.m_value = *other.m_data.m_value.string;
19120 case value_t::boolean: {
19121 m_data.m_value = other.m_data.m_value.boolean;
19125 case value_t::number_integer: {
19126 m_data.m_value = other.m_data.m_value.number_integer;
19130 case value_t::number_unsigned: {
19131 m_data.m_value = other.m_data.m_value.number_unsigned;
19135 case value_t::number_float: {
19136 m_data.m_value = other.m_data.m_value.number_float;
19140 case value_t::binary: {
19141 m_data.m_value = *other.m_data.m_value.binary;
19145 case value_t::null:
19146 case value_t::discarded:
19152 assert_invariant();
19158 : json_base_class_t(std::forward<json_base_class_t>(other)),
19159 m_data(std::move(other.m_data)) {
19161 other.assert_invariant(
false);
19164 other.m_data.m_type = value_t::null;
19165 other.m_data.m_value = {};
19168 assert_invariant();
19174 std::is_nothrow_move_constructible<value_t>::value &&
19175 std::is_nothrow_move_assignable<value_t>::value &&
19176 std::is_nothrow_move_constructible<json_value>::value &&
19177 std::is_nothrow_move_assignable<json_value>::value &&
19178 std::is_nothrow_move_assignable<json_base_class_t>::value) {
19180 other.assert_invariant();
19183 swap(m_data.m_type, other.m_data.m_type);
19184 swap(m_data.m_value, other.m_data.m_value);
19185 json_base_class_t::operator=(std::move(other));
19188 assert_invariant();
19210 const bool ensure_ascii =
false,
19211 const error_handler_t error_handler = error_handler_t::strict)
const {
19216 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
19218 s.dump(*
this,
false, ensure_ascii, 0);
19226 constexpr value_t
type() const noexcept {
return m_data.m_type; }
19240 constexpr bool is_null() const noexcept {
return m_data.m_type == value_t::null; }
19244 constexpr bool is_boolean() const noexcept {
return m_data.m_type == value_t::boolean; }
19253 return m_data.m_type == value_t::number_integer ||
19254 m_data.m_type == value_t::number_unsigned;
19260 return m_data.m_type == value_t::number_unsigned;
19266 return m_data.m_type == value_t::number_float;
19271 constexpr bool is_object() const noexcept {
return m_data.m_type == value_t::object; }
19275 constexpr bool is_array() const noexcept {
return m_data.m_type == value_t::array; }
19279 constexpr bool is_string() const noexcept {
return m_data.m_type == value_t::string; }
19283 constexpr bool is_binary() const noexcept {
return m_data.m_type == value_t::binary; }
19287 constexpr bool is_discarded() const noexcept {
return m_data.m_type == value_t::discarded; }
19291 constexpr operator value_t() const noexcept {
return m_data.m_type; }
19301 boolean_t get_impl(boolean_t* )
const {
19302 if (JSON_HEDLEY_LIKELY(is_boolean())) {
19303 return m_data.m_value.boolean;
19306 JSON_THROW(type_error::create(
19307 302, detail::concat(
"type must be boolean, but is ", type_name()),
this));
19311 object_t* get_impl_ptr(object_t* )
noexcept {
19312 return is_object() ? m_data.m_value.object :
nullptr;
19316 constexpr const object_t* get_impl_ptr(
const object_t* )
const noexcept {
19317 return is_object() ? m_data.m_value.object :
nullptr;
19321 array_t* get_impl_ptr(array_t* )
noexcept {
19322 return is_array() ? m_data.m_value.array :
nullptr;
19326 constexpr const array_t* get_impl_ptr(
const array_t* )
const noexcept {
19327 return is_array() ? m_data.m_value.array :
nullptr;
19331 string_t* get_impl_ptr(string_t* )
noexcept {
19332 return is_string() ? m_data.m_value.string :
nullptr;
19336 constexpr const string_t* get_impl_ptr(
const string_t* )
const noexcept {
19337 return is_string() ? m_data.m_value.string :
nullptr;
19341 boolean_t* get_impl_ptr(boolean_t* )
noexcept {
19342 return is_boolean() ? &m_data.m_value.boolean :
nullptr;
19346 constexpr const boolean_t* get_impl_ptr(
const boolean_t* )
const noexcept {
19347 return is_boolean() ? &m_data.m_value.boolean :
nullptr;
19351 number_integer_t* get_impl_ptr(number_integer_t* )
noexcept {
19352 return is_number_integer() ? &m_data.m_value.number_integer :
nullptr;
19356 constexpr const number_integer_t*
19357 get_impl_ptr(
const number_integer_t* )
const noexcept {
19358 return is_number_integer() ? &m_data.m_value.number_integer :
nullptr;
19362 number_unsigned_t* get_impl_ptr(number_unsigned_t* )
noexcept {
19363 return is_number_unsigned() ? &m_data.m_value.number_unsigned :
nullptr;
19367 constexpr const number_unsigned_t*
19368 get_impl_ptr(
const number_unsigned_t* )
const noexcept {
19369 return is_number_unsigned() ? &m_data.m_value.number_unsigned :
nullptr;
19373 number_float_t* get_impl_ptr(number_float_t* )
noexcept {
19374 return is_number_float() ? &m_data.m_value.number_float :
nullptr;
19378 constexpr const number_float_t* get_impl_ptr(
const number_float_t* )
const noexcept {
19379 return is_number_float() ? &m_data.m_value.number_float :
nullptr;
19383 binary_t* get_impl_ptr(binary_t* )
noexcept {
19384 return is_binary() ? m_data.m_value.binary :
nullptr;
19388 constexpr const binary_t* get_impl_ptr(
const binary_t* )
const noexcept {
19389 return is_binary() ? m_data.m_value.binary :
nullptr;
19403 template <
typename ReferenceType,
typename ThisType>
19404 static ReferenceType get_ref_impl(ThisType& obj) {
19406 auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
19408 if (JSON_HEDLEY_LIKELY(ptr !=
nullptr)) {
19412 JSON_THROW(type_error::create(
19414 detail::concat(
"incompatible ReferenceType for get_ref, actual type is ",
19426 template <
typename PointerType,
19427 typename std::enable_if<std::is_pointer<PointerType>::value,
int>::type = 0>
19429 -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>())) {
19431 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
19436 template <
typename PointerType,
19437 typename std::enable_if<
19438 std::is_pointer<PointerType>::value &&
19439 std::is_const<typename std::remove_pointer<PointerType>::type>::value,
19442 -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>())) {
19444 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
19488 template <
typename ValueType,
19489 detail::enable_if_t<detail::is_default_constructible<ValueType>::value &&
19493 noexcept(
noexcept(JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(),
19494 std::declval<ValueType&>()))) {
19495 auto ret = ValueType();
19496 JSONSerializer<ValueType>::from_json(*
this, ret);
19532 template <
typename ValueType,
19533 detail::enable_if_t<detail::has_non_default_from_json<basic_json_t, ValueType>::value,
19535 ValueType get_impl(detail::priority_tag<1> )
const noexcept(
19536 noexcept(JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>()))) {
19537 return JSONSerializer<ValueType>::from_json(*
this);
19555 template <
typename BasicJsonType,
19556 detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
19557 BasicJsonType get_impl(detail::priority_tag<2> )
const {
19575 template <
typename BasicJsonType,
19576 detail::enable_if_t<std::is_same<BasicJsonType, basic_json_t>::value,
int> = 0>
19577 basic_json get_impl(detail::priority_tag<3> )
const {
19585 template <
typename PointerType,
19586 detail::enable_if_t<std::is_pointer<PointerType>::value,
int> = 0>
19587 constexpr auto get_impl(detail::priority_tag<4> )
const noexcept
19588 ->
decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>()) {
19590 return get_ptr<PointerType>();
19619 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>>
19620#if defined(JSON_HAS_CPP_14)
19625 noexcept(noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(
19626 detail::priority_tag<4>{})))
19627 ->
decltype(std::declval<const basic_json_t&>().template get_impl<ValueType>(
19632 static_assert(!std::is_reference<ValueTypeCV>::value,
19633 "get() cannot be used with reference types, you might want "
19634 "to use get_ref()");
19635 return get_impl<ValueType>(detail::priority_tag<4>{});
19665 template <
typename PointerType,
19666 typename std::enable_if<std::is_pointer<PointerType>::value,
int>::type = 0>
19667 auto get() noexcept -> decltype(std::declval<basic_json_t&>().template
get_ptr<PointerType>()) {
19674 template <
typename ValueType,
19675 detail::enable_if_t<!detail::is_basic_json<ValueType>::value &&
19679 noexcept(
noexcept(JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(),
19681 JSONSerializer<ValueType>::from_json(*
this, v);
19687 template <
typename ValueType,
19688 detail::enable_if_t<detail::is_basic_json<ValueType>::value,
int> = 0>
19689 ValueType& get_to(ValueType& v)
const {
19695 typename T, std::size_t N,
19696 typename Array = T (&)
19698 detail::enable_if_t<detail::has_from_json<basic_json_t, Array>::value,
19700 Array get_to(T (&v)[N])
19702 noexcept(
noexcept(JSONSerializer<Array>::from_json(std::declval<const basic_json_t&>(),
19704 JSONSerializer<Array>::from_json(*
this, v);
19710 template <
typename ReferenceType,
19711 typename std::enable_if<std::is_reference<ReferenceType>::value,
int>::type = 0>
19714 return get_ref_impl<ReferenceType>(*
this);
19719 template <
typename ReferenceType,
19720 typename std::enable_if<
19721 std::is_reference<ReferenceType>::value &&
19722 std::is_const<typename std::remove_reference<ReferenceType>::type>::value,
19726 return get_ref_impl<ReferenceType>(*
this);
19758 template <
typename ValueType,
19759 typename std::enable_if<
19767 ValueType, std::initializer_list<typename string_t::value_type>>>,
19768#if defined(JSON_HAS_CPP_17) && \
19769 (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
19772#if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI
19776 ValueType>>::value,
19778 JSON_EXPLICIT
operator ValueType()
const {
19787 JSON_THROW(type_error::create(
19788 302, detail::concat(
"type must be binary, but is ",
type_name()),
this));
19798 JSON_THROW(type_error::create(
19799 302, detail::concat(
"type must be binary, but is ",
type_name()),
this));
19819 if (JSON_HEDLEY_LIKELY(
is_array())) {
19821 return set_parent(m_data.m_value.array->at(idx));
19823 JSON_CATCH(std::out_of_range&) {
19825 JSON_THROW(out_of_range::create(
19826 401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
19830 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
19839 if (JSON_HEDLEY_LIKELY(
is_array())) {
19841 return m_data.m_value.array->at(idx);
19843 JSON_CATCH(std::out_of_range&) {
19845 JSON_THROW(out_of_range::create(
19846 401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
19850 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
19859 if (JSON_HEDLEY_UNLIKELY(!
is_object())) {
19860 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
19865 if (it == m_data.m_value.object->end()) {
19867 out_of_range::create(403, detail::concat(
"key '",
key,
"' not found"),
this));
19869 return set_parent(it->second);
19874 template <
class KeyType,
19875 detail::enable_if_t<
19876 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
19879 if (JSON_HEDLEY_UNLIKELY(!
is_object())) {
19880 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
19884 auto it = m_data.
m_value.object->find(std::forward<KeyType>(
key));
19885 if (it == m_data.m_value.object->end()) {
19886 JSON_THROW(out_of_range::create(
19887 403, detail::concat(
"key '",
string_t(std::forward<KeyType>(
key)),
"' not found"),
19890 return set_parent(it->second);
19897 if (JSON_HEDLEY_UNLIKELY(!
is_object())) {
19898 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
19903 if (it == m_data.m_value.object->end()) {
19905 out_of_range::create(403, detail::concat(
"key '",
key,
"' not found"),
this));
19912 template <
class KeyType,
19913 detail::enable_if_t<
19914 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
19917 if (JSON_HEDLEY_UNLIKELY(!
is_object())) {
19918 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
19922 auto it = m_data.
m_value.object->find(std::forward<KeyType>(
key));
19923 if (it == m_data.m_value.object->end()) {
19924 JSON_THROW(out_of_range::create(
19925 403, detail::concat(
"key '",
string_t(std::forward<KeyType>(
key)),
"' not found"),
19936 m_data.m_type = value_t::array;
19937 m_data.m_value.array = create<array_t>();
19938 assert_invariant();
19942 if (JSON_HEDLEY_LIKELY(
is_array())) {
19944 if (idx >= m_data.m_value.array->size()) {
19945#if JSON_DIAGNOSTICS
19947 const auto old_size = m_data.m_value.array->size();
19948 const auto old_capacity = m_data.m_value.array->capacity();
19950 m_data.m_value.array->resize(idx + 1);
19952#if JSON_DIAGNOSTICS
19953 if (JSON_HEDLEY_UNLIKELY(m_data.m_value.array->capacity() != old_capacity)) {
19959 begin() +
static_cast<typename iterator::difference_type
>(old_size),
19960 static_cast<typename iterator::difference_type
>(idx + 1 - old_size));
19963 assert_invariant();
19966 return m_data.m_value.array->operator[](idx);
19969 JSON_THROW(type_error::create(
19970 305, detail::concat(
"cannot use operator[] with a numeric argument with ",
type_name()),
19978 if (JSON_HEDLEY_LIKELY(
is_array())) {
19979 return m_data.m_value.array->operator[](idx);
19982 JSON_THROW(type_error::create(
19983 305, detail::concat(
"cannot use operator[] with a numeric argument with ",
type_name()),
19992 m_data.m_type = value_t::object;
19993 m_data.m_value.object = create<object_t>();
19994 assert_invariant();
19999 auto result = m_data.m_value.object->emplace(std::move(
key),
nullptr);
20000 return set_parent(result.first->second);
20003 JSON_THROW(type_error::create(
20004 305, detail::concat(
"cannot use operator[] with a string argument with ",
type_name()),
20013 auto it = m_data.m_value.object->find(
key);
20014 JSON_ASSERT(it != m_data.m_value.object->end());
20018 JSON_THROW(type_error::create(
20019 305, detail::concat(
"cannot use operator[] with a string argument with ",
type_name()),
20025 template <
typename T> reference operator[](T*
key) {
20026 return operator[](
typename object_t::key_type(
key));
20029 template <
typename T> const_reference operator[](T*
key)
const {
20030 return operator[](
typename object_t::key_type(
key));
20035 template <
class KeyType,
20036 detail::enable_if_t<
20037 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
20041 m_data.m_type = value_t::object;
20042 m_data.m_value.object = create<object_t>();
20043 assert_invariant();
20048 auto result = m_data.m_value.object->emplace(std::forward<KeyType>(
key),
nullptr);
20049 return set_parent(result.first->second);
20052 JSON_THROW(type_error::create(
20053 305, detail::concat(
"cannot use operator[] with a string argument with ",
type_name()),
20059 template <
class KeyType,
20060 detail::enable_if_t<
20061 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
20065 auto it = m_data.m_value.object->find(std::forward<KeyType>(
key));
20066 JSON_ASSERT(it != m_data.m_value.object->end());
20070 JSON_THROW(type_error::create(
20071 305, detail::concat(
"cannot use operator[] with a string argument with ",
type_name()),
20076 template <
typename KeyType>
20077 using is_comparable_with_object_key =
20080 template <
typename ValueType>
20081 using value_return_type = std::conditional<detail::is_c_string_uncvref<ValueType>::value,
20082 string_t,
typename std::decay<ValueType>::type>;
20087 template <
class ValueType,
20088 detail::enable_if_t<!detail::is_transparent<object_comparator_t>::value &&
20089 detail::is_getable<basic_json_t, ValueType>::value &&
20090 !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
20092 ValueType
value(
const typename object_t::key_type&
key,
const ValueType& default_value)
const {
20101 return default_value;
20105 type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
20110 template <class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
20111 detail::enable_if_t<!detail::is_transparent<object_comparator_t>::value &&
20112 detail::is_getable<basic_json_t, ReturnType>::value &&
20113 !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
20115 ReturnType
value(
const typename object_t::key_type&
key, ValueType&& default_value)
const {
20124 return std::forward<ValueType>(default_value);
20128 type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
20133 template <
class ValueType,
class KeyType,
20134 detail::enable_if_t<detail::is_transparent<object_comparator_t>::value &&
20135 !detail::is_json_pointer<KeyType>::value &&
20136 is_comparable_with_object_key<KeyType>::value &&
20137 detail::is_getable<basic_json_t, ValueType>::value &&
20138 !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
20140 ValueType
value(KeyType&&
key,
const ValueType& default_value)
const {
20144 const auto it =
find(std::forward<KeyType>(
key));
20149 return default_value;
20153 type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
20158 template <
class ValueType,
class KeyType,
20159 class ReturnType =
typename value_return_type<ValueType>::type,
20160 detail::enable_if_t<detail::is_transparent<object_comparator_t>::value &&
20161 !detail::is_json_pointer<KeyType>::value &&
20162 is_comparable_with_object_key<KeyType>::value &&
20163 detail::is_getable<basic_json_t, ReturnType>::value &&
20164 !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
20166 ReturnType
value(KeyType&&
key, ValueType&& default_value)
const {
20170 const auto it =
find(std::forward<KeyType>(
key));
20175 return std::forward<ValueType>(default_value);
20179 type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
20184 template <
class ValueType,
20185 detail::enable_if_t<detail::is_getable<basic_json_t, ValueType>::value &&
20186 !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
20195 JSON_INTERNAL_CATCH(out_of_range&) {
20196 return default_value;
20201 type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
20206 template <class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
20207 detail::enable_if_t<detail::is_getable<basic_json_t, ReturnType>::value &&
20208 !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
20217 JSON_INTERNAL_CATCH(out_of_range&) {
20218 return std::forward<ValueType>(default_value);
20223 type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
20226 template <
class ValueType,
class BasicJsonType,
20227 detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value &&
20228 detail::is_getable<basic_json_t, ValueType>::value &&
20229 !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
20233 nlohmann::json_pointer<basic_json::string_t>)
20234 ValueType
value(const ::nlohmann::json_pointer<BasicJsonType>& ptr,
20235 const ValueType& default_value)
const {
20236 return value(ptr.convert(), default_value);
20239 template <
class ValueType,
class BasicJsonType,
20240 class ReturnType =
typename value_return_type<ValueType>::type,
20241 detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value &&
20242 detail::is_getable<basic_json_t, ReturnType>::value &&
20243 !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
20245 JSON_HEDLEY_DEPRECATED_FOR(
20247 nlohmann::json_pointer<basic_json::string_t>)
20249 value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, ValueType&& default_value)
const {
20250 return value(ptr.convert(), std::forward<ValueType>(default_value));
20255 reference front() {
return *begin(); }
20279 template <
class IteratorType,
20280 detail::enable_if_t<
20281 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
20282 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
20286 if (JSON_HEDLEY_UNLIKELY(
this != pos.m_object)) {
20287 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
20290 IteratorType result = end();
20292 switch (m_data.m_type) {
20293 case value_t::boolean:
20294 case value_t::number_float:
20295 case value_t::number_integer:
20296 case value_t::number_unsigned:
20297 case value_t::string:
20298 case value_t::binary: {
20299 if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin())) {
20300 JSON_THROW(invalid_iterator::create(205,
"iterator out of range",
this));
20304 AllocatorType<string_t> alloc;
20305 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.string);
20306 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.string,
20308 m_data.m_value.string =
nullptr;
20310 AllocatorType<binary_t> alloc;
20311 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.binary);
20312 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.binary,
20314 m_data.m_value.binary =
nullptr;
20317 m_data.m_type = value_t::null;
20318 assert_invariant();
20322 case value_t::object: {
20323 result.m_it.object_iterator =
20324 m_data.m_value.object->erase(pos.m_it.object_iterator);
20328 case value_t::array: {
20329 result.m_it.array_iterator = m_data.m_value.array->erase(pos.m_it.array_iterator);
20333 case value_t::null:
20334 case value_t::discarded:
20336 JSON_THROW(type_error::create(
20337 307, detail::concat(
"cannot use erase() with ",
type_name()),
this));
20345 template <
class IteratorType,
20346 detail::enable_if_t<
20347 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
20348 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
20350 IteratorType
erase(IteratorType first, IteratorType last) {
20352 if (JSON_HEDLEY_UNLIKELY(
this != first.m_object ||
this != last.m_object)) {
20353 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value",
this));
20356 IteratorType result = end();
20358 switch (m_data.m_type) {
20359 case value_t::boolean:
20360 case value_t::number_float:
20361 case value_t::number_integer:
20362 case value_t::number_unsigned:
20363 case value_t::string:
20364 case value_t::binary: {
20365 if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin() ||
20366 !last.m_it.primitive_iterator.is_end())) {
20367 JSON_THROW(invalid_iterator::create(204,
"iterators out of range",
this));
20371 AllocatorType<string_t> alloc;
20372 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.string);
20373 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.string,
20375 m_data.m_value.string =
nullptr;
20377 AllocatorType<binary_t> alloc;
20378 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.binary);
20379 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.binary,
20381 m_data.m_value.binary =
nullptr;
20384 m_data.m_type = value_t::null;
20385 assert_invariant();
20389 case value_t::object: {
20390 result.m_it.object_iterator = m_data.m_value.object->erase(
20391 first.m_it.object_iterator, last.m_it.object_iterator);
20395 case value_t::array: {
20396 result.m_it.array_iterator = m_data.m_value.array->erase(first.m_it.array_iterator,
20397 last.m_it.array_iterator);
20401 case value_t::null:
20402 case value_t::discarded:
20404 JSON_THROW(type_error::create(
20405 307, detail::concat(
"cannot use erase() with ",
type_name()),
this));
20414 detail::enable_if_t<detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int> = 0>
20415 size_type erase_internal(KeyType&&
key) {
20417 if (JSON_HEDLEY_UNLIKELY(!is_object())) {
20418 JSON_THROW(type_error::create(
20419 307, detail::concat(
"cannot use erase() with ", type_name()),
this));
20422 return m_data.m_value.object->erase(std::forward<KeyType>(
key));
20425 template <
typename KeyType,
20426 detail::enable_if_t<!detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
20428 size_type erase_internal(KeyType&&
key) {
20430 if (JSON_HEDLEY_UNLIKELY(!is_object())) {
20431 JSON_THROW(type_error::create(
20432 307, detail::concat(
"cannot use erase() with ", type_name()),
this));
20435 const auto it = m_data.m_value.object->find(std::forward<KeyType>(
key));
20436 if (it != m_data.m_value.object->end()) {
20437 m_data.m_value.object->erase(it);
20449 return erase_internal(
key);
20454 template <
class KeyType,
20455 detail::enable_if_t<
20456 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
20458 return erase_internal(std::forward<KeyType>(
key));
20465 if (JSON_HEDLEY_LIKELY(
is_array())) {
20466 if (JSON_HEDLEY_UNLIKELY(idx >= size())) {
20467 JSON_THROW(out_of_range::create(
20468 401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
20472 m_data.m_value.array->erase(m_data.m_value.array->begin() +
20475 JSON_THROW(type_error::create(
20476 307, detail::concat(
"cannot use erase() with ",
type_name()),
this));
20492 auto result = end();
20495 result.m_it.object_iterator = m_data.m_value.object->find(
key);
20504 auto result = cend();
20507 result.m_it.object_iterator = m_data.m_value.object->find(
key);
20515 template <
class KeyType,
20516 detail::enable_if_t<
20517 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
20519 auto result = end();
20522 result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(
key));
20530 template <
class KeyType,
20531 detail::enable_if_t<
20532 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
20534 auto result = cend();
20537 result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(
key));
20547 return is_object() ? m_data.m_value.object->count(
key) : 0;
20552 template <
class KeyType,
20553 detail::enable_if_t<
20554 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
20557 return is_object() ? m_data.m_value.object->count(std::forward<KeyType>(
key)) : 0;
20563 return is_object() && m_data.m_value.object->find(
key) != m_data.m_value.object->end();
20568 template <
class KeyType,
20569 detail::enable_if_t<
20570 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
20572 return is_object() && m_data.m_value.object->find(std::forward<KeyType>(
key)) !=
20573 m_data.m_value.object->end();
20581 template <
typename BasicJsonType,
20582 detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
20583 JSON_HEDLEY_DEPRECATED_FOR(
20585 nlohmann::json_pointer<basic_json::string_t>)
20586 bool contains(
const typename ::nlohmann::json_pointer<BasicJsonType>& ptr)
const {
20587 return ptr.contains(
this);
20601 iterator begin() noexcept {
20602 iterator result(
this);
20603 result.set_begin();
20609 const_iterator begin() const noexcept {
return cbegin(); }
20613 const_iterator cbegin() const noexcept {
20614 const_iterator result(
this);
20615 result.set_begin();
20621 iterator end() noexcept {
20622 iterator result(
this);
20629 const_iterator end() const noexcept {
return cend(); }
20633 const_iterator cend() const noexcept {
20634 const_iterator result(
this);
20641 reverse_iterator rbegin() noexcept {
return reverse_iterator(end()); }
20645 const_reverse_iterator rbegin() const noexcept {
return crbegin(); }
20649 reverse_iterator rend() noexcept {
return reverse_iterator(begin()); }
20653 const_reverse_iterator rend() const noexcept {
return crend(); }
20657 const_reverse_iterator crbegin() const noexcept {
return const_reverse_iterator(cend()); }
20661 const_reverse_iterator crend() const noexcept {
return const_reverse_iterator(cbegin()); }
20669 JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
20670 static iteration_proxy<iterator> iterator_wrapper(reference ref) noexcept {
20671 return ref.items();
20679 JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
20680 static iteration_proxy<const_iterator> iterator_wrapper(const_reference ref) noexcept {
20681 return ref.items();
20686 iteration_proxy<iterator> items() noexcept {
return iteration_proxy<iterator>(*
this); }
20690 iteration_proxy<const_iterator> items() const noexcept {
20691 return iteration_proxy<const_iterator>(*
this);
20705 bool empty() const noexcept {
20706 switch (m_data.m_type) {
20707 case value_t::null: {
20712 case value_t::array: {
20714 return m_data.m_value.array->empty();
20717 case value_t::object: {
20719 return m_data.m_value.object->empty();
20722 case value_t::string:
20723 case value_t::boolean:
20724 case value_t::number_integer:
20725 case value_t::number_unsigned:
20726 case value_t::number_float:
20727 case value_t::binary:
20728 case value_t::discarded:
20738 size_type size() const noexcept {
20739 switch (m_data.m_type) {
20740 case value_t::null: {
20745 case value_t::array: {
20747 return m_data.m_value.array->size();
20750 case value_t::object: {
20752 return m_data.m_value.object->size();
20755 case value_t::string:
20756 case value_t::boolean:
20757 case value_t::number_integer:
20758 case value_t::number_unsigned:
20759 case value_t::number_float:
20760 case value_t::binary:
20761 case value_t::discarded:
20771 size_type max_size() const noexcept {
20772 switch (m_data.m_type) {
20773 case value_t::array: {
20775 return m_data.m_value.array->max_size();
20778 case value_t::object: {
20780 return m_data.m_value.object->max_size();
20783 case value_t::null:
20784 case value_t::string:
20785 case value_t::boolean:
20786 case value_t::number_integer:
20787 case value_t::number_unsigned:
20788 case value_t::number_float:
20789 case value_t::binary:
20790 case value_t::discarded:
20809 void clear() noexcept {
20810 switch (m_data.m_type) {
20811 case value_t::number_integer: {
20812 m_data.m_value.number_integer = 0;
20816 case value_t::number_unsigned: {
20817 m_data.m_value.number_unsigned = 0;
20821 case value_t::number_float: {
20822 m_data.m_value.number_float = 0.0;
20826 case value_t::boolean: {
20827 m_data.m_value.boolean =
false;
20831 case value_t::string: {
20832 m_data.m_value.string->clear();
20836 case value_t::binary: {
20837 m_data.m_value.binary->clear();
20841 case value_t::array: {
20842 m_data.m_value.array->clear();
20846 case value_t::object: {
20847 m_data.m_value.object->clear();
20851 case value_t::null:
20852 case value_t::discarded:
20860 void push_back(basic_json&& val) {
20862 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array()))) {
20863 JSON_THROW(type_error::create(
20864 308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
20869 m_data.m_type = value_t::array;
20870 m_data.m_value = value_t::array;
20871 assert_invariant();
20875 const auto old_capacity = m_data.m_value.array->capacity();
20876 m_data.m_value.array->push_back(std::move(val));
20877 set_parent(m_data.m_value.array->back(), old_capacity);
20894 JSON_THROW(type_error::create(
20895 308, detail::concat(
"cannot use push_back() with ",
type_name()),
this));
20900 m_data.m_type = value_t::array;
20901 m_data.m_value = value_t::array;
20902 assert_invariant();
20906 const auto old_capacity = m_data.m_value.array->capacity();
20907 m_data.m_value.array->push_back(val);
20908 set_parent(m_data.m_value.array->back(), old_capacity);
20923 JSON_THROW(type_error::create(
20924 308, detail::concat(
"cannot use push_back() with ",
type_name()),
this));
20929 m_data.m_type = value_t::object;
20930 m_data.m_value = value_t::object;
20931 assert_invariant();
20935 auto res = m_data.m_value.object->insert(val);
20936 set_parent(res.first->second);
20949 if (
is_object() && init.size() == 2 && (*init.begin())->is_string()) {
20952 (init.begin() + 1)->moved_or_copied()));
20970 JSON_THROW(type_error::create(
20971 311, detail::concat(
"cannot use emplace_back() with ",
type_name()),
this));
20976 m_data.m_type = value_t::array;
20977 m_data.m_value = value_t::array;
20978 assert_invariant();
20982 const auto old_capacity = m_data.
m_value.array->capacity();
20983 m_data.m_value.array->emplace_back(std::forward<Args>(args)...);
20984 return set_parent(m_data.m_value.array->back(), old_capacity);
20989 template <
class... Args> std::pair<iterator, bool>
emplace(Args&&... args) {
20992 JSON_THROW(type_error::create(
20993 311, detail::concat(
"cannot use emplace() with ",
type_name()),
this));
20998 m_data.m_type = value_t::object;
20999 m_data.m_value = value_t::object;
21000 assert_invariant();
21004 auto res = m_data.m_value.object->emplace(std::forward<Args>(args)...);
21005 set_parent(res.first->second);
21009 it.m_it.object_iterator = res.first;
21012 return {it, res.second};
21020 JSON_ASSERT(m_data.m_value.array !=
nullptr);
21022 auto insert_pos = std::distance(m_data.m_value.array->begin(), pos.m_it.array_iterator);
21023 m_data.m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
21024 result.m_it.array_iterator = m_data.m_value.array->begin() + insert_pos;
21040 if (JSON_HEDLEY_LIKELY(
is_array())) {
21042 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this)) {
21044 invalid_iterator::create(202,
"iterator does not fit current value",
this));
21051 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ",
type_name()),
21063 if (JSON_HEDLEY_LIKELY(
is_array())) {
21065 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this)) {
21067 invalid_iterator::create(202,
"iterator does not fit current value",
this));
21074 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ",
type_name()),
21082 if (JSON_HEDLEY_UNLIKELY(!
is_array())) {
21083 JSON_THROW(type_error::create(
21084 309, detail::concat(
"cannot use insert() with ",
type_name()),
this));
21088 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this)) {
21089 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
21093 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) {
21094 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
21097 if (JSON_HEDLEY_UNLIKELY(first.m_object ==
this)) {
21098 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container",
21103 return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
21110 if (JSON_HEDLEY_UNLIKELY(!
is_array())) {
21111 JSON_THROW(type_error::create(
21112 309, detail::concat(
"cannot use insert() with ",
type_name()),
this));
21116 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this)) {
21117 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
21128 if (JSON_HEDLEY_UNLIKELY(!
is_object())) {
21129 JSON_THROW(type_error::create(
21130 309, detail::concat(
"cannot use insert() with ",
type_name()),
this));
21134 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) {
21135 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
21139 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object())) {
21140 JSON_THROW(invalid_iterator::create(
21141 202,
"iterators first and last must point to objects",
this));
21144 m_data.m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
21151 update(j.begin(), j.end(), merge_objects);
21160 m_data.m_type = value_t::object;
21161 m_data.m_value.object = create<object_t>();
21162 assert_invariant();
21165 if (JSON_HEDLEY_UNLIKELY(!
is_object())) {
21166 JSON_THROW(type_error::create(
21167 312, detail::concat(
"cannot use update() with ",
type_name()),
this));
21171 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) {
21172 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
21176 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object())) {
21177 JSON_THROW(type_error::create(
21178 312, detail::concat(
"cannot use update() with ", first.m_object->type_name()),
21182 for (
auto it = first; it != last; ++it) {
21183 if (merge_objects && it.value().is_object()) {
21184 auto it2 = m_data.m_value.object->find(it.key());
21185 if (it2 != m_data.m_value.object->end()) {
21186 it2->second.update(it.value(),
true);
21190 m_data.m_value.object->operator[](it.key()) = it.value();
21191#if JSON_DIAGNOSTICS
21192 m_data.m_value.object->operator[](it.key()).m_parent =
this;
21200 std::is_nothrow_move_constructible<value_t>::value &&
21201 std::is_nothrow_move_assignable<value_t>::value &&
21202 std::is_nothrow_move_constructible<json_value>::
21204 std::is_nothrow_move_assignable<json_value>::value) {
21205 std::swap(m_data.m_type, other.m_data.m_type);
21206 std::swap(m_data.m_value, other.m_data.m_value);
21209 other.set_parents();
21210 assert_invariant();
21216 std::is_nothrow_move_constructible<value_t>::value &&
21217 std::is_nothrow_move_assignable<value_t>::value &&
21218 std::is_nothrow_move_constructible<json_value>::
21220 std::is_nothrow_move_assignable<json_value>::value) {
21231 if (JSON_HEDLEY_LIKELY(
is_array())) {
21233 swap(*(m_data.m_value.array), other);
21235 JSON_THROW(type_error::create(
21236 310, detail::concat(
"cannot use swap(array_t&) with ",
type_name()),
this));
21249 swap(*(m_data.m_value.object), other);
21251 JSON_THROW(type_error::create(
21252 310, detail::concat(
"cannot use swap(object_t&) with ",
type_name()),
this));
21265 swap(*(m_data.m_value.string), other);
21267 JSON_THROW(type_error::create(
21268 310, detail::concat(
"cannot use swap(string_t&) with ",
type_name()),
this));
21281 swap(*(m_data.m_value.binary), other);
21283 JSON_THROW(type_error::create(
21284 310, detail::concat(
"cannot use swap(binary_t&) with ",
type_name()),
this));
21290 void swap(
typename binary_t::container_type& other)
21295 swap(*(m_data.m_value.binary), other);
21297 JSON_THROW(type_error::create(
21299 detail::concat(
"cannot use swap(binary_t::container_type&) with ",
type_name()),
21315#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result) \
21316 const auto lhs_type = lhs.type(); \
21317 const auto rhs_type = rhs.type(); \
21319 if (lhs_type == rhs_type) \
21321 switch (lhs_type) { \
21322 case value_t::array: \
21323 return (*lhs.m_data.m_value.array)op(*rhs.m_data.m_value.array); \
21325 case value_t::object: \
21326 return (*lhs.m_data.m_value.object)op(*rhs.m_data.m_value.object); \
21328 case value_t::null: \
21329 return (null_result); \
21331 case value_t::string: \
21332 return (*lhs.m_data.m_value.string)op(*rhs.m_data.m_value.string); \
21334 case value_t::boolean: \
21335 return (lhs.m_data.m_value.boolean)op(rhs.m_data.m_value.boolean); \
21337 case value_t::number_integer: \
21338 return (lhs.m_data.m_value.number_integer)op(rhs.m_data.m_value.number_integer); \
21340 case value_t::number_unsigned: \
21341 return (lhs.m_data.m_value.number_unsigned)op(rhs.m_data.m_value.number_unsigned); \
21343 case value_t::number_float: \
21344 return (lhs.m_data.m_value.number_float)op(rhs.m_data.m_value.number_float); \
21346 case value_t::binary: \
21347 return (*lhs.m_data.m_value.binary)op(*rhs.m_data.m_value.binary); \
21349 case value_t::discarded: \
21351 return (unordered_result); \
21353 } else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) { \
21354 return static_cast<number_float_t>(lhs.m_data.m_value.number_integer) \
21355 op rhs.m_data.m_value.number_float; \
21356 } else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) { \
21357 return lhs.m_data.m_value.number_float op static_cast<number_float_t>( \
21358 rhs.m_data.m_value.number_integer); \
21359 } else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) { \
21360 return static_cast<number_float_t>(lhs.m_data.m_value.number_unsigned) \
21361 op rhs.m_data.m_value.number_float; \
21362 } else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) { \
21363 return lhs.m_data.m_value.number_float op static_cast<number_float_t>( \
21364 rhs.m_data.m_value.number_unsigned); \
21365 } else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) { \
21366 return static_cast<number_integer_t>(lhs.m_data.m_value.number_unsigned) \
21367 op rhs.m_data.m_value.number_integer; \
21368 } else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) { \
21369 return lhs.m_data.m_value.number_integer op static_cast<number_integer_t>( \
21370 rhs.m_data.m_value.number_unsigned); \
21371 } else if (compares_unordered(lhs, rhs)) { \
21372 return (unordered_result); \
21375 return (default_result);
21377 JSON_PRIVATE_UNLESS_TESTED :
21384 compares_unordered(const_reference lhs, const_reference rhs,
21385 bool inverse =
false) noexcept {
21386 if ((lhs.is_number_float() && std::isnan(lhs.m_data.m_value.number_float) &&
21387 rhs.is_number()) ||
21388 (rhs.is_number_float() && std::isnan(rhs.m_data.m_value.number_float) &&
21389 lhs.is_number())) {
21392#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
21393 return (lhs.is_discarded() || rhs.is_discarded()) && !inverse;
21395 static_cast<void>(inverse);
21396 return lhs.is_discarded() || rhs.is_discarded();
21401 bool compares_unordered(const_reference rhs,
bool inverse =
false) const noexcept {
21402 return compares_unordered(*
this, rhs, inverse);
21406#if JSON_HAS_THREE_WAY_COMPARISON
21409 bool operator==(const_reference rhs)
const noexcept {
21411#pragma GCC diagnostic push
21412#pragma GCC diagnostic ignored "-Wfloat-equal"
21414 const_reference lhs = *
this;
21415 JSON_IMPLEMENT_OPERATOR(==,
true,
false,
false)
21417#pragma GCC diagnostic pop
21423 template <
typename ScalarType>
21424 requires std::is_scalar_v<ScalarType>
21425 bool operator==(ScalarType rhs)
const noexcept {
21426 return *
this == basic_json(rhs);
21431 bool operator!=(const_reference rhs)
const noexcept {
21432 if (compares_unordered(rhs,
true)) {
21435 return !operator==(rhs);
21440 std::partial_ordering operator<=>(const_reference rhs)
const noexcept
21442 const_reference lhs = *
this;
21445 JSON_IMPLEMENT_OPERATOR(<=>,
21446 std::partial_ordering::equivalent, std::partial_ordering::unordered,
21447 lhs_type <=> rhs_type)
21452 template <
typename ScalarType>
21453 requires std::is_scalar_v<ScalarType>
21454 std::partial_ordering operator<=>(ScalarType rhs)
const noexcept
21456 return *this <=> basic_json(rhs);
21459#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
21465 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON)
21466 bool operator<=(const_reference rhs)
const noexcept {
21467 if (compares_unordered(rhs,
true)) {
21470 return !(rhs < *
this);
21475 template <
typename ScalarType>
21476 requires std::is_scalar_v<ScalarType>
21477 bool operator<=(ScalarType rhs)
const noexcept {
21478 return *
this <= basic_json(rhs);
21483 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON)
21484 bool operator>=(const_reference rhs)
const noexcept {
21485 if (compares_unordered(rhs,
true)) {
21488 return !(*
this < rhs);
21493 template <
typename ScalarType>
21494 requires std::is_scalar_v<ScalarType>
21495 bool operator>=(ScalarType rhs)
const noexcept {
21496 return *
this >= basic_json(rhs);
21502 friend bool operator==(const_reference lhs, const_reference rhs)
noexcept {
21504#pragma GCC diagnostic push
21505#pragma GCC diagnostic ignored "-Wfloat-equal"
21507 JSON_IMPLEMENT_OPERATOR(==,
true,
false,
false)
21509#pragma GCC diagnostic pop
21515 template <
typename ScalarType,
21516 typename std::enable_if<std::is_scalar<ScalarType>::value,
int>::type = 0>
21517 friend bool operator==(const_reference lhs, ScalarType rhs)
noexcept {
21518 return lhs == basic_json(rhs);
21523 template <
typename ScalarType,
21524 typename std::enable_if<std::is_scalar<ScalarType>::value,
int>::type = 0>
21525 friend bool operator==(ScalarType lhs, const_reference rhs)
noexcept {
21526 return basic_json(lhs) == rhs;
21531 friend bool operator!=(const_reference lhs, const_reference rhs)
noexcept {
21532 if (compares_unordered(lhs, rhs,
true)) {
21535 return !(lhs == rhs);
21540 template <
typename ScalarType,
21541 typename std::enable_if<std::is_scalar<ScalarType>::value,
int>::type = 0>
21542 friend bool operator!=(const_reference lhs, ScalarType rhs)
noexcept {
21543 return lhs != basic_json(rhs);
21548 template <
typename ScalarType,
21549 typename std::enable_if<std::is_scalar<ScalarType>::value,
int>::type = 0>
21550 friend bool operator!=(ScalarType lhs, const_reference rhs)
noexcept {
21551 return basic_json(lhs) != rhs;
21556 friend bool operator<(const_reference lhs, const_reference rhs)
noexcept {
21560 JSON_IMPLEMENT_OPERATOR(<,
false,
false,
operator<(lhs_type, rhs_type))
21565 template <
typename ScalarType,
21566 typename std::enable_if<std::is_scalar<ScalarType>::value,
int>::type = 0>
21567 friend bool operator<(const_reference lhs, ScalarType rhs)
noexcept {
21568 return lhs < basic_json(rhs);
21573 template <
typename ScalarType,
21574 typename std::enable_if<std::is_scalar<ScalarType>::value,
int>::type = 0>
21575 friend bool operator<(ScalarType lhs, const_reference rhs)
noexcept {
21576 return basic_json(lhs) < rhs;
21581 friend bool operator<=(const_reference lhs, const_reference rhs)
noexcept {
21582 if (compares_unordered(lhs, rhs,
true)) {
21585 return !(rhs < lhs);
21590 template <
typename ScalarType,
21591 typename std::enable_if<std::is_scalar<ScalarType>::value,
int>::type = 0>
21592 friend bool operator<=(const_reference lhs, ScalarType rhs)
noexcept {
21593 return lhs <= basic_json(rhs);
21598 template <
typename ScalarType,
21599 typename std::enable_if<std::is_scalar<ScalarType>::value,
int>::type = 0>
21600 friend bool operator<=(ScalarType lhs, const_reference rhs)
noexcept {
21601 return basic_json(lhs) <= rhs;
21606 friend bool operator>(const_reference lhs, const_reference rhs)
noexcept {
21608 if (compares_unordered(lhs, rhs)) {
21611 return !(lhs <= rhs);
21616 template <
typename ScalarType,
21617 typename std::enable_if<std::is_scalar<ScalarType>::value,
int>::type = 0>
21618 friend bool operator>(const_reference lhs, ScalarType rhs)
noexcept {
21619 return lhs > basic_json(rhs);
21624 template <
typename ScalarType,
21625 typename std::enable_if<std::is_scalar<ScalarType>::value,
int>::type = 0>
21626 friend bool operator>(ScalarType lhs, const_reference rhs)
noexcept {
21627 return basic_json(lhs) > rhs;
21632 friend bool operator>=(const_reference lhs, const_reference rhs)
noexcept {
21633 if (compares_unordered(lhs, rhs,
true)) {
21636 return !(lhs < rhs);
21641 template <
typename ScalarType,
21642 typename std::enable_if<std::is_scalar<ScalarType>::value,
int>::type = 0>
21643 friend bool operator>=(const_reference lhs, ScalarType rhs)
noexcept {
21644 return lhs >= basic_json(rhs);
21649 template <
typename ScalarType,
21650 typename std::enable_if<std::is_scalar<ScalarType>::value,
int>::type = 0>
21651 friend bool operator>=(ScalarType lhs, const_reference rhs)
noexcept {
21652 return basic_json(lhs) >= rhs;
21656#undef JSON_IMPLEMENT_OPERATOR
21669 friend std::ostream& operator<<(std::ostream& o,
const basic_json& j) {
21671 const bool pretty_print = o.width() > 0;
21672 const auto indentation = pretty_print ? o.width() : 0;
21678 serializer s(detail::output_adapter<char>(o), o.fill());
21679 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
21689 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator<<(std::ostream&,
const basic_json&))
21690 friend std::ostream& operator>>(
const basic_json& j, std::ostream& o) {
return o << j; }
21703 template <
typename InputType>
21704 JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json
21705 parse(InputType&& i,
const parser_callback_t cb =
nullptr,
const bool allow_exceptions =
true,
21706 const bool ignore_comments =
false) {
21708 parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions,
21710 .parse(
true, result);
21716 template <
typename IteratorType>
21717 JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json
21718 parse(IteratorType first, IteratorType last,
const parser_callback_t cb =
nullptr,
21719 const bool allow_exceptions =
true,
const bool ignore_comments =
false) {
21721 parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions,
21723 .parse(
true, result);
21727 JSON_HEDLEY_WARN_UNUSED_RESULT
21728 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len))
21729 static basic_json parse(detail::span_input_adapter&& i,
const parser_callback_t cb =
nullptr,
21730 const bool allow_exceptions =
true,
21731 const bool ignore_comments =
false) {
21733 parser(i.get(), cb, allow_exceptions, ignore_comments).parse(
true, result);
21739 template <
typename InputType>
21740 static bool accept(InputType&& i,
const bool ignore_comments =
false) {
21741 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false,
21748 template <
typename IteratorType>
21749 static bool accept(IteratorType first, IteratorType last,
const bool ignore_comments =
false) {
21750 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false,
21755 JSON_HEDLEY_WARN_UNUSED_RESULT
21756 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len))
21757 static bool accept(detail::span_input_adapter&& i,
const bool ignore_comments =
false) {
21758 return parser(i.get(),
nullptr,
false, ignore_comments).accept(
true);
21763 template <
typename InputType,
typename SAX>
21764 JSON_HEDLEY_NON_NULL(2)
21765 static
bool sax_parse(InputType&& i, SAX* sax, input_format_t format = input_format_t::json,
21766 const
bool strict = true, const
bool ignore_comments = false) {
21767 auto ia = detail::input_adapter(std::forward<InputType>(i));
21768 return format == input_format_t::json
21769 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
21770 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format)
21771 .sax_parse(format, sax, strict);
21776 template <
class IteratorType,
class SAX>
21777 JSON_HEDLEY_NON_NULL(3)
21778 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
21779 input_format_t format = input_format_t::json, const
bool strict = true,
21780 const
bool ignore_comments = false) {
21781 auto ia = detail::input_adapter(std::move(first), std::move(last));
21782 return format == input_format_t::json
21783 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
21793 template <
typename SAX>
21794 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, sax_parse(ptr, ptr + len, ...))
21796 input_format_t format = input_format_t::json,
21797 const
bool strict = true,
21798 const
bool ignore_comments = false) {
21800 return format == input_format_t::json
21802 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
21815 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator>>(std::istream&,
basic_json&))
21821 parser(detail::input_adapter(i)).parse(
false, j);
21833 JSON_HEDLEY_RETURNS_NON_NULL
21835 switch (m_data.m_type) {
21836 case value_t::null:
21838 case value_t::object:
21840 case value_t::array:
21842 case value_t::string:
21844 case value_t::boolean:
21846 case value_t::binary:
21848 case value_t::discarded:
21849 return "discarded";
21850 case value_t::number_integer:
21851 case value_t::number_unsigned:
21852 case value_t::number_float:
21858 JSON_PRIVATE_UNLESS_TESTED :
21865 value_t m_type = value_t::null;
21870 data(
const value_t v) : m_type(v), m_value(v) {}
21872 data(size_type cnt,
const basic_json& val) : m_type(
value_t::
array) {
21873 m_value.array = create<array_t>(cnt, val);
21876 data() noexcept = default;
21877 data(data&&) noexcept = default;
21878 data(const data&) noexcept = delete;
21879 data& operator=(data&&) noexcept = delete;
21880 data& operator=(const data&) noexcept = delete;
21882 ~data() noexcept { m_value.destroy(m_type); }
21887#if JSON_DIAGNOSTICS
21889 basic_json* m_parent =
nullptr;
21903 std::vector<std::uint8_t> result;
21911 binary_writer<std::uint8_t>(o).write_cbor(j);
21917 binary_writer<char>(o).write_cbor(j);
21923 std::vector<std::uint8_t> result;
21931 binary_writer<std::uint8_t>(o).write_msgpack(j);
21937 binary_writer<char>(o).write_msgpack(j);
21943 const bool use_type =
false) {
21944 std::vector<std::uint8_t> result;
21945 to_ubjson(j, result, use_size, use_type);
21952 const bool use_size =
false,
const bool use_type =
false) {
21953 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);
21959 const bool use_size =
false,
const bool use_type =
false) {
21960 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
21966 const bool use_type =
false) {
21967 std::vector<std::uint8_t> result;
21968 to_bjdata(j, result, use_size, use_type);
21975 const bool use_size =
false,
const bool use_type =
false) {
21976 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type,
true,
true);
21982 const bool use_size =
false,
const bool use_type =
false) {
21983 binary_writer<char>(o).write_ubjson(j, use_size, use_type,
true,
true);
21989 std::vector<std::uint8_t> result;
21997 binary_writer<std::uint8_t>(o).write_bson(j);
22003 binary_writer<char>(o).write_bson(j);
22008 template <
typename InputType>
22009 JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json
22010 from_cbor(InputType&& i,
const bool strict =
true,
const bool allow_exceptions =
true,
22014 auto ia = detail::input_adapter(std::forward<InputType>(i));
22015 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor)
22016 .sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
22017 return res ? result :
basic_json(value_t::discarded);
22022 template <
typename IteratorType>
22023 JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json
22024 from_cbor(IteratorType first, IteratorType last,
const bool strict =
true,
22025 const bool allow_exceptions =
true,
22029 auto ia = detail::input_adapter(std::move(first), std::move(last));
22030 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor)
22031 .sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
22032 return res ? result :
basic_json(value_t::discarded);
22035 template <
typename T>
22036 JSON_HEDLEY_WARN_UNUSED_RESULT
22037 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
static basic_json
22038 from_cbor(
const T* ptr, std::size_t len,
const bool strict =
true,
22039 const bool allow_exceptions =
true,
22040 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) {
22041 return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
22044 JSON_HEDLEY_WARN_UNUSED_RESULT
22045 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
22046 static basic_json from_cbor(detail::span_input_adapter&& i,
const bool strict =
true,
22047 const bool allow_exceptions =
true,
22048 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) {
22050 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
22053 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor)
22054 .sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
22055 return res ? result : basic_json(value_t::discarded);
22060 template <
typename InputType>
22061 JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json
22062 from_msgpack(InputType&& i,
const bool strict =
true,
const bool allow_exceptions =
true) {
22064 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
22065 auto ia = detail::input_adapter(std::forward<InputType>(i));
22066 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack)
22067 .sax_parse(input_format_t::msgpack, &sdp, strict);
22068 return res ? result : basic_json(value_t::discarded);
22073 template <
typename IteratorType>
22074 JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json
22075 from_msgpack(IteratorType first, IteratorType last,
const bool strict =
true,
22076 const bool allow_exceptions =
true) {
22078 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
22079 auto ia = detail::input_adapter(std::move(first), std::move(last));
22080 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack)
22081 .sax_parse(input_format_t::msgpack, &sdp, strict);
22082 return res ? result : basic_json(value_t::discarded);
22085 template <
typename T>
22086 JSON_HEDLEY_WARN_UNUSED_RESULT
22087 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
static basic_json
22088 from_msgpack(
const T* ptr, std::size_t len,
const bool strict =
true,
22089 const bool allow_exceptions =
true) {
22090 return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
22093 JSON_HEDLEY_WARN_UNUSED_RESULT
22094 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
22095 static basic_json from_msgpack(detail::span_input_adapter&& i,
const bool strict =
true,
22096 const bool allow_exceptions =
true) {
22098 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
22101 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack)
22102 .sax_parse(input_format_t::msgpack, &sdp, strict);
22103 return res ? result : basic_json(value_t::discarded);
22108 template <
typename InputType>
22109 JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json
22110 from_ubjson(InputType&& i,
const bool strict =
true,
const bool allow_exceptions =
true) {
22112 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
22113 auto ia = detail::input_adapter(std::forward<InputType>(i));
22114 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson)
22115 .sax_parse(input_format_t::ubjson, &sdp, strict);
22116 return res ? result : basic_json(value_t::discarded);
22121 template <
typename IteratorType>
22122 JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json
22123 from_ubjson(IteratorType first, IteratorType last,
const bool strict =
true,
22124 const bool allow_exceptions =
true) {
22126 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
22127 auto ia = detail::input_adapter(std::move(first), std::move(last));
22128 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson)
22129 .sax_parse(input_format_t::ubjson, &sdp, strict);
22130 return res ? result : basic_json(value_t::discarded);
22133 template <
typename T>
22134 JSON_HEDLEY_WARN_UNUSED_RESULT
22135 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
static basic_json
22136 from_ubjson(
const T* ptr, std::size_t len,
const bool strict =
true,
22137 const bool allow_exceptions =
true) {
22138 return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
22141 JSON_HEDLEY_WARN_UNUSED_RESULT
22142 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
22143 static basic_json from_ubjson(detail::span_input_adapter&& i,
const bool strict =
true,
22144 const bool allow_exceptions =
true) {
22146 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
22149 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson)
22150 .sax_parse(input_format_t::ubjson, &sdp, strict);
22151 return res ? result : basic_json(value_t::discarded);
22156 template <
typename InputType>
22157 JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json
22158 from_bjdata(InputType&& i,
const bool strict =
true,
const bool allow_exceptions =
true) {
22160 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
22161 auto ia = detail::input_adapter(std::forward<InputType>(i));
22162 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata)
22163 .sax_parse(input_format_t::bjdata, &sdp, strict);
22164 return res ? result : basic_json(value_t::discarded);
22169 template <
typename IteratorType>
22170 JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json
22171 from_bjdata(IteratorType first, IteratorType last,
const bool strict =
true,
22172 const bool allow_exceptions =
true) {
22174 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
22175 auto ia = detail::input_adapter(std::move(first), std::move(last));
22176 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata)
22177 .sax_parse(input_format_t::bjdata, &sdp, strict);
22178 return res ? result : basic_json(value_t::discarded);
22183 template <
typename InputType>
22184 JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json
22185 from_bson(InputType&& i,
const bool strict =
true,
const bool allow_exceptions =
true) {
22187 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
22188 auto ia = detail::input_adapter(std::forward<InputType>(i));
22189 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson)
22190 .sax_parse(input_format_t::bson, &sdp, strict);
22191 return res ? result : basic_json(value_t::discarded);
22196 template <
typename IteratorType>
22197 JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json
22198 from_bson(IteratorType first, IteratorType last,
const bool strict =
true,
22199 const bool allow_exceptions =
true) {
22201 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
22202 auto ia = detail::input_adapter(std::move(first), std::move(last));
22203 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson)
22204 .sax_parse(input_format_t::bson, &sdp, strict);
22205 return res ? result : basic_json(value_t::discarded);
22208 template <
typename T>
22209 JSON_HEDLEY_WARN_UNUSED_RESULT
22210 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
static basic_json
22211 from_bson(
const T* ptr, std::size_t len,
const bool strict =
true,
22212 const bool allow_exceptions =
true) {
22213 return from_bson(ptr, ptr + len, strict, allow_exceptions);
22216 JSON_HEDLEY_WARN_UNUSED_RESULT
22217 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
22218 static basic_json from_bson(detail::span_input_adapter&& i,
const bool strict =
true,
22219 const bool allow_exceptions =
true) {
22221 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
22224 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson)
22225 .sax_parse(input_format_t::bson, &sdp, strict);
22226 return res ? result : basic_json(value_t::discarded);
22239 reference operator[](
const json_pointer& ptr) {
return ptr.get_unchecked(
this); }
22241 template <
typename BasicJsonType,
22242 detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
22243 JSON_HEDLEY_DEPRECATED_FOR(
22245 nlohmann::json_pointer<basic_json::string_t>)
22247 operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr) {
22248 return ptr.get_unchecked(
this);
22253 const_reference operator[](
const json_pointer& ptr)
const {
return ptr.get_unchecked(
this); }
22255 template <
typename BasicJsonType,
22256 detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
22257 JSON_HEDLEY_DEPRECATED_FOR(
22259 nlohmann::json_pointer<basic_json::string_t>)
22261 operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr)
const {
22262 return ptr.get_unchecked(
this);
22267 reference at(
const json_pointer& ptr) {
return ptr.get_checked(
this); }
22269 template <
typename BasicJsonType,
22270 detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
22271 JSON_HEDLEY_DEPRECATED_FOR(
22273 nlohmann::json_pointer<basic_json::string_t>)
22274 reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr) {
22275 return ptr.get_checked(
this);
22280 const_reference at(
const json_pointer& ptr)
const {
return ptr.get_checked(
this); }
22282 template <
typename BasicJsonType,
22283 detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
22284 JSON_HEDLEY_DEPRECATED_FOR(
22286 nlohmann::json_pointer<basic_json::string_t>)
22287 const_reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr)
const {
22288 return ptr.get_checked(
this);
22293 basic_json flatten()
const {
22294 basic_json result(value_t::object);
22295 json_pointer::flatten(
"", *
this, result);
22301 basic_json unflatten()
const {
return json_pointer::unflatten(*
this); }
22314 void patch_inplace(
const basic_json& json_patch) {
22315 basic_json& result = *
this;
22317 enum class patch_operations { add, remove,
replace, move, copy, test, invalid };
22319 const auto get_op = [](
const std::string& op) {
22321 return patch_operations::add;
22323 if (op ==
"remove") {
22324 return patch_operations::remove;
22326 if (op ==
"replace") {
22327 return patch_operations::replace;
22329 if (op ==
"move") {
22330 return patch_operations::move;
22332 if (op ==
"copy") {
22333 return patch_operations::copy;
22335 if (op ==
"test") {
22336 return patch_operations::test;
22339 return patch_operations::invalid;
22343 const auto operation_add = [&result](json_pointer& ptr, basic_json val) {
22351 json_pointer
const top_pointer = ptr.top();
22352 if (top_pointer != ptr) {
22353 result.
at(top_pointer);
22357 const auto last_path = ptr.
back();
22360 basic_json& parent = result.
at(ptr);
22362 switch (parent.m_data.m_type) {
22363 case value_t::null:
22364 case value_t::object: {
22366 parent[last_path] = val;
22370 case value_t::array: {
22371 if (last_path ==
"-") {
22376 json_pointer::template array_index<basic_json_t>(last_path);
22377 if (JSON_HEDLEY_UNLIKELY(idx > parent.size())) {
22379 JSON_THROW(out_of_range::create(401,
22380 detail::concat(
"array index ",
22381 std::to_string(idx),
22382 " is out of range"),
22387 parent.
insert(parent.begin() +
static_cast<difference_type
>(idx), val);
22393 case value_t::string:
22394 case value_t::boolean:
22395 case value_t::number_integer:
22396 case value_t::number_unsigned:
22397 case value_t::number_float:
22398 case value_t::binary:
22399 case value_t::discarded:
22408 const auto operation_remove = [
this, &result](json_pointer& ptr) {
22410 const auto last_path = ptr.
back();
22412 basic_json& parent = result.
at(ptr);
22417 auto it = parent.
find(last_path);
22418 if (JSON_HEDLEY_LIKELY(it != parent.end())) {
22421 JSON_THROW(out_of_range::create(
22422 403, detail::concat(
"key '", last_path,
"' not found"),
this));
22426 parent.
erase(json_pointer::template array_index<basic_json_t>(last_path));
22431 if (JSON_HEDLEY_UNLIKELY(!json_patch.
is_array())) {
22433 parse_error::create(104, 0,
"JSON patch must be an array of objects", &json_patch));
22437 for (
const auto& val : json_patch) {
22439 const auto get_value = [&val](
const std::string& op,
const std::string& member,
22440 bool string_type) -> basic_json& {
22442 auto it = val.m_data.m_value.object->find(member);
22445 const auto error_msg =
22446 (op ==
"op") ?
"operation"
22452 if (JSON_HEDLEY_UNLIKELY(it == val.m_data.m_value.object->end())) {
22454 JSON_THROW(parse_error::create(
22455 105, 0, detail::concat(error_msg,
" must have member '", member,
"'"),
22460 if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string())) {
22462 JSON_THROW(parse_error::create(
22464 detail::concat(error_msg,
" must have string member '", member,
"'"),
22473 if (JSON_HEDLEY_UNLIKELY(!val.is_object())) {
22475 parse_error::create(104, 0,
"JSON patch must be an array of objects", &val));
22479 const auto op = get_value(
"op",
"op",
true).template get<std::string>();
22480 const auto path = get_value(op,
"path",
true).template get<std::string>();
22481 json_pointer ptr(path);
22483 switch (get_op(op)) {
22484 case patch_operations::add: {
22485 operation_add(ptr, get_value(
"add",
"value",
false));
22489 case patch_operations::remove: {
22490 operation_remove(ptr);
22494 case patch_operations::replace: {
22496 result.
at(ptr) = get_value(
"replace",
"value",
false);
22500 case patch_operations::move: {
22501 const auto from_path =
22502 get_value(
"move",
"from",
true).template get<std::string>();
22503 json_pointer from_ptr(from_path);
22506 basic_json
const v = result.
at(from_ptr);
22512 operation_remove(from_ptr);
22513 operation_add(ptr, v);
22517 case patch_operations::copy: {
22518 const auto from_path =
22519 get_value(
"copy",
"from",
true).template get<std::string>();
22520 const json_pointer from_ptr(from_path);
22523 basic_json
const v = result.
at(from_ptr);
22528 operation_add(ptr, v);
22532 case patch_operations::test: {
22533 bool success =
false;
22537 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
22539 JSON_INTERNAL_CATCH(out_of_range&) {
22544 if (JSON_HEDLEY_UNLIKELY(!success)) {
22545 JSON_THROW(other_error::create(
22546 501, detail::concat(
"unsuccessful: ", val.dump()), &val));
22552 case patch_operations::invalid:
22556 JSON_THROW(parse_error::create(
22557 105, 0, detail::concat(
"operation value '", op,
"' is invalid"), &val));
22565 basic_json patch(
const basic_json& json_patch)
const {
22566 basic_json result = *
this;
22567 result.patch_inplace(json_patch);
22573 JSON_HEDLEY_WARN_UNUSED_RESULT
22574 static basic_json diff(
const basic_json& source,
const basic_json& target,
22575 const std::string& path =
"") {
22577 basic_json result(value_t::array);
22580 if (source == target) {
22584 if (source.
type() != target.
type()) {
22586 result.
push_back({{
"op",
"replace"}, {
"path", path}, {
"value", target}});
22590 switch (source.
type()) {
22591 case value_t::array: {
22594 while (i < source.size() && i < target.size()) {
22597 diff(source[i], target[i], detail::concat(path,
'/', std::to_string(i)));
22598 result.
insert(result.end(), temp_diff.begin(), temp_diff.end());
22606 const auto end_index =
static_cast<difference_type
>(result.size());
22607 while (i < source.size()) {
22610 result.
insert(result.begin() + end_index,
22611 object({{
"op",
"remove"},
22612 {
"path", detail::concat(path,
'/', std::to_string(i))}}));
22617 while (i < target.size()) {
22619 {
"path", detail::concat(path,
"/-")},
22620 {
"value", target[i]}});
22627 case value_t::object: {
22629 for (
auto it = source.cbegin(); it != source.cend(); ++it) {
22631 const auto path_key = detail::concat(path,
'/',
detail::escape(it.key()));
22633 if (target.
find(it.key()) != target.end()) {
22635 auto temp_diff = diff(it.value(), target[it.key()], path_key);
22636 result.
insert(result.end(), temp_diff.begin(), temp_diff.end());
22639 result.
push_back(
object({{
"op",
"remove"}, {
"path", path_key}}));
22644 for (
auto it = target.cbegin(); it != target.cend(); ++it) {
22645 if (source.
find(it.key()) == source.end()) {
22647 const auto path_key = detail::concat(path,
'/',
detail::escape(it.key()));
22649 {{
"op",
"add"}, {
"path", path_key}, {
"value", it.value()}});
22656 case value_t::null:
22657 case value_t::string:
22658 case value_t::boolean:
22659 case value_t::number_integer:
22660 case value_t::number_unsigned:
22661 case value_t::number_float:
22662 case value_t::binary:
22663 case value_t::discarded:
22666 result.
push_back({{
"op",
"replace"}, {
"path", path}, {
"value", target}});
22684 void merge_patch(
const basic_json& apply_patch) {
22686 if (!is_object()) {
22689 for (
auto it = apply_patch.begin(); it != apply_patch.end(); ++it) {
22690 if (it.value().is_null()) {
22693 operator[](it.key()).merge_patch(it.value());
22697 *
this = apply_patch;
22706NLOHMANN_BASIC_JSON_TPL_DECLARATION
22707std::string to_string(
const NLOHMANN_BASIC_JSON_TPL& j) {
22711inline namespace literals {
22712inline namespace json_literals {
22716JSON_HEDLEY_NON_NULL(1)
22717#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0)
22718inline nlohmann::json
operator""_json(
const char* s, std::size_t n)
22720inline nlohmann::json
operator"" _json(
const char* s, std::size_t n)
22723 return nlohmann::json::parse(s, s + n);
22728JSON_HEDLEY_NON_NULL(1)
22729#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0)
22730inline nlohmann::json::json_pointer
operator""_json_pointer(
const char* s, std::size_t n)
22732inline nlohmann::json::json_pointer
operator"" _json_pointer(
const char* s, std::size_t n)
22735 return nlohmann::json::json_pointer(std::string(s, n));
22740NLOHMANN_JSON_NAMESPACE_END
22751NLOHMANN_BASIC_JSON_TPL_DECLARATION
22752struct hash<nlohmann::NLOHMANN_BASIC_JSON_TPL>
22754 std::size_t operator()(
const nlohmann::NLOHMANN_BASIC_JSON_TPL& j)
const {
22755 return nlohmann::detail::hash(j);
22761struct less<::nlohmann::detail::value_t>
22769 ::nlohmann::detail::value_t rhs)
const noexcept {
22770#if JSON_HAS_THREE_WAY_COMPARISON
22771 return std::is_lt(lhs <=> rhs);
22773 return ::nlohmann::detail::operator<(lhs, rhs);
22779#ifndef JSON_HAS_CPP_20
22783NLOHMANN_BASIC_JSON_TPL_DECLARATION
22784inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1,
22785 nlohmann::NLOHMANN_BASIC_JSON_TPL&
22788 is_nothrow_move_constructible<nlohmann::NLOHMANN_BASIC_JSON_TPL>::
22790 is_nothrow_move_assignable<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value) {
22798#if JSON_USE_GLOBAL_UDLS
22799#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4, 9, 0)
22800using nlohmann::literals::json_literals::
22802using nlohmann::literals::json_literals::
22803operator
""_json_pointer;
22805using nlohmann::literals::json_literals::
22807using nlohmann::literals::json_literals::
22808operator
"" _json_pointer;
22822#if defined(__clang__)
22823#pragma clang diagnostic pop
22828#undef JSON_INTERNAL_CATCH
22830#undef JSON_PRIVATE_UNLESS_TESTED
22831#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
22832#undef NLOHMANN_BASIC_JSON_TPL
22833#undef JSON_EXPLICIT
22834#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
22835#undef JSON_INLINE_VARIABLE
22836#undef JSON_NO_UNIQUE_ADDRESS
22837#undef JSON_DISABLE_ENUM_SERIALIZATION
22838#undef JSON_USE_GLOBAL_UDLS
22840#ifndef JSON_TEST_KEEP_MACROS
22843#undef JSON_HAS_CPP_11
22844#undef JSON_HAS_CPP_14
22845#undef JSON_HAS_CPP_17
22846#undef JSON_HAS_CPP_20
22847#undef JSON_HAS_FILESYSTEM
22848#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
22849#undef JSON_HAS_THREE_WAY_COMPARISON
22850#undef JSON_HAS_RANGES
22851#undef JSON_HAS_STATIC_RTTI
22852#undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
22864#undef JSON_HEDLEY_ALWAYS_INLINE
22865#undef JSON_HEDLEY_ARM_VERSION
22866#undef JSON_HEDLEY_ARM_VERSION_CHECK
22867#undef JSON_HEDLEY_ARRAY_PARAM
22868#undef JSON_HEDLEY_ASSUME
22869#undef JSON_HEDLEY_BEGIN_C_DECLS
22870#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
22871#undef JSON_HEDLEY_CLANG_HAS_BUILTIN
22872#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
22873#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
22874#undef JSON_HEDLEY_CLANG_HAS_EXTENSION
22875#undef JSON_HEDLEY_CLANG_HAS_FEATURE
22876#undef JSON_HEDLEY_CLANG_HAS_WARNING
22877#undef JSON_HEDLEY_COMPCERT_VERSION
22878#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
22879#undef JSON_HEDLEY_CONCAT
22880#undef JSON_HEDLEY_CONCAT3
22881#undef JSON_HEDLEY_CONCAT3_EX
22882#undef JSON_HEDLEY_CONCAT_EX
22883#undef JSON_HEDLEY_CONST
22884#undef JSON_HEDLEY_CONSTEXPR
22885#undef JSON_HEDLEY_CONST_CAST
22886#undef JSON_HEDLEY_CPP_CAST
22887#undef JSON_HEDLEY_CRAY_VERSION
22888#undef JSON_HEDLEY_CRAY_VERSION_CHECK
22889#undef JSON_HEDLEY_C_DECL
22890#undef JSON_HEDLEY_DEPRECATED
22891#undef JSON_HEDLEY_DEPRECATED_FOR
22892#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
22893#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
22894#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
22895#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
22896#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
22897#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
22898#undef JSON_HEDLEY_DIAGNOSTIC_POP
22899#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
22900#undef JSON_HEDLEY_DMC_VERSION
22901#undef JSON_HEDLEY_DMC_VERSION_CHECK
22902#undef JSON_HEDLEY_EMPTY_BASES
22903#undef JSON_HEDLEY_EMSCRIPTEN_VERSION
22904#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
22905#undef JSON_HEDLEY_END_C_DECLS
22906#undef JSON_HEDLEY_FLAGS
22907#undef JSON_HEDLEY_FLAGS_CAST
22908#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
22909#undef JSON_HEDLEY_GCC_HAS_BUILTIN
22910#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
22911#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
22912#undef JSON_HEDLEY_GCC_HAS_EXTENSION
22913#undef JSON_HEDLEY_GCC_HAS_FEATURE
22914#undef JSON_HEDLEY_GCC_HAS_WARNING
22915#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
22916#undef JSON_HEDLEY_GCC_VERSION
22917#undef JSON_HEDLEY_GCC_VERSION_CHECK
22918#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
22919#undef JSON_HEDLEY_GNUC_HAS_BUILTIN
22920#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
22921#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
22922#undef JSON_HEDLEY_GNUC_HAS_EXTENSION
22923#undef JSON_HEDLEY_GNUC_HAS_FEATURE
22924#undef JSON_HEDLEY_GNUC_HAS_WARNING
22925#undef JSON_HEDLEY_GNUC_VERSION
22926#undef JSON_HEDLEY_GNUC_VERSION_CHECK
22927#undef JSON_HEDLEY_HAS_ATTRIBUTE
22928#undef JSON_HEDLEY_HAS_BUILTIN
22929#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
22930#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
22931#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
22932#undef JSON_HEDLEY_HAS_EXTENSION
22933#undef JSON_HEDLEY_HAS_FEATURE
22934#undef JSON_HEDLEY_HAS_WARNING
22935#undef JSON_HEDLEY_IAR_VERSION
22936#undef JSON_HEDLEY_IAR_VERSION_CHECK
22937#undef JSON_HEDLEY_IBM_VERSION
22938#undef JSON_HEDLEY_IBM_VERSION_CHECK
22939#undef JSON_HEDLEY_IMPORT
22940#undef JSON_HEDLEY_INLINE
22941#undef JSON_HEDLEY_INTEL_CL_VERSION
22942#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
22943#undef JSON_HEDLEY_INTEL_VERSION
22944#undef JSON_HEDLEY_INTEL_VERSION_CHECK
22945#undef JSON_HEDLEY_IS_CONSTANT
22946#undef JSON_HEDLEY_IS_CONSTEXPR_
22947#undef JSON_HEDLEY_LIKELY
22948#undef JSON_HEDLEY_MALLOC
22949#undef JSON_HEDLEY_MCST_LCC_VERSION
22950#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
22951#undef JSON_HEDLEY_MESSAGE
22952#undef JSON_HEDLEY_MSVC_VERSION
22953#undef JSON_HEDLEY_MSVC_VERSION_CHECK
22954#undef JSON_HEDLEY_NEVER_INLINE
22955#undef JSON_HEDLEY_NON_NULL
22956#undef JSON_HEDLEY_NO_ESCAPE
22957#undef JSON_HEDLEY_NO_RETURN
22958#undef JSON_HEDLEY_NO_THROW
22959#undef JSON_HEDLEY_NULL
22960#undef JSON_HEDLEY_PELLES_VERSION
22961#undef JSON_HEDLEY_PELLES_VERSION_CHECK
22962#undef JSON_HEDLEY_PGI_VERSION
22963#undef JSON_HEDLEY_PGI_VERSION_CHECK
22964#undef JSON_HEDLEY_PREDICT
22965#undef JSON_HEDLEY_PRINTF_FORMAT
22966#undef JSON_HEDLEY_PRIVATE
22967#undef JSON_HEDLEY_PUBLIC
22968#undef JSON_HEDLEY_PURE
22969#undef JSON_HEDLEY_REINTERPRET_CAST
22970#undef JSON_HEDLEY_REQUIRE
22971#undef JSON_HEDLEY_REQUIRE_CONSTEXPR
22972#undef JSON_HEDLEY_REQUIRE_MSG
22973#undef JSON_HEDLEY_RESTRICT
22974#undef JSON_HEDLEY_RETURNS_NON_NULL
22975#undef JSON_HEDLEY_SENTINEL
22976#undef JSON_HEDLEY_STATIC_ASSERT
22977#undef JSON_HEDLEY_STATIC_CAST
22978#undef JSON_HEDLEY_STRINGIFY
22979#undef JSON_HEDLEY_STRINGIFY_EX
22980#undef JSON_HEDLEY_SUNPRO_VERSION
22981#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
22982#undef JSON_HEDLEY_TINYC_VERSION
22983#undef JSON_HEDLEY_TINYC_VERSION_CHECK
22984#undef JSON_HEDLEY_TI_ARMCL_VERSION
22985#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
22986#undef JSON_HEDLEY_TI_CL2000_VERSION
22987#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
22988#undef JSON_HEDLEY_TI_CL430_VERSION
22989#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
22990#undef JSON_HEDLEY_TI_CL6X_VERSION
22991#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
22992#undef JSON_HEDLEY_TI_CL7X_VERSION
22993#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
22994#undef JSON_HEDLEY_TI_CLPRU_VERSION
22995#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
22996#undef JSON_HEDLEY_TI_VERSION
22997#undef JSON_HEDLEY_TI_VERSION_CHECK
22998#undef JSON_HEDLEY_UNAVAILABLE
22999#undef JSON_HEDLEY_UNLIKELY
23000#undef JSON_HEDLEY_UNPREDICTABLE
23001#undef JSON_HEDLEY_UNREACHABLE
23002#undef JSON_HEDLEY_UNREACHABLE_RETURN
23003#undef JSON_HEDLEY_VERSION
23004#undef JSON_HEDLEY_VERSION_DECODE_MAJOR
23005#undef JSON_HEDLEY_VERSION_DECODE_MINOR
23006#undef JSON_HEDLEY_VERSION_DECODE_REVISION
23007#undef JSON_HEDLEY_VERSION_ENCODE
23008#undef JSON_HEDLEY_WARNING
23009#undef JSON_HEDLEY_WARN_UNUSED_RESULT
23010#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
23011#undef JSON_HEDLEY_FALL_THROUGH
namespace for Niels Lohmann
Definition json.hpp:18132
constexpr bool is_string() const noexcept
Definition json.hpp:19279
size_type erase(const typename object_t::key_type &key)
remove element from a JSON object given a key
Definition json.hpp:20446
detail::cbor_tag_handler_t cbor_tag_handler_t
Definition json.hpp:18196
reference operator[](KeyType &&key)
access specified object element
Definition json.hpp:20038
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_cbor(IteratorType first, IteratorType last, 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
Definition json.hpp:22024
static std::vector< std::uint8_t > to_bjdata(const basic_json &j, const bool use_size=false, const bool use_type=false)
create a BJData serialization of a given JSON value
Definition json.hpp:21965
reference back()
access the last element
Definition json.hpp:20263
basic_json value_type
Definition json.hpp:18231
basic_json(CompatibleType &&val) noexcept(noexcept(//NOLINT(bugprone-forwarding-reference-overload, bugprone-exception-escape) JSONSerializer< U >::to_json(std::declval< basic_json_t & >(), std::forward< CompatibleType >(val))))
create a JSON value from compatible types
Definition json.hpp:18798
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
Definition json.hpp:21834
const_reference front() const
access the first element
Definition json.hpp:20259
constexpr bool is_array() const noexcept
Definition json.hpp:19275
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 &&//NOLINT(cppcoreguidelines-noexcept-swap, performance-noexcept-swap) std::is_nothrow_move_assignable< json_value >::value)
Definition json.hpp:21199
ReturnType value(const json_pointer &ptr, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:20210
size_type count(KeyType &&key) const
returns the number of occurrences of a key in a JSON object
Definition json.hpp:20555
iter_impl< const basic_json > const_iterator
Definition json.hpp:18254
static void to_bjdata(const basic_json &j, detail::output_adapter< char > o, const bool use_size=false, const bool use_type=false)
create a BJData serialization of a given JSON value
Definition json.hpp:21981
constexpr bool is_number_integer() const noexcept
Definition json.hpp:19252
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
Definition json.hpp:18258
static void to_bjdata(const basic_json &j, detail::output_adapter< std::uint8_t > o, const bool use_size=false, const bool use_type=false)
create a BJData serialization of a given JSON value
Definition json.hpp:21974
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
Definition json.hpp:18249
std::size_t size_type
Definition json.hpp:18241
constexpr bool is_structured() const noexcept
return whether type is structured
Definition json.hpp:19236
const_reference operator[](KeyType &&key) const
access specified object element
Definition json.hpp:20062
detail::error_handler_t error_handler_t
Definition json.hpp:18194
const value_type & const_reference
Definition json.hpp:18236
void swap(binary_t &other)
exchanges the values
Definition json.hpp:21274
ReferenceType get_ref()
Definition json.hpp:19712
void update(const_reference j, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
Definition json.hpp:21150
ReferenceType get_ref() const
get a reference value (implicit)
Definition json.hpp:19724
constexpr bool is_discarded() const noexcept
return whether value is discarded
Definition json.hpp:19287
auto get() const noexcept(noexcept(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 >{}))) -> decltype(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 >{}))
Definition json.hpp:19624
reference operator+=(initializer_list_t init)
add an object to an object
Definition json.hpp:20960
JSON_HEDLEY_DEPRECATED_FOR(3.11.0, basic_json::json_pointer or nlohmann::json_pointer< basic_json::string_t >) ValueType value(const
access the first element
Definition json.hpp:20231
const_reference operator[](const typename object_t::key_type &key) const
access specified object element
Definition json.hpp:20010
const_reference back() const
access the last element
Definition json.hpp:20271
IteratorType erase(IteratorType first, IteratorType last)
remove elements given an iterator range
Definition json.hpp:20350
reference operator+=(const basic_json &val)
add an object to an array
Definition json.hpp:20913
friend void swap(reference left, reference right) 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 &&//NOLINT(cppcoreguidelines-noexcept-swap, performance-noexcept-swap) std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition json.hpp:21215
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(const typename binary_t::container_type &init, typename binary_t::subtype_type subtype)
explicitly create a binary array (with subtype)
Definition json.hpp:18935
iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
inserts copies of element into array
Definition json.hpp:21061
static allocator_type get_allocator()
returns the allocator associated with the container
Definition json.hpp:18264
nlohmann::byte_container_with_subtype< std::vector< std::uint8_t > > binary_t
Definition json.hpp:18382
reference at(KeyType &&key)
access specified object element with bounds checking
Definition json.hpp:19877
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
Definition json.hpp:19259
void update(const_iterator first, const_iterator last, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
Definition json.hpp:21157
static std::vector< std::uint8_t > to_bson(const basic_json &j)
create a BSON serialization of a given JSON value
Definition json.hpp:21988
void push_back(initializer_list_t init)
add an object to an object
Definition json.hpp:20948
detail::parser_callback_t< basic_json > parser_callback_t
Definition json.hpp:18770
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
Definition json.hpp:18974
static void to_msgpack(const basic_json &j, detail::output_adapter< char > o)
create a MessagePack serialization of a given JSON value
Definition json.hpp:21936
detail::parse_event_t parse_event_t
Definition json.hpp:18766
ReturnType value(const typename object_t::key_type &key, ValueType &&default_value) const
access specified object element with default value
Definition json.hpp:20115
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init)
explicitly create a binary array
Definition json.hpp:18946
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
Definition json.hpp:18787
static JSON_HEDLEY_WARN_UNUSED_RESULT 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
Definition json.hpp:22010
size_type erase(KeyType &&key)
remove element from a JSON object given a key
Definition json.hpp:20457
std::vector< basic_json, std::allocator< basic_json > > array_t
Definition json.hpp:18358
const binary_t & get_binary() const
get a binary value
Definition json.hpp:19796
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
inserts range of elements into array
Definition json.hpp:21080
ReturnType value(KeyType &&key, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:20166
value_type & reference
Definition json.hpp:18234
std::initializer_list< detail::json_ref< basic_json > > initializer_list_t
Definition json.hpp:18198
bool contains(KeyType &&key) const
check the existence of an element in a JSON object
Definition json.hpp:20571
static void to_cbor(const basic_json &j, detail::output_adapter< std::uint8_t > o)
create a CBOR serialization of a given JSON value
Definition json.hpp:21910
nlohmann::ordered_map< std::string, basic_json, default_object_comparator_t, std::allocator< std::pair< const std::string, basic_json > > > object_t
Definition json.hpp:18353
static void to_bson(const basic_json &j, detail::output_adapter< char > o)
create a BSON serialization of a given JSON value
Definition json.hpp:22002
iterator find(const typename object_t::key_type &key)
Definition json.hpp:20491
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(const typename binary_t::container_type &init)
explicitly create a binary array (without subtype)
Definition json.hpp:18925
JSON_HEDLEY_NON_NULL(2) static bool sax_parse(detail
Definition json.hpp:21795
const_reference at(KeyType &&key) const
access specified object element with bounds checking
Definition json.hpp:19915
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json meta()
returns version information on the library
Definition json.hpp:18269
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
Definition json.hpp:18980
const_iterator find(const typename object_t::key_type &key) const
find an element in a JSON object
Definition json.hpp:20503
static std::vector< std::uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
Definition json.hpp:21902
IteratorType erase(IteratorType pos)
remove element given an iterator
Definition json.hpp:20284
iterator insert(const_iterator pos, const basic_json &val)
inserts element into array
Definition json.hpp:21038
double number_float_t
Definition json.hpp:18378
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition json.hpp:20092
std::allocator< basic_json > allocator_type
Definition json.hpp:18244
typename std::allocator_traits< allocator_type >::pointer pointer
Definition json.hpp:18247
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
Definition json.hpp:19209
ValueType & get_to(ValueType &v) const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), v)))
get a value (explicit)
Definition json.hpp:19678
reference at(size_type idx)
access specified array element with bounds checking
Definition json.hpp:19817
iterator find(KeyType &&key)
find an element in a JSON object
Definition json.hpp:20518
constexpr bool is_number_float() const noexcept
Definition json.hpp:19265
static std::vector< std::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
Definition json.hpp:21942
bool boolean_t
Definition json.hpp:18366
std::less< std::string > default_object_comparator_t
Definition json.hpp:18348
reference operator+=(const typename object_t::value_type &val)
add an object to an object
Definition json.hpp:20941
reference operator[](typename object_t::key_type key)
access specified object element
Definition json.hpp:19989
constexpr auto get_ptr() const noexcept -> decltype(std::declval< const basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition json.hpp:19441
~basic_json() noexcept
destructor
Definition json.hpp:19194
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
Definition json.hpp:18873
void swap(typename binary_t::container_type &other)
exchanges the values
Definition json.hpp:21290
binary_t & get_binary()
get a binary value
Definition json.hpp:19785
constexpr bool is_number() const noexcept
Definition json.hpp:19248
void insert(const_iterator first, const_iterator last)
inserts range of elements into object
Definition json.hpp:21126
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
Definition json.hpp:19667
reference operator[](size_type idx)
access specified array element
Definition json.hpp:19933
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 &&std::is_nothrow_move_assignable< json_base_class_t >::value)
copy assignment
Definition json.hpp:19173
static void to_ubjson(const basic_json &j, detail::output_adapter< char > o, const bool use_size=false, const bool use_type=false)
create a UBJSON serialization of a given JSON value
Definition json.hpp:21958
std::int64_t number_integer_t
Definition json.hpp:18370
auto get_ptr() noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition json.hpp:19428
const_reference at(const typename object_t::key_type &key) const
access specified object element with bounds checking
Definition json.hpp:19895
constexpr bool is_binary() const noexcept
Definition json.hpp:19283
void swap(object_t &other)
exchanges the values
Definition json.hpp:21242
iterator insert(const_iterator pos, initializer_list_t ilist)
inserts elements from initializer list into array
Definition json.hpp:21108
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init, typename binary_t::subtype_type subtype)
explicitly create a binary array (with subtype)
Definition json.hpp:18956
void swap(array_t &other)
exchanges the values
Definition json.hpp:21226
void erase(const size_type idx)
remove element from a JSON array given an index
Definition json.hpp:20463
reference operator+=(basic_json &&val)
add an object to an array
Definition json.hpp:20884
bool contains(const json_pointer &ptr) const
check the existence of an element in a JSON object given a JSON pointer
Definition json.hpp:20579
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition json.hpp:19226
reference emplace_back(Args &&... args)
add an object to an array
Definition json.hpp:20967
ValueType value(const json_pointer &ptr, const ValueType &default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:20188
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
Definition json.hpp:18967
std::string string_t
Definition json.hpp:18362
void push_back(const basic_json &val)
Definition json.hpp:20891
ValueType value(KeyType &&key, const ValueType &default_value) const
access specified object element with default value
Definition json.hpp:20140
reference at(const typename object_t::key_type &key)
access specified object element with bounds checking
Definition json.hpp:19857
json_value m_value
the value of the current element
Definition json.hpp:21868
json_sax< basic_json > json_sax_t
Definition json.hpp:18202
constexpr bool is_boolean() const noexcept
Definition json.hpp:19244
size_type count(const typename object_t::key_type &key) const
returns the number of occurrences of a key in a JSON object
Definition json.hpp:20545
constexpr bool is_primitive() const noexcept
return whether type is primitive
Definition json.hpp:19230
constexpr bool is_null() const noexcept
Definition json.hpp:19240
static void to_ubjson(const basic_json &j, detail::output_adapter< std::uint8_t > o, const bool use_size=false, const bool use_type=false)
create a UBJSON serialization of a given JSON value
Definition json.hpp:21951
basic_json(basic_json &&other) noexcept
move constructor
Definition json.hpp:19157
iter_impl< basic_json > iterator
Definition json.hpp:18252
basic_json(const value_t v)
create an empty value with a given type
Definition json.hpp:18783
const_reference operator[](size_type idx) const
access specified array element
Definition json.hpp:19976
std::ptrdiff_t difference_type
Definition json.hpp:18239
iterator insert(const_iterator pos, basic_json &&val)
inserts element into array
Definition json.hpp:21057
std::uint64_t number_unsigned_t
Definition json.hpp:18374
friend std::istream & operator>>(std::istream &i, basic_json &j)
Definition json.hpp:21820
static std::vector< std::uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
Definition json.hpp:21922
void swap(string_t &other)
exchanges the values
Definition json.hpp:21258
basic_json(const BasicJsonType &val)
create a JSON value from an existing one
Definition json.hpp:18813
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
Definition json.hpp:18256
const_reference at(size_type idx) const
access specified array element with bounds checking
Definition json.hpp:19837
detail::actual_object_comparator_t< basic_json > object_comparator_t
Definition json.hpp:18386
basic_json(const basic_json &other)
copy constructor
Definition json.hpp:19099
void push_back(const typename object_t::value_type &val)
add an object to an object
Definition json.hpp:20920
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
Definition json.hpp:20989
static void to_cbor(const basic_json &j, detail::output_adapter< char > o)
create a CBOR serialization of a given JSON value
Definition json.hpp:21916
constexpr bool is_object() const noexcept
Definition json.hpp:19271
static void to_msgpack(const basic_json &j, detail::output_adapter< std::uint8_t > o)
create a MessagePack serialization of a given JSON value
Definition json.hpp:21930
iterator insert_iterator(const_iterator pos, Args &&... args)
Definition json.hpp:21018
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
Definition json.hpp:18992
bool contains(const typename object_t::key_type &key) const
check the existence of an element in a JSON object
Definition json.hpp:20562
static void to_bson(const basic_json &j, detail::output_adapter< std::uint8_t > o)
create a BSON serialization of a given JSON value
Definition json.hpp:21996
const_iterator find(KeyType &&key) const
find an element in a JSON object
Definition json.hpp:20533
::nlohmann::json_pointer< std::string > json_pointer
Definition json.hpp:18191
an internal type for a backed binary type
Definition json.hpp:5770
byte_container_with_subtype() noexcept(noexcept(container_type()))
Definition json.hpp:5777
byte_container_with_subtype(container_type &&b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))
Definition json.hpp:5797
byte_container_with_subtype(container_type &&b) noexcept(noexcept(container_type(std::move(b))))
Definition json.hpp:5786
constexpr subtype_type subtype() const noexcept
return the binary subtype
Definition json.hpp:5817
byte_container_with_subtype(const container_type &b, subtype_type subtype_) noexcept(noexcept(container_type(b)))
Definition json.hpp:5791
constexpr bool has_subtype() const noexcept
return whether the value has a subtype
Definition json.hpp:5823
byte_container_with_subtype(const container_type &b) noexcept(noexcept(container_type(b)))
Definition json.hpp:5781
void set_subtype(subtype_type subtype_) noexcept
sets the binary subtype
Definition json.hpp:5810
void clear_subtype() noexcept
clears the binary subtype
Definition json.hpp:5828
deserialization of CBOR, MessagePack, and UBJSON values
Definition json.hpp:8752
binary_reader(InputAdapterType &&adapter, const input_format_t format=input_format_t::json) noexcept
create a binary reader
Definition json.hpp:8768
bool sax_parse(const input_format_t format, json_sax_t *sax_, const bool strict=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
Definition json.hpp:8792
void write_bson(const BasicJsonType &j)
Definition json.hpp:14273
binary_writer(output_adapter_t< CharType > adapter)
create a binary writer
Definition json.hpp:14265
void write_ubjson(const BasicJsonType &j, const bool use_count, const bool use_type, const bool add_prefix=true, const bool use_bjdata=false)
Definition json.hpp:14820
void write_msgpack(const BasicJsonType &j)
Definition json.hpp:14551
void write_cbor(const BasicJsonType &j)
Definition json.hpp:14302
general exception of the basic_json class
Definition json.hpp:4369
const int id
the id of the exception
Definition json.hpp:4375
const char * what() const noexcept override
returns the explanatory string
Definition json.hpp:4372
exception indicating errors with iterators
Definition json.hpp:4506
iter_impl operator+(difference_type i) const
add to iterator
Definition json.hpp:12872
iter_impl & operator=(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting assignment
Definition json.hpp:12479
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
Definition json.hpp:12826
iter_impl(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting constructor
Definition json.hpp:12470
bool operator<(const iter_impl &other) const
comparison: smaller
Definition json.hpp:12780
bool operator<=(const iter_impl &other) const
comparison: less than or equal
Definition json.hpp:12814
iter_impl & operator-=(difference_type i)
subtract from iterator
Definition json.hpp:12866
iter_impl & operator--()
pre-decrement (–it)
Definition json.hpp:12696
const object_t::key_type & key() const
return the key of an object iterator
Definition json.hpp:12965
bool operator==(const IterImpl &other) const
Definition json.hpp:12735
iter_impl operator++(int) &
post-increment (it++)
Definition json.hpp:12639
iter_impl & operator+=(difference_type i)
add to iterator
Definition json.hpp:12832
reference operator[](difference_type n) const
access to successor
Definition json.hpp:12930
typename BasicJsonType::difference_type difference_type
Definition json.hpp:12382
pointer operator->() const
dereference the iterator
Definition json.hpp:12603
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
Definition json.hpp:12986
difference_type operator-(const iter_impl &other) const
return difference
Definition json.hpp:12902
std::bidirectional_iterator_tag iterator_category
Definition json.hpp:12377
friend iter_impl operator+(difference_type i, const iter_impl &it)
addition of distance and iterator
Definition json.hpp:12882
reference value() const
return the value of an iterator
Definition json.hpp:12980
bool operator>(const iter_impl &other) const
comparison: greater than
Definition json.hpp:12820
typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_pointer, typename BasicJsonType::pointer >::type pointer
Definition json.hpp:12384
iter_impl & operator++()
pre-increment (++it)
Definition json.hpp:12650
typename BasicJsonType::value_type value_type
Definition json.hpp:12380
reference operator*() const
return a reference to the value pointed to by the iterator
Definition json.hpp:12565
iter_impl operator-(difference_type i) const
subtract from iterator
Definition json.hpp:12892
typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_reference, typename BasicJsonType::reference >::type reference
Definition json.hpp:12388
iter_impl & operator=(const iter_impl< const BasicJsonType > &other) noexcept
converting assignment
Definition json.hpp:12457
iter_impl operator--(int) &
post-decrement (it–)
Definition json.hpp:12685
iter_impl(const iter_impl< const BasicJsonType > &other) noexcept
const copy constructor
Definition json.hpp:12448
void set_end() noexcept
set the iterator past the last value
Definition json.hpp:12531
bool operator==(const iteration_proxy_value &o) const
equality operator (needed for InputIterator)
Definition json.hpp:5181
bool operator!=(const iteration_proxy_value &o) const
inequality operator (needed for range-based for)
Definition json.hpp:5184
iteration_proxy_value & operator++()
increment operator (needed for range-based for)
Definition json.hpp:5165
const iteration_proxy_value & operator*() const
dereference operator (needed for range-based for)
Definition json.hpp:5162
IteratorType::reference value() const
return value of the iterator
Definition json.hpp:5219
const string_type & key() const
return key of the iterator
Definition json.hpp:5187
proxy class for the items() function
Definition json.hpp:5223
iteration_proxy_value< IteratorType > end() const noexcept
return iterator end (needed for range-based for)
Definition json.hpp:5246
iteration_proxy_value< IteratorType > begin() const noexcept
return iterator begin (needed for range-based for)
Definition json.hpp:5241
iteration_proxy(typename IteratorType::reference cont) noexcept
construct iteration proxy from a container
Definition json.hpp:5232
Definition json.hpp:14050
json_reverse_iterator operator++(int) &
post-increment (it++)
Definition json.hpp:13050
json_reverse_iterator operator--(int) &
post-decrement (it–)
Definition json.hpp:13061
json_reverse_iterator & operator++()
pre-increment (++it)
Definition json.hpp:13056
json_reverse_iterator & operator+=(difference_type i)
add to iterator
Definition json.hpp:13072
reference operator[](difference_type n) const
access to successor
Definition json.hpp:13092
auto key() const -> decltype(std::declval< Base >().key())
return the key of an object iterator
Definition json.hpp:13095
difference_type operator-(const json_reverse_iterator &other) const
return difference
Definition json.hpp:13087
typename Base::reference reference
the reference type for the pointed-to element
Definition json.hpp:13040
reference value() const
return the value of an iterator
Definition json.hpp:13101
json_reverse_iterator(const base_iterator &it) noexcept
create reverse iterator from base class
Definition json.hpp:13047
json_reverse_iterator & operator--()
pre-decrement (–it)
Definition json.hpp:13067
std::reverse_iterator< Base > base_iterator
shortcut to the reverse iterator adapter
Definition json.hpp:13038
json_reverse_iterator operator-(difference_type i) const
subtract from iterator
Definition json.hpp:13082
json_reverse_iterator(const typename base_iterator::iterator_type &it) noexcept
create reverse iterator from iterator
Definition json.hpp:13043
json_reverse_iterator operator+(difference_type i) const
add to iterator
Definition json.hpp:13077
SAX implementation to create a JSON value from SAX events.
Definition json.hpp:6579
json_sax_dom_parser(BasicJsonType &r, const bool allow_exceptions_=true)
Definition json.hpp:6592
JSON_HEDLEY_RETURNS_NON_NULL static JSON_HEDLEY_CONST const char * token_type_name(const token_type t) noexcept
return name of values of type token_type (only used for errors)
Definition json.hpp:7120
token_type
token types for the parser
Definition json.hpp:7093
@ value_float
Definition json.hpp:7103
@ begin_array
the character for array begin [
Definition json.hpp:7105
@ value_string
a string – use get_string() for actual value
Definition json.hpp:7098
@ end_array
the character for array end ]
Definition json.hpp:7107
@ uninitialized
indicating the scanner is uninitialized
Definition json.hpp:7094
@ parse_error
indicating a parse error
Definition json.hpp:7111
@ value_integer
Definition json.hpp:7101
@ value_separator
the value separator ,
Definition json.hpp:7110
@ end_object
the character for object end }
Definition json.hpp:7108
@ literal_true
the true literal
Definition json.hpp:7095
@ begin_object
the character for object begin {
Definition json.hpp:7106
@ value_unsigned
Definition json.hpp:7099
@ literal_null
the null literal
Definition json.hpp:7097
@ end_of_input
indicating the end of the input buffer
Definition json.hpp:7112
@ name_separator
the name separator :
Definition json.hpp:7109
@ literal_or_value
Definition json.hpp:7113
@ literal_false
the false literal
Definition json.hpp:7096
lexical analysis
Definition json.hpp:7167
bool skip_bom()
skip the UTF-8 byte order mark
Definition json.hpp:8424
JSON_HEDLEY_RETURNS_NON_NULL constexpr const char * get_error_message() const noexcept
return syntax error message
Definition json.hpp:8414
std::string get_token_string() const
Definition json.hpp:8391
constexpr number_integer_t get_number_integer() const noexcept
return integer value
Definition json.hpp:8369
constexpr position_t get_position() const noexcept
return position of last read token
Definition json.hpp:8386
constexpr number_unsigned_t get_number_unsigned() const noexcept
return unsigned integer value
Definition json.hpp:8372
string_t & get_string()
Definition json.hpp:8379
constexpr number_float_t get_number_float() const noexcept
return floating-point value
Definition json.hpp:8375
exception indicating other library errors
Definition json.hpp:4557
exception indicating access out of the defined range
Definition json.hpp:4540
Definition json.hpp:14219
output adapter for output streams
Definition json.hpp:14187
output adapter for basic_string
Definition json.hpp:14205
output adapter for byte vectors
Definition json.hpp:14169
exception indicating a parse error
Definition json.hpp:4451
static parse_error create(int id_, const position_t &pos, const std::string &what_arg, BasicJsonContext context)
create a parse error exception
Definition json.hpp:4464
const std::size_t byte
byte index of the parse error
Definition json.hpp:4492
parser(InputAdapterType &&adapter, const parser_callback_t< BasicJsonType > cb=nullptr, const bool allow_exceptions_=true, const bool skip_comments=false)
a parser reading from an input adapter
Definition json.hpp:11740
void parse(const bool strict, BasicJsonType &result)
public parser interface
Definition json.hpp:11758
bool accept(const bool strict=true)
public accept interface
Definition json.hpp:11810
Definition json.hpp:12186
constexpr bool is_begin() const noexcept
return whether the iterator can be dereferenced
Definition json.hpp:12206
void set_end() noexcept
set iterator to a defined past the end
Definition json.hpp:12203
constexpr bool is_end() const noexcept
return whether the iterator is at end
Definition json.hpp:12209
void set_begin() noexcept
set iterator to a defined beginning
Definition json.hpp:12200
Definition json.hpp:16876
std::array< char, 512 > string_buffer
string buffer
Definition json.hpp:17760
serializer(output_adapter_t< char > s, const char ichar, error_handler_t error_handler_=error_handler_t::strict)
Definition json.hpp:16891
const char thousands_sep
the locale's thousand separator character
Definition json.hpp:17755
const char decimal_point
the locale's decimal point character
Definition json.hpp:17757
const error_handler_t error_handler
error_handler how to react on decoding errors
Definition json.hpp:17768
string_t indent_string
the indentation string
Definition json.hpp:17765
const std::lconv * loc
the locale
Definition json.hpp:17753
std::array< char, 64 > number_buffer
a (hopefully) large enough character buffer
Definition json.hpp:17750
const char indent_char
the indentation character
Definition json.hpp:17763
void dump(const BasicJsonType &val, const bool pretty_print, const bool ensure_ascii, const unsigned int indent_step, const unsigned int current_indent=0)
internal implementation of the serialization function
Definition json.hpp:16931
exception indicating executing a member function with a wrong type
Definition json.hpp:4523
JSON Pointer defines a string syntax for identifying a specific value within a JSON document.
Definition json.hpp:13184
friend json_pointer operator/(const json_pointer &lhs, string_t token)
create a new JSON pointer by appending the unescaped token at the end of the JSON pointer
Definition json.hpp:13260
friend json_pointer operator/(const json_pointer &lhs, std::size_t array_idx)
create a new JSON pointer by appending the array-index-token at the end of the JSON pointer
Definition json.hpp:13269
friend bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
compares two JSON pointers for equality
Definition json.hpp:13983
json_pointer(const string_t &s="")
create JSON pointer
Definition json.hpp:13206
bool empty() const noexcept
return whether pointer points to the root document
Definition json.hpp:13315
void pop_back()
remove last reference token
Definition json.hpp:13287
string_t to_string() const
return a string representation of the JSON pointer
Definition json.hpp:13210
json_pointer & operator/=(std::size_t array_idx)
append an array index at the end of this JSON pointer
Definition json.hpp:13248
void push_back(string_t &&token)
append an unescaped token at the end of the reference pointer
Definition json.hpp:13311
friend bool operator<(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
compares two JSON pointer for less-than
Definition json.hpp:14023
json_pointer & operator/=(const json_pointer &ptr)
append another JSON pointer at the end of this JSON pointer
Definition json.hpp:13233
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
Definition json.hpp:13253
json_pointer parent_pointer() const
returns the parent of this JSON pointer
Definition json.hpp:13275
json_pointer & operator/=(string_t token)
append an unescaped reference token at the end of this JSON pointer
Definition json.hpp:13241
const string_t & back() const
return last reference token
Definition json.hpp:13297
friend bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
compares two JSON pointers for inequality
Definition json.hpp:14003
friend std::ostream & operator<<(std::ostream &o, const json_pointer &ptr)
write string representation of the JSON pointer to stream
Definition json.hpp:13225
void push_back(const string_t &token)
append an unescaped token at the end of the reference pointer
Definition json.hpp:13307
implements the Grisu2 algorithm for binary to decimal floating-point conversion.
Definition json.hpp:15851
int find_largest_pow10(const std::uint32_t n, std::uint32_t &pow10)
Definition json.hpp:16248
cached_power get_cached_power_for_binary_exponent(int e)
Definition json.hpp:16126
boundaries compute_boundaries(FloatType value)
Definition json.hpp:15987
void grisu2(char *buf, int &len, int &decimal_exponent, diyfp m_minus, diyfp v, diyfp m_plus)
Definition json.hpp:16572
void grisu2_digit_gen(char *buffer, int &length, int &decimal_exponent, diyfp M_minus, diyfp w, diyfp M_plus)
Definition json.hpp:16330
JSON_HEDLEY_RETURNS_NON_NULL char * append_exponent(char *buf, int e)
appends a decimal representation of e to buf
Definition json.hpp:16674
JSON_HEDLEY_RETURNS_NON_NULL char * format_buffer(char *buf, int len, int decimal_exponent, int min_exp, int max_exp)
prettify v = buf * 10^decimal_exponent
Definition json.hpp:16717
detail namespace with internal helper functions
Definition json.hpp:224
input_format_t
the supported input formats
Definition json.hpp:6018
JSON_HEDLEY_RETURNS_NON_NULL char * to_chars(char *first, const char *last, FloatType value)
generates a decimal representation of the floating-point number value in [first, last).
Definition json.hpp:16795
parse_event_t
Definition json.hpp:11706
@ value
the parser finished reading a JSON value
Definition json.hpp:11718
@ key
the parser read a key of a value in an object
Definition json.hpp:11716
@ array_end
the parser read ] and finished processing a JSON array
Definition json.hpp:11714
@ array_start
the parser read [ and started to process a JSON array
Definition json.hpp:11712
@ object_start
the parser read { and started to process a JSON object
Definition json.hpp:11708
@ object_end
the parser read } and finished processing a JSON object
Definition json.hpp:11710
std::shared_ptr< output_adapter_protocol< CharType > > output_adapter_t
a type to simplify interfaces
Definition json.hpp:14165
void replace_substring(StringType &s, const StringType &f, const StringType &t)
replace all occurrences of a substring by another string
Definition json.hpp:3158
cbor_tag_handler_t
how to treat CBOR tags
Definition json.hpp:8726
@ ignore
ignore tags
Definition json.hpp:8728
@ store
store tags as binary type
Definition json.hpp:8729
@ error
throw a parse_error exception in case of a tag
Definition json.hpp:8727
value_t
the JSON type enumeration
Definition json.hpp:3067
@ null
null value
Definition json.hpp:3068
@ number_integer
number value (signed integer)
Definition json.hpp:3073
@ boolean
boolean value
Definition json.hpp:3072
@ discarded
discarded by the parser callback function
Definition json.hpp:3077
@ binary
binary array (ordered collection of bytes)
Definition json.hpp:3076
@ object
object (unordered set of name/value pairs)
Definition json.hpp:3069
@ string
string value
Definition json.hpp:3071
@ number_float
number value (floating-point)
Definition json.hpp:3075
@ number_unsigned
number value (unsigned integer)
Definition json.hpp:3074
@ array
array (ordered collection of values)
Definition json.hpp:3070
std::size_t hash(const BasicJsonType &j)
hash a JSON value
Definition json.hpp:5883
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
Definition json.hpp:3097
error_handler_t
how to treat decoding errors
Definition json.hpp:16870
@ strict
throw a type_error exception in case of invalid UTF-8
Definition json.hpp:16871
@ replace
replace invalid UTF-8 sequences with U+FFFD
Definition json.hpp:16872
StringType escape(StringType s)
string escaping as described in RFC 6901 (Sect. 4)
Definition json.hpp:3175
namespace for Niels Lohmann
Definition json.hpp:5718
static auto to_json(BasicJsonType &j, TargetType &&val) noexcept(noexcept(::nlohmann::to_json(j, std::forward< TargetType >(val)))) -> decltype(::nlohmann::to_json(j, std::forward< TargetType >(val)), void())
convert any value type to a JSON value
Definition json.hpp:5742
static auto from_json(BasicJsonType &&j) noexcept(noexcept(::nlohmann::from_json(std::forward< BasicJsonType >(j), detail::identity_tag< TargetType >{}))) -> decltype(::nlohmann::from_json(std::forward< BasicJsonType >(j), detail::identity_tag< TargetType >{}))
convert a JSON value to any value type
Definition json.hpp:5731
static auto from_json(BasicJsonType &&j, TargetType &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
Definition json.hpp:5722
Definition json.hpp:15975
Definition json.hpp:16113
Definition json.hpp:15862
static diyfp mul(const diyfp &x, const diyfp &y) noexcept
returns x * y
Definition json.hpp:15885
static diyfp normalize_to(const diyfp &x, const int target_exponent) noexcept
normalize x such that the result has the exponent E
Definition json.hpp:15965
static diyfp normalize(diyfp x) noexcept
normalize x such that the significand is >= 2^(q-1)
Definition json.hpp:15950
static diyfp sub(const diyfp &x, const diyfp &y) noexcept
returns x - y
Definition json.hpp:15874
an iterator value
Definition json.hpp:12278
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition json.hpp:12282
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition json.hpp:12284
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition json.hpp:12280
Default base class of the basic_json class.
Definition json.hpp:13138
struct to capture the start position of the current token
Definition json.hpp:3213
std::size_t chars_read_current_line
the number of characters read in the current line
Definition json.hpp:3217
std::size_t lines_read
the number of lines read
Definition json.hpp:3219
std::size_t chars_read_total
the total number of characters read
Definition json.hpp:3215
SAX interface.
Definition json.hpp:6453
virtual bool binary(binary_t &val)=0
a binary value was read
virtual bool number_float(number_float_t val, const string_t &s)=0
a floating-point number was read
virtual bool number_unsigned(number_unsigned_t val)=0
an unsigned integer number was read
virtual bool key(string_t &val)=0
an object key was read
virtual bool string(string_t &val)=0
a string value was read
virtual bool number_integer(number_integer_t val)=0
an integer number was read
virtual bool start_object(std::size_t elements)=0
the beginning of an object was read
virtual bool end_array()=0
the end of an array was read
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 null()=0
a null value 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 start_array(std::size_t elements)=0
the beginning of an array was read
a minimal map-like container that preserves insertion order
Definition json.hpp:17806
bool operator()(::nlohmann::detail::value_t lhs, ::nlohmann::detail::value_t rhs) const noexcept
compare two value_t enum values
Definition json.hpp:22768