18#ifndef INCLUDE_NLOHMANN_JSON_HPP_
19#define INCLUDE_NLOHMANN_JSON_HPP_
24#include <initializer_list>
60#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
61 #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH)
62 #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 2
63 #warning "Already included a different version of the library!"
68#define NLOHMANN_JSON_VERSION_MAJOR 3
69#define NLOHMANN_JSON_VERSION_MINOR 11
70#define NLOHMANN_JSON_VERSION_PATCH 2
72#ifndef JSON_DIAGNOSTICS
73 #define JSON_DIAGNOSTICS 0
76#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
77 #define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0
81 #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag
83 #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS
86#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
87 #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp
89 #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON
92#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION
93 #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0
97#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b
98#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \
99 NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b)
101#define NLOHMANN_JSON_ABI_TAGS \
102 NLOHMANN_JSON_ABI_TAGS_CONCAT( \
103 NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \
104 NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON)
107#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \
108 _v ## major ## _ ## minor ## _ ## patch
109#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \
110 NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch)
112#if NLOHMANN_JSON_NAMESPACE_NO_VERSION
113#define NLOHMANN_JSON_NAMESPACE_VERSION
115#define NLOHMANN_JSON_NAMESPACE_VERSION \
116 NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \
117 NLOHMANN_JSON_VERSION_MINOR, \
118 NLOHMANN_JSON_VERSION_PATCH)
122#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b
123#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \
124 NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b)
126#ifndef NLOHMANN_JSON_NAMESPACE
127#define NLOHMANN_JSON_NAMESPACE \
128 nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \
129 NLOHMANN_JSON_ABI_TAGS, \
130 NLOHMANN_JSON_NAMESPACE_VERSION)
133#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
134#define NLOHMANN_JSON_NAMESPACE_BEGIN \
137 inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \
138 NLOHMANN_JSON_ABI_TAGS, \
139 NLOHMANN_JSON_NAMESPACE_VERSION) \
143#ifndef NLOHMANN_JSON_NAMESPACE_END
144#define NLOHMANN_JSON_NAMESPACE_END \
162#include <forward_list>
167#include <type_traits>
168#include <unordered_map>
231#include <type_traits>
276template<
class Default,
278 template<
class...>
class Op,
286template<
class Default,
template<
class...>
class Op,
class... Args>
293template<
template<
class...>
class Op,
class... Args>
296template<
template<
class...>
class Op,
class... Args>
299template<
template<
class...>
class Op,
class... Args>
302template<
class Default,
template<
class...>
class Op,
class... Args>
305template<
class Default,
template<
class...>
class Op,
class... Args>
308template<
class Expected,
template<
class...>
class Op,
class... Args>
311template<
class To,
template<
class...>
class Op,
class... Args>
313 std::is_convertible<
detected_t<Op, Args...>, To>;
334#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15)
335#if defined(JSON_HEDLEY_VERSION)
336 #undef JSON_HEDLEY_VERSION
338#define JSON_HEDLEY_VERSION 15
340#if defined(JSON_HEDLEY_STRINGIFY_EX)
341 #undef JSON_HEDLEY_STRINGIFY_EX
343#define JSON_HEDLEY_STRINGIFY_EX(x) #x
345#if defined(JSON_HEDLEY_STRINGIFY)
346 #undef JSON_HEDLEY_STRINGIFY
348#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
350#if defined(JSON_HEDLEY_CONCAT_EX)
351 #undef JSON_HEDLEY_CONCAT_EX
353#define JSON_HEDLEY_CONCAT_EX(a,b) a##b
355#if defined(JSON_HEDLEY_CONCAT)
356 #undef JSON_HEDLEY_CONCAT
358#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
360#if defined(JSON_HEDLEY_CONCAT3_EX)
361 #undef JSON_HEDLEY_CONCAT3_EX
363#define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c
365#if defined(JSON_HEDLEY_CONCAT3)
366 #undef JSON_HEDLEY_CONCAT3
368#define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c)
370#if defined(JSON_HEDLEY_VERSION_ENCODE)
371 #undef JSON_HEDLEY_VERSION_ENCODE
373#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
375#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
376 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
378#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
380#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
381 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
383#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
385#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
386 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
388#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
390#if defined(JSON_HEDLEY_GNUC_VERSION)
391 #undef JSON_HEDLEY_GNUC_VERSION
393#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
394 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
395#elif defined(__GNUC__)
396 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
399#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
400 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
402#if defined(JSON_HEDLEY_GNUC_VERSION)
403 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
405 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
408#if defined(JSON_HEDLEY_MSVC_VERSION)
409 #undef JSON_HEDLEY_MSVC_VERSION
411#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL)
412 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
413#elif defined(_MSC_FULL_VER) && !defined(__ICL)
414 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
415#elif defined(_MSC_VER) && !defined(__ICL)
416 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
419#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
420 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
422#if !defined(JSON_HEDLEY_MSVC_VERSION)
423 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
424#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
425 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
426#elif defined(_MSC_VER) && (_MSC_VER >= 1200)
427 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
429 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))
432#if defined(JSON_HEDLEY_INTEL_VERSION)
433 #undef JSON_HEDLEY_INTEL_VERSION
435#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL)
436 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
437#elif defined(__INTEL_COMPILER) && !defined(__ICL)
438 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
441#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
442 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
444#if defined(JSON_HEDLEY_INTEL_VERSION)
445 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
447 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
450#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
451 #undef JSON_HEDLEY_INTEL_CL_VERSION
453#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL)
454 #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0)
457#if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK)
458 #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
460#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
461 #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
463 #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0)
466#if defined(JSON_HEDLEY_PGI_VERSION)
467 #undef JSON_HEDLEY_PGI_VERSION
469#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
470 #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
473#if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
474 #undef JSON_HEDLEY_PGI_VERSION_CHECK
476#if defined(JSON_HEDLEY_PGI_VERSION)
477 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
479 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
482#if defined(JSON_HEDLEY_SUNPRO_VERSION)
483 #undef JSON_HEDLEY_SUNPRO_VERSION
485#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
486 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10)
487#elif defined(__SUNPRO_C)
488 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
489#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
490 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10)
491#elif defined(__SUNPRO_CC)
492 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
495#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
496 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
498#if defined(JSON_HEDLEY_SUNPRO_VERSION)
499 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
501 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
504#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
505 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
507#if defined(__EMSCRIPTEN__)
508 #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
511#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
512 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
514#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
515 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
517 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
520#if defined(JSON_HEDLEY_ARM_VERSION)
521 #undef JSON_HEDLEY_ARM_VERSION
523#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
524 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)
525#elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
526 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
529#if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
530 #undef JSON_HEDLEY_ARM_VERSION_CHECK
532#if defined(JSON_HEDLEY_ARM_VERSION)
533 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
535 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
538#if defined(JSON_HEDLEY_IBM_VERSION)
539 #undef JSON_HEDLEY_IBM_VERSION
541#if defined(__ibmxl__)
542 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
543#elif defined(__xlC__) && defined(__xlC_ver__)
544 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
545#elif defined(__xlC__)
546 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
549#if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
550 #undef JSON_HEDLEY_IBM_VERSION_CHECK
552#if defined(JSON_HEDLEY_IBM_VERSION)
553 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
555 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
558#if defined(JSON_HEDLEY_TI_VERSION)
559 #undef JSON_HEDLEY_TI_VERSION
562 defined(__TI_COMPILER_VERSION__) && \
564 defined(__TMS470__) || defined(__TI_ARM__) || \
565 defined(__MSP430__) || \
566 defined(__TMS320C2000__) \
568#if (__TI_COMPILER_VERSION__ >= 16000000)
569 #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__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) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
579 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
582#if defined(JSON_HEDLEY_TI_CL2000_VERSION)
583 #undef JSON_HEDLEY_TI_CL2000_VERSION
585#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
586 #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
589#if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK)
590 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
592#if defined(JSON_HEDLEY_TI_CL2000_VERSION)
593 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
595 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0)
598#if defined(JSON_HEDLEY_TI_CL430_VERSION)
599 #undef JSON_HEDLEY_TI_CL430_VERSION
601#if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__)
602 #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
605#if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK)
606 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
608#if defined(JSON_HEDLEY_TI_CL430_VERSION)
609 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
611 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0)
614#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
615 #undef JSON_HEDLEY_TI_ARMCL_VERSION
617#if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__))
618 #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
621#if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK)
622 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
624#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
625 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
627 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0)
630#if defined(JSON_HEDLEY_TI_CL6X_VERSION)
631 #undef JSON_HEDLEY_TI_CL6X_VERSION
633#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__)
634 #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
637#if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK)
638 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
640#if defined(JSON_HEDLEY_TI_CL6X_VERSION)
641 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
643 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0)
646#if defined(JSON_HEDLEY_TI_CL7X_VERSION)
647 #undef JSON_HEDLEY_TI_CL7X_VERSION
649#if defined(__TI_COMPILER_VERSION__) && defined(__C7000__)
650 #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
653#if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK)
654 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
656#if defined(JSON_HEDLEY_TI_CL7X_VERSION)
657 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
659 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0)
662#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
663 #undef JSON_HEDLEY_TI_CLPRU_VERSION
665#if defined(__TI_COMPILER_VERSION__) && defined(__PRU__)
666 #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
669#if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK)
670 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
672#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
673 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
675 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0)
678#if defined(JSON_HEDLEY_CRAY_VERSION)
679 #undef JSON_HEDLEY_CRAY_VERSION
682 #if defined(_RELEASE_PATCHLEVEL)
683 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
685 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
689#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
690 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
692#if defined(JSON_HEDLEY_CRAY_VERSION)
693 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
695 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
698#if defined(JSON_HEDLEY_IAR_VERSION)
699 #undef JSON_HEDLEY_IAR_VERSION
701#if defined(__IAR_SYSTEMS_ICC__)
703 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
705 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0)
709#if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
710 #undef JSON_HEDLEY_IAR_VERSION_CHECK
712#if defined(JSON_HEDLEY_IAR_VERSION)
713 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
715 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
718#if defined(JSON_HEDLEY_TINYC_VERSION)
719 #undef JSON_HEDLEY_TINYC_VERSION
721#if defined(__TINYC__)
722 #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
725#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
726 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
728#if defined(JSON_HEDLEY_TINYC_VERSION)
729 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
731 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
734#if defined(JSON_HEDLEY_DMC_VERSION)
735 #undef JSON_HEDLEY_DMC_VERSION
738 #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
741#if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
742 #undef JSON_HEDLEY_DMC_VERSION_CHECK
744#if defined(JSON_HEDLEY_DMC_VERSION)
745 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
747 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
750#if defined(JSON_HEDLEY_COMPCERT_VERSION)
751 #undef JSON_HEDLEY_COMPCERT_VERSION
753#if defined(__COMPCERT_VERSION__)
754 #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)
757#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
758 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
760#if defined(JSON_HEDLEY_COMPCERT_VERSION)
761 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
763 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
766#if defined(JSON_HEDLEY_PELLES_VERSION)
767 #undef JSON_HEDLEY_PELLES_VERSION
770 #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
773#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
774 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
776#if defined(JSON_HEDLEY_PELLES_VERSION)
777 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
779 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
782#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
783 #undef JSON_HEDLEY_MCST_LCC_VERSION
785#if defined(__LCC__) && defined(__LCC_MINOR__)
786 #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__)
789#if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK)
790 #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
792#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
793 #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
795 #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0)
798#if defined(JSON_HEDLEY_GCC_VERSION)
799 #undef JSON_HEDLEY_GCC_VERSION
802 defined(JSON_HEDLEY_GNUC_VERSION) && \
803 !defined(__clang__) && \
804 !defined(JSON_HEDLEY_INTEL_VERSION) && \
805 !defined(JSON_HEDLEY_PGI_VERSION) && \
806 !defined(JSON_HEDLEY_ARM_VERSION) && \
807 !defined(JSON_HEDLEY_CRAY_VERSION) && \
808 !defined(JSON_HEDLEY_TI_VERSION) && \
809 !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \
810 !defined(JSON_HEDLEY_TI_CL430_VERSION) && \
811 !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \
812 !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \
813 !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \
814 !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \
815 !defined(__COMPCERT__) && \
816 !defined(JSON_HEDLEY_MCST_LCC_VERSION)
817 #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
820#if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
821 #undef JSON_HEDLEY_GCC_VERSION_CHECK
823#if defined(JSON_HEDLEY_GCC_VERSION)
824 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
826 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
829#if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
830 #undef JSON_HEDLEY_HAS_ATTRIBUTE
833 defined(__has_attribute) && \
835 (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \
837# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
839# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
842#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
843 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
845#if defined(__has_attribute)
846 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
848 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
851#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
852 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
854#if defined(__has_attribute)
855 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
857 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
860#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
861 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
864 defined(__has_cpp_attribute) && \
865 defined(__cplusplus) && \
866 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0))
867 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
869 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
872#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
873 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
875#if !defined(__cplusplus) || !defined(__has_cpp_attribute)
876 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
878 !defined(JSON_HEDLEY_PGI_VERSION) && \
879 !defined(JSON_HEDLEY_IAR_VERSION) && \
880 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \
881 (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0))
882 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)
884 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
887#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
888 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
890#if defined(__has_cpp_attribute) && defined(__cplusplus)
891 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
893 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
896#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
897 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
899#if defined(__has_cpp_attribute) && defined(__cplusplus)
900 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
902 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
905#if defined(JSON_HEDLEY_HAS_BUILTIN)
906 #undef JSON_HEDLEY_HAS_BUILTIN
908#if defined(__has_builtin)
909 #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
911 #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
914#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
915 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
917#if defined(__has_builtin)
918 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
920 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
923#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
924 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
926#if defined(__has_builtin)
927 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
929 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
932#if defined(JSON_HEDLEY_HAS_FEATURE)
933 #undef JSON_HEDLEY_HAS_FEATURE
935#if defined(__has_feature)
936 #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
938 #define JSON_HEDLEY_HAS_FEATURE(feature) (0)
941#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
942 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
944#if defined(__has_feature)
945 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
947 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
950#if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
951 #undef JSON_HEDLEY_GCC_HAS_FEATURE
953#if defined(__has_feature)
954 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
956 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
959#if defined(JSON_HEDLEY_HAS_EXTENSION)
960 #undef JSON_HEDLEY_HAS_EXTENSION
962#if defined(__has_extension)
963 #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
965 #define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
968#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
969 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
971#if defined(__has_extension)
972 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
974 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
977#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
978 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
980#if defined(__has_extension)
981 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
983 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
986#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
987 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
989#if defined(__has_declspec_attribute)
990 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
992 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
995#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
996 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
998#if defined(__has_declspec_attribute)
999 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
1001 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
1004#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
1005 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
1007#if defined(__has_declspec_attribute)
1008 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
1010 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
1013#if defined(JSON_HEDLEY_HAS_WARNING)
1014 #undef JSON_HEDLEY_HAS_WARNING
1016#if defined(__has_warning)
1017 #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
1019 #define JSON_HEDLEY_HAS_WARNING(warning) (0)
1022#if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
1023 #undef JSON_HEDLEY_GNUC_HAS_WARNING
1025#if defined(__has_warning)
1026 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
1028 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
1031#if defined(JSON_HEDLEY_GCC_HAS_WARNING)
1032 #undef JSON_HEDLEY_GCC_HAS_WARNING
1034#if defined(__has_warning)
1035 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
1037 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
1041 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1042 defined(__clang__) || \
1043 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1044 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1045 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1046 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
1047 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1048 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1049 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1050 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1051 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1052 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \
1053 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1054 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1055 JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
1056 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
1057 JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
1058 (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
1059 #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
1060#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1061 #define JSON_HEDLEY_PRAGMA(value) __pragma(value)
1063 #define JSON_HEDLEY_PRAGMA(value)
1066#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
1067 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
1069#if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
1070 #undef JSON_HEDLEY_DIAGNOSTIC_POP
1072#if defined(__clang__)
1073 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
1074 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
1075#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1076 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
1077 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
1078#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1079 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
1080 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
1082 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
1083 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1084 #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
1085 #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
1086#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
1087 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
1088 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
1090 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1091 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1092 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \
1093 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1094 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1095 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1096 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
1097 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
1098#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
1099 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
1100 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
1102 #define JSON_HEDLEY_DIAGNOSTIC_PUSH
1103 #define JSON_HEDLEY_DIAGNOSTIC_POP
1108#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
1109 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
1111#if defined(__cplusplus)
1112# if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
1113# if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions")
1114# if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions")
1115# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1116 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1117 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1118 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
1119 _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \
1121 JSON_HEDLEY_DIAGNOSTIC_POP
1123# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1124 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1125 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1126 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
1128 JSON_HEDLEY_DIAGNOSTIC_POP
1131# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1132 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1133 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1135 JSON_HEDLEY_DIAGNOSTIC_POP
1139#if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
1140 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
1143#if defined(JSON_HEDLEY_CONST_CAST)
1144 #undef JSON_HEDLEY_CONST_CAST
1146#if defined(__cplusplus)
1147# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
1149 JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
1150 JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \
1151 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1152# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \
1153 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1154 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
1156 JSON_HEDLEY_DIAGNOSTIC_POP \
1159# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
1162#if defined(JSON_HEDLEY_REINTERPRET_CAST)
1163 #undef JSON_HEDLEY_REINTERPRET_CAST
1165#if defined(__cplusplus)
1166 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
1168 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr))
1171#if defined(JSON_HEDLEY_STATIC_CAST)
1172 #undef JSON_HEDLEY_STATIC_CAST
1174#if defined(__cplusplus)
1175 #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
1177 #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
1180#if defined(JSON_HEDLEY_CPP_CAST)
1181 #undef JSON_HEDLEY_CPP_CAST
1183#if defined(__cplusplus)
1184# if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
1185# define JSON_HEDLEY_CPP_CAST(T, expr) \
1186 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1187 _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \
1189 JSON_HEDLEY_DIAGNOSTIC_POP
1190# elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0)
1191# define JSON_HEDLEY_CPP_CAST(T, expr) \
1192 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1193 _Pragma("diag_suppress=Pe137") \
1194 JSON_HEDLEY_DIAGNOSTIC_POP
1196# define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr))
1199# define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
1202#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
1203 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1205#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
1206 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
1207#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1208 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
1209#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1210 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786))
1211#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1212 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445")
1213#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1214 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1215#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1216 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1217#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1218 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
1219#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1220 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1222 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1223 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1224 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1225 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1226 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1227 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1228 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1229 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1230 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1231 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1232 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1233 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
1234#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
1235 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
1236#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
1237 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
1238#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1239 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
1240#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
1241 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
1243 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1246#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
1247 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1249#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1250 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
1251#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1252 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
1253#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1254 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161))
1255#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1256 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
1257#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1258 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
1259#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1260 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))
1262 JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \
1263 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1264 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1265 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)
1266 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1267#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0)
1268 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1269#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1270 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
1271#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1272 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161")
1274 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1277#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
1278 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1280#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
1281 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"")
1282#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1283 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1284#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
1285 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
1286#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1287 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292))
1288#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
1289 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))
1290#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1291 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098")
1292#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1293 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1294#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
1295 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
1297 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1298 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1299 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0)
1300 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
1301#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1302 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097")
1303#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1304 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1306 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1309#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
1310 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1312#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
1313 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
1314#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1315 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
1316#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
1317 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
1319 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1322#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION)
1323 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1325#if JSON_HEDLEY_HAS_WARNING("-Wunused-function")
1326 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"")
1327#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0)
1328 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"")
1329#elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0)
1330 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505))
1331#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1332 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142")
1334 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1337#if defined(JSON_HEDLEY_DEPRECATED)
1338 #undef JSON_HEDLEY_DEPRECATED
1340#if defined(JSON_HEDLEY_DEPRECATED_FOR)
1341 #undef JSON_HEDLEY_DEPRECATED_FOR
1344 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1345 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1346 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
1347 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
1349 (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1350 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1351 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1352 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1353 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \
1354 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1355 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1356 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \
1357 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1358 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1359 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \
1360 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1361 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
1362 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
1363#elif defined(__cplusplus) && (__cplusplus >= 201402L)
1364 #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
1365 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
1367 JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
1368 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1369 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1370 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1371 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1372 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1373 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1374 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1375 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1376 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1377 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1378 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1379 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1380 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1381 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1382 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1383 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
1384 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
1386 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1387 JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \
1388 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1389 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
1390 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
1391#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1392 #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
1393 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
1395 #define JSON_HEDLEY_DEPRECATED(since)
1396 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
1399#if defined(JSON_HEDLEY_UNAVAILABLE)
1400 #undef JSON_HEDLEY_UNAVAILABLE
1403 JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
1404 JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
1405 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1406 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1407 #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
1409 #define JSON_HEDLEY_UNAVAILABLE(available_since)
1412#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT)
1413 #undef JSON_HEDLEY_WARN_UNUSED_RESULT
1415#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG)
1416 #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
1419 JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
1420 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1421 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1422 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1423 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1424 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1425 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1426 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1427 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1428 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1429 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1430 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1431 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1432 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1433 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1434 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1435 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1436 #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
1437 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__))
1438#elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)
1439 #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1440 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
1441#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
1442 #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1443 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1444#elif defined(_Check_return_)
1445 #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_
1446 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_
1448 #define JSON_HEDLEY_WARN_UNUSED_RESULT
1449 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg)
1452#if defined(JSON_HEDLEY_SENTINEL)
1453 #undef JSON_HEDLEY_SENTINEL
1456 JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
1457 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1458 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1459 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1460 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1461 #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
1463 #define JSON_HEDLEY_SENTINEL(position)
1466#if defined(JSON_HEDLEY_NO_RETURN)
1467 #undef JSON_HEDLEY_NO_RETURN
1469#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1470 #define JSON_HEDLEY_NO_RETURN __noreturn
1472 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1473 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1474 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1475#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
1476 #define JSON_HEDLEY_NO_RETURN _Noreturn
1477#elif defined(__cplusplus) && (__cplusplus >= 201103L)
1478 #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
1480 JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
1481 JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \
1482 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1483 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1484 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1485 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1486 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1487 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1488 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1489 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1490 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1491 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1492 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1493 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1494 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1495 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1496 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1497 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1498#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1499 #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
1501 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1502 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1503 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1504#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1505 #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
1506#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1507 #define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
1508#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1509 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1511 #define JSON_HEDLEY_NO_RETURN
1514#if defined(JSON_HEDLEY_NO_ESCAPE)
1515 #undef JSON_HEDLEY_NO_ESCAPE
1517#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
1518 #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
1520 #define JSON_HEDLEY_NO_ESCAPE
1523#if defined(JSON_HEDLEY_UNREACHABLE)
1524 #undef JSON_HEDLEY_UNREACHABLE
1526#if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
1527 #undef JSON_HEDLEY_UNREACHABLE_RETURN
1529#if defined(JSON_HEDLEY_ASSUME)
1530 #undef JSON_HEDLEY_ASSUME
1533 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1534 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1535 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1536 #define JSON_HEDLEY_ASSUME(expr) __assume(expr)
1537#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
1538 #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
1540 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1541 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1542 #if defined(__cplusplus)
1543 #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
1545 #define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
1549 (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
1550 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1551 JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \
1552 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1553 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \
1554 JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \
1555 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1556 #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
1557#elif defined(JSON_HEDLEY_ASSUME)
1558 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1560#if !defined(JSON_HEDLEY_ASSUME)
1561 #if defined(JSON_HEDLEY_UNREACHABLE)
1562 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1)))
1564 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr)
1567#if defined(JSON_HEDLEY_UNREACHABLE)
1569 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1570 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1571 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))
1573 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
1576 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value)
1578#if !defined(JSON_HEDLEY_UNREACHABLE)
1579 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1583#if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
1584 #pragma clang diagnostic ignored "-Wpedantic"
1586#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
1587 #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
1589#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0)
1590 #if defined(__clang__)
1591 #pragma clang diagnostic ignored "-Wvariadic-macros"
1592 #elif defined(JSON_HEDLEY_GCC_VERSION)
1593 #pragma GCC diagnostic ignored "-Wvariadic-macros"
1596#if defined(JSON_HEDLEY_NON_NULL)
1597 #undef JSON_HEDLEY_NON_NULL
1600 JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
1601 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1602 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1603 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1604 #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
1606 #define JSON_HEDLEY_NON_NULL(...)
1610#if defined(JSON_HEDLEY_PRINTF_FORMAT)
1611 #undef JSON_HEDLEY_PRINTF_FORMAT
1613#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO)
1614 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))
1615#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO)
1616 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
1618 JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
1619 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1620 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1621 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1622 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1623 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1624 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1625 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1626 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1627 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1628 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1629 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1630 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1631 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1632 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1633 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1634 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1635 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
1636#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
1637 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
1639 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
1642#if defined(JSON_HEDLEY_CONSTEXPR)
1643 #undef JSON_HEDLEY_CONSTEXPR
1645#if defined(__cplusplus)
1646 #if __cplusplus >= 201103L
1647 #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)
1650#if !defined(JSON_HEDLEY_CONSTEXPR)
1651 #define JSON_HEDLEY_CONSTEXPR
1654#if defined(JSON_HEDLEY_PREDICT)
1655 #undef JSON_HEDLEY_PREDICT
1657#if defined(JSON_HEDLEY_LIKELY)
1658 #undef JSON_HEDLEY_LIKELY
1660#if defined(JSON_HEDLEY_UNLIKELY)
1661 #undef JSON_HEDLEY_UNLIKELY
1663#if defined(JSON_HEDLEY_UNPREDICTABLE)
1664 #undef JSON_HEDLEY_UNPREDICTABLE
1666#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
1667 #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
1670 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
1671 JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \
1672 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1673# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability))
1674# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability))
1675# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability))
1676# define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 )
1677# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 )
1679 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
1680 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1681 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1682 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1683 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1684 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1685 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1686 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1687 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1688 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1689 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1690 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1691 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1692 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \
1693 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1694 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1695# define JSON_HEDLEY_PREDICT(expr, expected, probability) \
1696 (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))
1697# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
1699 double hedley_probability_ = (probability); \
1700 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
1702# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
1704 double hedley_probability_ = (probability); \
1705 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
1707# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1708# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1710# define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))
1711# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
1712# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
1713# define JSON_HEDLEY_LIKELY(expr) (!!(expr))
1714# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
1716#if !defined(JSON_HEDLEY_UNPREDICTABLE)
1717 #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
1720#if defined(JSON_HEDLEY_MALLOC)
1721 #undef JSON_HEDLEY_MALLOC
1724 JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
1725 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1726 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1727 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1728 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1729 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1730 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1731 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1732 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1733 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1734 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1735 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1736 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1737 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1738 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1739 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1740 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1741 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1742 #define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
1743#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1744 #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
1746 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1747 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1748 #define JSON_HEDLEY_MALLOC __declspec(restrict)
1750 #define JSON_HEDLEY_MALLOC
1753#if defined(JSON_HEDLEY_PURE)
1754 #undef JSON_HEDLEY_PURE
1757 JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
1758 JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \
1759 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1760 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1761 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1762 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1763 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1764 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1765 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1766 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1767 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1768 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1769 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1770 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1771 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1772 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1773 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1774 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1775 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1776# define JSON_HEDLEY_PURE __attribute__((__pure__))
1777#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1778# define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
1779#elif defined(__cplusplus) && \
1781 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1782 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \
1783 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \
1785# define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
1787# define JSON_HEDLEY_PURE
1790#if defined(JSON_HEDLEY_CONST)
1791 #undef JSON_HEDLEY_CONST
1794 JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
1795 JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \
1796 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1797 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1798 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1799 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1800 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1801 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1802 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1803 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1804 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1805 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1806 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1807 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1808 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1809 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1810 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1811 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1812 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1813 #define JSON_HEDLEY_CONST __attribute__((__const__))
1815 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1816 #define JSON_HEDLEY_CONST _Pragma("no_side_effect")
1818 #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
1821#if defined(JSON_HEDLEY_RESTRICT)
1822 #undef JSON_HEDLEY_RESTRICT
1824#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
1825 #define JSON_HEDLEY_RESTRICT restrict
1827 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1828 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1829 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1830 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1831 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1832 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1833 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1834 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1835 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \
1836 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1837 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1838 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
1839 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1840 defined(__clang__) || \
1841 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1842 #define JSON_HEDLEY_RESTRICT __restrict
1843#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
1844 #define JSON_HEDLEY_RESTRICT _Restrict
1846 #define JSON_HEDLEY_RESTRICT
1849#if defined(JSON_HEDLEY_INLINE)
1850 #undef JSON_HEDLEY_INLINE
1853 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1854 (defined(__cplusplus) && (__cplusplus >= 199711L))
1855 #define JSON_HEDLEY_INLINE inline
1857 defined(JSON_HEDLEY_GCC_VERSION) || \
1858 JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
1859 #define JSON_HEDLEY_INLINE __inline__
1861 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1862 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1863 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1864 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \
1865 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1866 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1867 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1868 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1869 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1870 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1871 #define JSON_HEDLEY_INLINE __inline
1873 #define JSON_HEDLEY_INLINE
1876#if defined(JSON_HEDLEY_ALWAYS_INLINE)
1877 #undef JSON_HEDLEY_ALWAYS_INLINE
1880 JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
1881 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1882 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1883 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1884 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1885 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1886 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1887 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1888 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1889 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1890 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1891 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1892 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1893 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1894 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1895 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1896 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1897 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1898 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1899# define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
1901 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1902 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1903# define JSON_HEDLEY_ALWAYS_INLINE __forceinline
1904#elif defined(__cplusplus) && \
1906 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1907 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1908 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1909 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1910 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1911 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \
1913# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
1914#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1915# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
1917# define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
1920#if defined(JSON_HEDLEY_NEVER_INLINE)
1921 #undef JSON_HEDLEY_NEVER_INLINE
1924 JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
1925 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1926 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1927 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1928 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1929 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1930 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1931 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1932 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1933 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1934 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1935 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1936 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1937 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1938 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1939 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1940 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1941 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1942 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1943 #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
1945 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1946 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1947 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1948#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
1949 #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
1950#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1951 #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
1952#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1953 #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
1954#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1955 #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
1956#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1957 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1959 #define JSON_HEDLEY_NEVER_INLINE
1962#if defined(JSON_HEDLEY_PRIVATE)
1963 #undef JSON_HEDLEY_PRIVATE
1965#if defined(JSON_HEDLEY_PUBLIC)
1966 #undef JSON_HEDLEY_PUBLIC
1968#if defined(JSON_HEDLEY_IMPORT)
1969 #undef JSON_HEDLEY_IMPORT
1971#if defined(_WIN32) || defined(__CYGWIN__)
1972# define JSON_HEDLEY_PRIVATE
1973# define JSON_HEDLEY_PUBLIC __declspec(dllexport)
1974# define JSON_HEDLEY_IMPORT __declspec(dllimport)
1977 JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
1978 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1979 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1980 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1981 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1982 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1984 defined(__TI_EABI__) && \
1986 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1987 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \
1990 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1991# define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
1992# define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
1994# define JSON_HEDLEY_PRIVATE
1995# define JSON_HEDLEY_PUBLIC
1997# define JSON_HEDLEY_IMPORT extern
2000#if defined(JSON_HEDLEY_NO_THROW)
2001 #undef JSON_HEDLEY_NO_THROW
2004 JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
2005 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
2006 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2007 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2008 #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
2010 JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
2011 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
2012 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
2013 #define JSON_HEDLEY_NO_THROW __declspec(nothrow)
2015 #define JSON_HEDLEY_NO_THROW
2018#if defined(JSON_HEDLEY_FALL_THROUGH)
2019 #undef JSON_HEDLEY_FALL_THROUGH
2022 JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
2023 JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \
2024 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2025 #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
2026#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
2027 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
2028#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
2029 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])
2030#elif defined(__fallthrough)
2031 #define JSON_HEDLEY_FALL_THROUGH __fallthrough
2033 #define JSON_HEDLEY_FALL_THROUGH
2036#if defined(JSON_HEDLEY_RETURNS_NON_NULL)
2037 #undef JSON_HEDLEY_RETURNS_NON_NULL
2040 JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
2041 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
2042 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2043 #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__))
2044#elif defined(_Ret_notnull_)
2045 #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_
2047 #define JSON_HEDLEY_RETURNS_NON_NULL
2050#if defined(JSON_HEDLEY_ARRAY_PARAM)
2051 #undef JSON_HEDLEY_ARRAY_PARAM
2054 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
2055 !defined(__STDC_NO_VLA__) && \
2056 !defined(__cplusplus) && \
2057 !defined(JSON_HEDLEY_PGI_VERSION) && \
2058 !defined(JSON_HEDLEY_TINYC_VERSION)
2059 #define JSON_HEDLEY_ARRAY_PARAM(name) (name)
2061 #define JSON_HEDLEY_ARRAY_PARAM(name)
2064#if defined(JSON_HEDLEY_IS_CONSTANT)
2065 #undef JSON_HEDLEY_IS_CONSTANT
2067#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
2068 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
2072#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
2073 #undef JSON_HEDLEY_IS_CONSTEXPR_
2076 JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
2077 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
2078 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2079 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
2080 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
2081 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
2082 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
2083 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
2084 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
2085 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2086 #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
2088#if !defined(__cplusplus)
2090 JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
2091 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
2092 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2093 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
2094 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
2095 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
2096 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
2097#if defined(__INTPTR_TYPE__)
2098 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
2101 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
2105 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
2106 !defined(JSON_HEDLEY_SUNPRO_VERSION) && \
2107 !defined(JSON_HEDLEY_PGI_VERSION) && \
2108 !defined(JSON_HEDLEY_IAR_VERSION)) || \
2109 (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
2110 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
2111 JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
2112 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
2113 JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
2114#if defined(__INTPTR_TYPE__)
2115 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
2118 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)
2121 defined(JSON_HEDLEY_GCC_VERSION) || \
2122 defined(JSON_HEDLEY_INTEL_VERSION) || \
2123 defined(JSON_HEDLEY_TINYC_VERSION) || \
2124 defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
2125 JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \
2126 defined(JSON_HEDLEY_TI_CL2000_VERSION) || \
2127 defined(JSON_HEDLEY_TI_CL6X_VERSION) || \
2128 defined(JSON_HEDLEY_TI_CL7X_VERSION) || \
2129 defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \
2131# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
2135 ((void*) ((expr) * 0L) ) : \
2136((struct { char v[sizeof(void) * 2]; } *) 1) \
2142#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
2143 #if !defined(JSON_HEDLEY_IS_CONSTANT)
2144 #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
2146 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))
2148 #if !defined(JSON_HEDLEY_IS_CONSTANT)
2149 #define JSON_HEDLEY_IS_CONSTANT(expr) (0)
2151 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
2154#if defined(JSON_HEDLEY_BEGIN_C_DECLS)
2155 #undef JSON_HEDLEY_BEGIN_C_DECLS
2157#if defined(JSON_HEDLEY_END_C_DECLS)
2158 #undef JSON_HEDLEY_END_C_DECLS
2160#if defined(JSON_HEDLEY_C_DECL)
2161 #undef JSON_HEDLEY_C_DECL
2163#if defined(__cplusplus)
2164 #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
2165 #define JSON_HEDLEY_END_C_DECLS }
2166 #define JSON_HEDLEY_C_DECL extern "C"
2168 #define JSON_HEDLEY_BEGIN_C_DECLS
2169 #define JSON_HEDLEY_END_C_DECLS
2170 #define JSON_HEDLEY_C_DECL
2173#if defined(JSON_HEDLEY_STATIC_ASSERT)
2174 #undef JSON_HEDLEY_STATIC_ASSERT
2177 !defined(__cplusplus) && ( \
2178 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
2179 (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
2180 JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
2181 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2182 defined(_Static_assert) \
2184# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
2186 (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
2187 JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \
2188 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2189# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
2191# define JSON_HEDLEY_STATIC_ASSERT(expr, message)
2194#if defined(JSON_HEDLEY_NULL)
2195 #undef JSON_HEDLEY_NULL
2197#if defined(__cplusplus)
2198 #if __cplusplus >= 201103L
2199 #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)
2201 #define JSON_HEDLEY_NULL NULL
2203 #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
2206 #define JSON_HEDLEY_NULL NULL
2208 #define JSON_HEDLEY_NULL ((void*) 0)
2211#if defined(JSON_HEDLEY_MESSAGE)
2212 #undef JSON_HEDLEY_MESSAGE
2214#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2215# define JSON_HEDLEY_MESSAGE(msg) \
2216 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2217 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2218 JSON_HEDLEY_PRAGMA(message msg) \
2219 JSON_HEDLEY_DIAGNOSTIC_POP
2221 JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
2222 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2223# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
2224#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
2225# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
2226#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
2227# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2228#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
2229# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2231# define JSON_HEDLEY_MESSAGE(msg)
2234#if defined(JSON_HEDLEY_WARNING)
2235 #undef JSON_HEDLEY_WARNING
2237#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2238# define JSON_HEDLEY_WARNING(msg) \
2239 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2240 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2241 JSON_HEDLEY_PRAGMA(clang warning msg) \
2242 JSON_HEDLEY_DIAGNOSTIC_POP
2244 JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
2245 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
2246 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2247# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
2249 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
2250 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2251# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
2253# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
2256#if defined(JSON_HEDLEY_REQUIRE)
2257 #undef JSON_HEDLEY_REQUIRE
2259#if defined(JSON_HEDLEY_REQUIRE_MSG)
2260 #undef JSON_HEDLEY_REQUIRE_MSG
2262#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
2263# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
2264# define JSON_HEDLEY_REQUIRE(expr) \
2265 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2266 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2267 __attribute__((diagnose_if(!(expr), #expr, "error"))) \
2268 JSON_HEDLEY_DIAGNOSTIC_POP
2269# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \
2270 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2271 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2272 __attribute__((diagnose_if(!(expr), msg, "error"))) \
2273 JSON_HEDLEY_DIAGNOSTIC_POP
2275# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error")))
2276# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error")))
2279# define JSON_HEDLEY_REQUIRE(expr)
2280# define JSON_HEDLEY_REQUIRE_MSG(expr,msg)
2283#if defined(JSON_HEDLEY_FLAGS)
2284 #undef JSON_HEDLEY_FLAGS
2286#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion"))
2287 #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
2289 #define JSON_HEDLEY_FLAGS
2292#if defined(JSON_HEDLEY_FLAGS_CAST)
2293 #undef JSON_HEDLEY_FLAGS_CAST
2295#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)
2296# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \
2297 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2298 _Pragma("warning(disable:188)") \
2300 JSON_HEDLEY_DIAGNOSTIC_POP \
2303# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
2306#if defined(JSON_HEDLEY_EMPTY_BASES)
2307 #undef JSON_HEDLEY_EMPTY_BASES
2310 (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \
2311 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2312 #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
2314 #define JSON_HEDLEY_EMPTY_BASES
2319#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
2320 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
2322#if defined(__clang__)
2323 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
2325 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
2328#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
2329 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
2331#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
2333#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
2334 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
2336#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
2338#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
2339 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
2341#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
2343#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
2344 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
2346#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
2348#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
2349 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
2351#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
2353#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
2354 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
2356#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
2358#if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
2359 #undef JSON_HEDLEY_CLANG_HAS_WARNING
2361#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
2373#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
2374 #if defined(__clang__)
2375 #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
2376 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
2378 #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
2379 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
2380 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
2387#if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)
2388 #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
2389 #define JSON_HAS_CPP_20
2390 #define JSON_HAS_CPP_17
2391 #define JSON_HAS_CPP_14
2392 #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1)
2393 #define JSON_HAS_CPP_17
2394 #define JSON_HAS_CPP_14
2395 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
2396 #define JSON_HAS_CPP_14
2399 #define JSON_HAS_CPP_11
2403 #if __has_include(<version>)
2408#if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM)
2409 #ifdef JSON_HAS_CPP_17
2410 #if defined(__cpp_lib_filesystem)
2411 #define JSON_HAS_FILESYSTEM 1
2412 #elif defined(__cpp_lib_experimental_filesystem)
2413 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2414 #elif !defined(__has_include)
2415 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2416 #elif __has_include(<filesystem>)
2417 #define JSON_HAS_FILESYSTEM 1
2418 #elif __has_include(<experimental/filesystem>)
2419 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2423 #if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8
2424 #undef JSON_HAS_FILESYSTEM
2425 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2429 #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 8
2430 #undef JSON_HAS_FILESYSTEM
2431 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2435 #if defined(__clang_major__) && __clang_major__ < 7
2436 #undef JSON_HAS_FILESYSTEM
2437 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2441 #if defined(_MSC_VER) && _MSC_VER < 1914
2442 #undef JSON_HAS_FILESYSTEM
2443 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2447 #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000
2448 #undef JSON_HAS_FILESYSTEM
2449 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2453 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
2454 #undef JSON_HAS_FILESYSTEM
2455 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2460#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2461 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0
2464#ifndef JSON_HAS_FILESYSTEM
2465 #define JSON_HAS_FILESYSTEM 0
2468#ifndef JSON_HAS_THREE_WAY_COMPARISON
2469 #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L \
2470 && defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L
2471 #define JSON_HAS_THREE_WAY_COMPARISON 1
2473 #define JSON_HAS_THREE_WAY_COMPARISON 0
2477#ifndef JSON_HAS_RANGES
2479 #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427
2480 #define JSON_HAS_RANGES 0
2481 #elif defined(__cpp_lib_ranges)
2482 #define JSON_HAS_RANGES 1
2484 #define JSON_HAS_RANGES 0
2488#ifdef JSON_HAS_CPP_17
2489 #define JSON_INLINE_VARIABLE inline
2491 #define JSON_INLINE_VARIABLE
2494#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address)
2495 #define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]]
2497 #define JSON_NO_UNIQUE_ADDRESS
2501#if defined(__clang__)
2502 #pragma clang diagnostic push
2503 #pragma clang diagnostic ignored "-Wdocumentation"
2504 #pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
2508#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
2509 #define JSON_THROW(exception) throw exception
2510 #define JSON_TRY try
2511 #define JSON_CATCH(exception) catch(exception)
2512 #define JSON_INTERNAL_CATCH(exception) catch(exception)
2515 #define JSON_THROW(exception) std::abort()
2516 #define JSON_TRY if(true)
2517 #define JSON_CATCH(exception) if(false)
2518 #define JSON_INTERNAL_CATCH(exception) if(false)
2522#if defined(JSON_THROW_USER)
2524 #define JSON_THROW JSON_THROW_USER
2526#if defined(JSON_TRY_USER)
2528 #define JSON_TRY JSON_TRY_USER
2530#if defined(JSON_CATCH_USER)
2532 #define JSON_CATCH JSON_CATCH_USER
2533 #undef JSON_INTERNAL_CATCH
2534 #define JSON_INTERNAL_CATCH JSON_CATCH_USER
2536#if defined(JSON_INTERNAL_CATCH_USER)
2537 #undef JSON_INTERNAL_CATCH
2538 #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2542#if !defined(JSON_ASSERT)
2544 #define JSON_ASSERT(x) assert(x)
2548#if defined(JSON_TESTS_PRIVATE)
2549 #define JSON_PRIVATE_UNLESS_TESTED public
2551 #define JSON_PRIVATE_UNLESS_TESTED private
2559#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2560 template<typename BasicJsonType> \
2561 inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
2563 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2564 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2565 auto it = std::find_if(std::begin(m), std::end(m), \
2566 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2568 return ej_pair.first == e; \
2570 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2572 template<typename BasicJsonType> \
2573 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
2575 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2576 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2577 auto it = std::find_if(std::begin(m), std::end(m), \
2578 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2580 return ej_pair.second == j; \
2582 e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2588#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2589 template<template<typename, typename, typename...> class ObjectType, \
2590 template<typename, typename...> class ArrayType, \
2591 class StringType, class BooleanType, class NumberIntegerType, \
2592 class NumberUnsignedType, class NumberFloatType, \
2593 template<typename> class AllocatorType, \
2594 template<typename, typename = void> class JSONSerializer, \
2596 class CustomBaseClass>
2598#define NLOHMANN_BASIC_JSON_TPL \
2599 basic_json<ObjectType, ArrayType, StringType, BooleanType, \
2600 NumberIntegerType, NumberUnsignedType, NumberFloatType, \
2601 AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>
2605#define NLOHMANN_JSON_EXPAND( x ) x
2606#define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME,...) NAME
2607#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
2608 NLOHMANN_JSON_PASTE64, \
2609 NLOHMANN_JSON_PASTE63, \
2610 NLOHMANN_JSON_PASTE62, \
2611 NLOHMANN_JSON_PASTE61, \
2612 NLOHMANN_JSON_PASTE60, \
2613 NLOHMANN_JSON_PASTE59, \
2614 NLOHMANN_JSON_PASTE58, \
2615 NLOHMANN_JSON_PASTE57, \
2616 NLOHMANN_JSON_PASTE56, \
2617 NLOHMANN_JSON_PASTE55, \
2618 NLOHMANN_JSON_PASTE54, \
2619 NLOHMANN_JSON_PASTE53, \
2620 NLOHMANN_JSON_PASTE52, \
2621 NLOHMANN_JSON_PASTE51, \
2622 NLOHMANN_JSON_PASTE50, \
2623 NLOHMANN_JSON_PASTE49, \
2624 NLOHMANN_JSON_PASTE48, \
2625 NLOHMANN_JSON_PASTE47, \
2626 NLOHMANN_JSON_PASTE46, \
2627 NLOHMANN_JSON_PASTE45, \
2628 NLOHMANN_JSON_PASTE44, \
2629 NLOHMANN_JSON_PASTE43, \
2630 NLOHMANN_JSON_PASTE42, \
2631 NLOHMANN_JSON_PASTE41, \
2632 NLOHMANN_JSON_PASTE40, \
2633 NLOHMANN_JSON_PASTE39, \
2634 NLOHMANN_JSON_PASTE38, \
2635 NLOHMANN_JSON_PASTE37, \
2636 NLOHMANN_JSON_PASTE36, \
2637 NLOHMANN_JSON_PASTE35, \
2638 NLOHMANN_JSON_PASTE34, \
2639 NLOHMANN_JSON_PASTE33, \
2640 NLOHMANN_JSON_PASTE32, \
2641 NLOHMANN_JSON_PASTE31, \
2642 NLOHMANN_JSON_PASTE30, \
2643 NLOHMANN_JSON_PASTE29, \
2644 NLOHMANN_JSON_PASTE28, \
2645 NLOHMANN_JSON_PASTE27, \
2646 NLOHMANN_JSON_PASTE26, \
2647 NLOHMANN_JSON_PASTE25, \
2648 NLOHMANN_JSON_PASTE24, \
2649 NLOHMANN_JSON_PASTE23, \
2650 NLOHMANN_JSON_PASTE22, \
2651 NLOHMANN_JSON_PASTE21, \
2652 NLOHMANN_JSON_PASTE20, \
2653 NLOHMANN_JSON_PASTE19, \
2654 NLOHMANN_JSON_PASTE18, \
2655 NLOHMANN_JSON_PASTE17, \
2656 NLOHMANN_JSON_PASTE16, \
2657 NLOHMANN_JSON_PASTE15, \
2658 NLOHMANN_JSON_PASTE14, \
2659 NLOHMANN_JSON_PASTE13, \
2660 NLOHMANN_JSON_PASTE12, \
2661 NLOHMANN_JSON_PASTE11, \
2662 NLOHMANN_JSON_PASTE10, \
2663 NLOHMANN_JSON_PASTE9, \
2664 NLOHMANN_JSON_PASTE8, \
2665 NLOHMANN_JSON_PASTE7, \
2666 NLOHMANN_JSON_PASTE6, \
2667 NLOHMANN_JSON_PASTE5, \
2668 NLOHMANN_JSON_PASTE4, \
2669 NLOHMANN_JSON_PASTE3, \
2670 NLOHMANN_JSON_PASTE2, \
2671 NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
2672#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
2673#define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
2674#define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
2675#define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
2676#define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
2677#define NLOHMANN_JSON_PASTE7(func, v1, v2, v3, v4, v5, v6) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE6(func, v2, v3, v4, v5, v6)
2678#define NLOHMANN_JSON_PASTE8(func, v1, v2, v3, v4, v5, v6, v7) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE7(func, v2, v3, v4, v5, v6, v7)
2679#define NLOHMANN_JSON_PASTE9(func, v1, v2, v3, v4, v5, v6, v7, v8) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE8(func, v2, v3, v4, v5, v6, v7, v8)
2680#define NLOHMANN_JSON_PASTE10(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE9(func, v2, v3, v4, v5, v6, v7, v8, v9)
2681#define NLOHMANN_JSON_PASTE11(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE10(func, v2, v3, v4, v5, v6, v7, v8, v9, v10)
2682#define NLOHMANN_JSON_PASTE12(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE11(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11)
2683#define NLOHMANN_JSON_PASTE13(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE12(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)
2684#define NLOHMANN_JSON_PASTE14(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE13(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)
2685#define NLOHMANN_JSON_PASTE15(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE14(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)
2686#define NLOHMANN_JSON_PASTE16(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE15(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)
2687#define NLOHMANN_JSON_PASTE17(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE16(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16)
2688#define NLOHMANN_JSON_PASTE18(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE17(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17)
2689#define NLOHMANN_JSON_PASTE19(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE18(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18)
2690#define NLOHMANN_JSON_PASTE20(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE19(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19)
2691#define NLOHMANN_JSON_PASTE21(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE20(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20)
2692#define NLOHMANN_JSON_PASTE22(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE21(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21)
2693#define NLOHMANN_JSON_PASTE23(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE22(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22)
2694#define NLOHMANN_JSON_PASTE24(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE23(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23)
2695#define NLOHMANN_JSON_PASTE25(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE24(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24)
2696#define NLOHMANN_JSON_PASTE26(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE25(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25)
2697#define NLOHMANN_JSON_PASTE27(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE26(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26)
2698#define NLOHMANN_JSON_PASTE28(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE27(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27)
2699#define NLOHMANN_JSON_PASTE29(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE28(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28)
2700#define NLOHMANN_JSON_PASTE30(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE29(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29)
2701#define NLOHMANN_JSON_PASTE31(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE30(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30)
2702#define NLOHMANN_JSON_PASTE32(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE31(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31)
2703#define NLOHMANN_JSON_PASTE33(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE32(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32)
2704#define NLOHMANN_JSON_PASTE34(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE33(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33)
2705#define NLOHMANN_JSON_PASTE35(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE34(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34)
2706#define NLOHMANN_JSON_PASTE36(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE35(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35)
2707#define NLOHMANN_JSON_PASTE37(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE36(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36)
2708#define NLOHMANN_JSON_PASTE38(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE37(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37)
2709#define NLOHMANN_JSON_PASTE39(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE38(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38)
2710#define NLOHMANN_JSON_PASTE40(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE39(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39)
2711#define NLOHMANN_JSON_PASTE41(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE40(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40)
2712#define NLOHMANN_JSON_PASTE42(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE41(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41)
2713#define NLOHMANN_JSON_PASTE43(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE42(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42)
2714#define NLOHMANN_JSON_PASTE44(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE43(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43)
2715#define NLOHMANN_JSON_PASTE45(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE44(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44)
2716#define NLOHMANN_JSON_PASTE46(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE45(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45)
2717#define NLOHMANN_JSON_PASTE47(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE46(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46)
2718#define NLOHMANN_JSON_PASTE48(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE47(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47)
2719#define NLOHMANN_JSON_PASTE49(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE48(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48)
2720#define NLOHMANN_JSON_PASTE50(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE49(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49)
2721#define NLOHMANN_JSON_PASTE51(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE50(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50)
2722#define NLOHMANN_JSON_PASTE52(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE51(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51)
2723#define NLOHMANN_JSON_PASTE53(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE52(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52)
2724#define NLOHMANN_JSON_PASTE54(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE53(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53)
2725#define NLOHMANN_JSON_PASTE55(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE54(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54)
2726#define NLOHMANN_JSON_PASTE56(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE55(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55)
2727#define NLOHMANN_JSON_PASTE57(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE56(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56)
2728#define NLOHMANN_JSON_PASTE58(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE57(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57)
2729#define NLOHMANN_JSON_PASTE59(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE58(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58)
2730#define NLOHMANN_JSON_PASTE60(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE59(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59)
2731#define NLOHMANN_JSON_PASTE61(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE60(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60)
2732#define NLOHMANN_JSON_PASTE62(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE61(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61)
2733#define NLOHMANN_JSON_PASTE63(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE62(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62)
2734#define NLOHMANN_JSON_PASTE64(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE63(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63)
2736#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2737#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2738#define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) nlohmann_json_t.v1 = nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1);
2745#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
2746 friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2747 friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2749#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \
2750 friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2751 friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
2758#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
2759 inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2760 inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2762#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \
2763 inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2764 inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
2773#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \
2774 namespace detail { \
2775 using std::std_name; \
2777 template<typename... T> \
2778 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2781 namespace detail2 { \
2782 struct std_name##_tag \
2786 template<typename... T> \
2787 std_name##_tag std_name(T&&...); \
2789 template<typename... T> \
2790 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2792 template<typename... T> \
2793 struct would_call_std_##std_name \
2795 static constexpr auto const value = ::nlohmann::detail:: \
2796 is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \
2800 template<typename... T> \
2801 struct would_call_std_##std_name : detail2::would_call_std_##std_name<T...> \
2805#ifndef JSON_USE_IMPLICIT_CONVERSIONS
2806 #define JSON_USE_IMPLICIT_CONVERSIONS 1
2809#if JSON_USE_IMPLICIT_CONVERSIONS
2810 #define JSON_EXPLICIT
2812 #define JSON_EXPLICIT explicit
2815#ifndef JSON_DISABLE_ENUM_SERIALIZATION
2816 #define JSON_DISABLE_ENUM_SERIALIZATION 0
2819#ifndef JSON_USE_GLOBAL_UDLS
2820 #define JSON_USE_GLOBAL_UDLS 1
2823#if JSON_HAS_THREE_WAY_COMPARISON
2886#if JSON_HAS_THREE_WAY_COMPARISON
2887 inline std::partial_ordering operator<=>(
const value_t lhs,
const value_t rhs)
noexcept
2892 static constexpr std::array<std::uint8_t, 9> order = {{
2899 const auto l_index =
static_cast<std::size_t
>(lhs);
2900 const auto r_index =
static_cast<std::size_t
>(rhs);
2901#if JSON_HAS_THREE_WAY_COMPARISON
2902 if (l_index < order.size() && r_index < order.size())
2904 return order[l_index] <=> order[r_index];
2906 return std::partial_ordering::unordered;
2908 return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
2916#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__)
2919 return std::is_lt(lhs <=> rhs);
2957template<
typename StringType>
2959 const StringType& t)
2962 for (
auto pos = s.find(f);
2963 pos != StringType::npos;
2964 s.replace(pos, f.size(), t),
2965 pos = s.find(f, pos + t.size()))
2976template<
typename StringType>
2991template<
typename StringType>
2992static void unescape(StringType& s)
3032 constexpr operator size_t()
const
3057#include <type_traits>
3068using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
3070#ifdef JSON_HAS_CPP_14
3073using std::enable_if_t;
3074using std::index_sequence;
3075using std::make_index_sequence;
3076using std::index_sequence_for;
3081template<
bool B,
typename T =
void>
3108template <
typename T, T... Ints>
3112 static constexpr std::size_t
size() noexcept
3114 return sizeof...(Ints);
3123template <
size_t... Ints>
3126namespace utility_internal
3129template <
typename Seq,
size_t SeqSize,
size_t Rem>
3133template <
typename T, T... Ints,
size_t SeqSize>
3139template <
typename T, T... Ints,
size_t SeqSize>
3147template <
typename T,
size_t N>
3154template <
typename T>
3169template <
typename T, T N>
3185template <
typename... Ts>
3203#ifndef JSON_HAS_CPP_17
3204 template<
typename T>
3208template<
typename T,
typename... Args>
3209inline constexpr std::array<T,
sizeof...(Args)>
make_array(Args&& ... args)
3211 return std::array<T,
sizeof...(Args)> {{
static_cast<T
>(std::forward<Args>(args))...}};
3229#include <type_traits>
3257template<
typename It,
typename =
void>
3260template<
typename It>
3264 typename It::reference, typename It::iterator_category >>
3275template<
typename T,
typename =
void>
3354#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
3355 #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
3380 template<
typename T =
void,
typename SFINAE =
void>
3385 template<
template<
typename U,
typename V,
typename... Args>
class ObjectType =
3387 template<
typename U,
typename... Args>
class ArrayType = std::vector,
3388 class StringType = std::string,
class BooleanType = bool,
3389 class NumberIntegerType = std::int64_t,
3390 class NumberUnsignedType = std::uint64_t,
3391 class NumberFloatType = double,
3392 template<
typename U>
class AllocatorType = std::allocator,
3393 template<
typename T,
typename SFINAE =
void>
class JSONSerializer =
3395 class BinaryType = std::vector<std::uint8_t>,
3396 class CustomBaseClass =
void>
3401 template<
typename RefStringType>
3412 template<
class Key,
class T,
class IgnoredLess,
class Allocator>
3457template<
typename BasicJsonContext>
3459 std::integral_constant < bool,
3460 is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value
3461 || std::is_same<BasicJsonContext, std::nullptr_t>::value >
3502template<
typename T,
typename... Args>
3505template<
typename T,
typename... Args>
3508template<
typename T,
typename U>
3512template<
typename BasicJsonType,
typename T,
typename =
void>
3519template <
typename BasicJsonType,
typename T>
3525template<
typename BasicJsonType,
typename T>
3528 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3530 static constexpr bool value =
3532 const BasicJsonType&, T&>::value;
3537template<
typename BasicJsonType,
typename T,
typename =
void>
3540template<
typename BasicJsonType,
typename T>
3543 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3545 static constexpr bool value =
3547 const BasicJsonType&>::value;
3552template<
typename BasicJsonType,
typename T,
typename =
void>
3555template<
typename BasicJsonType,
typename T>
3558 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3560 static constexpr bool value =
3569struct has_key_compare : std::integral_constant<bool, is_detected<detect_key_compare, T>::value> {};
3572template<
typename BasicJsonType>
3577 using type =
typename std::conditional < has_key_compare<object_t>::value,
3581template<
typename BasicJsonType>
3591template<
class B,
class... Bn>
3593: std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {};
3596template<
class B>
struct negation : std::integral_constant < bool, !B::value > { };
3601template <
typename T>
3604template <
typename T1,
typename T2>
3606 :
conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3608template <
typename T1,
typename T2>
3610 :
conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3612template <
typename... Ts>
3614 :
conjunction<is_default_constructible<Ts>...> {};
3616template <
typename... Ts>
3618 :
conjunction<is_default_constructible<Ts>...> {};
3621template <
typename T,
typename... Args>
3624template <
typename T1,
typename T2>
3627template <
typename T1,
typename T2>
3630template <
typename... Ts>
3633template <
typename... Ts>
3637template<
typename T,
typename =
void>
3647 static constexpr auto value =
3659 using t_ref =
typename std::add_lvalue_reference<T>::type;
3667 static constexpr auto is_iterator_begin =
3671 static constexpr bool value = !std::is_same<iterator, nonesuch>::value && !std::is_same<sentinel, nonesuch>::value && is_iterator_begin;
3684template<
typename T,
typename =
void>
3690template<
typename BasicJsonType,
typename CompatibleObjectType,
3694template<
typename BasicJsonType,
typename CompatibleObjectType>
3696 BasicJsonType, CompatibleObjectType,
3698 is_detected<key_type_t, CompatibleObjectType>::value >>
3703 static constexpr bool value =
3705 typename CompatibleObjectType::key_type>::value &&
3707 typename CompatibleObjectType::mapped_type>::value;
3710template<
typename BasicJsonType,
typename CompatibleObjectType>
3714template<
typename BasicJsonType,
typename ConstructibleObjectType,
3718template<
typename BasicJsonType,
typename ConstructibleObjectType>
3720 BasicJsonType, ConstructibleObjectType,
3722 is_detected<key_type_t, ConstructibleObjectType>::value >>
3726 static constexpr bool value =
3728 (std::is_move_assignable<ConstructibleObjectType>::value ||
3729 std::is_copy_assignable<ConstructibleObjectType>::value) &&
3731 typename object_t::key_type>::value &&
3733 typename object_t::mapped_type,
3734 typename ConstructibleObjectType::mapped_type >::value)) ||
3736 typename ConstructibleObjectType::mapped_type>::value ||
3739 typename ConstructibleObjectType::mapped_type >::value);
3742template<
typename BasicJsonType,
typename ConstructibleObjectType>
3745 ConstructibleObjectType> {};
3747template<
typename BasicJsonType,
typename CompatibleStringType>
3754template<
typename BasicJsonType,
typename ConstructibleStringType>
3758#ifdef __INTEL_COMPILER
3759 using laundered_type =
decltype(std::declval<ConstructibleStringType>());
3771template<
typename BasicJsonType,
typename CompatibleArrayType,
typename =
void>
3774template<
typename BasicJsonType,
typename CompatibleArrayType>
3776 BasicJsonType, CompatibleArrayType,
3779 is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value&&
3782 !std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value >>
3784 static constexpr bool value =
3789template<
typename BasicJsonType,
typename CompatibleArrayType>
3793template<
typename BasicJsonType,
typename ConstructibleArrayType,
typename =
void>
3796template<
typename BasicJsonType,
typename ConstructibleArrayType>
3798 BasicJsonType, ConstructibleArrayType,
3800 typename BasicJsonType::value_type>::value >>
3801 : std::true_type {};
3803template<
typename BasicJsonType,
typename ConstructibleArrayType>
3805 BasicJsonType, ConstructibleArrayType,
3807 typename BasicJsonType::value_type>::value&&
3810(std::is_move_assignable<ConstructibleArrayType>::value ||
3811 std::is_copy_assignable<ConstructibleArrayType>::value)&&
3812is_detected<iterator_t, ConstructibleArrayType>::value&&
3813is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value&&
3814is_detected<range_value_t, ConstructibleArrayType>::value&&
3817!std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>::value&&
3819 detected_t<range_value_t, ConstructibleArrayType >>::value >>
3823 static constexpr bool value =
3825 typename BasicJsonType::array_t::value_type>::value ||
3833template<
typename BasicJsonType,
typename ConstructibleArrayType>
3837template<
typename RealIntegerType,
typename CompatibleNumberIntegerType,
3841template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3843 RealIntegerType, CompatibleNumberIntegerType,
3845 std::is_integral<CompatibleNumberIntegerType>::value&&
3846 !std::is_same<bool, CompatibleNumberIntegerType>::value >>
3852 static constexpr auto value =
3854 CompatibleNumberIntegerType>::value &&
3855 CompatibleLimits::is_integer &&
3856 RealLimits::is_signed == CompatibleLimits::is_signed;
3859template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3862 CompatibleNumberIntegerType> {};
3864template<
typename BasicJsonType,
typename CompatibleType,
typename =
void>
3867template<
typename BasicJsonType,
typename CompatibleType>
3869 BasicJsonType, CompatibleType,
3872 static constexpr bool value =
3876template<
typename BasicJsonType,
typename CompatibleType>
3880template<
typename T1,
typename T2>
3883template<
typename T1,
typename... Args>
3886template<
typename BasicJsonType,
typename T>
3889template<
typename BasicJsonType>
3892template<
typename BasicJsonType>
3897template<
template <
typename...>
class Primary,
typename T>
3900template<
template <
typename...>
class Primary,
typename... Args>
3907template<
typename Compare,
typename A,
typename B,
typename =
void>
3910template<
typename Compare,
typename A,
typename B>
3912decltype(
std::declval<Compare>()(std::declval<A>(), std::declval<B>())),
3913decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))
3914>> : std::true_type {};
3921template<
typename Comparator,
typename ObjectKeyType,
typename KeyTypeCVRef,
bool RequireTransparentComparator =
true,
3925 && !(ExcludeObjectKeyType && std::is_same<KeyType,
3926 ObjectKeyType>::value)
3927 && (!RequireTransparentComparator
3928 || is_detected <detect_is_transparent, Comparator>::value)
3931 std::false_type >::type;
3939template<
typename BasicJsonType,
typename KeyTypeCVRef,
bool RequireTransparentComparator =
true,
3943 typename BasicJsonType::object_t::key_type, KeyTypeCVRef,
3944 RequireTransparentComparator, ExcludeObjectKeyType>::value
3947 std::false_type >::type;
3949template<
typename ObjectType,
typename KeyType>
3953template<
typename BasicJsonType,
typename KeyType>
3957 typename BasicJsonType::object_t, KeyType >::value,
3959 std::false_type >::type;
3963template <
typename T>
3973 template <
typename C>
static one test(
decltype(&C::capacity) ) ;
3976 enum {
value =
sizeof(test<T>(
nullptr)) ==
sizeof(
char) };
3980template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value,
int > = 0 >
3983 return static_cast<T
>(value);
3986template<typename T, typename U, enable_if_t<std::is_same<T, U>::value,
int> = 0>
3992template<
typename... Types>
3995template<
typename... Types>
3998template<
typename... Types>
4002template<
typename... Types>
4006template<
typename OfType,
typename T>
4008 (std::is_signed<OfType>::value && (
sizeof(T) <
sizeof(OfType)))
4011template<
typename OfType,
typename T,
4012 bool OfTypeSigned = std::is_signed<OfType>::value,
4013 bool TSigned = std::is_signed<T>::value>
4016template<
typename OfType,
typename T>
4021 using CommonType =
typename std::common_type<OfType, T>::type;
4022 return static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4026template<
typename OfType,
typename T>
4031 using CommonType =
typename std::common_type<OfType, T>::type;
4032 return static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4036template<
typename OfType,
typename T>
4041 using CommonType =
typename std::common_type<OfType, T>::type;
4042 return val >= 0 &&
static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4047template<
typename OfType,
typename T>
4052 using CommonType =
typename std::common_type<OfType, T>::type;
4053 return static_cast<CommonType
>(val) >=
static_cast<CommonType
>((std::numeric_limits<OfType>::min)())
4054 &&
static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4058template<
typename OfType,
typename T,
4059 bool NeverOutOfRange = never_out_of_range<OfType, T>::value,
4063template<
typename OfType,
typename T>
4072template<
typename OfType,
typename T>
4081template<
typename OfType,
typename T>
4100 using TUnExt =
typename std::remove_extent<T>::type;
4101 using TUnCVExt =
typename std::remove_cv<TUnExt>::type;
4102 using TUnPtr =
typename std::remove_pointer<T>::type;
4103 using TUnCVPtr =
typename std::remove_cv<TUnPtr>::type;
4105 (std::is_array<T>::value && std::is_same<TUnCVExt, char>::value)
4106 || (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value);
4171template<
typename... Args>
4172inline std::size_t
concat_length(
const char* cstr,
const Args& ... rest);
4174template<
typename StringType,
typename... Args>
4175inline std::size_t
concat_length(
const StringType& str,
const Args& ... rest);
4177template<
typename... Args>
4183template<
typename... Args>
4190template<
typename StringType,
typename... Args>
4196template<
typename OutStringType>
4200template<
typename StringType,
typename Arg>
4203template<
typename StringType,
typename Arg>
4206template<
typename StringType,
typename Arg>
4209template<
typename StringType,
typename Arg>
4212template<
typename StringType,
typename Arg>
4213using string_can_append_iter =
decltype(std::declval<StringType&>().append(std::declval<const Arg&>().begin(), std::declval<const Arg&>().end()));
4215template<
typename StringType,
typename Arg>
4218template<
typename StringType,
typename Arg>
4219using string_can_append_data =
decltype(std::declval<StringType&>().append(std::declval<const Arg&>().data(), std::declval<const Arg&>().size()));
4221template<
typename StringType,
typename Arg>
4224template <
typename OutStringType,
typename Arg,
typename... Args,
4225 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4227inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest);
4229template <
typename OutStringType,
typename Arg,
typename... Args,
4230 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4233inline void concat_into(OutStringType& out,
const Arg& arg, Args && ... rest);
4235template <
typename OutStringType,
typename Arg,
typename... Args,
4236 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4240inline void concat_into(OutStringType& out,
const Arg& arg, Args && ... rest);
4242template<
typename OutStringType,
typename Arg,
typename... Args,
4244inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest)
4246 out.append(std::forward<Arg>(arg));
4250template <
typename OutStringType,
typename Arg,
typename... Args,
4251 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4252 && detect_string_can_append_op<OutStringType, Arg>::value,
int > >
4253inline void concat_into(OutStringType& out, Arg&& arg, Args&& ... rest)
4255 out += std::forward<Arg>(arg);
4259template <
typename OutStringType,
typename Arg,
typename... Args,
4260 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4261 && !detect_string_can_append_op<OutStringType, Arg>::value
4262 && detect_string_can_append_iter<OutStringType, Arg>::value,
int > >
4263inline void concat_into(OutStringType& out,
const Arg& arg, Args&& ... rest)
4265 out.append(arg.begin(), arg.end());
4269template <
typename OutStringType,
typename Arg,
typename... Args,
4270 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4271 && !detect_string_can_append_op<OutStringType, Arg>::value
4272 && !detect_string_can_append_iter<OutStringType, Arg>::value
4273 && detect_string_can_append_data<OutStringType, Arg>::value,
int > >
4274inline void concat_into(OutStringType& out,
const Arg& arg, Args&& ... rest)
4276 out.append(arg.data(), arg.size());
4280template<
typename OutStringType = std::string,
typename... Args>
4308 const char*
what() const noexcept
override
4318 exception(
int id_, const
char* what_arg) :
id(id_), m(what_arg) {}
4320 static std::string
name(
const std::string& ename,
int id_)
4322 return concat(
"[json.exception.", ename,
'.', std::to_string(id_),
"] ");
4330 template<
typename BasicJsonType>
4334 std::vector<std::string> tokens;
4335 for (
const auto* current = leaf_element; current !=
nullptr && current->m_parent !=
nullptr; current = current->m_parent)
4337 switch (current->m_parent->type())
4341 for (std::size_t i = 0; i < current->m_parent->m_data.m_value.array->size(); ++i)
4343 if (¤t->m_parent->m_data.m_value.array->operator[](i) == current)
4345 tokens.emplace_back(std::to_string(i));
4354 for (
const auto& element : *current->m_parent->m_data.m_value.object)
4356 if (&element.second == current)
4358 tokens.emplace_back(element.first.c_str());
4383 auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
4384 [](
const std::string & a,
const std::string & b)
4386 return concat(a,
'/', detail::escape(b));
4388 return concat(
'(', str,
") ");
4390 static_cast<void>(leaf_element);
4397 std::runtime_error m;
4414 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4422 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4423 static parse_error create(
int id_, std::size_t byte_,
const std::string& what_arg, BasicJsonContext context)
4426 (byte_ != 0 ? (
concat(
" at byte ", std::to_string(byte_))) :
""),
4428 return {id_, byte_, w.c_str()};
4443 parse_error(
int id_, std::size_t byte_,
const char* what_arg)
4446 static std::string position_string(
const position_t& pos)
4458 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4462 return {id_, w.c_str()};
4476 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4480 return {id_, w.c_str()};
4493 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4497 return {id_, w.c_str()};
4510 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4514 return {id_, w.c_str()};
4548template <
class T>
struct identity_tag {};
4567#if JSON_HAS_EXPERIMENTAL_FILESYSTEM
4568#include <experimental/filesystem>
4572namespace std_fs = std::experimental::filesystem;
4575#elif JSON_HAS_FILESYSTEM
4576#include <filesystem>
4580namespace std_fs = std::filesystem;
4596template<
typename BasicJsonType>
4597inline void from_json(
const BasicJsonType& j,
typename std::nullptr_t& n)
4607template <
typename BasicJsonType,
typename ArithmeticType,
4608 enable_if_t < std::is_arithmetic<ArithmeticType>::value&&
4609 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4611void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val)
4613 switch (
static_cast<value_t>(j))
4617 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4622 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4627 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4643template<
typename BasicJsonType>
4644inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::boolean_t& b)
4650 b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
4653template<
typename BasicJsonType>
4654inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::string_t& s)
4660 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4664 typename BasicJsonType,
typename StringType,
4666 std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value
4667 && is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value
4668 && !std::is_same<typename BasicJsonType::string_t, StringType>::value
4669 && !is_json_ref<StringType>::value,
int > = 0 >
4670inline void from_json(
const BasicJsonType& j, StringType& s)
4677 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4680template<
typename BasicJsonType>
4681inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_float_t& val)
4683 get_arithmetic_value(j, val);
4686template<
typename BasicJsonType>
4687inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_unsigned_t& val)
4689 get_arithmetic_value(j, val);
4692template<
typename BasicJsonType>
4693inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_integer_t& val)
4695 get_arithmetic_value(j, val);
4698#if !JSON_DISABLE_ENUM_SERIALIZATION
4699template<
typename BasicJsonType,
typename EnumType,
4700 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
4701inline void from_json(
const BasicJsonType& j, EnumType& e)
4703 typename std::underlying_type<EnumType>::type val;
4704 get_arithmetic_value(j, val);
4705 e =
static_cast<EnumType
>(val);
4710template<
typename BasicJsonType,
typename T,
typename Allocator,
4711 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4712inline void from_json(
const BasicJsonType& j, std::forward_list<T, Allocator>& l)
4719 std::transform(j.rbegin(), j.rend(),
4720 std::front_inserter(l), [](
const BasicJsonType & i)
4722 return i.template get<T>();
4727template<
typename BasicJsonType,
typename T,
4728 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4729inline void from_json(
const BasicJsonType& j, std::valarray<T>& l)
4736 std::transform(j.begin(), j.end(), std::begin(l),
4737 [](
const BasicJsonType & elem)
4739 return elem.template get<T>();
4743template<
typename BasicJsonType,
typename T, std::
size_t N>
4744auto from_json(
const BasicJsonType& j, T (&arr)[N])
4745->
decltype(j.template get<T>(), void())
4747 for (std::size_t i = 0; i < N; ++i)
4749 arr[i] = j.at(i).template get<T>();
4753template<
typename BasicJsonType>
4754inline void from_json_array_impl(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr, priority_tag<3> )
4756 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
4759template<
typename BasicJsonType,
typename T, std::
size_t N>
4760auto from_json_array_impl(
const BasicJsonType& j, std::array<T, N>& arr,
4762->
decltype(j.template get<T>(), void())
4764 for (std::size_t i = 0; i < N; ++i)
4766 arr[i] = j.at(i).template get<T>();
4770template<
typename BasicJsonType,
typename ConstructibleArrayType,
4772 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4774auto from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> )
4776 arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
4777 j.template get<typename ConstructibleArrayType::value_type>(),
4782 ConstructibleArrayType ret;
4783 ret.reserve(j.size());
4784 std::transform(j.begin(), j.end(),
4785 std::inserter(ret, end(ret)), [](
const BasicJsonType & i)
4789 return i.template get<typename ConstructibleArrayType::value_type>();
4791 arr = std::move(ret);
4794template<
typename BasicJsonType,
typename ConstructibleArrayType,
4796 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4798inline void from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
4803 ConstructibleArrayType ret;
4805 j.begin(), j.end(), std::inserter(ret, end(ret)),
4806 [](
const BasicJsonType & i)
4810 return i.template get<typename ConstructibleArrayType::value_type>();
4812 arr = std::move(ret);
4815template <
typename BasicJsonType,
typename ConstructibleArrayType,
4817 is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&&
4818 !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&&
4820 !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&&
4821 !is_basic_json<ConstructibleArrayType>::value,
4823auto from_json(
const BasicJsonType& j, ConstructibleArrayType& arr)
4824->
decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
4825j.template get<typename ConstructibleArrayType::value_type>(),
4833 from_json_array_impl(j, arr, priority_tag<3> {});
4836template <
typename BasicJsonType,
typename T, std::size_t... Idx >
4837std::array<T,
sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j,
4838 identity_tag<std::array<T,
sizeof...(Idx)>> ,
index_sequence<Idx...> )
4840 return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
4843template <
typename BasicJsonType,
typename T, std::
size_t N >
4844auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag)
4845->
decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}))
4852 return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {});
4855template<
typename BasicJsonType>
4856inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::binary_t& bin)
4863 bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
4866template<
typename BasicJsonType,
typename ConstructibleObjectType,
4867 enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value,
int> = 0>
4868inline void from_json(
const BasicJsonType& j, ConstructibleObjectType& obj)
4875 ConstructibleObjectType ret;
4876 const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
4877 using value_type =
typename ConstructibleObjectType::value_type;
4879 inner_object->begin(), inner_object->end(),
4880 std::inserter(ret, ret.begin()),
4881 [](
typename BasicJsonType::object_t::value_type
const & p)
4883 return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
4885 obj = std::move(ret);
4892template <
typename BasicJsonType,
typename ArithmeticType,
4894 std::is_arithmetic<ArithmeticType>::value&&
4895 !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&&
4896 !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&&
4897 !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&&
4898 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4900inline void from_json(
const BasicJsonType& j, ArithmeticType& val)
4902 switch (
static_cast<value_t>(j))
4906 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4911 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4916 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4921 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
4936template<
typename BasicJsonType,
typename... Args, std::size_t... Idx>
4937std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<Idx...> )
4939 return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).
template get<Args>()...);
4942template <
typename BasicJsonType,
class A1,
class A2 >
4943std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> , priority_tag<0> )
4945 return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
4946 std::forward<BasicJsonType>(j).at(1).template get<A2>()};
4949template<
typename BasicJsonType,
typename A1,
typename A2>
4950inline void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> )
4952 p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {});
4955template<
typename BasicJsonType,
typename... Args>
4956std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> , priority_tag<2> )
4958 return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j),
index_sequence_for<Args...> {});
4961template<
typename BasicJsonType,
typename... Args>
4962inline void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> )
4964 t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j),
index_sequence_for<Args...> {});
4967template<
typename BasicJsonType,
typename TupleRelated>
4968auto from_json(BasicJsonType&& j, TupleRelated&& t)
4969->
decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}))
4976 return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {});
4979template <
typename BasicJsonType,
typename Key,
typename Value,
typename Compare,
typename Allocator,
4981 typename BasicJsonType::string_t, Key >::value >>
4982inline void from_json(
const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
4989 for (
const auto& p : j)
4995 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
4999template <
typename BasicJsonType,
typename Key,
typename Value,
typename Hash,
typename KeyEqual,
typename Allocator,
5001 typename BasicJsonType::string_t, Key >::value >>
5002inline void from_json(
const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
5009 for (
const auto& p : j)
5015 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
5019#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
5020template<
typename BasicJsonType>
5021inline void from_json(
const BasicJsonType& j, std_fs::path& p)
5027 p = *j.template get_ptr<const typename BasicJsonType::string_t*>();
5033 template<
typename BasicJsonType,
typename T>
5034 auto operator()(
const BasicJsonType& j, T&& val)
const
5035 noexcept(
noexcept(from_json(j, std::forward<T>(val))))
5036 ->
decltype(from_json(j, std::forward<T>(val)))
5038 return from_json(j, std::forward<T>(val));
5044#ifndef JSON_HAS_CPP_17
5053#ifndef JSON_HAS_CPP_17
5074#include <type_traits>
5111template<
typename string_type>
5115 using std::to_string;
5126 using string_type =
typename std::remove_cv< 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;
5143 noexcept(
std::is_nothrow_move_constructible<IteratorType>::
value
5145 : anchor(
std::move(it))
5146 , array_index(array_index_)
5153 noexcept(
std::is_nothrow_move_constructible<IteratorType>::
value
5156 noexcept(
std::is_nothrow_move_assignable<IteratorType>::
value
5186 return anchor == o.anchor;
5192 return anchor != o.anchor;
5200 switch (anchor.m_object->type())
5205 if (array_index != array_index_last)
5208 array_index_last = array_index;
5210 return array_index_str;
5215 return anchor.key();
5232 typename IteratorType::reference
value()
const
5234 return anchor.value();
5243 typename IteratorType::pointer container =
nullptr;
5250 : container(&cont) {}
5274template<std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
5275auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.key())
5282template<std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
5283auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.value())
5298#if defined(__clang__)
5300 #pragma clang diagnostic push
5301 #pragma clang diagnostic ignored "-Wmismatched-tags"
5303template<
typename IteratorType>
5304class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
5305 :
public std::integral_constant<std::size_t, 2> {};
5307template<std::
size_t N,
typename IteratorType>
5308class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
5312 get<N>(std::declval <
5313 ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));
5315#if defined(__clang__)
5316 #pragma clang diagnostic pop
5322 template <
typename IteratorType>
5323 inline constexpr bool ::std::ranges::enable_borrowed_range<::nlohmann::detail::iteration_proxy<IteratorType>> =
true;
5357 template<
typename BasicJsonType>
5358 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t b)
noexcept
5360 j.m_data.m_value.destroy(j.m_data.m_type);
5362 j.m_data.m_value = b;
5363 j.assert_invariant();
5370 template<
typename BasicJsonType>
5371 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t& s)
5373 j.m_data.m_value.destroy(j.m_data.m_type);
5375 j.m_data.m_value = s;
5376 j.assert_invariant();
5379 template<
typename BasicJsonType>
5380 static void construct(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
5382 j.m_data.m_value.destroy(j.m_data.m_type);
5384 j.m_data.m_value = std::move(s);
5385 j.assert_invariant();
5388 template <
typename BasicJsonType,
typename CompatibleStringType,
5389 enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
5391 static void construct(BasicJsonType& j,
const CompatibleStringType& str)
5393 j.m_data.m_value.destroy(j.m_data.m_type);
5395 j.m_data.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
5396 j.assert_invariant();
5403 template<
typename BasicJsonType>
5404 static void construct(BasicJsonType& j,
const typename BasicJsonType::binary_t& b)
5406 j.m_data.m_value.destroy(j.m_data.m_type);
5408 j.m_data.m_value =
typename BasicJsonType::binary_t(b);
5409 j.assert_invariant();
5412 template<
typename BasicJsonType>
5413 static void construct(BasicJsonType& j,
typename BasicJsonType::binary_t&& b)
5415 j.m_data.m_value.destroy(j.m_data.m_type);
5417 j.m_data.m_value =
typename BasicJsonType::binary_t(std::move(b));
5418 j.assert_invariant();
5425 template<
typename BasicJsonType>
5426 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val)
noexcept
5428 j.m_data.m_value.destroy(j.m_data.m_type);
5430 j.m_data.m_value = val;
5431 j.assert_invariant();
5438 template<
typename BasicJsonType>
5439 static void construct(BasicJsonType& j,
typename BasicJsonType::number_unsigned_t val)
noexcept
5441 j.m_data.m_value.destroy(j.m_data.m_type);
5443 j.m_data.m_value = val;
5444 j.assert_invariant();
5451 template<
typename BasicJsonType>
5452 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val)
noexcept
5454 j.m_data.m_value.destroy(j.m_data.m_type);
5456 j.m_data.m_value = val;
5457 j.assert_invariant();
5464 template<
typename BasicJsonType>
5465 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
5467 j.m_data.m_value.destroy(j.m_data.m_type);
5469 j.m_data.m_value = arr;
5471 j.assert_invariant();
5474 template<
typename BasicJsonType>
5475 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
5477 j.m_data.m_value.destroy(j.m_data.m_type);
5479 j.m_data.m_value = std::move(arr);
5481 j.assert_invariant();
5484 template <
typename BasicJsonType,
typename CompatibleArrayType,
5485 enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
5487 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
5492 j.m_data.m_value.destroy(j.m_data.m_type);
5494 j.m_data.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
5496 j.assert_invariant();
5499 template<
typename BasicJsonType>
5500 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
5502 j.m_data.m_value.destroy(j.m_data.m_type);
5505 j.m_data.m_value.array->reserve(arr.size());
5506 for (
const bool x : arr)
5508 j.m_data.m_value.array->push_back(x);
5509 j.set_parent(j.m_data.m_value.array->back());
5511 j.assert_invariant();
5514 template<
typename BasicJsonType,
typename T,
5516 static void construct(BasicJsonType& j,
const std::valarray<T>& arr)
5518 j.m_data.m_value.destroy(j.m_data.m_type);
5521 j.m_data.m_value.array->resize(arr.size());
5524 std::copy(std::begin(arr), std::end(arr), j.m_data.m_value.array->begin());
5527 j.assert_invariant();
5534 template<
typename BasicJsonType>
5535 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
5537 j.m_data.m_value.destroy(j.m_data.m_type);
5539 j.m_data.m_value = obj;
5541 j.assert_invariant();
5544 template<
typename BasicJsonType>
5545 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
5547 j.m_data.m_value.destroy(j.m_data.m_type);
5549 j.m_data.m_value = std::move(obj);
5551 j.assert_invariant();
5554 template <
typename BasicJsonType,
typename CompatibleObjectType,
5555 enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
int > = 0 >
5556 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
5561 j.m_data.m_value.destroy(j.m_data.m_type);
5563 j.m_data.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
5565 j.assert_invariant();
5573template<
typename BasicJsonType,
typename T,
5574 enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value,
int> = 0>
5575inline void to_json(BasicJsonType& j, T b)
noexcept
5580template <
typename BasicJsonType,
typename BoolRef,
5582 ((std::is_same<std::vector<bool>::reference, BoolRef>::value
5583 && !std::is_same <std::vector<bool>::reference,
typename BasicJsonType::boolean_t&>::value)
5584 || (std::is_same<std::vector<bool>::const_reference, BoolRef>::value
5586 typename BasicJsonType::boolean_t >::value))
5587 && std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value,
int > = 0 >
5588inline void to_json(BasicJsonType& j,
const BoolRef& b)
noexcept
5593template<
typename BasicJsonType,
typename CompatibleString,
5594 enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value,
int> = 0>
5595inline void to_json(BasicJsonType& j,
const CompatibleString& s)
5600template<
typename BasicJsonType>
5601inline void to_json(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
5606template<
typename BasicJsonType,
typename FloatType,
5607 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
5608inline void to_json(BasicJsonType& j, FloatType val)
noexcept
5613template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
5614 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value,
int> = 0>
5615inline void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val)
noexcept
5620template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
5621 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value,
int> = 0>
5622inline void to_json(BasicJsonType& j, CompatibleNumberIntegerType val)
noexcept
5627#if !JSON_DISABLE_ENUM_SERIALIZATION
5628template<
typename BasicJsonType,
typename EnumType,
5629 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
5630inline void to_json(BasicJsonType& j, EnumType e)
noexcept
5632 using underlying_type =
typename std::underlying_type<EnumType>::type;
5637template<
typename BasicJsonType>
5638inline void to_json(BasicJsonType& j,
const std::vector<bool>& e)
5643template <
typename BasicJsonType,
typename CompatibleArrayType,
5644 enable_if_t < is_compatible_array_type<BasicJsonType,
5645 CompatibleArrayType>::value&&
5646 !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&&
5648 !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
5649 !is_basic_json<CompatibleArrayType>::value,
5651inline void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
5656template<
typename BasicJsonType>
5657inline void to_json(BasicJsonType& j,
const typename BasicJsonType::binary_t& bin)
5662template<
typename BasicJsonType,
typename T,
5663 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
5664inline void to_json(BasicJsonType& j,
const std::valarray<T>& arr)
5669template<
typename BasicJsonType>
5670inline void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
5675template <
typename BasicJsonType,
typename CompatibleObjectType,
5676 enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value,
int > = 0 >
5677inline void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
5682template<
typename BasicJsonType>
5683inline void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
5689 typename BasicJsonType,
typename T, std::size_t N,
5690 enable_if_t < !std::is_constructible<
typename BasicJsonType::string_t,
5691 const T(&)[N]>::value,
5693inline void to_json(BasicJsonType& j,
const T(&arr)[N])
5698template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value,
int > = 0 >
5699inline void to_json(BasicJsonType& j,
const std::pair<T1, T2>& p)
5701 j = { p.first, p.second };
5705template<
typename BasicJsonType,
typename T,
5706 enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value,
int> = 0>
5709 j = { {b.key(), b.value()} };
5712template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
5715 j = { std::get<Idx>(t)... };
5718template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value,
int > = 0>
5719inline void to_json(BasicJsonType& j,
const T& t)
5724#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
5725template<
typename BasicJsonType>
5726inline void to_json(BasicJsonType& j,
const std_fs::path& p)
5734 template<
typename BasicJsonType,
typename T>
5735 auto operator()(BasicJsonType& j, T&& val)
const noexcept(
noexcept(
to_json(j, std::forward<T>(val))))
5736 ->
decltype(
to_json(j, std::forward<T>(val)), void())
5738 return to_json(j, std::forward<T>(val));
5743#ifndef JSON_HAS_CPP_17
5752#ifndef JSON_HAS_CPP_17
5764template<
typename ValueType,
typename>
5769 template<
typename BasicJsonType,
typename TargetType = ValueType>
5770 static auto from_json(BasicJsonType && j, TargetType& val)
noexcept(
5771 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
5772 ->
decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
5774 ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
5779 template<
typename BasicJsonType,
typename TargetType = ValueType>
5781 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
5782 ->
decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
5784 return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
5789 template<
typename BasicJsonType,
typename TargetType = ValueType>
5790 static auto to_json(BasicJsonType& j, TargetType && val)
noexcept(
5791 noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
5792 ->
decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
5794 ::nlohmann::to_json(j, std::forward<TargetType>(val));
5822template<
typename BinaryType>
5847 , m_subtype(subtype_)
5848 , m_has_subtype(
true)
5854 , m_subtype(subtype_)
5855 , m_has_subtype(
true)
5860 return std::tie(
static_cast<const BinaryType&
>(*
this), m_subtype, m_has_subtype) ==
5861 std::tie(
static_cast<const BinaryType&
>(rhs), rhs.m_subtype, rhs.m_has_subtype);
5866 return !(rhs == *
this);
5873 m_subtype = subtype_;
5874 m_has_subtype =
true;
5881 return m_has_subtype ? m_subtype :
static_cast<subtype_type>(-1);
5888 return m_has_subtype;
5896 m_has_subtype =
false;
5901 bool m_has_subtype =
false;
5925#include <functional>
5937inline std::size_t combine(std::size_t seed, std::size_t h)
noexcept
5939 seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
5954template<
typename BasicJsonType>
5955std::size_t hash(
const BasicJsonType& j)
5957 using string_t =
typename BasicJsonType::string_t;
5958 using number_integer_t =
typename BasicJsonType::number_integer_t;
5959 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5960 using number_float_t =
typename BasicJsonType::number_float_t;
5962 const auto type =
static_cast<std::size_t
>(j.type());
5965 case BasicJsonType::value_t::null:
5966 case BasicJsonType::value_t::discarded:
5968 return combine(type, 0);
5971 case BasicJsonType::value_t::object:
5973 auto seed = combine(type, j.size());
5974 for (
const auto& element : j.items())
5976 const auto h = std::hash<string_t> {}(element.key());
5977 seed = combine(seed, h);
5978 seed = combine(seed, hash(element.value()));
5983 case BasicJsonType::value_t::array:
5985 auto seed = combine(type, j.size());
5986 for (
const auto& element : j)
5988 seed = combine(seed, hash(element));
5993 case BasicJsonType::value_t::string:
5995 const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
5996 return combine(type, h);
5999 case BasicJsonType::value_t::boolean:
6001 const auto h = std::hash<bool> {}(j.template get<bool>());
6002 return combine(type, h);
6005 case BasicJsonType::value_t::number_integer:
6007 const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
6008 return combine(type, h);
6011 case BasicJsonType::value_t::number_unsigned:
6013 const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
6014 return combine(type, h);
6017 case BasicJsonType::value_t::number_float:
6019 const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
6020 return combine(type, h);
6023 case BasicJsonType::value_t::binary:
6025 auto seed = combine(type, j.get_binary().size());
6026 const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
6027 seed = combine(seed, h);
6028 seed = combine(seed,
static_cast<std::size_t
>(j.get_binary().subtype()));
6029 for (
const auto byte : j.get_binary())
6031 seed = combine(seed, std::hash<std::uint8_t> {}(byte));
6089#include <type_traits>
6107enum class input_format_t {
json, cbor, msgpack, ubjson, bson, bjdata };
6118class file_input_adapter
6121 using char_type = char;
6124 explicit file_input_adapter(
std::FILE* f) noexcept
6131 file_input_adapter(
const file_input_adapter&) =
delete;
6132 file_input_adapter(file_input_adapter&&) noexcept = default;
6133 file_input_adapter& operator=(const file_input_adapter&) = delete;
6134 file_input_adapter& operator=(file_input_adapter&&) = delete;
6135 ~file_input_adapter() = default;
6137 std::char_traits<
char>::int_type get_character() noexcept
6139 return std::fgetc(m_file);
6157class input_stream_adapter
6160 using char_type = char;
6162 ~input_stream_adapter()
6168 is->clear(is->rdstate() & std::ios::eofbit);
6172 explicit input_stream_adapter(std::istream& i)
6173 : is(&i), sb(i.rdbuf())
6177 input_stream_adapter(
const input_stream_adapter&) =
delete;
6178 input_stream_adapter& operator=(input_stream_adapter&) =
delete;
6179 input_stream_adapter& operator=(input_stream_adapter&&) =
delete;
6181 input_stream_adapter(input_stream_adapter&& rhs) noexcept
6182 : is(rhs.is), sb(rhs.sb)
6191 std::char_traits<char>::int_type get_character()
6193 auto res = sb->sbumpc();
6197 is->clear(is->rdstate() | std::ios::eofbit);
6204 std::istream* is =
nullptr;
6205 std::streambuf* sb =
nullptr;
6211template<
typename IteratorType>
6212class iterator_input_adapter
6215 using char_type =
typename std::iterator_traits<IteratorType>::value_type;
6217 iterator_input_adapter(IteratorType first, IteratorType last)
6218 : current(
std::move(first)), end(
std::move(last))
6221 typename std::char_traits<char_type>::int_type get_character()
6225 auto result = std::char_traits<char_type>::to_int_type(*current);
6226 std::advance(current, 1);
6230 return std::char_traits<char_type>::eof();
6234 IteratorType current;
6237 template<
typename BaseInputAdapter,
size_t T>
6238 friend struct wide_string_input_helper;
6242 return current == end;
6247template<
typename BaseInputAdapter,
size_t T>
6248struct wide_string_input_helper;
6250template<
typename BaseInputAdapter>
6251struct wide_string_input_helper<BaseInputAdapter, 4>
6254 static void fill_buffer(BaseInputAdapter& input,
6255 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
6256 size_t& utf8_bytes_index,
6257 size_t& utf8_bytes_filled)
6259 utf8_bytes_index = 0;
6263 utf8_bytes[0] = std::char_traits<char>::eof();
6264 utf8_bytes_filled = 1;
6269 const auto wc = input.get_character();
6274 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6275 utf8_bytes_filled = 1;
6277 else if (wc <= 0x7FF)
6279 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
6280 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6281 utf8_bytes_filled = 2;
6283 else if (wc <= 0xFFFF)
6285 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
6286 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6287 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6288 utf8_bytes_filled = 3;
6290 else if (wc <= 0x10FFFF)
6292 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | ((
static_cast<unsigned int>(wc) >> 18u) & 0x07u));
6293 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
6294 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6295 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6296 utf8_bytes_filled = 4;
6301 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6302 utf8_bytes_filled = 1;
6308template<
typename BaseInputAdapter>
6309struct wide_string_input_helper<BaseInputAdapter, 2>
6312 static void fill_buffer(BaseInputAdapter& input,
6313 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
6314 size_t& utf8_bytes_index,
6315 size_t& utf8_bytes_filled)
6317 utf8_bytes_index = 0;
6321 utf8_bytes[0] = std::char_traits<char>::eof();
6322 utf8_bytes_filled = 1;
6327 const auto wc = input.get_character();
6332 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6333 utf8_bytes_filled = 1;
6335 else if (wc <= 0x7FF)
6337 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u)));
6338 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6339 utf8_bytes_filled = 2;
6341 else if (0xD800 > wc || wc >= 0xE000)
6343 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u)));
6344 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6345 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6346 utf8_bytes_filled = 3;
6352 const auto wc2 =
static_cast<unsigned int>(input.get_character());
6353 const auto charcode = 0x10000u + (((
static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
6354 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | (charcode >> 18u));
6355 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 12u) & 0x3Fu));
6356 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 6u) & 0x3Fu));
6357 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (charcode & 0x3Fu));
6358 utf8_bytes_filled = 4;
6362 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6363 utf8_bytes_filled = 1;
6371template<
typename BaseInputAdapter,
typename W
ideCharType>
6372class wide_string_input_adapter
6375 using char_type = char;
6377 wide_string_input_adapter(BaseInputAdapter base)
6378 : base_adapter(base) {}
6380 typename std::char_traits<char>::int_type get_character() noexcept
6383 if (utf8_bytes_index == utf8_bytes_filled)
6385 fill_buffer<sizeof(WideCharType)>();
6393 JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);
6394 return utf8_bytes[utf8_bytes_index++];
6398 BaseInputAdapter base_adapter;
6403 wide_string_input_helper<BaseInputAdapter, T>::fill_buffer(base_adapter, utf8_bytes, utf8_bytes_index, utf8_bytes_filled);
6407 std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
6410 std::size_t utf8_bytes_index = 0;
6412 std::size_t utf8_bytes_filled = 0;
6416template<
typename IteratorType,
typename Enable =
void>
6417struct iterator_input_adapter_factory
6419 using iterator_type = IteratorType;
6420 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
6421 using adapter_type = iterator_input_adapter<iterator_type>;
6423 static adapter_type create(IteratorType first, IteratorType last)
6425 return adapter_type(std::move(first), std::move(last));
6430struct is_iterator_of_multibyte
6432 using value_type =
typename std::iterator_traits<T>::value_type;
6435 value =
sizeof(value_type) > 1
6439template<
typename IteratorType>
6440struct iterator_input_adapter_factory<IteratorType,
enable_if_t<is_iterator_of_multibyte<IteratorType>::value>>
6442 using iterator_type = IteratorType;
6443 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
6444 using base_adapter_type = iterator_input_adapter<iterator_type>;
6445 using adapter_type = wide_string_input_adapter<base_adapter_type, char_type>;
6447 static adapter_type create(IteratorType first, IteratorType last)
6449 return adapter_type(base_adapter_type(std::move(first), std::move(last)));
6454template<
typename IteratorType>
6455typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapter(IteratorType first, IteratorType last)
6457 using factory_type = iterator_input_adapter_factory<IteratorType>;
6458 return factory_type::create(first, last);
6465namespace container_input_adapter_factory_impl
6471template<
typename ContainerType,
typename Enable =
void>
6474template<
typename ContainerType>
6476 void_t<decltype(begin(
std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
6478 using adapter_type =
decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
6482 return input_adapter(begin(container), end(container));
6488template<
typename ContainerType>
6489typename container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::adapter_type input_adapter(
const ContainerType& container)
6491 return container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::create(container);
6496inline file_input_adapter input_adapter(std::FILE* file)
6498 return file_input_adapter(file);
6501inline input_stream_adapter input_adapter(std::istream& stream)
6503 return input_stream_adapter(stream);
6506inline input_stream_adapter input_adapter(std::istream&& stream)
6508 return input_stream_adapter(stream);
6512using contiguous_bytes_input_adapter =
decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
6515template <
typename CharT,
6516 typename std::enable_if <
6517 std::is_pointer<CharT>::value&&
6518 !std::is_array<CharT>::value&&
6519 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
6520 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
6522contiguous_bytes_input_adapter input_adapter(CharT b)
6524 auto length = std::strlen(
reinterpret_cast<const char*
>(b));
6525 const auto* ptr =
reinterpret_cast<const char*
>(b);
6526 return input_adapter(ptr, ptr + length);
6529template<
typename T, std::
size_t N>
6530auto input_adapter(T (&
array)[N]) ->
decltype(input_adapter(
array,
array + N))
6538class span_input_adapter
6541 template <
typename CharT,
6542 typename std::enable_if <
6543 std::is_pointer<CharT>::value&&
6544 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
6545 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
6547 span_input_adapter(CharT b, std::size_t l)
6548 : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {}
6550 template<
class IteratorType,
6551 typename std::enable_if<
6552 std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
6554 span_input_adapter(IteratorType first, IteratorType last)
6555 : ia(input_adapter(first, last)) {}
6557 contiguous_bytes_input_adapter&&
get()
6559 return std::move(ia);
6563 contiguous_bytes_input_adapter ia;
6602template<
typename BasicJsonType>
6706 const std::string& last_token,
6733template<
typename BasicJsonType>
6749 : root(r), allow_exceptions(allow_exceptions_)
6761 handle_value(
nullptr);
6797 handle_value(std::move(val));
6803 ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
6805 if (
JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) && len > ref_stack.back()->max_size()))
6807 JSON_THROW(out_of_range::create(408,
concat(
"excessive object size: ", std::to_string(len)), ref_stack.back()));
6819 object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val));
6828 ref_stack.back()->set_parents();
6829 ref_stack.pop_back();
6835 ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
6837 if (
JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) && len > ref_stack.back()->max_size()))
6839 JSON_THROW(out_of_range::create(408,
concat(
"excessive array size: ", std::to_string(len)), ref_stack.back()));
6850 ref_stack.back()->set_parents();
6851 ref_stack.pop_back();
6855 template<
class Exception>
6857 const Exception& ex)
6860 static_cast<void>(ex);
6861 if (allow_exceptions)
6880 template<
typename Value>
6882 BasicJsonType* handle_value(Value&& v)
6884 if (ref_stack.empty())
6886 root = BasicJsonType(std::forward<Value>(v));
6890 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6892 if (ref_stack.back()->is_array())
6894 ref_stack.back()->m_data.m_value.array->emplace_back(std::forward<Value>(v));
6895 return &(ref_stack.back()->m_data.m_value.array->back());
6900 *object_element = BasicJsonType(std::forward<Value>(v));
6901 return object_element;
6905 BasicJsonType& root;
6907 std::vector<BasicJsonType*> ref_stack {};
6909 BasicJsonType* object_element =
nullptr;
6911 bool errored =
false;
6913 const bool allow_exceptions =
true;
6916template<
typename BasicJsonType>
6930 const bool allow_exceptions_ =
true)
6931 : root(r), callback(cb), allow_exceptions(allow_exceptions_)
6933 keep_stack.push_back(
true);
6945 handle_value(
nullptr);
6981 handle_value(std::move(val));
6988 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::object_start,
discarded);
6989 keep_stack.push_back(keep);
6991 auto val = handle_value(BasicJsonType::value_t::object,
true);
6992 ref_stack.push_back(val.second);
6995 if (ref_stack.back() &&
JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) && len > ref_stack.back()->max_size()))
6997 JSON_THROW(out_of_range::create(408,
concat(
"excessive object size: ", std::to_string(len)), ref_stack.back()));
7005 BasicJsonType k = BasicJsonType(val);
7008 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::key, k);
7009 key_keep_stack.push_back(keep);
7012 if (keep && ref_stack.back())
7014 object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val) =
discarded);
7022 if (ref_stack.back())
7024 if (!callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
7031 ref_stack.back()->set_parents();
7037 ref_stack.pop_back();
7038 keep_stack.pop_back();
7040 if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
7043 for (
auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
7045 if (it->is_discarded())
7047 ref_stack.back()->erase(it);
7058 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::array_start,
discarded);
7059 keep_stack.push_back(keep);
7061 auto val = handle_value(BasicJsonType::value_t::array,
true);
7062 ref_stack.push_back(val.second);
7065 if (ref_stack.back() &&
JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) && len > ref_stack.back()->max_size()))
7067 JSON_THROW(out_of_range::create(408,
concat(
"excessive array size: ", std::to_string(len)), ref_stack.back()));
7077 if (ref_stack.back())
7079 keep = callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
7082 ref_stack.back()->set_parents();
7093 ref_stack.pop_back();
7094 keep_stack.pop_back();
7097 if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
7099 ref_stack.back()->m_data.m_value.array->pop_back();
7105 template<
class Exception>
7107 const Exception& ex)
7110 static_cast<void>(ex);
7111 if (allow_exceptions)
7139 template<
typename Value>
7140 std::pair<bool, BasicJsonType*> handle_value(Value&& v,
const bool skip_callback =
false)
7146 if (!keep_stack.back())
7148 return {
false,
nullptr};
7152 auto value = BasicJsonType(std::forward<Value>(v));
7155 const bool keep = skip_callback || callback(
static_cast<int>(ref_stack.size()), parse_event_t::value, value);
7160 return {
false,
nullptr};
7163 if (ref_stack.empty())
7165 root = std::move(value);
7166 return {
true, &root};
7171 if (!ref_stack.back())
7173 return {
false,
nullptr};
7177 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
7180 if (ref_stack.back()->is_array())
7182 ref_stack.back()->m_data.m_value.array->emplace_back(std::move(value));
7183 return {
true, &(ref_stack.back()->m_data.m_value.array->back())};
7190 const bool store_element = key_keep_stack.back();
7191 key_keep_stack.pop_back();
7195 return {
false,
nullptr};
7199 *object_element = std::move(value);
7200 return {
true, object_element};
7204 BasicJsonType& root;
7206 std::vector<BasicJsonType*> ref_stack {};
7208 std::vector<bool> keep_stack {};
7210 std::vector<bool> key_keep_stack {};
7212 BasicJsonType* object_element =
nullptr;
7214 bool errored =
false;
7216 const parser_callback_t callback =
nullptr;
7218 const bool allow_exceptions =
true;
7220 BasicJsonType
discarded = BasicJsonType::value_t::discarded;
7223template<
typename BasicJsonType>
7318#include <initializer_list>
7338template<
typename BasicJsonType>
7371 case token_type::uninitialized:
7372 return "<uninitialized>";
7373 case token_type::literal_true:
7374 return "true literal";
7375 case token_type::literal_false:
7376 return "false literal";
7377 case token_type::literal_null:
7378 return "null literal";
7379 case token_type::value_string:
7380 return "string literal";
7381 case token_type::value_unsigned:
7382 case token_type::value_integer:
7383 case token_type::value_float:
7384 return "number literal";
7385 case token_type::begin_array:
7387 case token_type::begin_object:
7389 case token_type::end_array:
7391 case token_type::end_object:
7393 case token_type::name_separator:
7395 case token_type::value_separator:
7397 case token_type::parse_error:
7398 return "<parse error>";
7399 case token_type::end_of_input:
7400 return "end of input";
7401 case token_type::literal_or_value:
7402 return "'[', '{', or a literal";
7405 return "unknown token";
7415template<
typename BasicJsonType,
typename InputAdapterType>
7418 using number_integer_t =
typename BasicJsonType::number_integer_t;
7419 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7420 using number_float_t =
typename BasicJsonType::number_float_t;
7421 using string_t =
typename BasicJsonType::string_t;
7422 using char_type =
typename InputAdapterType::char_type;
7423 using char_int_type =
typename std::char_traits<char_type>::int_type;
7428 explicit lexer(InputAdapterType&& adapter,
bool ignore_comments_ =
false) noexcept
7429 : ia(
std::move(adapter))
7430 , ignore_comments(ignore_comments_)
7431 , decimal_point_char(static_cast<char_int_type>(get_decimal_point()))
7448 static char get_decimal_point() noexcept
7450 const auto* loc = localeconv();
7452 return (loc->decimal_point ==
nullptr) ?
'.' : *(loc->decimal_point);
7480 const auto factors = { 12u, 8u, 4u, 0u };
7481 for (
const auto factor : factors)
7485 if (current >=
'0' && current <=
'9')
7487 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x30u) << factor);
7489 else if (current >=
'A' && current <=
'F')
7491 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x37u) << factor);
7493 else if (current >=
'a' && current <=
'f')
7495 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x57u) << factor);
7503 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
7522 bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
7524 JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
7527 for (
auto range = ranges.begin(); range != ranges.end(); ++range)
7536 error_message =
"invalid string: ill-formed UTF-8 byte";
7559 token_type scan_string()
7573 case std::char_traits<char_type>::eof():
7575 error_message =
"invalid string: missing closing quote";
7576 return token_type::parse_error;
7582 return token_type::value_string;
7626 const int codepoint1 = get_codepoint();
7627 int codepoint = codepoint1;
7631 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7632 return token_type::parse_error;
7636 if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
7641 const int codepoint2 = get_codepoint();
7645 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7646 return token_type::parse_error;
7653 codepoint =
static_cast<int>(
7655 (
static_cast<unsigned int>(codepoint1) << 10u)
7657 +
static_cast<unsigned int>(codepoint2)
7665 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
7666 return token_type::parse_error;
7671 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
7672 return token_type::parse_error;
7679 error_message =
"invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
7680 return token_type::parse_error;
7685 JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
7688 if (codepoint < 0x80)
7691 add(
static_cast<char_int_type
>(codepoint));
7693 else if (codepoint <= 0x7FF)
7696 add(
static_cast<char_int_type
>(0xC0u | (
static_cast<unsigned int>(codepoint) >> 6u)));
7697 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7699 else if (codepoint <= 0xFFFF)
7702 add(
static_cast<char_int_type
>(0xE0u | (
static_cast<unsigned int>(codepoint) >> 12u)));
7703 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7704 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7709 add(
static_cast<char_int_type
>(0xF0u | (
static_cast<unsigned int>(codepoint) >> 18u)));
7710 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
7711 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7712 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7720 error_message =
"invalid string: forbidden character after backslash";
7721 return token_type::parse_error;
7730 error_message =
"invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
7731 return token_type::parse_error;
7736 error_message =
"invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
7737 return token_type::parse_error;
7742 error_message =
"invalid string: control character U+0002 (STX) must be escaped to \\u0002";
7743 return token_type::parse_error;
7748 error_message =
"invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
7749 return token_type::parse_error;
7754 error_message =
"invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
7755 return token_type::parse_error;
7760 error_message =
"invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
7761 return token_type::parse_error;
7766 error_message =
"invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
7767 return token_type::parse_error;
7772 error_message =
"invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
7773 return token_type::parse_error;
7778 error_message =
"invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
7779 return token_type::parse_error;
7784 error_message =
"invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
7785 return token_type::parse_error;
7790 error_message =
"invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
7791 return token_type::parse_error;
7796 error_message =
"invalid string: control character U+000B (VT) must be escaped to \\u000B";
7797 return token_type::parse_error;
7802 error_message =
"invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
7803 return token_type::parse_error;
7808 error_message =
"invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
7809 return token_type::parse_error;
7814 error_message =
"invalid string: control character U+000E (SO) must be escaped to \\u000E";
7815 return token_type::parse_error;
7820 error_message =
"invalid string: control character U+000F (SI) must be escaped to \\u000F";
7821 return token_type::parse_error;
7826 error_message =
"invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
7827 return token_type::parse_error;
7832 error_message =
"invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
7833 return token_type::parse_error;
7838 error_message =
"invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
7839 return token_type::parse_error;
7844 error_message =
"invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
7845 return token_type::parse_error;
7850 error_message =
"invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
7851 return token_type::parse_error;
7856 error_message =
"invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
7857 return token_type::parse_error;
7862 error_message =
"invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
7863 return token_type::parse_error;
7868 error_message =
"invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
7869 return token_type::parse_error;
7874 error_message =
"invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
7875 return token_type::parse_error;
7880 error_message =
"invalid string: control character U+0019 (EM) must be escaped to \\u0019";
7881 return token_type::parse_error;
7886 error_message =
"invalid string: control character U+001A (SUB) must be escaped to \\u001A";
7887 return token_type::parse_error;
7892 error_message =
"invalid string: control character U+001B (ESC) must be escaped to \\u001B";
7893 return token_type::parse_error;
7898 error_message =
"invalid string: control character U+001C (FS) must be escaped to \\u001C";
7899 return token_type::parse_error;
7904 error_message =
"invalid string: control character U+001D (GS) must be escaped to \\u001D";
7905 return token_type::parse_error;
7910 error_message =
"invalid string: control character U+001E (RS) must be escaped to \\u001E";
7911 return token_type::parse_error;
7916 error_message =
"invalid string: control character U+001F (US) must be escaped to \\u001F";
7917 return token_type::parse_error;
8054 return token_type::parse_error;
8064 return token_type::parse_error;
8088 return token_type::parse_error;
8098 return token_type::parse_error;
8108 return token_type::parse_error;
8120 return token_type::parse_error;
8130 return token_type::parse_error;
8138 error_message =
"invalid string: ill-formed UTF-8 byte";
8139 return token_type::parse_error;
8162 case std::char_traits<char_type>::eof():
8179 case std::char_traits<char_type>::eof():
8182 error_message =
"invalid comment; missing closing '*/'";
8210 error_message =
"invalid comment; expecting '/' or '*' after '/'";
8217 static
void strtof(
float& f, const
char* str,
char** endptr) noexcept
8219 f = std::strtof(str, endptr);
8223 static
void strtof(
double& f, const
char* str,
char** endptr) noexcept
8225 f = std::strtod(str, endptr);
8229 static
void strtof(
long double& f, const
char* str,
char** endptr) noexcept
8231 f = std::strtold(str, endptr);
8274 token_type scan_number()
8281 token_type number_type = token_type::value_unsigned;
8289 goto scan_number_minus;
8295 goto scan_number_zero;
8309 goto scan_number_any1;
8319 number_type = token_type::value_integer;
8325 goto scan_number_zero;
8339 goto scan_number_any1;
8344 error_message =
"invalid number; expected digit after '-'";
8345 return token_type::parse_error;
8355 add(decimal_point_char);
8356 goto scan_number_decimal1;
8363 goto scan_number_exponent;
8367 goto scan_number_done;
8386 goto scan_number_any1;
8391 add(decimal_point_char);
8392 goto scan_number_decimal1;
8399 goto scan_number_exponent;
8403 goto scan_number_done;
8406scan_number_decimal1:
8408 number_type = token_type::value_float;
8423 goto scan_number_decimal2;
8428 error_message =
"invalid number; expected digit after '.'";
8429 return token_type::parse_error;
8433scan_number_decimal2:
8449 goto scan_number_decimal2;
8456 goto scan_number_exponent;
8460 goto scan_number_done;
8463scan_number_exponent:
8465 number_type = token_type::value_float;
8472 goto scan_number_sign;
8487 goto scan_number_any2;
8493 "invalid number; expected '+', '-', or digit after exponent";
8494 return token_type::parse_error;
8514 goto scan_number_any2;
8519 error_message =
"invalid number; expected digit after exponent sign";
8520 return token_type::parse_error;
8540 goto scan_number_any2;
8544 goto scan_number_done;
8552 char* endptr =
nullptr;
8556 if (number_type == token_type::value_unsigned)
8558 const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
8561 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8565 value_unsigned =
static_cast<number_unsigned_t
>(x);
8566 if (value_unsigned == x)
8568 return token_type::value_unsigned;
8572 else if (number_type == token_type::value_integer)
8574 const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
8577 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8581 value_integer =
static_cast<number_integer_t
>(x);
8582 if (value_integer == x)
8584 return token_type::value_integer;
8591 strtof(value_float, token_buffer.data(), &endptr);
8594 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8596 return token_type::value_float;
8605 token_type scan_literal(const char_type* literal_text, const
std::
size_t length,
8606 token_type return_type)
8608 JSON_ASSERT(std::char_traits<char_type>::to_char_type(current) == literal_text[0]);
8609 for (std::size_t i = 1; i < length; ++i)
8613 error_message =
"invalid literal";
8614 return token_type::parse_error;
8625 void reset() noexcept
8627 token_buffer.clear();
8628 token_string.clear();
8629 token_string.push_back(std::char_traits<char_type>::to_char_type(current));
8644 ++position.chars_read_total;
8645 ++position.chars_read_current_line;
8654 current = ia.get_character();
8659 token_string.push_back(std::char_traits<char_type>::to_char_type(current));
8662 if (current ==
'\n')
8664 ++position.lines_read;
8665 position.chars_read_current_line = 0;
8683 --position.chars_read_total;
8686 if (position.chars_read_current_line == 0)
8688 if (position.lines_read > 0)
8690 --position.lines_read;
8695 --position.chars_read_current_line;
8701 token_string.pop_back();
8706 void add(char_int_type c)
8708 token_buffer.push_back(
static_cast<typename string_t::value_type
>(c));
8719 return value_integer;
8725 return value_unsigned;
8737 return token_buffer;
8757 for (
const auto c : token_string)
8759 if (
static_cast<unsigned char>(c) <=
'\x1F')
8762 std::array<char, 9> cs{{}};
8763 static_cast<void>((std::snprintf)(cs.data(), cs.size(),
"<U+%.4X>",
static_cast<unsigned char>(c)));
8764 result += cs.data();
8769 result.push_back(
static_cast<std::string::value_type
>(c));
8780 return error_message;
8796 return get() == 0xBB &&
get() == 0xBF;
8811 while (current ==
' ' || current ==
'\t' || current ==
'\n' || current ==
'\r');
8817 if (position.chars_read_total == 0 && !skip_bom())
8819 error_message =
"invalid BOM; must be 0xEF 0xBB 0xBF if given";
8820 return token_type::parse_error;
8827 while (ignore_comments && current ==
'/')
8829 if (!scan_comment())
8831 return token_type::parse_error;
8842 return token_type::begin_array;
8844 return token_type::end_array;
8846 return token_type::begin_object;
8848 return token_type::end_object;
8850 return token_type::name_separator;
8852 return token_type::value_separator;
8857 std::array<char_type, 4> true_literal = {{
static_cast<char_type
>(
't'),
static_cast<char_type
>(
'r'),
static_cast<char_type
>(
'u'),
static_cast<char_type
>(
'e')}};
8858 return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
8862 std::array<char_type, 5> false_literal = {{
static_cast<char_type
>(
'f'),
static_cast<char_type
>(
'a'),
static_cast<char_type
>(
'l'),
static_cast<char_type
>(
's'),
static_cast<char_type
>(
'e')}};
8863 return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
8867 std::array<char_type, 4> null_literal = {{
static_cast<char_type
>(
'n'),
static_cast<char_type
>(
'u'),
static_cast<char_type
>(
'l'),
static_cast<char_type
>(
'l')}};
8868 return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
8873 return scan_string();
8887 return scan_number();
8892 case std::char_traits<char_type>::eof():
8893 return token_type::end_of_input;
8897 error_message =
"invalid literal";
8898 return token_type::parse_error;
8904 InputAdapterType ia;
8907 const bool ignore_comments =
false;
8910 char_int_type current = std::char_traits<char_type>::eof();
8913 bool next_unget =
false;
8919 std::vector<char_type> token_string {};
8922 string_t token_buffer {};
8925 const char* error_message =
"";
8928 number_integer_t value_integer = 0;
8929 number_unsigned_t value_unsigned = 0;
8930 number_float_t value_float = 0;
8933 const char_int_type decimal_point_char =
'.';
8968using null_function_t =
decltype(std::declval<T&>().null());
8971using boolean_function_t =
8972 decltype(std::declval<T&>().boolean(std::declval<bool>()));
8974template<
typename T,
typename Integer>
8975using number_integer_function_t =
8976 decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
8978template<
typename T,
typename Un
signed>
8979using number_unsigned_function_t =
8980 decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
8982template<
typename T,
typename Float,
typename String>
8983using number_float_function_t =
decltype(std::declval<T&>().number_float(
8984 std::declval<Float>(), std::declval<const String&>()));
8986template<
typename T,
typename String>
8987using string_function_t =
8988 decltype(std::declval<T&>().string(std::declval<String&>()));
8990template<
typename T,
typename Binary>
8991using binary_function_t =
8992 decltype(std::declval<T&>().binary(std::declval<Binary&>()));
8995using start_object_function_t =
8996 decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
8998template<
typename T,
typename String>
8999using key_function_t =
9000 decltype(std::declval<T&>().key(std::declval<String&>()));
9003using end_object_function_t =
decltype(std::declval<T&>().end_object());
9006using start_array_function_t =
9007 decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
9010using end_array_function_t =
decltype(std::declval<T&>().end_array());
9012template<
typename T,
typename Exception>
9013using parse_error_function_t =
decltype(std::declval<T&>().parse_error(
9014 std::declval<std::size_t>(), std::declval<const std::string&>(),
9015 std::declval<const Exception&>()));
9017template<
typename SAX,
typename BasicJsonType>
9021 static_assert(is_basic_json<BasicJsonType>::value,
9022 "BasicJsonType must be of type basic_json<...>");
9024 using number_integer_t =
typename BasicJsonType::number_integer_t;
9025 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9026 using number_float_t =
typename BasicJsonType::number_float_t;
9027 using string_t =
typename BasicJsonType::string_t;
9028 using binary_t =
typename BasicJsonType::binary_t;
9029 using exception_t =
typename BasicJsonType::exception;
9032 static constexpr bool value =
9033 is_detected_exact<bool, null_function_t, SAX>::value &&
9034 is_detected_exact<bool, boolean_function_t, SAX>::value &&
9035 is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
9036 is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
9037 is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
9038 is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
9039 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
9040 is_detected_exact<bool, start_object_function_t, SAX>::value &&
9041 is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
9042 is_detected_exact<bool, end_object_function_t, SAX>::value &&
9043 is_detected_exact<bool, start_array_function_t, SAX>::value &&
9044 is_detected_exact<bool, end_array_function_t, SAX>::value &&
9045 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
9048template<
typename SAX,
typename BasicJsonType>
9049struct is_sax_static_asserts
9052 static_assert(is_basic_json<BasicJsonType>::value,
9053 "BasicJsonType must be of type basic_json<...>");
9055 using number_integer_t =
typename BasicJsonType::number_integer_t;
9056 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9057 using number_float_t =
typename BasicJsonType::number_float_t;
9058 using string_t =
typename BasicJsonType::string_t;
9059 using binary_t =
typename BasicJsonType::binary_t;
9060 using exception_t =
typename BasicJsonType::exception;
9063 static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
9064 "Missing/invalid function: bool null()");
9065 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
9066 "Missing/invalid function: bool boolean(bool)");
9067 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
9068 "Missing/invalid function: bool boolean(bool)");
9071 number_integer_t>::value,
9072 "Missing/invalid function: bool number_integer(number_integer_t)");
9075 number_unsigned_t>::value,
9076 "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
9078 number_float_t, string_t>::value,
9079 "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
9081 is_detected_exact<bool, string_function_t, SAX, string_t>::value,
9082 "Missing/invalid function: bool string(string_t&)");
9084 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
9085 "Missing/invalid function: bool binary(binary_t&)");
9086 static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
9087 "Missing/invalid function: bool start_object(std::size_t)");
9088 static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
9089 "Missing/invalid function: bool key(string_t&)");
9090 static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
9091 "Missing/invalid function: bool end_object()");
9092 static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
9093 "Missing/invalid function: bool start_array(std::size_t)");
9094 static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
9095 "Missing/invalid function: bool end_array()");
9097 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
9098 "Missing/invalid function: bool parse_error(std::size_t, const "
9099 "std::string&, const exception&)");
9131static inline bool little_endianness(
int num = 1) noexcept
9133 return *
reinterpret_cast<char*
>(&num) == 1;
9144template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX = json_sax_dom_parser<BasicJsonType>>
9147 using number_integer_t =
typename BasicJsonType::number_integer_t;
9148 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9149 using number_float_t =
typename BasicJsonType::number_float_t;
9150 using string_t =
typename BasicJsonType::string_t;
9151 using binary_t =
typename BasicJsonType::binary_t;
9152 using json_sax_t = SAX;
9153 using char_type =
typename InputAdapterType::char_type;
9154 using char_int_type =
typename std::char_traits<char_type>::int_type;
9162 explicit binary_reader(InputAdapterType&& adapter,
const input_format_t format = input_format_t::json) noexcept : ia(std::move(adapter)), input_format(format)
9164 (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
9185 const
bool strict = true,
9189 bool result =
false;
9193 case input_format_t::bson:
9194 result = parse_bson_internal();
9197 case input_format_t::cbor:
9198 result = parse_cbor_internal(
true, tag_handler);
9201 case input_format_t::msgpack:
9202 result = parse_msgpack_internal();
9205 case input_format_t::ubjson:
9206 case input_format_t::bjdata:
9207 result = parse_ubjson_internal();
9210 case input_format_t::json:
9218 if (input_format == input_format_t::ubjson || input_format == input_format_t::bjdata)
9229 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(110, chars_read,
9230 exception_message(input_format,
concat(
"expected end of input; last byte: 0x", get_token_string()),
"value"),
nullptr));
9246 bool parse_bson_internal()
9248 std::int32_t document_size{};
9249 get_number<std::int32_t, true>(input_format_t::bson, document_size);
9261 return sax->end_object();
9271 bool get_bson_cstr(string_t& result)
9273 auto out = std::back_inserter(result);
9281 if (current == 0x00)
9285 *out++ =
static_cast<typename string_t::value_type
>(current);
9300 template<
typename NumberType>
9301 bool get_bson_string(
const NumberType len, string_t& result)
9305 auto last_token = get_token_string();
9307 exception_message(input_format_t::bson,
concat(
"string length must be at least 1, is ", std::to_string(len)),
"string"),
nullptr));
9310 return get_string(input_format_t::bson, len -
static_cast<NumberType
>(1), result) && get() != std::char_traits<char_type>::eof();
9322 template<
typename NumberType>
9323 bool get_bson_binary(
const NumberType len, binary_t& result)
9327 auto last_token = get_token_string();
9329 exception_message(input_format_t::bson,
concat(
"byte array length cannot be negative, is ", std::to_string(len)),
"binary"),
nullptr));
9333 std::uint8_t subtype{};
9334 get_number<std::uint8_t>(input_format_t::bson, subtype);
9335 result.set_subtype(subtype);
9337 return get_binary(input_format_t::bson, len, result);
9350 bool parse_bson_element_internal(
const char_int_type element_type,
9351 const std::size_t element_type_parse_position)
9353 switch (element_type)
9358 return get_number<double, true>(input_format_t::bson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9365 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
9370 return parse_bson_internal();
9375 return parse_bson_array();
9382 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
9387 return sax->boolean(get() != 0);
9397 std::int32_t value{};
9398 return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
9403 std::int64_t value{};
9404 return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
9409 std::array<char, 3> cr{{}};
9410 static_cast<void>((std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(element_type)));
9411 const std::string cr_str{cr.data()};
9412 return sax->parse_error(element_type_parse_position, cr_str,
9430 bool parse_bson_element_list(
const bool is_array)
9434 while (
auto element_type = get())
9441 const std::size_t element_type_parse_position = chars_read;
9447 if (!is_array && !sax->key(key))
9452 if (
JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
9468 bool parse_bson_array()
9470 std::int32_t document_size{};
9471 get_number<std::int32_t, true>(input_format_t::bson, document_size);
9483 return sax->end_array();
9498 bool parse_cbor_internal(
const bool get_char,
9501 switch (get_char ? get() : current)
9504 case std::char_traits<char_type>::eof():
9505 return unexpect_eof(input_format_t::cbor,
"value");
9532 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
9536 std::uint8_t number{};
9537 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9542 std::uint16_t number{};
9543 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9548 std::uint32_t number{};
9549 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9554 std::uint64_t number{};
9555 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9583 return sax->number_integer(
static_cast<std::int8_t
>(0x20 - 1 - current));
9587 std::uint8_t number{};
9588 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
9593 std::uint16_t number{};
9594 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
9599 std::uint32_t number{};
9600 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
9605 std::uint64_t number{};
9606 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1)
9607 -
static_cast<number_integer_t
>(number));
9642 return get_cbor_binary(b) && sax->binary(b);
9677 return get_cbor_string(s) && sax->string(s);
9705 return get_cbor_array(
9706 conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
9711 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
9716 std::uint16_t len{};
9717 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
9722 std::uint32_t len{};
9723 return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
9728 std::uint64_t len{};
9729 return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
9733 return get_cbor_array(
static_cast<std::size_t
>(-1), tag_handler);
9760 return get_cbor_object(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
9765 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
9770 std::uint16_t len{};
9771 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
9776 std::uint32_t len{};
9777 return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
9782 std::uint64_t len{};
9783 return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
9787 return get_cbor_object(
static_cast<std::size_t
>(-1), tag_handler);
9809 switch (tag_handler)
9813 auto last_token = get_token_string();
9815 exception_message(input_format_t::cbor,
concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
9825 std::uint8_t subtype_to_ignore{};
9826 get_number(input_format_t::cbor, subtype_to_ignore);
9831 std::uint16_t subtype_to_ignore{};
9832 get_number(input_format_t::cbor, subtype_to_ignore);
9837 std::uint32_t subtype_to_ignore{};
9838 get_number(input_format_t::cbor, subtype_to_ignore);
9843 std::uint64_t subtype_to_ignore{};
9844 get_number(input_format_t::cbor, subtype_to_ignore);
9850 return parse_cbor_internal(
true, tag_handler);
9861 std::uint8_t subtype{};
9862 get_number(input_format_t::cbor, subtype);
9863 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9868 std::uint16_t subtype{};
9869 get_number(input_format_t::cbor, subtype);
9870 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9875 std::uint32_t subtype{};
9876 get_number(input_format_t::cbor, subtype);
9877 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9882 std::uint64_t subtype{};
9883 get_number(input_format_t::cbor, subtype);
9884 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9888 return parse_cbor_internal(
true, tag_handler);
9891 return get_cbor_binary(b) && sax->binary(b);
9901 return sax->boolean(
false);
9904 return sax->boolean(
true);
9911 const auto byte1_raw = get();
9916 const auto byte2_raw = get();
9922 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
9923 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
9933 const auto half =
static_cast<unsigned int>((byte1 << 8u) + byte2);
9934 const double val = [&half]
9936 const int exp = (half >> 10u) & 0x1Fu;
9937 const unsigned int mant = half & 0x3FFu;
9943 return std::ldexp(mant, -24);
9946 ? std::numeric_limits<double>::infinity()
9947 :
std::numeric_limits<double>::quiet_NaN();
9949 return std::ldexp(mant + 1024, exp - 25);
9952 return sax->number_float((half & 0x8000u) != 0
9953 ?
static_cast<number_float_t
>(-val)
9954 : static_cast<number_float_t>(val),
"");
9960 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9966 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9971 auto last_token = get_token_string();
9973 exception_message(input_format_t::cbor,
concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
9989 bool get_cbor_string(string_t& result)
10024 return get_string(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
10029 std::uint8_t len{};
10030 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10035 std::uint16_t len{};
10036 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10041 std::uint32_t len{};
10042 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10047 std::uint64_t len{};
10048 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10053 while (get() != 0xFF)
10056 if (!get_cbor_string(chunk))
10060 result.append(chunk);
10067 auto last_token = get_token_string();
10069 exception_message(input_format_t::cbor,
concat(
"expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token),
"string"),
nullptr));
10085 bool get_cbor_binary(binary_t& result)
10120 return get_binary(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
10125 std::uint8_t len{};
10126 return get_number(input_format_t::cbor, len) &&
10127 get_binary(input_format_t::cbor, len, result);
10132 std::uint16_t len{};
10133 return get_number(input_format_t::cbor, len) &&
10134 get_binary(input_format_t::cbor, len, result);
10139 std::uint32_t len{};
10140 return get_number(input_format_t::cbor, len) &&
10141 get_binary(input_format_t::cbor, len, result);
10146 std::uint64_t len{};
10147 return get_number(input_format_t::cbor, len) &&
10148 get_binary(input_format_t::cbor, len, result);
10153 while (get() != 0xFF)
10156 if (!get_cbor_binary(chunk))
10160 result.insert(result.end(), chunk.begin(), chunk.end());
10167 auto last_token = get_token_string();
10169 exception_message(input_format_t::cbor,
concat(
"expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x", last_token),
"binary"),
nullptr));
10180 bool get_cbor_array(
const std::size_t len,
10188 if (len !=
static_cast<std::size_t
>(-1))
10190 for (std::size_t i = 0; i < len; ++i)
10200 while (get() != 0xFF)
10209 return sax->end_array();
10218 bool get_cbor_object(
const std::size_t len,
10229 if (len !=
static_cast<std::size_t
>(-1))
10231 for (std::size_t i = 0; i < len; ++i)
10248 while (get() != 0xFF)
10264 return sax->end_object();
10274 bool parse_msgpack_internal()
10279 case std::char_traits<char_type>::eof():
10280 return unexpect_eof(input_format_t::msgpack,
"value");
10411 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
10430 return get_msgpack_object(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x0Fu));
10449 return get_msgpack_array(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x0Fu));
10489 return get_msgpack_string(s) && sax->string(s);
10493 return sax->null();
10496 return sax->boolean(
false);
10499 return sax->boolean(
true);
10514 return get_msgpack_binary(b) && sax->binary(b);
10520 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10526 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10531 std::uint8_t number{};
10532 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10537 std::uint16_t number{};
10538 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10543 std::uint32_t number{};
10544 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10549 std::uint64_t number{};
10550 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10555 std::int8_t number{};
10556 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10561 std::int16_t number{};
10562 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10567 std::int32_t number{};
10568 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10573 std::int64_t number{};
10574 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10579 std::uint16_t len{};
10580 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
10585 std::uint32_t len{};
10586 return get_number(input_format_t::msgpack, len) && get_msgpack_array(conditional_static_cast<std::size_t>(len));
10591 std::uint16_t len{};
10592 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
10597 std::uint32_t len{};
10598 return get_number(input_format_t::msgpack, len) && get_msgpack_object(conditional_static_cast<std::size_t>(len));
10634 return sax->number_integer(
static_cast<std::int8_t
>(current));
10638 auto last_token = get_token_string();
10640 exception_message(input_format_t::msgpack,
concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
10655 bool get_msgpack_string(string_t& result)
10698 return get_string(input_format_t::msgpack,
static_cast<unsigned int>(current) & 0x1Fu, result);
10703 std::uint8_t len{};
10704 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
10709 std::uint16_t len{};
10710 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
10715 std::uint32_t len{};
10716 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
10721 auto last_token = get_token_string();
10723 exception_message(input_format_t::msgpack,
concat(
"expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token),
"string"),
nullptr));
10738 bool get_msgpack_binary(binary_t& result)
10741 auto assign_and_return_true = [&result](std::int8_t subtype)
10743 result.set_subtype(
static_cast<std::uint8_t
>(subtype));
10751 std::uint8_t len{};
10752 return get_number(input_format_t::msgpack, len) &&
10753 get_binary(input_format_t::msgpack, len, result);
10758 std::uint16_t len{};
10759 return get_number(input_format_t::msgpack, len) &&
10760 get_binary(input_format_t::msgpack, len, result);
10765 std::uint32_t len{};
10766 return get_number(input_format_t::msgpack, len) &&
10767 get_binary(input_format_t::msgpack, len, result);
10772 std::uint8_t len{};
10773 std::int8_t subtype{};
10774 return get_number(input_format_t::msgpack, len) &&
10775 get_number(input_format_t::msgpack, subtype) &&
10776 get_binary(input_format_t::msgpack, len, result) &&
10777 assign_and_return_true(subtype);
10782 std::uint16_t len{};
10783 std::int8_t subtype{};
10784 return get_number(input_format_t::msgpack, len) &&
10785 get_number(input_format_t::msgpack, subtype) &&
10786 get_binary(input_format_t::msgpack, len, result) &&
10787 assign_and_return_true(subtype);
10792 std::uint32_t len{};
10793 std::int8_t subtype{};
10794 return get_number(input_format_t::msgpack, len) &&
10795 get_number(input_format_t::msgpack, subtype) &&
10796 get_binary(input_format_t::msgpack, len, result) &&
10797 assign_and_return_true(subtype);
10802 std::int8_t subtype{};
10803 return get_number(input_format_t::msgpack, subtype) &&
10804 get_binary(input_format_t::msgpack, 1, result) &&
10805 assign_and_return_true(subtype);
10810 std::int8_t subtype{};
10811 return get_number(input_format_t::msgpack, subtype) &&
10812 get_binary(input_format_t::msgpack, 2, result) &&
10813 assign_and_return_true(subtype);
10818 std::int8_t subtype{};
10819 return get_number(input_format_t::msgpack, subtype) &&
10820 get_binary(input_format_t::msgpack, 4, result) &&
10821 assign_and_return_true(subtype);
10826 std::int8_t subtype{};
10827 return get_number(input_format_t::msgpack, subtype) &&
10828 get_binary(input_format_t::msgpack, 8, result) &&
10829 assign_and_return_true(subtype);
10834 std::int8_t subtype{};
10835 return get_number(input_format_t::msgpack, subtype) &&
10836 get_binary(input_format_t::msgpack, 16, result) &&
10837 assign_and_return_true(subtype);
10849 bool get_msgpack_array(
const std::size_t len)
10856 for (std::size_t i = 0; i < len; ++i)
10864 return sax->end_array();
10871 bool get_msgpack_object(
const std::size_t len)
10879 for (std::size_t i = 0; i < len; ++i)
10894 return sax->end_object();
10908 bool parse_ubjson_internal(
const bool get_char =
true)
10910 return get_ubjson_value(get_char ? get_ignore_noop() : current);
10927 bool get_ubjson_string(string_t& result,
const bool get_char =
true)
10943 std::uint8_t len{};
10944 return get_number(input_format, len) && get_string(input_format, len, result);
10950 return get_number(input_format, len) && get_string(input_format, len, result);
10955 std::int16_t len{};
10956 return get_number(input_format, len) && get_string(input_format, len, result);
10961 std::int32_t len{};
10962 return get_number(input_format, len) && get_string(input_format, len, result);
10967 std::int64_t len{};
10968 return get_number(input_format, len) && get_string(input_format, len, result);
10973 if (input_format != input_format_t::bjdata)
10977 std::uint16_t len{};
10978 return get_number(input_format, len) && get_string(input_format, len, result);
10983 if (input_format != input_format_t::bjdata)
10987 std::uint32_t len{};
10988 return get_number(input_format, len) && get_string(input_format, len, result);
10993 if (input_format != input_format_t::bjdata)
10997 std::uint64_t len{};
10998 return get_number(input_format, len) && get_string(input_format, len, result);
11004 auto last_token = get_token_string();
11005 std::string message;
11007 if (input_format != input_format_t::bjdata)
11009 message =
"expected length type specification (U, i, I, l, L); last byte: 0x" + last_token;
11013 message =
"expected length type specification (U, i, u, I, m, l, M, L); last byte: 0x" + last_token;
11015 return sax->parse_error(chars_read, last_token,
parse_error::create(113, chars_read, exception_message(input_format, message,
"string"),
nullptr));
11022 bool get_ubjson_ndarray_size(std::vector<size_t>& dim)
11024 std::pair<std::size_t, char_int_type> size_and_type;
11026 bool no_ndarray =
true;
11033 if (size_and_type.first != npos)
11035 if (size_and_type.second != 0)
11037 if (size_and_type.second !=
'N')
11039 for (std::size_t i = 0; i < size_and_type.first; ++i)
11045 dim.push_back(dimlen);
11051 for (std::size_t i = 0; i < size_and_type.first; ++i)
11057 dim.push_back(dimlen);
11063 while (current !=
']')
11069 dim.push_back(dimlen);
11087 bool get_ubjson_size_value(std::size_t& result,
bool& is_ndarray, char_int_type prefix = 0)
11091 prefix = get_ignore_noop();
11098 std::uint8_t number{};
11103 result =
static_cast<std::size_t
>(number);
11109 std::int8_t number{};
11116 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(113, chars_read,
11117 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11119 result =
static_cast<std::size_t
>(number);
11125 std::int16_t number{};
11132 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(113, chars_read,
11133 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11135 result =
static_cast<std::size_t
>(number);
11141 std::int32_t number{};
11148 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(113, chars_read,
11149 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11151 result =
static_cast<std::size_t
>(number);
11157 std::int64_t number{};
11164 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(113, chars_read,
11165 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11167 if (!value_in_range_of<std::size_t>(number))
11170 exception_message(input_format,
"integer value overflow",
"size"),
nullptr));
11172 result =
static_cast<std::size_t
>(number);
11178 if (input_format != input_format_t::bjdata)
11182 std::uint16_t number{};
11187 result =
static_cast<std::size_t
>(number);
11193 if (input_format != input_format_t::bjdata)
11197 std::uint32_t number{};
11202 result = conditional_static_cast<std::size_t>(number);
11208 if (input_format != input_format_t::bjdata)
11212 std::uint64_t number{};
11217 if (!value_in_range_of<std::size_t>(number))
11220 exception_message(input_format,
"integer value overflow",
"size"),
nullptr));
11222 result = detail::conditional_static_cast<std::size_t>(number);
11228 if (input_format != input_format_t::bjdata)
11234 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(113, chars_read, exception_message(input_format,
"ndarray dimensional vector is not allowed",
"size"),
nullptr));
11236 std::vector<size_t> dim;
11241 if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1))
11243 result = dim.at(dim.size() - 1);
11257 string_t key =
"_ArraySize_";
11258 if (
JSON_HEDLEY_UNLIKELY(!sax->start_object(3) || !sax->key(key) || !sax->start_array(dim.size())))
11266 if (result == 0 || result == npos)
11268 return sax->parse_error(chars_read, get_token_string(),
out_of_range::create(408, exception_message(input_format,
"excessive ndarray size caused overflow",
"size"),
nullptr));
11276 return sax->end_array();
11285 auto last_token = get_token_string();
11286 std::string message;
11288 if (input_format != input_format_t::bjdata)
11290 message =
"expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token;
11294 message =
"expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x" + last_token;
11296 return sax->parse_error(chars_read, last_token,
parse_error::create(113, chars_read, exception_message(input_format, message,
"size"),
nullptr));
11310 bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result,
bool inside_ndarray =
false)
11312 result.first = npos;
11314 bool is_ndarray =
false;
11318 if (current ==
'$')
11320 result.second = get();
11321 if (input_format == input_format_t::bjdata
11322 &&
JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second)))
11324 auto last_token = get_token_string();
11326 exception_message(input_format,
concat(
"marker 0x", last_token,
" is not a permitted optimized array type"),
"type"),
nullptr));
11341 auto last_token = get_token_string();
11343 exception_message(input_format,
concat(
"expected '#' after type information; last byte: 0x", last_token),
"size"),
nullptr));
11346 const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
11347 if (input_format == input_format_t::bjdata && is_ndarray)
11349 if (inside_ndarray)
11351 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(112, chars_read,
11352 exception_message(input_format,
"ndarray can not be recursive",
"size"),
nullptr));
11354 result.second |= (1 << 8);
11359 if (current ==
'#')
11361 const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
11362 if (input_format == input_format_t::bjdata && is_ndarray)
11364 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(112, chars_read,
11365 exception_message(input_format,
"ndarray requires both type and size",
"size"),
nullptr));
11377 bool get_ubjson_value(
const char_int_type prefix)
11381 case std::char_traits<char_type>::eof():
11382 return unexpect_eof(input_format,
"value");
11385 return sax->boolean(
true);
11387 return sax->boolean(
false);
11390 return sax->null();
11394 std::uint8_t number{};
11395 return get_number(input_format, number) && sax->number_unsigned(number);
11400 std::int8_t number{};
11401 return get_number(input_format, number) && sax->number_integer(number);
11406 std::int16_t number{};
11407 return get_number(input_format, number) && sax->number_integer(number);
11412 std::int32_t number{};
11413 return get_number(input_format, number) && sax->number_integer(number);
11418 std::int64_t number{};
11419 return get_number(input_format, number) && sax->number_integer(number);
11424 if (input_format != input_format_t::bjdata)
11428 std::uint16_t number{};
11429 return get_number(input_format, number) && sax->number_unsigned(number);
11434 if (input_format != input_format_t::bjdata)
11438 std::uint32_t number{};
11439 return get_number(input_format, number) && sax->number_unsigned(number);
11444 if (input_format != input_format_t::bjdata)
11448 std::uint64_t number{};
11449 return get_number(input_format, number) && sax->number_unsigned(number);
11454 if (input_format != input_format_t::bjdata)
11458 const auto byte1_raw = get();
11463 const auto byte2_raw = get();
11469 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
11470 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
11480 const auto half =
static_cast<unsigned int>((byte2 << 8u) + byte1);
11481 const double val = [&half]
11483 const int exp = (half >> 10u) & 0x1Fu;
11484 const unsigned int mant = half & 0x3FFu;
11490 return std::ldexp(mant, -24);
11493 ? std::numeric_limits<double>::infinity()
11494 :
std::numeric_limits<double>::quiet_NaN();
11496 return std::ldexp(mant + 1024, exp - 25);
11499 return sax->number_float((half & 0x8000u) != 0
11500 ?
static_cast<number_float_t
>(-val)
11501 : static_cast<number_float_t>(val),
"");
11507 return get_number(input_format, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
11513 return get_number(input_format, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
11518 return get_ubjson_high_precision_number();
11530 auto last_token = get_token_string();
11532 exception_message(input_format,
concat(
"byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token),
"char"),
nullptr));
11534 string_t s(1,
static_cast<typename string_t::value_type
>(current));
11535 return sax->string(s);
11541 return get_ubjson_string(s) && sax->string(s);
11545 return get_ubjson_array();
11548 return get_ubjson_object();
11553 auto last_token = get_token_string();
11554 return sax->parse_error(chars_read, last_token,
parse_error::create(112, chars_read, exception_message(input_format,
"invalid byte: 0x" + last_token,
"value"),
nullptr));
11560 bool get_ubjson_array()
11562 std::pair<std::size_t, char_int_type> size_and_type;
11571 if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
11573 size_and_type.second &= ~(
static_cast<char_int_type
>(1) << 8);
11574 auto it = std::lower_bound(bjd_types_map.begin(), bjd_types_map.end(), size_and_type.second, [](
const bjd_type & p, char_int_type t)
11576 return p.first < t;
11578 string_t key =
"_ArrayType_";
11581 auto last_token = get_token_string();
11583 exception_message(input_format,
"invalid byte: 0x" + last_token,
"type"),
nullptr));
11586 string_t type = it->second;
11592 if (size_and_type.second ==
'C')
11594 size_and_type.second =
'U';
11597 key =
"_ArrayData_";
11603 for (std::size_t i = 0; i < size_and_type.first; ++i)
11611 return (sax->end_array() && sax->end_object());
11614 if (size_and_type.first != npos)
11621 if (size_and_type.second != 0)
11623 if (size_and_type.second !=
'N')
11625 for (std::size_t i = 0; i < size_and_type.first; ++i)
11636 for (std::size_t i = 0; i < size_and_type.first; ++i)
11652 while (current !=
']')
11662 return sax->end_array();
11668 bool get_ubjson_object()
11670 std::pair<std::size_t, char_int_type> size_and_type;
11677 if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
11679 auto last_token = get_token_string();
11681 exception_message(input_format,
"BJData object does not support ND-array size in optimized format",
"object"),
nullptr));
11685 if (size_and_type.first != npos)
11692 if (size_and_type.second != 0)
11694 for (std::size_t i = 0; i < size_and_type.first; ++i)
11709 for (std::size_t i = 0; i < size_and_type.first; ++i)
11730 while (current !=
'}')
11745 return sax->end_object();
11751 bool get_ubjson_high_precision_number()
11754 std::size_t size{};
11755 bool no_ndarray =
true;
11756 auto res = get_ubjson_size_value(size, no_ndarray);
11763 std::vector<char> number_vector;
11764 for (std::size_t i = 0; i < size; ++i)
11771 number_vector.push_back(
static_cast<char>(current));
11775 using ia_type =
decltype(detail::input_adapter(number_vector));
11777 const auto result_number = number_lexer.scan();
11778 const auto number_string = number_lexer.get_token_string();
11779 const auto result_remainder = number_lexer.scan();
11786 exception_message(input_format,
concat(
"invalid number text: ", number_lexer.get_token_string()),
"high-precision number"),
nullptr));
11789 switch (result_number)
11791 case token_type::value_integer:
11792 return sax->number_integer(number_lexer.get_number_integer());
11793 case token_type::value_unsigned:
11794 return sax->number_unsigned(number_lexer.get_number_unsigned());
11795 case token_type::value_float:
11796 return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
11797 case token_type::uninitialized:
11798 case token_type::literal_true:
11799 case token_type::literal_false:
11800 case token_type::literal_null:
11801 case token_type::value_string:
11802 case token_type::begin_array:
11803 case token_type::begin_object:
11804 case token_type::end_array:
11805 case token_type::end_object:
11806 case token_type::name_separator:
11807 case token_type::value_separator:
11808 case token_type::parse_error:
11809 case token_type::end_of_input:
11810 case token_type::literal_or_value:
11813 exception_message(input_format,
concat(
"invalid number text: ", number_lexer.get_token_string()),
"high-precision number"),
nullptr));
11830 char_int_type get()
11833 return current = ia.get_character();
11839 char_int_type get_ignore_noop()
11845 while (current ==
'N');
11865 template<
typename NumberType,
bool InputIsLittleEndian = false>
11866 bool get_number(
const input_format_t format, NumberType& result)
11869 std::array<std::uint8_t,
sizeof(NumberType)> vec{};
11870 for (std::size_t i = 0; i <
sizeof(NumberType); ++i)
11879 if (is_little_endian != (InputIsLittleEndian || format == input_format_t::bjdata))
11881 vec[
sizeof(NumberType) - i - 1] =
static_cast<std::uint8_t
>(current);
11885 vec[i] =
static_cast<std::uint8_t
>(current);
11890 std::memcpy(&result, vec.data(),
sizeof(NumberType));
11908 template<
typename NumberType>
11909 bool get_string(
const input_format_t format,
11910 const NumberType len,
11913 bool success =
true;
11914 for (NumberType i = 0; i < len; i++)
11922 result.push_back(
static_cast<typename string_t::value_type
>(current));
11941 template<
typename NumberType>
11942 bool get_binary(
const input_format_t format,
11943 const NumberType len,
11946 bool success =
true;
11947 for (NumberType i = 0; i < len; i++)
11955 result.push_back(
static_cast<std::uint8_t
>(current));
11966 bool unexpect_eof(const input_format_t format, const
char* context)
const
11970 return sax->parse_error(chars_read,
"<end of file>",
11971 parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context),
nullptr));
11979 std::string get_token_string()
const
11981 std::array<char, 3> cr{{}};
11982 static_cast<void>((std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(current)));
11983 return std::string{cr.data()};
11992 std::string exception_message(
const input_format_t format,
11993 const std::string&
detail,
11994 const std::string& context)
const
11996 std::string error_msg =
"syntax error while parsing ";
12000 case input_format_t::cbor:
12001 error_msg +=
"CBOR";
12004 case input_format_t::msgpack:
12005 error_msg +=
"MessagePack";
12008 case input_format_t::ubjson:
12009 error_msg +=
"UBJSON";
12012 case input_format_t::bson:
12013 error_msg +=
"BSON";
12016 case input_format_t::bjdata:
12017 error_msg +=
"BJData";
12020 case input_format_t::json:
12032 InputAdapterType ia;
12035 char_int_type current = std::char_traits<char_type>::eof();
12038 std::size_t chars_read = 0;
12041 const bool is_little_endian = little_endianness();
12044 const input_format_t input_format = input_format_t::json;
12047 json_sax_t* sax =
nullptr;
12050#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ \
12051 make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
12053#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
12054 make_array<bjd_type>( \
12055 bjd_type{'C', "char"}, \
12056 bjd_type{'D', "double"}, \
12057 bjd_type{'I', "int16"}, \
12058 bjd_type{'L', "int64"}, \
12059 bjd_type{'M', "uint64"}, \
12060 bjd_type{'U', "uint8"}, \
12061 bjd_type{'d', "single"}, \
12062 bjd_type{'i', "int8"}, \
12063 bjd_type{'l', "int32"}, \
12064 bjd_type{'m', "uint32"}, \
12065 bjd_type{'u', "uint16"})
12073 using bjd_type = std::pair<char_int_type, string_t>;
12078#undef JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_
12079#undef JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_
12082#ifndef JSON_HAS_CPP_17
12083 template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX>
12084 constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos;
12107#include <functional>
12136enum class parse_event_t : std::uint8_t
12152template<
typename BasicJsonType>
12153using parser_callback_t =
12154 std::function<bool(
int , parse_event_t , BasicJsonType& )>;
12161template<
typename BasicJsonType,
typename InputAdapterType>
12164 using number_integer_t =
typename BasicJsonType::number_integer_t;
12165 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
12166 using number_float_t =
typename BasicJsonType::number_float_t;
12167 using string_t =
typename BasicJsonType::string_t;
12168 using lexer_t = lexer<BasicJsonType, InputAdapterType>;
12169 using token_type =
typename lexer_t::token_type;
12173 explicit parser(InputAdapterType&& adapter,
12174 const parser_callback_t<BasicJsonType> cb =
nullptr,
12175 const bool allow_exceptions_ =
true,
12176 const bool skip_comments =
false)
12178 , m_lexer(
std::move(adapter), skip_comments)
12179 , allow_exceptions(allow_exceptions_)
12195 void parse(
const bool strict, BasicJsonType& result)
12199 json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions);
12200 sax_parse_internal(&sdp);
12203 if (
strict && (get_token() != token_type::end_of_input))
12205 sdp.parse_error(m_lexer.get_position(),
12206 m_lexer.get_token_string(),
12208 exception_message(token_type::end_of_input,
"value"),
nullptr));
12212 if (sdp.is_errored())
12220 if (result.is_discarded())
12227 json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions);
12228 sax_parse_internal(&sdp);
12231 if (
strict && (get_token() != token_type::end_of_input))
12233 sdp.parse_error(m_lexer.get_position(),
12234 m_lexer.get_token_string(),
12235 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"),
nullptr));
12239 if (sdp.is_errored())
12246 result.assert_invariant();
12255 bool accept(
const bool strict =
true)
12257 json_sax_acceptor<BasicJsonType> sax_acceptor;
12258 return sax_parse(&sax_acceptor,
strict);
12261 template<
typename SAX>
12263 bool sax_parse(SAX* sax, const
bool strict = true)
12265 (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
12266 const bool result = sax_parse_internal(sax);
12269 if (result &&
strict && (get_token() != token_type::end_of_input))
12271 return sax->parse_error(m_lexer.get_position(),
12272 m_lexer.get_token_string(),
12273 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"),
nullptr));
12280 template<
typename SAX>
12282 bool sax_parse_internal(SAX* sax)
12286 std::vector<bool> states;
12288 bool skip_to_state_evaluation =
false;
12292 if (!skip_to_state_evaluation)
12295 switch (last_token)
12297 case token_type::begin_object:
12305 if (get_token() == token_type::end_object)
12317 return sax->parse_error(m_lexer.get_position(),
12318 m_lexer.get_token_string(),
12319 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"),
nullptr));
12329 return sax->parse_error(m_lexer.get_position(),
12330 m_lexer.get_token_string(),
12331 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"),
nullptr));
12335 states.push_back(
false);
12342 case token_type::begin_array:
12350 if (get_token() == token_type::end_array)
12360 states.push_back(
true);
12366 case token_type::value_float:
12368 const auto res = m_lexer.get_number_float();
12372 return sax->parse_error(m_lexer.get_position(),
12373 m_lexer.get_token_string(),
12385 case token_type::literal_false:
12394 case token_type::literal_null:
12403 case token_type::literal_true:
12412 case token_type::value_integer:
12421 case token_type::value_string:
12430 case token_type::value_unsigned:
12439 case token_type::parse_error:
12442 return sax->parse_error(m_lexer.get_position(),
12443 m_lexer.get_token_string(),
12444 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized,
"value"),
nullptr));
12447 case token_type::uninitialized:
12448 case token_type::end_array:
12449 case token_type::end_object:
12450 case token_type::name_separator:
12451 case token_type::value_separator:
12452 case token_type::end_of_input:
12453 case token_type::literal_or_value:
12456 return sax->parse_error(m_lexer.get_position(),
12457 m_lexer.get_token_string(),
12458 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value,
"value"),
nullptr));
12464 skip_to_state_evaluation =
false;
12468 if (states.empty())
12477 if (get_token() == token_type::value_separator)
12498 skip_to_state_evaluation =
true;
12502 return sax->parse_error(m_lexer.get_position(),
12503 m_lexer.get_token_string(),
12504 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array,
"array"),
nullptr));
12510 if (get_token() == token_type::value_separator)
12515 return sax->parse_error(m_lexer.get_position(),
12516 m_lexer.get_token_string(),
12517 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"),
nullptr));
12528 return sax->parse_error(m_lexer.get_position(),
12529 m_lexer.get_token_string(),
12530 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"),
nullptr));
12552 skip_to_state_evaluation =
true;
12556 return sax->parse_error(m_lexer.get_position(),
12557 m_lexer.get_token_string(),
12558 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object,
"object"),
nullptr));
12563 token_type get_token()
12565 return last_token = m_lexer.scan();
12568 std::string exception_message(
const token_type expected,
const std::string& context)
12570 std::string error_msg =
"syntax error ";
12572 if (!context.empty())
12574 error_msg +=
concat(
"while parsing ", context,
' ');
12579 if (last_token == token_type::parse_error)
12581 error_msg +=
concat(m_lexer.get_error_message(),
"; last read: '",
12582 m_lexer.get_token_string(),
'\'');
12586 error_msg +=
concat(
"unexpected ", lexer_t::token_type_name(last_token));
12589 if (expected != token_type::uninitialized)
12591 error_msg +=
concat(
"; expected ", lexer_t::token_type_name(expected));
12599 const parser_callback_t<BasicJsonType> callback =
nullptr;
12601 token_type last_token = token_type::uninitialized;
12605 const bool allow_exceptions =
true;
12654class primitive_iterator_t
12657 using difference_type = std::ptrdiff_t;
12658 static constexpr difference_type begin_value = 0;
12659 static constexpr difference_type end_value = begin_value + 1;
12663 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
12666 constexpr difference_type get_value() const noexcept
12672 void set_begin() noexcept
12674 m_it = begin_value;
12678 void set_end() noexcept
12684 constexpr bool is_begin() const noexcept
12686 return m_it == begin_value;
12690 constexpr bool is_end() const noexcept
12692 return m_it == end_value;
12695 friend constexpr bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
12697 return lhs.m_it == rhs.m_it;
12700 friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
12702 return lhs.m_it < rhs.m_it;
12705 primitive_iterator_t operator+(difference_type n)
noexcept
12707 auto result = *
this;
12712 friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
12714 return lhs.m_it - rhs.m_it;
12717 primitive_iterator_t& operator++() noexcept
12723 primitive_iterator_t operator++(
int)&
noexcept
12725 auto result = *
this;
12730 primitive_iterator_t& operator--() noexcept
12736 primitive_iterator_t operator--(
int)&
noexcept
12738 auto result = *
this;
12743 primitive_iterator_t& operator+=(difference_type n)
noexcept
12749 primitive_iterator_t& operator-=(difference_type n)
noexcept
12795#include <type_traits>
12817template<
typename IteratorType>
class iteration_proxy;
12818template<
typename IteratorType>
class iteration_proxy_value;
12836template<
typename BasicJsonType>
12842 friend other_iter_impl;
12843 friend BasicJsonType;
12847 using object_t =
typename BasicJsonType::object_t;
12848 using array_t =
typename BasicJsonType::array_t;
12851 "iter_impl only accepts (const) basic_json");
12853 static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value
12854 && std::is_base_of<std::bidirectional_iterator_tag, typename std::iterator_traits<typename array_t::iterator>::iterator_category>
::value,
12855 "basic_json iterator assumes array and object type iterators satisfy the LegacyBidirectionalIterator named requirement.");
12870 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
12871 typename BasicJsonType::const_pointer,
12872 typename BasicJsonType::pointer>::type;
12875 typename std::conditional<std::is_const<BasicJsonType>::value,
12876 typename BasicJsonType::const_reference,
12877 typename BasicJsonType::reference>::type;
12894 switch (m_object->m_data.m_type)
12941 : m_object(other.m_object),
m_it(other.m_it)
12952 if (&other !=
this)
12954 m_object = other.m_object;
12966 : m_object(other.m_object),
m_it(other.m_it)
12977 m_object = other.m_object;
12987 void set_begin() noexcept
12991 switch (m_object->m_data.m_type)
13035 switch (m_object->m_data.m_type)
13074 switch (m_object->m_data.m_type)
13118 switch (m_object->m_data.m_type)
13158 auto result = *
this;
13171 switch (m_object->m_data.m_type)
13209 auto result = *
this;
13222 switch (m_object->m_data.m_type)
13258 template <
typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::
nullptr_t > =
nullptr >
13269 switch (m_object->m_data.m_type)
13294 template <
typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::
nullptr_t > =
nullptr >
13314 switch (m_object->m_data.m_type)
13341 return !other.operator < (*this);
13370 switch (m_object->m_data.m_type)
13414 auto result = *
this;
13436 auto result = *
this;
13449 switch (m_object->m_data.m_type)
13478 switch (m_object->m_data.m_type)
13512 const typename object_t::key_type&
key()
const
13589template<
typename Base>
13663 auto it = --this->base();
13670 auto it = --this->base();
13671 return it.operator * ();
13683#include <type_traits>
13706 std::is_same<T, void>::value,
13725#include <algorithm>
13753template<
typename RefStringType>
13763 template<
typename T>
13764 struct string_t_helper
13772 using type = StringType;
13777 using string_t =
typename string_t_helper<RefStringType>::type;
13782 : reference_tokens(split(s))
13789 return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
13793 return detail::concat(a,
'/', detail::escape(b));
13819 reference_tokens.insert(reference_tokens.end(),
13820 ptr.reference_tokens.begin(),
13821 ptr.reference_tokens.end());
13837 return *
this /= std::to_string(array_idx);
13885 reference_tokens.pop_back();
13897 return reference_tokens.back();
13904 reference_tokens.push_back(token);
13911 reference_tokens.push_back(std::move(token));
13918 return reference_tokens.empty();
13932 template<
typename BasicJsonType>
13933 static typename BasicJsonType::size_type array_index(
const string_t& s)
13935 using size_type =
typename BasicJsonType::size_type;
13949 const char* p = s.c_str();
13950 char* p_end =
nullptr;
13952 const unsigned long long res = std::strtoull(p, &p_end, 10);
13962 if (res >=
static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))
13967 return static_cast<size_type
>(res);
13979 result.reference_tokens = {reference_tokens[0]};
13992 template<
typename BasicJsonType>
13993 BasicJsonType& get_and_create(BasicJsonType& j)
const
13999 for (
const auto& reference_token : reference_tokens)
14001 switch (result->type())
14005 if (reference_token ==
"0")
14008 result = &result->operator[](0);
14013 result = &result->operator[](reference_token);
14021 result = &result->operator[](reference_token);
14028 result = &result->operator[](array_index<BasicJsonType>(reference_token));
14072 template<
typename BasicJsonType>
14073 BasicJsonType& get_unchecked(BasicJsonType* ptr)
const
14075 for (
const auto& reference_token : reference_tokens)
14078 if (ptr->is_null())
14082 std::all_of(reference_token.begin(), reference_token.end(),
14083 [](
const unsigned char x)
14085 return std::isdigit(x);
14089 *ptr = (nums || reference_token ==
"-")
14094 switch (ptr->type())
14099 ptr = &ptr->operator[](reference_token);
14105 if (reference_token ==
"-")
14108 ptr = &ptr->operator[](ptr->m_data.m_value.array->size());
14113 ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));
14140 template<
typename BasicJsonType>
14141 BasicJsonType& get_checked(BasicJsonType* ptr)
const
14143 for (
const auto& reference_token : reference_tokens)
14145 switch (ptr->type())
14150 ptr = &ptr->at(reference_token);
14160 "array index '-' (", std::to_string(ptr->m_data.m_value.array->size()),
14161 ") is out of range"), ptr));
14165 ptr = &ptr->at(array_index<BasicJsonType>(reference_token));
14198 template<
typename BasicJsonType>
14199 const BasicJsonType& get_unchecked(
const BasicJsonType* ptr)
const
14201 for (
const auto& reference_token : reference_tokens)
14203 switch (ptr->type())
14208 ptr = &ptr->operator[](reference_token);
14221 ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));
14247 template<
typename BasicJsonType>
14248 const BasicJsonType& get_checked(
const BasicJsonType* ptr)
const
14250 for (
const auto& reference_token : reference_tokens)
14252 switch (ptr->type())
14257 ptr = &ptr->at(reference_token);
14267 "array index '-' (", std::to_string(ptr->m_data.m_value.array->size()),
14268 ") is out of range"), ptr));
14272 ptr = &ptr->at(array_index<BasicJsonType>(reference_token));
14296 template<
typename BasicJsonType>
14297 bool contains(
const BasicJsonType* ptr)
const
14299 for (
const auto& reference_token : reference_tokens)
14301 switch (ptr->type())
14305 if (!ptr->contains(reference_token))
14311 ptr = &ptr->operator[](reference_token);
14322 if (
JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !(
"0" <= reference_token && reference_token <=
"9")))
14334 for (std::size_t i = 1; i < reference_token.size(); i++)
14344 const auto idx = array_index<BasicJsonType>(reference_token);
14345 if (idx >= ptr->size())
14351 ptr = &ptr->operator[](idx);
14385 static std::vector<string_t> split(
const string_t& reference_string)
14387 std::vector<string_t> result;
14390 if (reference_string.empty())
14406 std::size_t slash = reference_string.find_first_of(
'/', 1),
14413 start = (slash == string_t::npos) ? 0 : slash + 1,
14415 slash = reference_string.find_first_of(
'/', start))
14419 auto reference_token = reference_string.substr(start, slash - start);
14422 for (std::size_t pos = reference_token.find_first_of(
'~');
14423 pos != string_t::npos;
14424 pos = reference_token.find_first_of(
'~', pos + 1))
14430 (reference_token[pos + 1] !=
'0' &&
14431 reference_token[pos + 1] !=
'1')))
14438 detail::unescape(reference_token);
14439 result.push_back(reference_token);
14453 template<
typename BasicJsonType>
14454 static void flatten(
const string_t& reference_string,
14455 const BasicJsonType& value,
14456 BasicJsonType& result)
14458 switch (value.type())
14462 if (value.m_data.m_value.array->empty())
14465 result[reference_string] =
nullptr;
14470 for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i)
14472 flatten(
detail::concat(reference_string,
'/', std::to_string(i)),
14473 value.m_data.m_value.array->operator[](i), result);
14481 if (value.m_data.m_value.object->empty())
14484 result[reference_string] =
nullptr;
14489 for (
const auto& element : *value.m_data.m_value.
object)
14508 result[reference_string] = value;
14524 template<
typename BasicJsonType>
14525 static BasicJsonType
14526 unflatten(
const BasicJsonType& value)
14533 BasicJsonType result;
14536 for (
const auto& element : *value.m_data.m_value.
object)
14547 json_pointer(element.first).get_and_create(result) = element.second;
14557 result.reference_tokens = reference_tokens;
14564 result.reference_tokens = std::move(reference_tokens);
14569#if JSON_HAS_THREE_WAY_COMPARISON
14572 template<
typename RefStringTypeRhs>
14575 return reference_tokens == rhs.reference_tokens;
14587 template<
typename RefStringTypeRhs>
14590 return reference_tokens <=> rhs.reference_tokens;
14595 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14602 template<
typename RefStringTypeLhs,
typename StringType>
14605 const StringType& rhs);
14609 template<
typename RefStringTypeRhs,
typename StringType>
14611 friend bool operator==(
const StringType& lhs,
14616 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14623 template<
typename RefStringTypeLhs,
typename StringType>
14626 const StringType& rhs);
14630 template<
typename RefStringTypeRhs,
typename StringType>
14632 friend bool operator!=(
const StringType& lhs,
14636 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14644 std::vector<string_t> reference_tokens;
14647#if !JSON_HAS_THREE_WAY_COMPARISON
14649template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14653 return lhs.reference_tokens == rhs.reference_tokens;
14656template<
typename RefStringTypeLhs,
14660 const StringType& rhs)
14665template<
typename RefStringTypeRhs,
14668inline
bool operator==(const StringType& lhs,
14674template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14678 return !(lhs == rhs);
14681template<
typename RefStringTypeLhs,
14685 const StringType& rhs)
14687 return !(lhs == rhs);
14690template<
typename RefStringTypeRhs,
14693inline
bool operator!=(const StringType& lhs,
14696 return !(lhs == rhs);
14699template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14703 return lhs.reference_tokens < rhs.reference_tokens;
14720#include <initializer_list>
14732template<
typename BasicJsonType>
14739 : owned_value(
std::move(value))
14743 : value_ref(&value)
14747 : owned_value(init)
14754 : owned_value(
std::forward<Args>(args)...)
14766 if (value_ref ==
nullptr)
14768 return std::move(owned_value);
14775 return value_ref ? *value_ref : owned_value;
14812#include <algorithm>
14838#include <algorithm>
14858template<
typename CharType>
struct output_adapter_protocol
14860 virtual void write_character(CharType c) = 0;
14861 virtual void write_characters(
const CharType* s, std::size_t length) = 0;
14862 virtual ~output_adapter_protocol() =
default;
14864 output_adapter_protocol() =
default;
14865 output_adapter_protocol(
const output_adapter_protocol&) =
default;
14866 output_adapter_protocol(output_adapter_protocol&&) noexcept = default;
14867 output_adapter_protocol& operator=(const output_adapter_protocol&) = default;
14868 output_adapter_protocol& operator=(output_adapter_protocol&&) noexcept = default;
14872template<typename CharType>
14873using output_adapter_t =
std::shared_ptr<output_adapter_protocol<CharType>>;
14876template<typename CharType, typename AllocatorType =
std::allocator<CharType>>
14877class output_vector_adapter : public output_adapter_protocol<CharType>
14880 explicit output_vector_adapter(std::vector<CharType, AllocatorType>& vec) noexcept
14884 void write_character(CharType c)
override
14890 void write_characters(const CharType* s,
std::
size_t length)
override
14892 v.insert(v.end(), s, s + length);
14896 std::vector<CharType, AllocatorType>& v;
14901template<
typename CharType>
14902class output_stream_adapter :
public output_adapter_protocol<CharType>
14905 explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
14909 void write_character(CharType c)
override
14915 void write_characters(const CharType* s,
std::
size_t length)
override
14917 stream.write(s,
static_cast<std::streamsize
>(length));
14921 std::basic_ostream<CharType>& stream;
14926template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
14927class output_string_adapter :
public output_adapter_protocol<CharType>
14930 explicit output_string_adapter(StringType& s) noexcept
14934 void write_character(CharType c)
override
14940 void write_characters(const CharType* s,
std::
size_t length)
override
14942 str.append(s, length);
14949template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
14950class output_adapter
14953 template<
typename AllocatorType = std::allocator<CharType>>
14954 output_adapter(std::vector<CharType, AllocatorType>& vec)
14955 : oa(
std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) {}
14958 output_adapter(std::basic_ostream<CharType>& s)
14959 : oa(
std::make_shared<output_stream_adapter<CharType>>(s)) {}
14962 output_adapter(StringType& s)
14963 : oa(
std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
14965 operator output_adapter_t<CharType>()
14971 output_adapter_t<CharType> oa =
nullptr;
14991template<
typename BasicJsonType,
typename CharType>
14994 using string_t =
typename BasicJsonType::string_t;
14995 using binary_t =
typename BasicJsonType::binary_t;
14996 using number_float_t =
typename BasicJsonType::number_float_t;
15004 explicit binary_writer(output_adapter_t<CharType> adapter) : oa(
std::move(adapter))
15013 void write_bson(
const BasicJsonType& j)
15017 case value_t::object:
15019 write_bson_object(*j.m_data.m_value.object);
15023 case value_t::null:
15024 case value_t::array:
15025 case value_t::string:
15026 case value_t::boolean:
15027 case value_t::number_integer:
15028 case value_t::number_unsigned:
15029 case value_t::number_float:
15030 case value_t::binary:
15031 case value_t::discarded:
15034 JSON_THROW(type_error::create(317,
concat(
"to serialize to BSON, top-level type must be object, but is ", j.type_name()), &j));
15042 void write_cbor(
const BasicJsonType& j)
15046 case value_t::null:
15048 oa->write_character(to_char_type(0xF6));
15052 case value_t::boolean:
15054 oa->write_character(j.m_data.m_value.boolean
15055 ? to_char_type(0xF5)
15056 : to_char_type(0xF4));
15060 case value_t::number_integer:
15062 if (j.m_data.m_value.number_integer >= 0)
15067 if (j.m_data.m_value.number_integer <= 0x17)
15069 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15071 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
15073 oa->write_character(to_char_type(0x18));
15074 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15076 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
15078 oa->write_character(to_char_type(0x19));
15079 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
15081 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
15083 oa->write_character(to_char_type(0x1A));
15084 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
15088 oa->write_character(to_char_type(0x1B));
15089 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
15096 const auto positive_number = -1 - j.m_data.m_value.number_integer;
15097 if (j.m_data.m_value.number_integer >= -24)
15099 write_number(
static_cast<std::uint8_t
>(0x20 + positive_number));
15101 else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
15103 oa->write_character(to_char_type(0x38));
15104 write_number(
static_cast<std::uint8_t
>(positive_number));
15106 else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
15108 oa->write_character(to_char_type(0x39));
15109 write_number(
static_cast<std::uint16_t
>(positive_number));
15111 else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
15113 oa->write_character(to_char_type(0x3A));
15114 write_number(
static_cast<std::uint32_t
>(positive_number));
15118 oa->write_character(to_char_type(0x3B));
15119 write_number(
static_cast<std::uint64_t
>(positive_number));
15125 case value_t::number_unsigned:
15127 if (j.m_data.m_value.number_unsigned <= 0x17)
15129 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_unsigned));
15131 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
15133 oa->write_character(to_char_type(0x18));
15134 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_unsigned));
15136 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
15138 oa->write_character(to_char_type(0x19));
15139 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_unsigned));
15141 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
15143 oa->write_character(to_char_type(0x1A));
15144 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_unsigned));
15148 oa->write_character(to_char_type(0x1B));
15149 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_unsigned));
15154 case value_t::number_float:
15156 if (std::isnan(j.m_data.m_value.number_float))
15159 oa->write_character(to_char_type(0xF9));
15160 oa->write_character(to_char_type(0x7E));
15161 oa->write_character(to_char_type(0x00));
15163 else if (std::isinf(j.m_data.m_value.number_float))
15166 oa->write_character(to_char_type(0xf9));
15167 oa->write_character(j.m_data.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
15168 oa->write_character(to_char_type(0x00));
15172 write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::cbor);
15177 case value_t::string:
15180 const auto N = j.m_data.m_value.string->size();
15183 write_number(
static_cast<std::uint8_t
>(0x60 + N));
15185 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15187 oa->write_character(to_char_type(0x78));
15188 write_number(
static_cast<std::uint8_t
>(N));
15190 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15192 oa->write_character(to_char_type(0x79));
15193 write_number(
static_cast<std::uint16_t
>(N));
15195 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15197 oa->write_character(to_char_type(0x7A));
15198 write_number(
static_cast<std::uint32_t
>(N));
15201 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15203 oa->write_character(to_char_type(0x7B));
15204 write_number(
static_cast<std::uint64_t
>(N));
15209 oa->write_characters(
15210 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
15211 j.m_data.m_value.string->size());
15215 case value_t::array:
15218 const auto N = j.m_data.m_value.array->size();
15221 write_number(
static_cast<std::uint8_t
>(0x80 + N));
15223 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15225 oa->write_character(to_char_type(0x98));
15226 write_number(
static_cast<std::uint8_t
>(N));
15228 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15230 oa->write_character(to_char_type(0x99));
15231 write_number(
static_cast<std::uint16_t
>(N));
15233 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15235 oa->write_character(to_char_type(0x9A));
15236 write_number(
static_cast<std::uint32_t
>(N));
15239 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15241 oa->write_character(to_char_type(0x9B));
15242 write_number(
static_cast<std::uint64_t
>(N));
15247 for (
const auto& el : *j.m_data.m_value.
array)
15254 case value_t::binary:
15256 if (j.m_data.m_value.binary->has_subtype())
15258 if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)())
15260 write_number(
static_cast<std::uint8_t
>(0xd8));
15261 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.binary->subtype()));
15263 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint16_t>::max)())
15265 write_number(
static_cast<std::uint8_t
>(0xd9));
15266 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.binary->subtype()));
15268 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint32_t>::max)())
15270 write_number(
static_cast<std::uint8_t
>(0xda));
15271 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.binary->subtype()));
15273 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint64_t>::max)())
15275 write_number(
static_cast<std::uint8_t
>(0xdb));
15276 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.binary->subtype()));
15281 const auto N = j.m_data.m_value.binary->size();
15284 write_number(
static_cast<std::uint8_t
>(0x40 + N));
15286 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15288 oa->write_character(to_char_type(0x58));
15289 write_number(
static_cast<std::uint8_t
>(N));
15291 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15293 oa->write_character(to_char_type(0x59));
15294 write_number(
static_cast<std::uint16_t
>(N));
15296 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15298 oa->write_character(to_char_type(0x5A));
15299 write_number(
static_cast<std::uint32_t
>(N));
15302 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15304 oa->write_character(to_char_type(0x5B));
15305 write_number(
static_cast<std::uint64_t
>(N));
15310 oa->write_characters(
15311 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
15317 case value_t::object:
15320 const auto N = j.m_data.m_value.object->size();
15323 write_number(
static_cast<std::uint8_t
>(0xA0 + N));
15325 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15327 oa->write_character(to_char_type(0xB8));
15328 write_number(
static_cast<std::uint8_t
>(N));
15330 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15332 oa->write_character(to_char_type(0xB9));
15333 write_number(
static_cast<std::uint16_t
>(N));
15335 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15337 oa->write_character(to_char_type(0xBA));
15338 write_number(
static_cast<std::uint32_t
>(N));
15341 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15343 oa->write_character(to_char_type(0xBB));
15344 write_number(
static_cast<std::uint64_t
>(N));
15349 for (
const auto& el : *j.m_data.m_value.
object)
15351 write_cbor(el.first);
15352 write_cbor(el.second);
15357 case value_t::discarded:
15366 void write_msgpack(
const BasicJsonType& j)
15370 case value_t::null:
15372 oa->write_character(to_char_type(0xC0));
15376 case value_t::boolean:
15378 oa->write_character(j.m_data.m_value.boolean
15379 ? to_char_type(0xC3)
15380 : to_char_type(0xC2));
15384 case value_t::number_integer:
15386 if (j.m_data.m_value.number_integer >= 0)
15391 if (j.m_data.m_value.number_unsigned < 128)
15394 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15396 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
15399 oa->write_character(to_char_type(0xCC));
15400 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15402 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
15405 oa->write_character(to_char_type(0xCD));
15406 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
15408 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
15411 oa->write_character(to_char_type(0xCE));
15412 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
15414 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
15417 oa->write_character(to_char_type(0xCF));
15418 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
15423 if (j.m_data.m_value.number_integer >= -32)
15426 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.number_integer));
15428 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&
15429 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
15432 oa->write_character(to_char_type(0xD0));
15433 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.number_integer));
15435 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&
15436 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
15439 oa->write_character(to_char_type(0xD1));
15440 write_number(
static_cast<std::int16_t
>(j.m_data.m_value.number_integer));
15442 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&
15443 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
15446 oa->write_character(to_char_type(0xD2));
15447 write_number(
static_cast<std::int32_t
>(j.m_data.m_value.number_integer));
15449 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&
15450 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
15453 oa->write_character(to_char_type(0xD3));
15454 write_number(
static_cast<std::int64_t
>(j.m_data.m_value.number_integer));
15460 case value_t::number_unsigned:
15462 if (j.m_data.m_value.number_unsigned < 128)
15465 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15467 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
15470 oa->write_character(to_char_type(0xCC));
15471 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15473 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
15476 oa->write_character(to_char_type(0xCD));
15477 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
15479 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
15482 oa->write_character(to_char_type(0xCE));
15483 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
15485 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
15488 oa->write_character(to_char_type(0xCF));
15489 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
15494 case value_t::number_float:
15496 write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::msgpack);
15500 case value_t::string:
15503 const auto N = j.m_data.m_value.string->size();
15507 write_number(
static_cast<std::uint8_t
>(0xA0 | N));
15509 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15512 oa->write_character(to_char_type(0xD9));
15513 write_number(
static_cast<std::uint8_t
>(N));
15515 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15518 oa->write_character(to_char_type(0xDA));
15519 write_number(
static_cast<std::uint16_t
>(N));
15521 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15524 oa->write_character(to_char_type(0xDB));
15525 write_number(
static_cast<std::uint32_t
>(N));
15529 oa->write_characters(
15530 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
15531 j.m_data.m_value.string->size());
15535 case value_t::array:
15538 const auto N = j.m_data.m_value.array->size();
15542 write_number(
static_cast<std::uint8_t
>(0x90 | N));
15544 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15547 oa->write_character(to_char_type(0xDC));
15548 write_number(
static_cast<std::uint16_t
>(N));
15550 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15553 oa->write_character(to_char_type(0xDD));
15554 write_number(
static_cast<std::uint32_t
>(N));
15558 for (
const auto& el : *j.m_data.m_value.
array)
15565 case value_t::binary:
15569 const bool use_ext = j.m_data.m_value.binary->has_subtype();
15572 const auto N = j.m_data.m_value.binary->size();
15573 if (N <= (std::numeric_limits<std::uint8_t>::max)())
15575 std::uint8_t output_type{};
15582 output_type = 0xD4;
15585 output_type = 0xD5;
15588 output_type = 0xD6;
15591 output_type = 0xD7;
15594 output_type = 0xD8;
15597 output_type = 0xC7;
15605 output_type = 0xC4;
15609 oa->write_character(to_char_type(output_type));
15612 write_number(
static_cast<std::uint8_t
>(N));
15615 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15617 const std::uint8_t output_type = use_ext
15621 oa->write_character(to_char_type(output_type));
15622 write_number(
static_cast<std::uint16_t
>(N));
15624 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15626 const std::uint8_t output_type = use_ext
15630 oa->write_character(to_char_type(output_type));
15631 write_number(
static_cast<std::uint32_t
>(N));
15637 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.binary->subtype()));
15641 oa->write_characters(
15642 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
15648 case value_t::object:
15651 const auto N = j.m_data.m_value.object->size();
15655 write_number(
static_cast<std::uint8_t
>(0x80 | (N & 0xF)));
15657 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15660 oa->write_character(to_char_type(0xDE));
15661 write_number(
static_cast<std::uint16_t
>(N));
15663 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15666 oa->write_character(to_char_type(0xDF));
15667 write_number(
static_cast<std::uint32_t
>(N));
15671 for (
const auto& el : *j.m_data.m_value.
object)
15673 write_msgpack(el.first);
15674 write_msgpack(el.second);
15679 case value_t::discarded:
15692 void write_ubjson(
const BasicJsonType& j,
const bool use_count,
15693 const bool use_type,
const bool add_prefix =
true,
15694 const bool use_bjdata =
false)
15698 case value_t::null:
15702 oa->write_character(to_char_type(
'Z'));
15707 case value_t::boolean:
15711 oa->write_character(j.m_data.m_value.boolean
15712 ? to_char_type(
'T')
15713 : to_char_type(
'F'));
15718 case value_t::number_integer:
15720 write_number_with_ubjson_prefix(j.m_data.m_value.number_integer, add_prefix, use_bjdata);
15724 case value_t::number_unsigned:
15726 write_number_with_ubjson_prefix(j.m_data.m_value.number_unsigned, add_prefix, use_bjdata);
15730 case value_t::number_float:
15732 write_number_with_ubjson_prefix(j.m_data.m_value.number_float, add_prefix, use_bjdata);
15736 case value_t::string:
15740 oa->write_character(to_char_type(
'S'));
15742 write_number_with_ubjson_prefix(j.m_data.m_value.string->size(),
true, use_bjdata);
15743 oa->write_characters(
15744 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
15745 j.m_data.m_value.string->size());
15749 case value_t::array:
15753 oa->write_character(to_char_type(
'['));
15756 bool prefix_required =
true;
15757 if (use_type && !j.m_data.m_value.array->empty())
15760 const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
15761 const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
15762 [
this, first_prefix, use_bjdata](
const BasicJsonType & v)
15764 return ubjson_prefix(v, use_bjdata) == first_prefix;
15767 std::vector<CharType> bjdx = {
'[',
'{',
'S',
'H',
'T',
'F',
'N',
'Z'};
15769 if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
15771 prefix_required =
false;
15772 oa->write_character(to_char_type(
'$'));
15773 oa->write_character(first_prefix);
15779 oa->write_character(to_char_type(
'#'));
15780 write_number_with_ubjson_prefix(j.m_data.m_value.array->size(),
true, use_bjdata);
15783 for (
const auto& el : *j.m_data.m_value.
array)
15785 write_ubjson(el, use_count, use_type, prefix_required, use_bjdata);
15790 oa->write_character(to_char_type(
']'));
15796 case value_t::binary:
15800 oa->write_character(to_char_type(
'['));
15803 if (use_type && !j.m_data.m_value.binary->empty())
15806 oa->write_character(to_char_type(
'$'));
15807 oa->write_character(
'U');
15812 oa->write_character(to_char_type(
'#'));
15813 write_number_with_ubjson_prefix(j.m_data.m_value.binary->size(),
true, use_bjdata);
15818 oa->write_characters(
15819 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
15820 j.m_data.m_value.binary->size());
15824 for (
size_t i = 0; i < j.m_data.m_value.binary->size(); ++i)
15826 oa->write_character(to_char_type(
'U'));
15827 oa->write_character(j.m_data.m_value.binary->data()[i]);
15833 oa->write_character(to_char_type(
']'));
15839 case value_t::object:
15841 if (use_bjdata && j.m_data.m_value.object->size() == 3 && j.m_data.m_value.object->find(
"_ArrayType_") != j.m_data.m_value.object->end() && j.m_data.m_value.object->find(
"_ArraySize_") != j.m_data.m_value.object->end() && j.m_data.m_value.object->find(
"_ArrayData_") != j.m_data.m_value.object->end())
15843 if (!write_bjdata_ndarray(*j.m_data.m_value.object, use_count, use_type))
15851 oa->write_character(to_char_type(
'{'));
15854 bool prefix_required =
true;
15855 if (use_type && !j.m_data.m_value.object->empty())
15858 const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
15859 const bool same_prefix = std::all_of(j.begin(), j.end(),
15860 [
this, first_prefix, use_bjdata](
const BasicJsonType & v)
15862 return ubjson_prefix(v, use_bjdata) == first_prefix;
15865 std::vector<CharType> bjdx = {
'[',
'{',
'S',
'H',
'T',
'F',
'N',
'Z'};
15867 if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
15869 prefix_required =
false;
15870 oa->write_character(to_char_type(
'$'));
15871 oa->write_character(first_prefix);
15877 oa->write_character(to_char_type(
'#'));
15878 write_number_with_ubjson_prefix(j.m_data.m_value.object->size(),
true, use_bjdata);
15881 for (
const auto& el : *j.m_data.m_value.
object)
15883 write_number_with_ubjson_prefix(el.first.size(),
true, use_bjdata);
15884 oa->write_characters(
15885 reinterpret_cast<const CharType*
>(el.first.c_str()),
15887 write_ubjson(el.second, use_count, use_type, prefix_required, use_bjdata);
15892 oa->write_character(to_char_type(
'}'));
15898 case value_t::discarded:
15913 static std::size_t calc_bson_entry_header_size(
const string_t& name,
const BasicJsonType& j)
15915 const auto it = name.find(
static_cast<typename string_t::value_type
>(0));
15918 JSON_THROW(out_of_range::create(409,
concat(
"BSON key cannot contain code point U+0000 (at byte ", std::to_string(it),
")"), &j));
15919 static_cast<void>(j);
15922 return 1ul + name.size() + 1u;
15928 void write_bson_entry_header(
const string_t& name,
15929 const std::uint8_t element_type)
15931 oa->write_character(to_char_type(element_type));
15932 oa->write_characters(
15933 reinterpret_cast<const CharType*
>(name.c_str()),
15940 void write_bson_boolean(
const string_t& name,
15943 write_bson_entry_header(name, 0x08);
15944 oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
15950 void write_bson_double(
const string_t& name,
15951 const double value)
15953 write_bson_entry_header(name, 0x01);
15954 write_number<double>(value,
true);
15960 static std::size_t calc_bson_string_size(
const string_t& value)
15962 return sizeof(std::int32_t) + value.size() + 1ul;
15968 void write_bson_string(
const string_t& name,
15969 const string_t& value)
15971 write_bson_entry_header(name, 0x02);
15973 write_number<std::int32_t>(
static_cast<std::int32_t
>(value.size() + 1ul),
true);
15974 oa->write_characters(
15975 reinterpret_cast<const CharType*
>(value.c_str()),
15982 void write_bson_null(
const string_t& name)
15984 write_bson_entry_header(name, 0x0A);
15990 static std::size_t calc_bson_integer_size(
const std::int64_t value)
15992 return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()
15993 ?
sizeof(std::int32_t)
15994 :
sizeof(std::int64_t);
16000 void write_bson_integer(
const string_t& name,
16001 const std::int64_t value)
16003 if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
16005 write_bson_entry_header(name, 0x10);
16006 write_number<std::int32_t>(
static_cast<std::int32_t
>(value),
true);
16010 write_bson_entry_header(name, 0x12);
16011 write_number<std::int64_t>(
static_cast<std::int64_t
>(value),
true);
16018 static constexpr std::size_t calc_bson_unsigned_size(
const std::uint64_t value)
noexcept
16020 return (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16021 ?
sizeof(std::int32_t)
16022 : sizeof(
std::int64_t);
16028 void write_bson_unsigned(
const string_t& name,
16029 const BasicJsonType& j)
16031 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16033 write_bson_entry_header(name, 0x10 );
16034 write_number<std::int32_t>(
static_cast<std::int32_t
>(j.m_data.m_value.number_unsigned),
true);
16036 else if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
16038 write_bson_entry_header(name, 0x12 );
16039 write_number<std::int64_t>(
static_cast<std::int64_t
>(j.m_data.m_value.number_unsigned),
true);
16043 JSON_THROW(out_of_range::create(407,
concat(
"integer number ", std::to_string(j.m_data.m_value.number_unsigned),
" cannot be represented by BSON as it does not fit int64"), &j));
16050 void write_bson_object_entry(
const string_t& name,
16051 const typename BasicJsonType::object_t& value)
16053 write_bson_entry_header(name, 0x03);
16054 write_bson_object(value);
16060 static std::size_t calc_bson_array_size(
const typename BasicJsonType::array_t& value)
16062 std::size_t array_index = 0ul;
16064 const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value),
static_cast<std::size_t
>(0), [&array_index](std::size_t result,
const typename BasicJsonType::array_t::value_type & el)
16066 return result + calc_bson_element_size(std::to_string(array_index++), el);
16069 return sizeof(std::int32_t) + embedded_document_size + 1ul;
16075 static std::size_t calc_bson_binary_size(
const typename BasicJsonType::binary_t& value)
16077 return sizeof(std::int32_t) + value.size() + 1ul;
16083 void write_bson_array(
const string_t& name,
16084 const typename BasicJsonType::array_t& value)
16086 write_bson_entry_header(name, 0x04);
16087 write_number<std::int32_t>(
static_cast<std::int32_t
>(calc_bson_array_size(value)),
true);
16089 std::size_t array_index = 0ul;
16091 for (
const auto& el : value)
16093 write_bson_element(std::to_string(array_index++), el);
16096 oa->write_character(to_char_type(0x00));
16102 void write_bson_binary(
const string_t& name,
16103 const binary_t& value)
16105 write_bson_entry_header(name, 0x05);
16107 write_number<std::int32_t>(
static_cast<std::int32_t
>(value.size()),
true);
16108 write_number(value.has_subtype() ?
static_cast<std::uint8_t
>(value.subtype()) : static_cast<
std::uint8_t>(0x00));
16110 oa->write_characters(
reinterpret_cast<const CharType*
>(value.data()), value.size());
16117 static std::size_t calc_bson_element_size(
const string_t& name,
16118 const BasicJsonType& j)
16120 const auto header_size = calc_bson_entry_header_size(name, j);
16123 case value_t::object:
16124 return header_size + calc_bson_object_size(*j.m_data.m_value.object);
16126 case value_t::array:
16127 return header_size + calc_bson_array_size(*j.m_data.m_value.array);
16129 case value_t::binary:
16130 return header_size + calc_bson_binary_size(*j.m_data.m_value.binary);
16132 case value_t::boolean:
16133 return header_size + 1ul;
16135 case value_t::number_float:
16136 return header_size + 8ul;
16138 case value_t::number_integer:
16139 return header_size + calc_bson_integer_size(j.m_data.m_value.number_integer);
16141 case value_t::number_unsigned:
16142 return header_size + calc_bson_unsigned_size(j.m_data.m_value.number_unsigned);
16144 case value_t::string:
16145 return header_size + calc_bson_string_size(*j.m_data.m_value.string);
16147 case value_t::null:
16148 return header_size + 0ul;
16151 case value_t::discarded:
16165 void write_bson_element(
const string_t& name,
16166 const BasicJsonType& j)
16170 case value_t::object:
16171 return write_bson_object_entry(name, *j.m_data.m_value.object);
16173 case value_t::array:
16174 return write_bson_array(name, *j.m_data.m_value.array);
16176 case value_t::binary:
16177 return write_bson_binary(name, *j.m_data.m_value.binary);
16179 case value_t::boolean:
16180 return write_bson_boolean(name, j.m_data.m_value.boolean);
16182 case value_t::number_float:
16183 return write_bson_double(name, j.m_data.m_value.number_float);
16185 case value_t::number_integer:
16186 return write_bson_integer(name, j.m_data.m_value.number_integer);
16188 case value_t::number_unsigned:
16189 return write_bson_unsigned(name, j);
16191 case value_t::string:
16192 return write_bson_string(name, *j.m_data.m_value.string);
16194 case value_t::null:
16195 return write_bson_null(name);
16198 case value_t::discarded:
16212 static std::size_t calc_bson_object_size(
const typename BasicJsonType::object_t& value)
16214 const std::size_t document_size = std::accumulate(value.begin(), value.end(),
static_cast<std::size_t
>(0),
16215 [](
size_t result,
const typename BasicJsonType::object_t::value_type & el)
16217 return result += calc_bson_element_size(el.first, el.second);
16220 return sizeof(std::int32_t) + document_size + 1ul;
16227 void write_bson_object(
const typename BasicJsonType::object_t& value)
16229 write_number<std::int32_t>(
static_cast<std::int32_t
>(calc_bson_object_size(value)),
true);
16231 for (
const auto& el : value)
16233 write_bson_element(el.first, el.second);
16236 oa->write_character(to_char_type(0x00));
16243 static constexpr CharType get_cbor_float_prefix(
float )
16245 return to_char_type(0xFA);
16248 static constexpr CharType get_cbor_float_prefix(
double )
16250 return to_char_type(0xFB);
16257 static constexpr CharType get_msgpack_float_prefix(
float )
16259 return to_char_type(0xCA);
16262 static constexpr CharType get_msgpack_float_prefix(
double )
16264 return to_char_type(0xCB);
16272 template<
typename NumberType,
typename std::enable_if<
16273 std::is_floating_point<NumberType>::value,
int>::type = 0>
16274 void write_number_with_ubjson_prefix(
const NumberType n,
16275 const bool add_prefix,
16276 const bool use_bjdata)
16280 oa->write_character(get_ubjson_float_prefix(n));
16282 write_number(n, use_bjdata);
16286 template<
typename NumberType,
typename std::enable_if<
16287 std::is_unsigned<NumberType>::value,
int>::type = 0>
16288 void write_number_with_ubjson_prefix(
const NumberType n,
16289 const bool add_prefix,
16290 const bool use_bjdata)
16292 if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
16296 oa->write_character(to_char_type(
'i'));
16298 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
16300 else if (n <= (std::numeric_limits<std::uint8_t>::max)())
16304 oa->write_character(to_char_type(
'U'));
16306 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
16308 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
16312 oa->write_character(to_char_type(
'I'));
16314 write_number(
static_cast<std::int16_t
>(n), use_bjdata);
16316 else if (use_bjdata && n <=
static_cast<uint64_t
>((std::numeric_limits<uint16_t>::max)()))
16320 oa->write_character(to_char_type(
'u'));
16322 write_number(
static_cast<std::uint16_t
>(n), use_bjdata);
16324 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16328 oa->write_character(to_char_type(
'l'));
16330 write_number(
static_cast<std::int32_t
>(n), use_bjdata);
16332 else if (use_bjdata && n <=
static_cast<uint64_t
>((std::numeric_limits<uint32_t>::max)()))
16336 oa->write_character(to_char_type(
'm'));
16338 write_number(
static_cast<std::uint32_t
>(n), use_bjdata);
16340 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
16344 oa->write_character(to_char_type(
'L'));
16346 write_number(
static_cast<std::int64_t
>(n), use_bjdata);
16348 else if (use_bjdata && n <= (std::numeric_limits<uint64_t>::max)())
16352 oa->write_character(to_char_type(
'M'));
16354 write_number(
static_cast<std::uint64_t
>(n), use_bjdata);
16360 oa->write_character(to_char_type(
'H'));
16363 const auto number = BasicJsonType(n).dump();
16364 write_number_with_ubjson_prefix(number.size(),
true, use_bjdata);
16365 for (std::size_t i = 0; i < number.size(); ++i)
16367 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
16373 template <
typename NumberType,
typename std::enable_if <
16374 std::is_signed<NumberType>::value&&
16375 !std::is_floating_point<NumberType>::value,
int >::type = 0 >
16376 void write_number_with_ubjson_prefix(
const NumberType n,
16377 const bool add_prefix,
16378 const bool use_bjdata)
16380 if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
16384 oa->write_character(to_char_type(
'i'));
16386 write_number(
static_cast<std::int8_t
>(n), use_bjdata);
16388 else if (
static_cast<std::int64_t
>((std::numeric_limits<std::uint8_t>::min)()) <= n && n <=
static_cast<std::int64_t
>((std::numeric_limits<std::uint8_t>::max)()))
16392 oa->write_character(to_char_type(
'U'));
16394 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
16396 else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
16400 oa->write_character(to_char_type(
'I'));
16402 write_number(
static_cast<std::int16_t
>(n), use_bjdata);
16404 else if (use_bjdata && (
static_cast<std::int64_t
>((std::numeric_limits<std::uint16_t>::min)()) <= n && n <=
static_cast<std::int64_t
>((std::numeric_limits<std::uint16_t>::max)())))
16408 oa->write_character(to_char_type(
'u'));
16410 write_number(
static_cast<uint16_t
>(n), use_bjdata);
16412 else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
16416 oa->write_character(to_char_type(
'l'));
16418 write_number(
static_cast<std::int32_t
>(n), use_bjdata);
16420 else if (use_bjdata && (
static_cast<std::int64_t
>((std::numeric_limits<std::uint32_t>::min)()) <= n && n <=
static_cast<std::int64_t
>((std::numeric_limits<std::uint32_t>::max)())))
16424 oa->write_character(to_char_type(
'm'));
16426 write_number(
static_cast<uint32_t
>(n), use_bjdata);
16428 else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
16432 oa->write_character(to_char_type(
'L'));
16434 write_number(
static_cast<std::int64_t
>(n), use_bjdata);
16441 oa->write_character(to_char_type(
'H'));
16444 const auto number = BasicJsonType(n).dump();
16445 write_number_with_ubjson_prefix(number.size(),
true, use_bjdata);
16446 for (std::size_t i = 0; i < number.size(); ++i)
16448 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
16457 CharType ubjson_prefix(
const BasicJsonType& j,
const bool use_bjdata)
const noexcept
16461 case value_t::null:
16464 case value_t::boolean:
16465 return j.m_data.m_value.boolean ?
'T' :
'F';
16467 case value_t::number_integer:
16469 if ((std::numeric_limits<std::int8_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
16473 if ((std::numeric_limits<std::uint8_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
16477 if ((std::numeric_limits<std::int16_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
16481 if (use_bjdata && ((std::numeric_limits<std::uint16_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)()))
16485 if ((std::numeric_limits<std::int32_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
16489 if (use_bjdata && ((std::numeric_limits<std::uint32_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)()))
16493 if ((std::numeric_limits<std::int64_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
16501 case value_t::number_unsigned:
16503 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
16507 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint8_t>::max)()))
16511 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
16515 if (use_bjdata && j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint16_t>::max)()))
16519 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16523 if (use_bjdata && j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint32_t>::max)()))
16527 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
16531 if (use_bjdata && j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
16539 case value_t::number_float:
16540 return get_ubjson_float_prefix(j.m_data.m_value.number_float);
16542 case value_t::string:
16545 case value_t::array:
16546 case value_t::binary:
16549 case value_t::object:
16552 case value_t::discarded:
16558 static constexpr CharType get_ubjson_float_prefix(
float )
16563 static constexpr CharType get_ubjson_float_prefix(
double )
16571 bool write_bjdata_ndarray(
const typename BasicJsonType::object_t& value,
const bool use_count,
const bool use_type)
16573 std::map<string_t, CharType> bjdtype = {{
"uint8",
'U'}, {
"int8",
'i'}, {
"uint16",
'u'}, {
"int16",
'I'},
16574 {
"uint32",
'm'}, {
"int32",
'l'}, {
"uint64",
'M'}, {
"int64",
'L'}, {
"single",
'd'}, {
"double",
'D'}, {
"char",
'C'}
16577 string_t key =
"_ArrayType_";
16578 auto it = bjdtype.find(
static_cast<string_t
>(value.at(key)));
16579 if (it == bjdtype.end())
16583 CharType dtype = it->second;
16585 key =
"_ArraySize_";
16586 std::size_t len = (value.at(key).empty() ? 0 : 1);
16587 for (
const auto& el : value.at(key))
16589 len *=
static_cast<std::size_t
>(el.m_data.m_value.number_unsigned);
16592 key =
"_ArrayData_";
16593 if (value.at(key).size() != len)
16598 oa->write_character(
'[');
16599 oa->write_character(
'$');
16600 oa->write_character(dtype);
16601 oa->write_character(
'#');
16603 key =
"_ArraySize_";
16604 write_ubjson(value.at(key), use_count, use_type,
true,
true);
16606 key =
"_ArrayData_";
16607 if (dtype ==
'U' || dtype ==
'C')
16609 for (
const auto& el : value.at(key))
16611 write_number(
static_cast<std::uint8_t
>(el.m_data.m_value.number_unsigned),
true);
16614 else if (dtype ==
'i')
16616 for (
const auto& el : value.at(key))
16618 write_number(
static_cast<std::int8_t
>(el.m_data.m_value.number_integer),
true);
16621 else if (dtype ==
'u')
16623 for (
const auto& el : value.at(key))
16625 write_number(
static_cast<std::uint16_t
>(el.m_data.m_value.number_unsigned),
true);
16628 else if (dtype ==
'I')
16630 for (
const auto& el : value.at(key))
16632 write_number(
static_cast<std::int16_t
>(el.m_data.m_value.number_integer),
true);
16635 else if (dtype ==
'm')
16637 for (
const auto& el : value.at(key))
16639 write_number(
static_cast<std::uint32_t
>(el.m_data.m_value.number_unsigned),
true);
16642 else if (dtype ==
'l')
16644 for (
const auto& el : value.at(key))
16646 write_number(
static_cast<std::int32_t
>(el.m_data.m_value.number_integer),
true);
16649 else if (dtype ==
'M')
16651 for (
const auto& el : value.at(key))
16653 write_number(
static_cast<std::uint64_t
>(el.m_data.m_value.number_unsigned),
true);
16656 else if (dtype ==
'L')
16658 for (
const auto& el : value.at(key))
16660 write_number(
static_cast<std::int64_t
>(el.m_data.m_value.number_integer),
true);
16663 else if (dtype ==
'd')
16665 for (
const auto& el : value.at(key))
16667 write_number(
static_cast<float>(el.m_data.m_value.number_float),
true);
16670 else if (dtype ==
'D')
16672 for (
const auto& el : value.at(key))
16674 write_number(
static_cast<double>(el.m_data.m_value.number_float),
true);
16697 template<
typename NumberType>
16698 void write_number(
const NumberType n,
const bool OutputIsLittleEndian =
false)
16701 std::array<CharType,
sizeof(NumberType)> vec{};
16702 std::memcpy(vec.data(), &n,
sizeof(NumberType));
16705 if (is_little_endian != OutputIsLittleEndian)
16708 std::reverse(vec.begin(), vec.end());
16711 oa->write_characters(vec.data(),
sizeof(NumberType));
16714 void write_compact_float(
const number_float_t n, detail::input_format_t format)
16717#pragma GCC diagnostic push
16718#pragma GCC diagnostic ignored "-Wfloat-equal"
16720 if (
static_cast<double>(n) >=
static_cast<double>(std::numeric_limits<float>::lowest()) &&
16721 static_cast<double>(n) <=
static_cast<double>((std::numeric_limits<float>::max)()) &&
16722 static_cast<double>(
static_cast<float>(n)) ==
static_cast<double>(n))
16724 oa->write_character(format == detail::input_format_t::cbor
16725 ? get_cbor_float_prefix(
static_cast<float>(n))
16726 : get_msgpack_float_prefix(static_cast<float>(n)));
16727 write_number(
static_cast<float>(n));
16731 oa->write_character(format == detail::input_format_t::cbor
16732 ? get_cbor_float_prefix(n)
16733 : get_msgpack_float_prefix(n));
16737#pragma GCC diagnostic pop
16746 template <
typename C = CharType,
16747 enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * =
nullptr >
16748 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
16750 return *
reinterpret_cast<char*
>(&x);
16753 template <
typename C = CharType,
16754 enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * =
nullptr >
16755 static CharType to_char_type(std::uint8_t x)
noexcept
16757 static_assert(
sizeof(std::uint8_t) ==
sizeof(CharType),
"size of CharType must be equal to std::uint8_t");
16758 static_assert(std::is_trivial<CharType>::value,
"CharType must be trivial");
16760 std::memcpy(&result, &x,
sizeof(x));
16764 template<
typename C = CharType,
16765 enable_if_t<std::is_unsigned<C>::value>* =
nullptr>
16766 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
16771 template <
typename InputCharType,
typename C = CharType,
16773 std::is_signed<C>::value &&
16774 std::is_signed<char>::value &&
16775 std::is_same<char, typename std::remove_cv<InputCharType>::type>::value
16777 static constexpr CharType to_char_type(InputCharType x)
noexcept
16784 const bool is_little_endian = little_endianness();
16787 output_adapter_t<CharType> oa =
nullptr;
16807#include <algorithm>
16817#include <type_traits>
16837#include <type_traits>
16868template<
typename Target,
typename Source>
16869Target reinterpret_bits(
const Source source)
16871 static_assert(
sizeof(Target) ==
sizeof(Source),
"size mismatch");
16874 std::memcpy(&target, &source,
sizeof(Source));
16880 static constexpr int kPrecision = 64;
16882 std::uint64_t f = 0;
16885 constexpr diyfp(std::uint64_t f_,
int e_) noexcept : f(f_), e(e_) {}
16891 static diyfp sub(
const diyfp& x,
const diyfp& y)
noexcept
16896 return {x.f - y.f, x.e};
16903 static diyfp mul(
const diyfp& x,
const diyfp& y)
noexcept
16905 static_assert(kPrecision == 64,
"internal error");
16930 const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
16931 const std::uint64_t u_hi = x.f >> 32u;
16932 const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
16933 const std::uint64_t v_hi = y.f >> 32u;
16935 const std::uint64_t p0 = u_lo * v_lo;
16936 const std::uint64_t p1 = u_lo * v_hi;
16937 const std::uint64_t p2 = u_hi * v_lo;
16938 const std::uint64_t p3 = u_hi * v_hi;
16940 const std::uint64_t p0_hi = p0 >> 32u;
16941 const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
16942 const std::uint64_t p1_hi = p1 >> 32u;
16943 const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
16944 const std::uint64_t p2_hi = p2 >> 32u;
16946 std::uint64_t Q = p0_hi + p1_lo + p2_lo;
16957 Q += std::uint64_t{1} << (64u - 32u - 1u);
16959 const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
16961 return {h, x.e + y.e + 64};
16968 static diyfp normalize(diyfp x)
noexcept
16972 while ((x.f >> 63u) == 0)
16985 static diyfp normalize_to(
const diyfp& x,
const int target_exponent)
noexcept
16987 const int delta = x.e - target_exponent;
16992 return {x.f << delta, target_exponent};
17009template<
typename FloatType>
17010boundaries compute_boundaries(FloatType value)
17022 static_assert(std::numeric_limits<FloatType>::is_iec559,
17023 "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
17025 constexpr int kPrecision = std::numeric_limits<FloatType>::digits;
17026 constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
17027 constexpr int kMinExp = 1 - kBias;
17028 constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
17030 using bits_type =
typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
17032 const auto bits =
static_cast<std::uint64_t
>(reinterpret_bits<bits_type>(value));
17033 const std::uint64_t E = bits >> (kPrecision - 1);
17034 const std::uint64_t F = bits & (kHiddenBit - 1);
17036 const bool is_denormal = E == 0;
17037 const diyfp v = is_denormal
17038 ? diyfp(F, kMinExp)
17039 : diyfp(F + kHiddenBit,
static_cast<int>(E) - kBias);
17062 const bool lower_boundary_is_closer = F == 0 && E > 1;
17063 const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1);
17064 const diyfp m_minus = lower_boundary_is_closer
17065 ? diyfp(4 * v.f - 1, v.e - 2)
17066 : diyfp(2 * v.f - 1, v.e - 1);
17069 const diyfp w_plus = diyfp::normalize(m_plus);
17072 const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
17074 return {diyfp::normalize(v), w_minus, w_plus};
17132constexpr int kAlpha = -60;
17133constexpr int kGamma = -32;
17149inline cached_power get_cached_power_for_binary_exponent(
int e)
17201 constexpr int kCachedPowersMinDecExp = -300;
17202 constexpr int kCachedPowersDecStep = 8;
17204 static constexpr std::array<cached_power, 79> kCachedPowers =
17207 { 0xAB70FE17C79AC6CA, -1060, -300 },
17208 { 0xFF77B1FCBEBCDC4F, -1034, -292 },
17209 { 0xBE5691EF416BD60C, -1007, -284 },
17210 { 0x8DD01FAD907FFC3C, -980, -276 },
17211 { 0xD3515C2831559A83, -954, -268 },
17212 { 0x9D71AC8FADA6C9B5, -927, -260 },
17213 { 0xEA9C227723EE8BCB, -901, -252 },
17214 { 0xAECC49914078536D, -874, -244 },
17215 { 0x823C12795DB6CE57, -847, -236 },
17216 { 0xC21094364DFB5637, -821, -228 },
17217 { 0x9096EA6F3848984F, -794, -220 },
17218 { 0xD77485CB25823AC7, -768, -212 },
17219 { 0xA086CFCD97BF97F4, -741, -204 },
17220 { 0xEF340A98172AACE5, -715, -196 },
17221 { 0xB23867FB2A35B28E, -688, -188 },
17222 { 0x84C8D4DFD2C63F3B, -661, -180 },
17223 { 0xC5DD44271AD3CDBA, -635, -172 },
17224 { 0x936B9FCEBB25C996, -608, -164 },
17225 { 0xDBAC6C247D62A584, -582, -156 },
17226 { 0xA3AB66580D5FDAF6, -555, -148 },
17227 { 0xF3E2F893DEC3F126, -529, -140 },
17228 { 0xB5B5ADA8AAFF80B8, -502, -132 },
17229 { 0x87625F056C7C4A8B, -475, -124 },
17230 { 0xC9BCFF6034C13053, -449, -116 },
17231 { 0x964E858C91BA2655, -422, -108 },
17232 { 0xDFF9772470297EBD, -396, -100 },
17233 { 0xA6DFBD9FB8E5B88F, -369, -92 },
17234 { 0xF8A95FCF88747D94, -343, -84 },
17235 { 0xB94470938FA89BCF, -316, -76 },
17236 { 0x8A08F0F8BF0F156B, -289, -68 },
17237 { 0xCDB02555653131B6, -263, -60 },
17238 { 0x993FE2C6D07B7FAC, -236, -52 },
17239 { 0xE45C10C42A2B3B06, -210, -44 },
17240 { 0xAA242499697392D3, -183, -36 },
17241 { 0xFD87B5F28300CA0E, -157, -28 },
17242 { 0xBCE5086492111AEB, -130, -20 },
17243 { 0x8CBCCC096F5088CC, -103, -12 },
17244 { 0xD1B71758E219652C, -77, -4 },
17245 { 0x9C40000000000000, -50, 4 },
17246 { 0xE8D4A51000000000, -24, 12 },
17247 { 0xAD78EBC5AC620000, 3, 20 },
17248 { 0x813F3978F8940984, 30, 28 },
17249 { 0xC097CE7BC90715B3, 56, 36 },
17250 { 0x8F7E32CE7BEA5C70, 83, 44 },
17251 { 0xD5D238A4ABE98068, 109, 52 },
17252 { 0x9F4F2726179A2245, 136, 60 },
17253 { 0xED63A231D4C4FB27, 162, 68 },
17254 { 0xB0DE65388CC8ADA8, 189, 76 },
17255 { 0x83C7088E1AAB65DB, 216, 84 },
17256 { 0xC45D1DF942711D9A, 242, 92 },
17257 { 0x924D692CA61BE758, 269, 100 },
17258 { 0xDA01EE641A708DEA, 295, 108 },
17259 { 0xA26DA3999AEF774A, 322, 116 },
17260 { 0xF209787BB47D6B85, 348, 124 },
17261 { 0xB454E4A179DD1877, 375, 132 },
17262 { 0x865B86925B9BC5C2, 402, 140 },
17263 { 0xC83553C5C8965D3D, 428, 148 },
17264 { 0x952AB45CFA97A0B3, 455, 156 },
17265 { 0xDE469FBD99A05FE3, 481, 164 },
17266 { 0xA59BC234DB398C25, 508, 172 },
17267 { 0xF6C69A72A3989F5C, 534, 180 },
17268 { 0xB7DCBF5354E9BECE, 561, 188 },
17269 { 0x88FCF317F22241E2, 588, 196 },
17270 { 0xCC20CE9BD35C78A5, 614, 204 },
17271 { 0x98165AF37B2153DF, 641, 212 },
17272 { 0xE2A0B5DC971F303A, 667, 220 },
17273 { 0xA8D9D1535CE3B396, 694, 228 },
17274 { 0xFB9B7CD9A4A7443C, 720, 236 },
17275 { 0xBB764C4CA7A44410, 747, 244 },
17276 { 0x8BAB8EEFB6409C1A, 774, 252 },
17277 { 0xD01FEF10A657842C, 800, 260 },
17278 { 0x9B10A4E5E9913129, 827, 268 },
17279 { 0xE7109BFBA19C0C9D, 853, 276 },
17280 { 0xAC2820D9623BF429, 880, 284 },
17281 { 0x80444B5E7AA7CF85, 907, 292 },
17282 { 0xBF21E44003ACDD2D, 933, 300 },
17283 { 0x8E679C2F5E44FF8F, 960, 308 },
17284 { 0xD433179D9C8CB841, 986, 316 },
17285 { 0x9E19DB92B4E31BA9, 1013, 324 },
17295 const int f = kAlpha - e - 1;
17296 const int k = (f * 78913) / (1 << 18) +
static_cast<int>(f > 0);
17298 const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
17300 JSON_ASSERT(
static_cast<std::size_t
>(index) < kCachedPowers.size());
17302 const cached_power cached = kCachedPowers[
static_cast<std::size_t
>(index)];
17313inline int find_largest_pow10(
const std::uint32_t n, std::uint32_t& pow10)
17316 if (n >= 1000000000)
17318 pow10 = 1000000000;
17322 if (n >= 100000000)
17367inline void grisu2_round(
char* buf,
int len, std::uint64_t dist, std::uint64_t delta,
17368 std::uint64_t rest, std::uint64_t ten_k)
17395 && delta - rest >= ten_k
17396 && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
17408inline void grisu2_digit_gen(
char* buffer,
int& length,
int& decimal_exponent,
17409 diyfp M_minus, diyfp w, diyfp M_plus)
17411 static_assert(kAlpha >= -60,
"internal error");
17412 static_assert(kGamma <= -32,
"internal error");
17429 std::uint64_t delta = diyfp::sub(M_plus, M_minus).f;
17430 std::uint64_t dist = diyfp::sub(M_plus, w ).f;
17439 const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
17441 auto p1 =
static_cast<std::uint32_t
>(M_plus.f >> -one.e);
17442 std::uint64_t p2 = M_plus.f & (one.f - 1);
17450 std::uint32_t pow10{};
17451 const int k = find_largest_pow10(p1, pow10);
17478 const std::uint32_t d = p1 / pow10;
17479 const std::uint32_t r = p1 % pow10;
17485 buffer[length++] =
static_cast<char>(
'0' + d);
17504 const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
17509 decimal_exponent += n;
17520 const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
17521 grisu2_round(buffer, length, dist, delta, rest, ten_n);
17582 JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
17584 const std::uint64_t d = p2 >> -one.e;
17585 const std::uint64_t r = p2 & (one.f - 1);
17592 buffer[length++] =
static_cast<char>(
'0' + d);
17617 decimal_exponent -= m;
17625 const std::uint64_t ten_m = one.f;
17626 grisu2_round(buffer, length, dist, delta, p2, ten_m);
17649inline void grisu2(
char* buf,
int& len,
int& decimal_exponent,
17650 diyfp m_minus, diyfp v, diyfp m_plus)
17664 const cached_power cached = get_cached_power_for_binary_exponent(m_plus.e);
17666 const diyfp c_minus_k(cached.f, cached.e);
17669 const diyfp w = diyfp::mul(v, c_minus_k);
17670 const diyfp w_minus = diyfp::mul(m_minus, c_minus_k);
17671 const diyfp w_plus = diyfp::mul(m_plus, c_minus_k);
17694 const diyfp M_minus(w_minus.f + 1, w_minus.e);
17695 const diyfp M_plus (w_plus.f - 1, w_plus.e );
17697 decimal_exponent = -cached.k;
17699 grisu2_digit_gen(buf, len, decimal_exponent, M_minus, w, M_plus);
17707template<
typename FloatType>
17709void grisu2(
char* buf,
int& len,
int& decimal_exponent, FloatType value)
17711 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
17712 "internal error: not enough precision");
17734 const boundaries w = compute_boundaries(
static_cast<double>(value));
17736 const boundaries w = compute_boundaries(value);
17739 grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
17749inline char* append_exponent(
char* buf,
int e)
17764 auto k =
static_cast<std::uint32_t
>(e);
17770 *buf++ =
static_cast<char>(
'0' + k);
17774 *buf++ =
static_cast<char>(
'0' + k / 10);
17776 *buf++ =
static_cast<char>(
'0' + k);
17780 *buf++ =
static_cast<char>(
'0' + k / 100);
17782 *buf++ =
static_cast<char>(
'0' + k / 10);
17784 *buf++ =
static_cast<char>(
'0' + k);
17801inline char* format_buffer(
char* buf,
int len,
int decimal_exponent,
17802 int min_exp,
int max_exp)
17808 const int n = len + decimal_exponent;
17814 if (k <= n && n <= max_exp)
17819 std::memset(buf + k,
'0',
static_cast<size_t>(n) -
static_cast<size_t>(k));
17823 return buf + (
static_cast<size_t>(n) + 2);
17826 if (0 < n && n <= max_exp)
17833 std::memmove(buf + (
static_cast<size_t>(n) + 1), buf + n,
static_cast<size_t>(k) -
static_cast<size_t>(n));
17835 return buf + (
static_cast<size_t>(k) + 1U);
17838 if (min_exp < n && n <= 0)
17843 std::memmove(buf + (2 +
static_cast<size_t>(-n)), buf,
static_cast<size_t>(k));
17846 std::memset(buf + 2,
'0',
static_cast<size_t>(-n));
17847 return buf + (2U +
static_cast<size_t>(-n) +
static_cast<size_t>(k));
17862 std::memmove(buf + 2, buf + 1,
static_cast<size_t>(k) - 1);
17864 buf += 1 +
static_cast<size_t>(k);
17868 return append_exponent(buf, n - 1);
17883template<
typename FloatType>
17886char* to_chars(
char* first, const
char* last, FloatType value)
17888 static_cast<void>(last);
17892 if (std::signbit(value))
17899#pragma GCC diagnostic push
17900#pragma GCC diagnostic ignored "-Wfloat-equal"
17911#pragma GCC diagnostic pop
17914 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
17921 int decimal_exponent = 0;
17922 dtoa_impl::grisu2(first, len, decimal_exponent, value);
17924 JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
17927 constexpr int kMinExp = -4;
17929 constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10;
17932 JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
17933 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
17935 return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);
17972template<
typename BasicJsonType>
17975 using string_t =
typename BasicJsonType::string_t;
17976 using number_float_t =
typename BasicJsonType::number_float_t;
17977 using number_integer_t =
typename BasicJsonType::number_integer_t;
17978 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
17979 using binary_char_t =
typename BasicJsonType::binary_t::value_type;
17980 static constexpr std::uint8_t UTF8_ACCEPT = 0;
17981 static constexpr std::uint8_t UTF8_REJECT = 1;
17992 ,
loc(
std::localeconv())
18030 const bool pretty_print,
18032 const unsigned int indent_step,
18033 const unsigned int current_indent = 0)
18035 switch (val.m_data.m_type)
18039 if (val.m_data.m_value.object->empty())
18041 o->write_characters(
"{}", 2);
18047 o->write_characters(
"{\n", 2);
18050 const auto new_indent = current_indent + indent_step;
18057 auto i = val.m_data.m_value.object->cbegin();
18058 for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)
18061 o->write_character(
'\"');
18063 o->write_characters(
"\": ", 3);
18065 o->write_characters(
",\n", 2);
18069 JSON_ASSERT(i != val.m_data.m_value.object->cend());
18070 JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
18072 o->write_character(
'\"');
18074 o->write_characters(
"\": ", 3);
18077 o->write_character(
'\n');
18078 o->write_characters(
indent_string.c_str(), current_indent);
18079 o->write_character(
'}');
18083 o->write_character(
'{');
18086 auto i = val.m_data.m_value.object->cbegin();
18087 for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)
18089 o->write_character(
'\"');
18091 o->write_characters(
"\":", 2);
18093 o->write_character(
',');
18097 JSON_ASSERT(i != val.m_data.m_value.object->cend());
18098 JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
18099 o->write_character(
'\"');
18101 o->write_characters(
"\":", 2);
18104 o->write_character(
'}');
18112 if (val.m_data.m_value.array->empty())
18114 o->write_characters(
"[]", 2);
18120 o->write_characters(
"[\n", 2);
18123 const auto new_indent = current_indent + indent_step;
18130 for (
auto i = val.m_data.m_value.array->cbegin();
18131 i != val.m_data.m_value.array->cend() - 1; ++i)
18135 o->write_characters(
",\n", 2);
18141 dump(val.m_data.m_value.array->back(),
true,
ensure_ascii, indent_step, new_indent);
18143 o->write_character(
'\n');
18144 o->write_characters(
indent_string.c_str(), current_indent);
18145 o->write_character(
']');
18149 o->write_character(
'[');
18152 for (
auto i = val.m_data.m_value.array->cbegin();
18153 i != val.m_data.m_value.array->cend() - 1; ++i)
18156 o->write_character(
',');
18161 dump(val.m_data.m_value.array->back(),
false,
ensure_ascii, indent_step, current_indent);
18163 o->write_character(
']');
18171 o->write_character(
'\"');
18172 dump_escaped(*val.m_data.m_value.string,
ensure_ascii);
18173 o->write_character(
'\"');
18181 o->write_characters(
"{\n", 2);
18184 const auto new_indent = current_indent + indent_step;
18192 o->write_characters(
"\"bytes\": [", 10);
18194 if (!val.m_data.m_value.binary->empty())
18196 for (
auto i = val.m_data.m_value.binary->cbegin();
18197 i != val.m_data.m_value.binary->cend() - 1; ++i)
18200 o->write_characters(
", ", 2);
18202 dump_integer(val.m_data.m_value.binary->back());
18205 o->write_characters(
"],\n", 3);
18208 o->write_characters(
"\"subtype\": ", 11);
18209 if (val.m_data.m_value.binary->has_subtype())
18211 dump_integer(val.m_data.m_value.binary->subtype());
18215 o->write_characters(
"null", 4);
18217 o->write_character(
'\n');
18218 o->write_characters(
indent_string.c_str(), current_indent);
18219 o->write_character(
'}');
18223 o->write_characters(
"{\"bytes\":[", 10);
18225 if (!val.m_data.m_value.binary->empty())
18227 for (
auto i = val.m_data.m_value.binary->cbegin();
18228 i != val.m_data.m_value.binary->cend() - 1; ++i)
18231 o->write_character(
',');
18233 dump_integer(val.m_data.m_value.binary->back());
18236 o->write_characters(
"],\"subtype\":", 12);
18237 if (val.m_data.m_value.binary->has_subtype())
18239 dump_integer(val.m_data.m_value.binary->subtype());
18240 o->write_character(
'}');
18244 o->write_characters(
"null}", 5);
18252 if (val.m_data.m_value.boolean)
18254 o->write_characters(
"true", 4);
18258 o->write_characters(
"false", 5);
18265 dump_integer(val.m_data.m_value.number_integer);
18271 dump_integer(val.m_data.m_value.number_unsigned);
18277 dump_float(val.m_data.m_value.number_float);
18283 o->write_characters(
"<discarded>", 11);
18289 o->write_characters(
"null", 4);
18315 std::uint32_t codepoint{};
18323 for (std::size_t i = 0; i < s.size(); ++i)
18325 const auto byte =
static_cast<std::uint8_t
>(s[i]);
18327 switch (decode(
state, codepoint,
byte))
18386 if ((codepoint <= 0x1F) || (
ensure_ascii && (codepoint >= 0x7F)))
18388 if (codepoint <= 0xFFFF)
18392 static_cast<std::uint16_t
>(codepoint)));
18398 static_cast<void>((std::snprintf)(
string_buffer.data() +
bytes, 13,
"\\u%04x\\u%04x",
18399 static_cast<std::uint16_t
>(0xD7C0u + (codepoint >> 10u)),
18400 static_cast<std::uint16_t
>(0xDC00u + (codepoint & 0x3FFu))));
18468 string_buffer[
bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xEF');
18469 string_buffer[
bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBF');
18470 string_buffer[
bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBD');
18488 state = UTF8_ACCEPT;
18544 o->write_characters(
"\\ufffd", 6);
18548 o->write_characters(
"\xEF\xBF\xBD", 3);
18568 inline unsigned int count_digits(number_unsigned_t x)
noexcept
18570 unsigned int n_digits = 1;
18579 return n_digits + 1;
18583 return n_digits + 2;
18587 return n_digits + 3;
18599 static std::string hex_bytes(std::uint8_t
byte)
18601 std::string result =
"FF";
18602 constexpr const char* nibble_to_hex =
"0123456789ABCDEF";
18603 result[0] = nibble_to_hex[
byte / 16];
18604 result[1] = nibble_to_hex[
byte % 16];
18609 template <typename NumberType, enable_if_t<std::is_signed<NumberType>::value,
int> = 0>
18610 bool is_negative_number(NumberType x)
18615 template < typename NumberType, enable_if_t <std::is_unsigned<NumberType>::value,
int > = 0 >
18616 bool is_negative_number(NumberType )
18631 std::is_integral<NumberType>::value ||
18632 std::is_same<NumberType, number_unsigned_t>::value ||
18633 std::is_same<NumberType, number_integer_t>::value ||
18634 std::is_same<NumberType, binary_char_t>::value,
18636 void dump_integer(NumberType x)
18638 static constexpr std::array<std::array<char, 2>, 100> digits_to_99
18641 {{
'0',
'0'}}, {{
'0',
'1'}}, {{
'0',
'2'}}, {{
'0',
'3'}}, {{
'0',
'4'}}, {{
'0',
'5'}}, {{
'0',
'6'}}, {{
'0',
'7'}}, {{
'0',
'8'}}, {{
'0',
'9'}},
18642 {{
'1',
'0'}}, {{
'1',
'1'}}, {{
'1',
'2'}}, {{
'1',
'3'}}, {{
'1',
'4'}}, {{
'1',
'5'}}, {{
'1',
'6'}}, {{
'1',
'7'}}, {{
'1',
'8'}}, {{
'1',
'9'}},
18643 {{
'2',
'0'}}, {{
'2',
'1'}}, {{
'2',
'2'}}, {{
'2',
'3'}}, {{
'2',
'4'}}, {{
'2',
'5'}}, {{
'2',
'6'}}, {{
'2',
'7'}}, {{
'2',
'8'}}, {{
'2',
'9'}},
18644 {{
'3',
'0'}}, {{
'3',
'1'}}, {{
'3',
'2'}}, {{
'3',
'3'}}, {{
'3',
'4'}}, {{
'3',
'5'}}, {{
'3',
'6'}}, {{
'3',
'7'}}, {{
'3',
'8'}}, {{
'3',
'9'}},
18645 {{
'4',
'0'}}, {{
'4',
'1'}}, {{
'4',
'2'}}, {{
'4',
'3'}}, {{
'4',
'4'}}, {{
'4',
'5'}}, {{
'4',
'6'}}, {{
'4',
'7'}}, {{
'4',
'8'}}, {{
'4',
'9'}},
18646 {{
'5',
'0'}}, {{
'5',
'1'}}, {{
'5',
'2'}}, {{
'5',
'3'}}, {{
'5',
'4'}}, {{
'5',
'5'}}, {{
'5',
'6'}}, {{
'5',
'7'}}, {{
'5',
'8'}}, {{
'5',
'9'}},
18647 {{
'6',
'0'}}, {{
'6',
'1'}}, {{
'6',
'2'}}, {{
'6',
'3'}}, {{
'6',
'4'}}, {{
'6',
'5'}}, {{
'6',
'6'}}, {{
'6',
'7'}}, {{
'6',
'8'}}, {{
'6',
'9'}},
18648 {{
'7',
'0'}}, {{
'7',
'1'}}, {{
'7',
'2'}}, {{
'7',
'3'}}, {{
'7',
'4'}}, {{
'7',
'5'}}, {{
'7',
'6'}}, {{
'7',
'7'}}, {{
'7',
'8'}}, {{
'7',
'9'}},
18649 {{
'8',
'0'}}, {{
'8',
'1'}}, {{
'8',
'2'}}, {{
'8',
'3'}}, {{
'8',
'4'}}, {{
'8',
'5'}}, {{
'8',
'6'}}, {{
'8',
'7'}}, {{
'8',
'8'}}, {{
'8',
'9'}},
18650 {{
'9',
'0'}}, {{
'9',
'1'}}, {{
'9',
'2'}}, {{
'9',
'3'}}, {{
'9',
'4'}}, {{
'9',
'5'}}, {{
'9',
'6'}}, {{
'9',
'7'}}, {{
'9',
'8'}}, {{
'9',
'9'}},
18657 o->write_character(
'0');
18664 number_unsigned_t abs_value;
18666 unsigned int n_chars{};
18668 if (is_negative_number(x))
18671 abs_value = remove_sign(
static_cast<number_integer_t
>(x));
18674 n_chars = 1 + count_digits(abs_value);
18678 abs_value =
static_cast<number_unsigned_t
>(x);
18679 n_chars = count_digits(abs_value);
18687 buffer_ptr += n_chars;
18691 while (abs_value >= 100)
18693 const auto digits_index =
static_cast<unsigned>((abs_value % 100));
18695 *(--buffer_ptr) = digits_to_99[digits_index][1];
18696 *(--buffer_ptr) = digits_to_99[digits_index][0];
18699 if (abs_value >= 10)
18701 const auto digits_index =
static_cast<unsigned>(abs_value);
18702 *(--buffer_ptr) = digits_to_99[digits_index][1];
18703 *(--buffer_ptr) = digits_to_99[digits_index][0];
18707 *(--buffer_ptr) =
static_cast<char>(
'0' + abs_value);
18721 void dump_float(number_float_t x)
18724 if (!std::isfinite(x))
18726 o->write_characters(
"null", 4);
18735 static constexpr bool is_ieee_single_or_double
18736 = (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 24 && std::numeric_limits<number_float_t>::max_exponent == 128) ||
18737 (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 53 && std::numeric_limits<number_float_t>::max_exponent == 1024);
18739 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
18742 void dump_float(number_float_t x, std::true_type )
18745 auto* end = ::nlohmann::detail::to_chars(begin, begin +
number_buffer.size(), x);
18747 o->write_characters(begin,
static_cast<size_t>(end - begin));
18750 void dump_float(number_float_t x, std::false_type )
18753 static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
18785 o->write_characters(
number_buffer.data(),
static_cast<std::size_t
>(len));
18788 const bool value_is_int_like =
18792 return c ==
'.' || c ==
'e';
18795 if (value_is_int_like)
18797 o->write_characters(
".0", 2);
18822 static std::uint8_t decode(std::uint8_t&
state, std::uint32_t& codep,
const std::uint8_t
byte)
noexcept
18824 static const std::array<std::uint8_t, 400> utf8d =
18827 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18828 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18829 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18830 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18831 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
18832 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
18833 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
18834 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3,
18835 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
18836 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1,
18837 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1,
18838 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1,
18839 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1,
18840 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
18845 const std::uint8_t type = utf8d[byte];
18847 codep = (
state != UTF8_ACCEPT)
18848 ? (
byte & 0x3fu) | (codep << 6u)
18849 : (0xFFu >> type) & (byte);
18851 const std::size_t index = 256u +
static_cast<size_t>(
state) * 16u +
static_cast<size_t>(type);
18853 state = utf8d[index];
18862 number_unsigned_t remove_sign(number_unsigned_t x)
18877 inline number_unsigned_t remove_sign(number_integer_t x)
noexcept
18879 JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)());
18880 return static_cast<number_unsigned_t
>(-(x + 1)) + 1;
18885 output_adapter_t<char> o =
nullptr;
18927#include <functional>
18928#include <initializer_list>
18931#include <stdexcept>
18932#include <type_traits>
18945template <
class Key,
class T,
class IgnoredLess = std::less<Key>,
18946 class Allocator = std::allocator<std::pair<const Key, T>>>
18951 using Container = std::vector<std::pair<const Key, T>, Allocator>;
18956#ifdef JSON_HAS_CPP_14
18966 template <
class It>
18969 ordered_map(std::initializer_list<value_type> init,
const Allocator& alloc = Allocator() )
18974 for (
auto it = this->begin(); it != this->end(); ++it)
18976 if (m_compare(it->first, key))
18978 return {it,
false};
18981 Container::emplace_back(key, std::forward<T>(t));
18982 return {std::prev(this->end()),
true};
18987 std::pair<iterator, bool>
emplace(KeyType && key, T && t)
18989 for (
auto it = this->begin(); it != this->end(); ++it)
18991 if (m_compare(it->first, key))
18993 return {it,
false};
18996 Container::emplace_back(std::forward<KeyType>(key), std::forward<T>(t));
18997 return {std::prev(this->end()),
true};
19002 return emplace(key, T{}).first->second;
19009 return emplace(std::forward<KeyType>(key), T{}).first->second;
19021 return at(std::forward<KeyType>(key));
19026 for (
auto it = this->begin(); it != this->end(); ++it)
19028 if (m_compare(it->first, key))
19034 JSON_THROW(std::out_of_range(
"key not found"));
19041 for (
auto it = this->begin(); it != this->end(); ++it)
19043 if (m_compare(it->first, key))
19049 JSON_THROW(std::out_of_range(
"key not found"));
19054 for (
auto it = this->begin(); it != this->end(); ++it)
19056 if (m_compare(it->first, key))
19062 JSON_THROW(std::out_of_range(
"key not found"));
19067 const T &
at(KeyType && key)
const
19069 for (
auto it = this->begin(); it != this->end(); ++it)
19071 if (m_compare(it->first, key))
19077 JSON_THROW(std::out_of_range(
"key not found"));
19082 for (
auto it = this->begin(); it != this->end(); ++it)
19084 if (m_compare(it->first, key))
19087 for (
auto next = it; ++next != this->end(); ++it)
19092 Container::pop_back();
19103 for (
auto it = this->begin(); it != this->end(); ++it)
19105 if (m_compare(it->first, key))
19108 for (
auto next = it; ++next != this->end(); ++it)
19113 Container::pop_back();
19122 return erase(pos, std::next(pos));
19132 const auto elements_affected = std::distance(first, last);
19133 const auto offset = std::distance(Container::begin(), first);
19155 for (
auto it = first; std::next(it, elements_affected) != Container::end(); ++it)
19158 new (&*it)
value_type{std::move(*std::next(it, elements_affected))};
19166 Container::resize(this->size() -
static_cast<size_type>(elements_affected));
19175 return Container::begin() + offset;
19180 for (
auto it = this->begin(); it != this->end(); ++it)
19182 if (m_compare(it->first, key))
19194 for (
auto it = this->begin(); it != this->end(); ++it)
19196 if (m_compare(it->first, key))
19206 for (
auto it = this->begin(); it != this->end(); ++it)
19208 if (m_compare(it->first, key))
19213 return Container::end();
19220 for (
auto it = this->begin(); it != this->end(); ++it)
19222 if (m_compare(it->first, key))
19227 return Container::end();
19232 for (
auto it = this->begin(); it != this->end(); ++it)
19234 if (m_compare(it->first, key))
19239 return Container::end();
19244 return emplace(value.first, std::move(value.second));
19249 for (
auto it = this->begin(); it != this->end(); ++it)
19251 if (m_compare(it->first, value.first))
19253 return {it,
false};
19256 Container::push_back(value);
19257 return {--this->end(),
true};
19260 template<
typename InputIt>
19261 using require_input_iter =
typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
19262 std::input_iterator_tag>::value>::type;
19264 template<
typename InputIt,
typename = require_input_iter<InputIt>>
19267 for (
auto it = first; it != last; ++it)
19280#if defined(JSON_HAS_CPP_17)
19282 #include <string_view>
19312 :
public ::nlohmann::detail::json_base_class<CustomBaseClass>
19318 friend class ::nlohmann::json_pointer;
19322 template<
typename BasicJsonType,
typename InputType>
19323 friend class ::nlohmann::detail::parser;
19324 friend ::nlohmann::detail::serializer<basic_json>;
19325 template<
typename BasicJsonType>
19326 friend class ::nlohmann::detail::iter_impl;
19327 template<
typename BasicJsonType,
typename CharType>
19328 friend class ::nlohmann::detail::binary_writer;
19329 template<
typename BasicJsonType,
typename InputType,
typename SAX>
19330 friend class ::nlohmann::detail::binary_reader;
19331 template<
typename BasicJsonType>
19332 friend class ::nlohmann::detail::json_sax_dom_parser;
19333 template<
typename BasicJsonType>
19334 friend class ::nlohmann::detail::json_sax_dom_callback_parser;
19335 friend class ::nlohmann::detail::exception;
19339 using json_base_class_t = ::nlohmann::detail::json_base_class<CustomBaseClass>;
19343 using lexer = ::nlohmann::detail::lexer_base<basic_json>;
19345 template<
typename InputAdapterType>
19346 static ::nlohmann::detail::parser<basic_json, InputAdapterType>
parser(
19347 InputAdapterType adapter,
19348 detail::parser_callback_t<basic_json>cb =
nullptr,
19349 const bool allow_exceptions =
true,
19350 const bool ignore_comments =
false
19353 return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
19354 std::move(cb), allow_exceptions, ignore_comments);
19358 using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
19359 template<
typename BasicJsonType>
19360 using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
19361 template<
typename BasicJsonType>
19362 using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>;
19363 template<
typename Iterator>
19364 using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>;
19365 template<
typename Base>
using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>;
19367 template<
typename CharType>
19368 using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>;
19370 template<
typename InputType>
19371 using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
19372 template<
typename CharType>
using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
19375 using serializer = ::nlohmann::detail::serializer<basic_json>;
19381 template<
typename T,
typename SFINAE>
19390 using input_format_t = detail::input_format_t;
19438 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
19440 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
19468 result[
"copyright"] =
"(C) 2013-2022 Niels Lohmann";
19469 result[
"name"] =
"JSON for Modern C++";
19470 result[
"url"] =
"https://github.com/nlohmann/json";
19471 result[
"version"][
"string"] =
19480 result[
"platform"] =
"win32";
19481#elif defined __linux__
19482 result[
"platform"] =
"linux";
19483#elif defined __APPLE__
19484 result[
"platform"] =
"apple";
19485#elif defined __unix__
19486 result[
"platform"] =
"unix";
19488 result[
"platform"] =
"unknown";
19491#if defined(__ICC) || defined(__INTEL_COMPILER)
19492 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
19493#elif defined(__clang__)
19494 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
19495#elif defined(__GNUC__) || defined(__GNUG__)
19496 result[
"compiler"] = {{
"family",
"gcc"}, {
"version",
detail::concat(
19497 std::to_string(__GNUC__),
'.',
19498 std::to_string(__GNUC_MINOR__),
'.',
19499 std::to_string(__GNUC_PATCHLEVEL__))
19502#elif defined(__HP_cc) || defined(__HP_aCC)
19503 result[
"compiler"] =
"hp"
19504#elif defined(__IBMCPP__)
19505 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
19506#elif defined(_MSC_VER)
19507 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
19508#elif defined(__PGI)
19509 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
19510#elif defined(__SUNPRO_CC)
19511 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
19513 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
19517#if defined(_MSVC_LANG)
19518 result[
"compiler"][
"c++"] = std::to_string(_MSVC_LANG);
19519#elif defined(__cplusplus)
19520 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
19522 result[
"compiler"][
"c++"] =
"unknown";
19541#if defined(JSON_HAS_CPP_14)
19554 AllocatorType<std::pair<
const StringType,
19559 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
19583 using binary_t = nlohmann::byte_container_with_subtype<BinaryType>;
19594 template<
typename T,
typename... Args>
19596 static T* create(Args&& ... args)
19598 AllocatorType<T> alloc;
19599 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
19601 auto deleter = [&](T * obj)
19603 AllocatorTraits::deallocate(alloc, obj, 1);
19605 std::unique_ptr<T,
decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
19606 AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
19608 return obj.release();
19661 json_value() =
default;
19663 json_value(
boolean_t v) noexcept : boolean(v) {}
19675 case value_t::object:
19677 object = create<object_t>();
19681 case value_t::array:
19683 array = create<array_t>();
19687 case value_t::string:
19689 string = create<string_t>(
"");
19693 case value_t::binary:
19695 binary = create<binary_t>();
19699 case value_t::boolean:
19701 boolean =
static_cast<boolean_t>(
false);
19705 case value_t::number_integer:
19711 case value_t::number_unsigned:
19717 case value_t::number_float:
19723 case value_t::null:
19729 case value_t::discarded:
19775 (t == value_t::object &&
object ==
nullptr) ||
19776 (t == value_t::array && array ==
nullptr) ||
19777 (t == value_t::string &&
string ==
nullptr) ||
19778 (t == value_t::binary && binary ==
nullptr)
19784 if (t == value_t::array || t == value_t::object)
19787 std::vector<basic_json> stack;
19790 if (t == value_t::array)
19792 stack.reserve(
array->size());
19793 std::move(
array->begin(),
array->end(), std::back_inserter(stack));
19798 for (
auto&& it : *
object)
19800 stack.push_back(std::move(it.second));
19804 while (!stack.empty())
19807 basic_json current_item(std::move(stack.back()));
19812 if (current_item.is_array())
19814 std::move(current_item.m_data.m_value.array->begin(), current_item.m_data.m_value.array->end(), std::back_inserter(stack));
19816 current_item.m_data.m_value.array->clear();
19818 else if (current_item.is_object())
19822 stack.push_back(std::move(it.second));
19825 current_item.m_data.m_value.object->clear();
19835 case value_t::object:
19837 AllocatorType<object_t> alloc;
19838 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
object);
19839 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
object, 1);
19843 case value_t::array:
19845 AllocatorType<array_t> alloc;
19846 std::allocator_traits<
decltype(alloc)>::destroy(alloc, array);
19847 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, array, 1);
19851 case value_t::string:
19853 AllocatorType<string_t> alloc;
19854 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
string);
19855 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
string, 1);
19859 case value_t::binary:
19861 AllocatorType<binary_t> alloc;
19862 std::allocator_traits<
decltype(alloc)>::destroy(alloc, binary);
19863 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, binary, 1);
19867 case value_t::null:
19868 case value_t::boolean:
19869 case value_t::number_integer:
19870 case value_t::number_unsigned:
19871 case value_t::number_float:
19872 case value_t::discarded:
19900 void assert_invariant(
bool check_parents =
true) const noexcept
19907#if JSON_DIAGNOSTICS
19913 return j.m_parent ==
this;
19918 static_cast<void>(check_parents);
19923#if JSON_DIAGNOSTICS
19926 case value_t::array:
19930 element.m_parent =
this;
19935 case value_t::object:
19939 element.second.m_parent =
this;
19944 case value_t::null:
19945 case value_t::string:
19946 case value_t::boolean:
19947 case value_t::number_integer:
19948 case value_t::number_unsigned:
19949 case value_t::number_float:
19950 case value_t::binary:
19951 case value_t::discarded:
19958 iterator set_parents(
iterator it,
typename iterator::difference_type count_set_parents)
19960#if JSON_DIAGNOSTICS
19961 for (
typename iterator::difference_type i = 0; i < count_set_parents; ++i)
19963 (it + i)->m_parent =
this;
19966 static_cast<void>(count_set_parents);
19971 reference set_parent(
reference j, std::size_t old_capacity =
static_cast<std::size_t
>(-1))
19973#if JSON_DIAGNOSTICS
19974 if (old_capacity !=
static_cast<std::size_t
>(-1))
19988#ifdef JSON_HEDLEY_MSVC_VERSION
19989#pragma warning(push )
19990#pragma warning(disable : 4127)
19997#ifdef JSON_HEDLEY_MSVC_VERSION
19998#pragma warning( pop )
20003 static_cast<void>(j);
20004 static_cast<void>(old_capacity);
20016 using parse_event_t = detail::parse_event_t;
20036 assert_invariant();
20044 assert_invariant();
20049 template <
typename CompatibleType,
20054 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
20055 std::forward<CompatibleType>(val))))
20057 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
20059 assert_invariant();
20064 template <
typename BasicJsonType,
20069 using other_boolean_t =
typename BasicJsonType::boolean_t;
20070 using other_number_float_t =
typename BasicJsonType::number_float_t;
20071 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
20072 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
20073 using other_string_t =
typename BasicJsonType::string_t;
20074 using other_object_t =
typename BasicJsonType::object_t;
20075 using other_array_t =
typename BasicJsonType::array_t;
20076 using other_binary_t =
typename BasicJsonType::binary_t;
20078 switch (val.type())
20080 case value_t::boolean:
20081 JSONSerializer<other_boolean_t>::to_json(*
this, val.template get<other_boolean_t>());
20083 case value_t::number_float:
20084 JSONSerializer<other_number_float_t>::to_json(*
this, val.template get<other_number_float_t>());
20086 case value_t::number_integer:
20087 JSONSerializer<other_number_integer_t>::to_json(*
this, val.template get<other_number_integer_t>());
20089 case value_t::number_unsigned:
20090 JSONSerializer<other_number_unsigned_t>::to_json(*
this, val.template get<other_number_unsigned_t>());
20092 case value_t::string:
20093 JSONSerializer<other_string_t>::to_json(*
this, val.template get_ref<const other_string_t&>());
20095 case value_t::object:
20096 JSONSerializer<other_object_t>::to_json(*
this, val.template get_ref<const other_object_t&>());
20098 case value_t::array:
20099 JSONSerializer<other_array_t>::to_json(*
this, val.template get_ref<const other_array_t&>());
20101 case value_t::binary:
20102 JSONSerializer<other_binary_t>::to_json(*
this, val.template get_ref<const other_binary_t&>());
20104 case value_t::null:
20107 case value_t::discarded:
20108 m_data.m_type = value_t::discarded;
20115 assert_invariant();
20121 bool type_deduction =
true,
20122 value_t manual_type = value_t::array)
20126 bool is_an_object = std::all_of(init.begin(), init.end(),
20129 return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string();
20133 if (!type_deduction)
20136 if (manual_type == value_t::array)
20138 is_an_object =
false;
20151 m_data.m_type = value_t::object;
20152 m_data.m_value = value_t::object;
20154 for (
auto& element_ref : init)
20158 std::move(*((*element.m_data.m_value.array)[0].m_data.m_value.string)),
20159 std::move((*element.m_data.m_value.array)[1]));
20165 m_data.m_type = value_t::array;
20166 m_data.m_value.array = create<array_t>(init.begin(), init.end());
20170 assert_invariant();
20179 res.m_data.m_type = value_t::binary;
20180 res.m_data.m_value = init;
20187 static basic_json binary(
const typename binary_t::container_type& init,
typename binary_t::subtype_type subtype)
20190 res.m_data.m_type = value_t::binary;
20191 res.m_data.m_value =
binary_t(init, subtype);
20201 res.m_data.m_type = value_t::binary;
20202 res.m_data.m_value = std::move(init);
20209 static basic_json binary(
typename binary_t::container_type&& init,
typename binary_t::subtype_type subtype)
20212 res.m_data.m_type = value_t::binary;
20213 res.m_data.m_value =
binary_t(std::move(init), subtype);
20222 return basic_json(init,
false, value_t::array);
20230 return basic_json(init,
false, value_t::object);
20239 assert_invariant();
20244 template <
class InputIT,
typename std::enable_if <
20245 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
20246 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int >
::type = 0 >
20259 m_data.m_type = first.m_object->m_data.m_type;
20264 case value_t::boolean:
20265 case value_t::number_float:
20266 case value_t::number_integer:
20267 case value_t::number_unsigned:
20268 case value_t::string:
20271 || !last.m_it.primitive_iterator.is_end()))
20278 case value_t::null:
20279 case value_t::object:
20280 case value_t::array:
20281 case value_t::binary:
20282 case value_t::discarded:
20289 case value_t::number_integer:
20291 m_data.m_value.number_integer = first.m_object->m_data.m_value.number_integer;
20295 case value_t::number_unsigned:
20297 m_data.m_value.number_unsigned = first.m_object->m_data.m_value.number_unsigned;
20301 case value_t::number_float:
20303 m_data.m_value.number_float = first.m_object->m_data.m_value.number_float;
20307 case value_t::boolean:
20309 m_data.m_value.boolean = first.m_object->m_data.m_value.boolean;
20313 case value_t::string:
20315 m_data.m_value = *first.m_object->m_data.m_value.string;
20319 case value_t::object:
20321 m_data.m_value.object = create<object_t>(first.m_it.object_iterator,
20322 last.m_it.object_iterator);
20326 case value_t::array:
20328 m_data.m_value.array = create<array_t>(first.m_it.array_iterator,
20329 last.m_it.array_iterator);
20333 case value_t::binary:
20335 m_data.m_value = *first.m_object->m_data.m_value.binary;
20339 case value_t::null:
20340 case value_t::discarded:
20346 assert_invariant();
20354 template<
typename JsonRef,
20356 std::is_same<typename JsonRef::value_type, basic_json>>
::value,
int> = 0 >
20362 : json_base_class_t(other)
20366 other.assert_invariant();
20370 case value_t::object:
20376 case value_t::array:
20382 case value_t::string:
20388 case value_t::boolean:
20394 case value_t::number_integer:
20400 case value_t::number_unsigned:
20402 m_data.m_value = other.
m_data.m_value.number_unsigned;
20406 case value_t::number_float:
20412 case value_t::binary:
20418 case value_t::null:
20419 case value_t::discarded:
20425 assert_invariant();
20431 : json_base_class_t(std::forward<json_base_class_t>(other)),
20432 m_data(std::move(other.m_data))
20435 other.assert_invariant(
false);
20438 other.m_data.m_type = value_t::null;
20439 other.m_data.m_value = {};
20442 assert_invariant();
20448 std::is_nothrow_move_constructible<value_t>::value&&
20449 std::is_nothrow_move_assignable<value_t>::value&&
20450 std::is_nothrow_move_constructible<json_value>::value&&
20451 std::is_nothrow_move_assignable<json_value>::value&&
20452 std::is_nothrow_move_assignable<json_base_class_t>::value
20456 other.assert_invariant();
20461 json_base_class_t::operator=(std::move(other));
20464 assert_invariant();
20472 assert_invariant(
false);
20489 const char indent_char =
' ',
20490 const bool ensure_ascii =
false,
20494 serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler);
20498 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
20502 s.dump(*
this,
false, ensure_ascii, 0);
20533 return m_data.m_type == value_t::null;
20540 return m_data.m_type == value_t::boolean;
20554 return m_data.m_type == value_t::number_integer ||
m_data.m_type == value_t::number_unsigned;
20561 return m_data.m_type == value_t::number_unsigned;
20568 return m_data.m_type == value_t::number_float;
20575 return m_data.m_type == value_t::object;
20582 return m_data.m_type == value_t::array;
20589 return m_data.m_type == value_t::string;
20596 return m_data.m_type == value_t::binary;
20603 return m_data.m_type == value_t::discarded;
20625 return m_data.m_value.boolean;
20650 constexpr const array_t* get_impl_ptr(
const array_t* )
const noexcept
20738 template<
typename ReferenceType,
typename ThisType>
20739 static ReferenceType get_ref_impl(ThisType& obj)
20742 auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
20759 template<
typename PointerType,
typename std::enable_if<
20760 std::is_pointer<PointerType>::value,
int>
::type = 0>
20761 auto get_ptr() noexcept -> decltype(
std::declval<basic_json_t&>().get_impl_ptr(
std::declval<PointerType>()))
20764 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
20769 template <
typename PointerType,
typename std::enable_if <
20770 std::is_pointer<PointerType>::value&&
20771 std::is_const<typename std::remove_pointer<PointerType>::type>
::value,
int >
::type = 0 >
20772 constexpr auto get_ptr() const noexcept -> decltype(
std::declval<const basic_json_t&>().get_impl_ptr(
std::declval<PointerType>()))
20775 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
20817 template <
typename ValueType,
20823 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
20825 auto ret = ValueType();
20826 JSONSerializer<ValueType>::from_json(*
this, ret);
20860 template <
typename ValueType,
20865 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
20867 return JSONSerializer<ValueType>::from_json(*
this);
20885 template <
typename BasicJsonType,
20908 template<
typename BasicJsonType,
20910 std::is_same<BasicJsonType, basic_json_t>::value,
20921 template<
typename PointerType,
20923 std::is_pointer<PointerType>::value,
20926 ->
decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>())
20929 return get_ptr<PointerType>();
20956 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>>
20957#if defined(JSON_HAS_CPP_14)
20961 noexcept(
std::declval<const basic_json_t&>().template get_impl<ValueType>(
detail::priority_tag<4> {})))
20967 static_assert(!std::is_reference<ValueTypeCV>::value,
20968 "get() cannot be used with reference types, you might want to use get_ref()");
20999 template<
typename PointerType,
typename std::enable_if<
21000 std::is_pointer<PointerType>::value,
int>
::type = 0>
21001 auto get() noexcept -> decltype(
std::declval<basic_json_t&>().template
get_ptr<PointerType>())
21004 return get_ptr<PointerType>();
21009 template <
typename ValueType,
21014 ValueType &
get_to(ValueType& v)
const noexcept(
noexcept(
21015 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
21017 JSONSerializer<ValueType>::from_json(*
this, v);
21023 template<
typename ValueType,
21034 typename T, std::size_t N,
21035 typename Array = T (&)[N],
21039 noexcept(
noexcept(JSONSerializer<Array>::from_json(
21040 std::declval<const basic_json_t&>(), v)))
21042 JSONSerializer<Array>::from_json(*
this, v);
21048 template<
typename ReferenceType,
typename std::enable_if<
21049 std::is_reference<ReferenceType>::value,
int>
::type = 0>
21053 return get_ref_impl<ReferenceType>(*
this);
21058 template <
typename ReferenceType,
typename std::enable_if <
21059 std::is_reference<ReferenceType>::value&&
21060 std::is_const<typename std::remove_reference<ReferenceType>::type>
::value,
int >
::type = 0 >
21064 return get_ref_impl<ReferenceType>(*
this);
21096 template <
typename ValueType,
typename std::enable_if <
21104#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
21107#if defined(JSON_HAS_CPP_17)
21115 return get<ValueType>();
21127 return *get_ptr<binary_t*>();
21139 return *get_ptr<const binary_t*>();
21162 return set_parent(
m_data.m_value.array->at(idx));
21209 auto it =
m_data.m_value.object->find(key);
21210 if (it ==
m_data.m_value.object->end())
21214 return set_parent(it->second);
21229 auto it =
m_data.m_value.object->find(std::forward<KeyType>(key));
21230 if (it ==
m_data.m_value.object->end())
21234 return set_parent(it->second);
21247 auto it =
m_data.m_value.object->find(key);
21248 if (it ==
m_data.m_value.object->end())
21267 auto it =
m_data.m_value.object->find(std::forward<KeyType>(key));
21268 if (it ==
m_data.m_value.object->end())
21282 m_data.m_type = value_t::array;
21284 assert_invariant();
21291 if (idx >=
m_data.m_value.array->size())
21293#if JSON_DIAGNOSTICS
21295 const auto old_size =
m_data.m_value.array->size();
21296 const auto old_capacity =
m_data.m_value.array->capacity();
21298 m_data.m_value.array->resize(idx + 1);
21300#if JSON_DIAGNOSTICS
21309 set_parents(
begin() +
static_cast<typename iterator::difference_type
>(old_size),
static_cast<typename iterator::difference_type
>(idx + 1 - old_size));
21312 assert_invariant();
21315 return m_data.m_value.array->operator[](idx);
21341 m_data.m_type = value_t::object;
21343 assert_invariant();
21349 auto result =
m_data.m_value.object->emplace(std::move(key),
nullptr);
21350 return set_parent(result.first->second);
21373 template<
typename T>
21376 return operator[](
typename object_t::key_type(key));
21379 template<
typename T>
21382 return operator[](
typename object_t::key_type(key));
21394 m_data.m_type = value_t::object;
21396 assert_invariant();
21402 auto result =
m_data.m_value.object->emplace(std::forward<KeyType>(key),
nullptr);
21403 return set_parent(result.first->second);
21418 auto it =
m_data.
m_value.object->find(std::forward<KeyType>(key));
21427 template<
typename KeyType>
21431 template<
typename ValueType>
21432 using value_return_type = std::conditional <
21434 string_t,
typename std::decay<ValueType>::type >;
21442 && !std::is_same<value_t, detail::uncvref_t<ValueType>>
::value,
int > = 0 >
21443 ValueType
value(
const typename object_t::key_type& key,
const ValueType& default_value)
const
21449 const auto it =
find(key);
21452 return it->template get<ValueType>();
21455 return default_value;
21463 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
21467 && !std::is_same<value_t, detail::uncvref_t<ValueType>>
::value,
int > = 0 >
21468 ReturnType
value(
const typename object_t::key_type& key, ValueType && default_value)
const
21474 const auto it =
find(key);
21477 return it->template get<ReturnType>();
21480 return std::forward<ValueType>(default_value);
21491 && is_comparable_with_object_key<KeyType>::value
21493 && !std::is_same<value_t, detail::uncvref_t<ValueType>>
::value,
int > = 0 >
21494 ValueType
value(KeyType && key,
const ValueType& default_value)
const
21500 const auto it =
find(std::forward<KeyType>(key));
21503 return it->template get<ValueType>();
21506 return default_value;
21514 template < class ValueType, class KeyType, class ReturnType = typename value_return_type<ValueType>::type,
21518 && is_comparable_with_object_key<KeyType>::value
21520 && !std::is_same<value_t, detail::uncvref_t<ValueType>>
::value,
int > = 0 >
21521 ReturnType
value(KeyType && key, ValueType && default_value)
const
21527 const auto it =
find(std::forward<KeyType>(key));
21530 return it->template get<ReturnType>();
21533 return std::forward<ValueType>(default_value);
21543 && !std::is_same<value_t, detail::uncvref_t<ValueType>>
::value,
int > = 0 >
21552 return ptr.get_checked(
this).template get<ValueType>();
21556 return default_value;
21565 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
21568 && !std::is_same<value_t, detail::uncvref_t<ValueType>>
::value,
int > = 0 >
21577 return ptr.get_checked(
this).template get<ReturnType>();
21581 return std::forward<ValueType>(default_value);
21591 && !std::is_same<value_t, detail::uncvref_t<ValueType>>
::value,
int > = 0 >
21593 ValueType
value(const ::nlohmann::
json_pointer<BasicJsonType>& ptr, const ValueType& default_value)
const
21595 return value(ptr.convert(), default_value);
21598 template < class ValueType, class BasicJsonType, class ReturnType = typename value_return_type<ValueType>::type,
21602 && !std::is_same<value_t, detail::uncvref_t<ValueType>>
::value,
int > = 0 >
21606 return value(ptr.convert(), std::forward<ValueType>(default_value));
21644 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21645 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
21654 IteratorType result =
end();
21658 case value_t::boolean:
21659 case value_t::number_float:
21660 case value_t::number_integer:
21661 case value_t::number_unsigned:
21662 case value_t::string:
21663 case value_t::binary:
21672 AllocatorType<string_t> alloc;
21673 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
m_data.m_value.string);
21674 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
m_data.m_value.string, 1);
21675 m_data.m_value.string =
nullptr;
21679 AllocatorType<binary_t> alloc;
21680 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
m_data.m_value.binary);
21681 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
m_data.m_value.binary, 1);
21682 m_data.m_value.binary =
nullptr;
21685 m_data.m_type = value_t::null;
21686 assert_invariant();
21690 case value_t::object:
21692 result.m_it.object_iterator =
m_data.m_value.object->erase(pos.m_it.object_iterator);
21696 case value_t::array:
21698 result.m_it.array_iterator =
m_data.m_value.array->erase(pos.m_it.array_iterator);
21702 case value_t::null:
21703 case value_t::discarded:
21714 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21715 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
21716 IteratorType
erase(IteratorType first, IteratorType last)
21724 IteratorType result =
end();
21728 case value_t::boolean:
21729 case value_t::number_float:
21730 case value_t::number_integer:
21731 case value_t::number_unsigned:
21732 case value_t::string:
21733 case value_t::binary:
21736 || !last.m_it.primitive_iterator.is_end()))
21743 AllocatorType<string_t> alloc;
21744 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
m_data.m_value.string);
21745 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
m_data.m_value.string, 1);
21746 m_data.m_value.string =
nullptr;
21750 AllocatorType<binary_t> alloc;
21751 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
m_data.m_value.binary);
21752 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
m_data.m_value.binary, 1);
21753 m_data.m_value.binary =
nullptr;
21756 m_data.m_type = value_t::null;
21757 assert_invariant();
21761 case value_t::object:
21763 result.m_it.object_iterator =
m_data.m_value.object->erase(first.m_it.object_iterator,
21764 last.m_it.object_iterator);
21768 case value_t::array:
21770 result.m_it.array_iterator =
m_data.m_value.array->erase(first.m_it.array_iterator,
21771 last.m_it.array_iterator);
21775 case value_t::null:
21776 case value_t::discarded:
21787 size_type erase_internal(KeyType && key)
21795 return m_data.m_value.object->erase(std::forward<KeyType>(key));
21800 size_type erase_internal(KeyType && key)
21808 const auto it =
m_data.m_value.object->find(std::forward<KeyType>(key));
21809 if (it !=
m_data.m_value.object->end())
21811 m_data.m_value.object->erase(it);
21825 return erase_internal(key);
21834 return erase_internal(std::forward<KeyType>(key));
21871 auto result =
end();
21875 result.m_it.object_iterator =
m_data.m_value.object->find(key);
21885 auto result =
cend();
21889 result.m_it.object_iterator =
m_data.m_value.object->find(key);
21901 auto result =
end();
21905 result.m_it.object_iterator =
m_data.m_value.object->find(std::forward<KeyType>(key));
21917 auto result =
cend();
21921 result.m_it.object_iterator =
m_data.m_value.object->find(std::forward<KeyType>(key));
21942 return is_object() ?
m_data.m_value.object->count(std::forward<KeyType>(key)) : 0;
21947 bool contains(
const typename object_t::key_type& key)
const
21958 return is_object() &&
m_data.m_value.object->find(std::forward<KeyType>(key)) !=
m_data.m_value.object->end();
21965 return ptr.contains(
this);
21968 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
21972 return ptr.contains(
this);
21990 result.set_begin();
22006 result.set_begin();
22086 return ref.items();
22097 return ref.items();
22104 return iteration_proxy<iterator>(*
this);
22109 iteration_proxy<const_iterator>
items() const noexcept
22111 return iteration_proxy<const_iterator>(*
this);
22130 case value_t::null:
22136 case value_t::array:
22139 return m_data.m_value.array->empty();
22142 case value_t::object:
22145 return m_data.m_value.object->empty();
22148 case value_t::string:
22149 case value_t::boolean:
22150 case value_t::number_integer:
22151 case value_t::number_unsigned:
22152 case value_t::number_float:
22153 case value_t::binary:
22154 case value_t::discarded:
22169 case value_t::null:
22175 case value_t::array:
22178 return m_data.m_value.array->size();
22181 case value_t::object:
22184 return m_data.m_value.object->size();
22187 case value_t::string:
22188 case value_t::boolean:
22189 case value_t::number_integer:
22190 case value_t::number_unsigned:
22191 case value_t::number_float:
22192 case value_t::binary:
22193 case value_t::discarded:
22208 case value_t::array:
22211 return m_data.m_value.array->max_size();
22214 case value_t::object:
22217 return m_data.m_value.object->max_size();
22220 case value_t::null:
22221 case value_t::string:
22222 case value_t::boolean:
22223 case value_t::number_integer:
22224 case value_t::number_unsigned:
22225 case value_t::number_float:
22226 case value_t::binary:
22227 case value_t::discarded:
22252 case value_t::number_integer:
22254 m_data.m_value.number_integer = 0;
22258 case value_t::number_unsigned:
22260 m_data.m_value.number_unsigned = 0;
22264 case value_t::number_float:
22266 m_data.m_value.number_float = 0.0;
22270 case value_t::boolean:
22272 m_data.m_value.boolean =
false;
22276 case value_t::string:
22278 m_data.m_value.string->clear();
22282 case value_t::binary:
22284 m_data.m_value.binary->clear();
22288 case value_t::array:
22290 m_data.m_value.array->clear();
22294 case value_t::object:
22296 m_data.m_value.object->clear();
22300 case value_t::null:
22301 case value_t::discarded:
22320 m_data.m_type = value_t::array;
22321 m_data.m_value = value_t::array;
22322 assert_invariant();
22326 const auto old_capacity =
m_data.m_value.array->capacity();
22327 m_data.m_value.array->push_back(std::move(val));
22328 set_parent(
m_data.m_value.array->back(), old_capacity);
22353 m_data.m_type = value_t::array;
22354 m_data.m_value = value_t::array;
22355 assert_invariant();
22359 const auto old_capacity =
m_data.m_value.array->capacity();
22360 m_data.m_value.array->push_back(val);
22361 set_parent(
m_data.m_value.array->back(), old_capacity);
22385 m_data.m_type = value_t::object;
22386 m_data.m_value = value_t::object;
22387 assert_invariant();
22391 auto res =
m_data.m_value.object->insert(val);
22392 set_parent(res.first->second);
22407 if (
is_object() && init.size() == 2 && (*init.begin())->is_string())
22409 basic_json&& key = init.begin()->moved_or_copied();
22410 push_back(
typename object_t::value_type(
22411 std::move(key.get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
22429 template<
class... Args>
22441 m_data.m_type = value_t::array;
22442 m_data.m_value = value_t::array;
22443 assert_invariant();
22447 const auto old_capacity =
m_data.m_value.array->capacity();
22448 m_data.m_value.array->emplace_back(std::forward<Args>(args)...);
22449 return set_parent(
m_data.m_value.array->back(), old_capacity);
22454 template<
class... Args>
22466 m_data.m_type = value_t::object;
22467 m_data.m_value = value_t::object;
22468 assert_invariant();
22472 auto res =
m_data.m_value.object->emplace(std::forward<Args>(args)...);
22473 set_parent(res.first->second);
22477 it.m_it.object_iterator = res.first;
22480 return {it, res.second};
22486 template<
typename... Args>
22492 auto insert_pos = std::distance(
m_data.m_value.array->begin(), pos.m_it.array_iterator);
22493 m_data.m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
22494 result.m_it.array_iterator =
m_data.m_value.array->begin() + insert_pos;
22528 return insert(pos, val);
22579 return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
22624 m_data.m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
22641 m_data.m_type = value_t::object;
22642 m_data.m_value.object = create<object_t>();
22643 assert_invariant();
22663 for (
auto it = first; it != last; ++it)
22665 if (merge_objects && it.value().is_object())
22667 auto it2 =
m_data.m_value.object->find(it.key());
22668 if (it2 !=
m_data.m_value.object->end())
22670 it2->second.update(it.value(),
true);
22674 m_data.m_value.object->operator[](it.key()) = it.value();
22675#if JSON_DIAGNOSTICS
22676 m_data.m_value.object->operator[](it.key()).m_parent =
this;
22684 std::is_nothrow_move_constructible<value_t>::value&&
22685 std::is_nothrow_move_assignable<value_t>::value&&
22686 std::is_nothrow_move_constructible<json_value>::value&&
22687 std::is_nothrow_move_assignable<json_value>::value
22694 other.set_parents();
22695 assert_invariant();
22701 std::is_nothrow_move_constructible<value_t>::value&&
22702 std::is_nothrow_move_assignable<value_t>::value&&
22703 std::is_nothrow_move_constructible<json_value>::value&&
22704 std::is_nothrow_move_assignable<json_value>::value
22776 void swap(
typename binary_t::container_type& other)
22801#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result) \
22802 const auto lhs_type = lhs.type(); \
22803 const auto rhs_type = rhs.type(); \
22805 if (lhs_type == rhs_type) \
22807 switch (lhs_type) \
22809 case value_t::array: \
22810 return (*lhs.m_data.m_value.array) op (*rhs.m_data.m_value.array); \
22812 case value_t::object: \
22813 return (*lhs.m_data.m_value.object) op (*rhs.m_data.m_value.object); \
22815 case value_t::null: \
22816 return (null_result); \
22818 case value_t::string: \
22819 return (*lhs.m_data.m_value.string) op (*rhs.m_data.m_value.string); \
22821 case value_t::boolean: \
22822 return (lhs.m_data.m_value.boolean) op (rhs.m_data.m_value.boolean); \
22824 case value_t::number_integer: \
22825 return (lhs.m_data.m_value.number_integer) op (rhs.m_data.m_value.number_integer); \
22827 case value_t::number_unsigned: \
22828 return (lhs.m_data.m_value.number_unsigned) op (rhs.m_data.m_value.number_unsigned); \
22830 case value_t::number_float: \
22831 return (lhs.m_data.m_value.number_float) op (rhs.m_data.m_value.number_float); \
22833 case value_t::binary: \
22834 return (*lhs.m_data.m_value.binary) op (*rhs.m_data.m_value.binary); \
22836 case value_t::discarded: \
22838 return (unordered_result); \
22841 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) \
22843 return static_cast<number_float_t>(lhs.m_data.m_value.number_integer) op rhs.m_data.m_value.number_float; \
22845 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) \
22847 return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_integer); \
22849 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) \
22851 return static_cast<number_float_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_float; \
22853 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) \
22855 return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_unsigned); \
22857 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) \
22859 return static_cast<number_integer_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_integer; \
22861 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) \
22863 return lhs.m_data.m_value.number_integer op static_cast<number_integer_t>(rhs.m_data.m_value.number_unsigned); \
22865 else if(compares_unordered(lhs, rhs))\
22867 return (unordered_result);\
22870 return (default_result);
22885#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
22896 return compares_unordered(*
this,
rhs,
inverse);
22900#if JSON_HAS_THREE_WAY_COMPARISON
22906#pragma GCC diagnostic push
22907#pragma GCC diagnostic ignored "-Wfloat-equal"
22912#pragma GCC diagnostic pop
22918 template<
typename ScalarType>
22919 requires std::is_scalar_v<ScalarType>
22929 if (compares_unordered(
rhs,
true))
22944 std::partial_ordering::equivalent,
22945 std::partial_ordering::unordered,
22946 lhs_type <=> rhs_type)
22951 template<
typename ScalarType>
22952 requires std::is_scalar_v<ScalarType>
22953 std::partial_ordering operator<=>(ScalarType
rhs)
const noexcept
22958#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
22967 if (compares_unordered(
rhs,
true))
22971 return !(
rhs < *
this);
22976 template<
typename ScalarType>
22977 requires std::is_scalar_v<ScalarType>
22978 bool operator<=(ScalarType
rhs)
const noexcept
22988 if (compares_unordered(
rhs,
true))
22992 return !(*
this <
rhs);
22997 template<
typename ScalarType>
22998 requires std::is_scalar_v<ScalarType>
22999 bool operator>=(ScalarType
rhs)
const noexcept
23010#pragma GCC diagnostic push
23011#pragma GCC diagnostic ignored "-Wfloat-equal"
23015#pragma GCC diagnostic pop
23021 template<
typename ScalarType,
typename std::enable_if<
23022 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23030 template<
typename ScalarType,
typename std::enable_if<
23031 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23041 if (compares_unordered(lhs,
rhs,
true))
23045 return !(lhs ==
rhs);
23050 template<
typename ScalarType,
typename std::enable_if<
23051 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23059 template<
typename ScalarType,
typename std::enable_if<
23060 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23078 template<
typename ScalarType,
typename std::enable_if<
23079 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23087 template<
typename ScalarType,
typename std::enable_if<
23088 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23098 if (compares_unordered(lhs,
rhs,
true))
23102 return !(
rhs < lhs);
23107 template<
typename ScalarType,
typename std::enable_if<
23108 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23116 template<
typename ScalarType,
typename std::enable_if<
23117 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23128 if (compares_unordered(lhs,
rhs))
23132 return !(lhs <=
rhs);
23137 template<
typename ScalarType,
typename std::enable_if<
23138 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23146 template<
typename ScalarType,
typename std::enable_if<
23147 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23157 if (compares_unordered(lhs,
rhs,
true))
23161 return !(lhs <
rhs);
23166 template<
typename ScalarType,
typename std::enable_if<
23167 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23175 template<
typename ScalarType,
typename std::enable_if<
23176 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23183#undef JSON_IMPLEMENT_OPERATOR
23199 const bool pretty_print = o.width() > 0;
23200 const auto indentation = pretty_print ? o.width() : 0;
23206 serializer s(detail::output_adapter<char>(o), o.fill());
23207 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
23235 template<
typename InputType>
23239 const bool allow_exceptions =
true,
23240 const bool ignore_comments =
false)
23243 parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(
true, result);
23249 template<
typename IteratorType>
23254 const bool allow_exceptions =
true,
23255 const bool ignore_comments =
false)
23258 parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(
true, result);
23264 static basic_json parse(detail::span_input_adapter&& i,
23266 const bool allow_exceptions =
true,
23267 const bool ignore_comments =
false)
23270 parser(i.get(), cb, allow_exceptions, ignore_comments).parse(
true, result);
23276 template<
typename InputType>
23277 static bool accept(InputType&& i,
23278 const bool ignore_comments =
false)
23280 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false, ignore_comments).accept(
true);
23285 template<
typename IteratorType>
23286 static bool accept(IteratorType first, IteratorType last,
23287 const bool ignore_comments =
false)
23289 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false, ignore_comments).accept(
true);
23294 static bool accept(detail::span_input_adapter&& i,
23295 const bool ignore_comments =
false)
23297 return parser(i.get(),
nullptr,
false, ignore_comments).accept(
true);
23302 template <
typename InputType,
typename SAX>
23305 input_format_t format = input_format_t::
json,
23306 const
bool strict = true,
23307 const
bool ignore_comments = false)
23309 auto ia = detail::input_adapter(std::forward<InputType>(i));
23310 return format == input_format_t::json
23311 ?
parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23317 template<
class IteratorType,
class SAX>
23319 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
23320 input_format_t format = input_format_t::
json,
23321 const
bool strict = true,
23322 const
bool ignore_comments = false)
23324 auto ia = detail::input_adapter(std::move(first), std::move(last));
23325 return format == input_format_t::json
23326 ?
parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23335 template <
typename SAX>
23339 input_format_t format = input_format_t::
json,
23340 const
bool strict = true,
23341 const
bool ignore_comments = false)
23344 return format == input_format_t::json
23346 ?
parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23367 parser(detail::input_adapter(i)).parse(
false, j);
23384 case value_t::null:
23386 case value_t::object:
23388 case value_t::array:
23390 case value_t::string:
23392 case value_t::boolean:
23394 case value_t::binary:
23396 case value_t::discarded:
23397 return "discarded";
23398 case value_t::number_integer:
23399 case value_t::number_unsigned:
23400 case value_t::number_float:
23415 value_t m_type = value_t::null;
23428 m_value.array = create<array_t>(cnt, val);
23445#if JSON_DIAGNOSTICS
23462 std::vector<std::uint8_t> result;
23471 binary_writer<std::uint8_t>(o).write_cbor(j);
23478 binary_writer<char>(o).write_cbor(j);
23485 std::vector<std::uint8_t> result;
23494 binary_writer<std::uint8_t>(o).write_msgpack(j);
23501 binary_writer<char>(o).write_msgpack(j);
23507 const bool use_size =
false,
23508 const bool use_type =
false)
23510 std::vector<std::uint8_t> result;
23511 to_ubjson(j, result, use_size, use_type);
23518 const bool use_size =
false,
const bool use_type =
false)
23520 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);
23526 const bool use_size =
false,
const bool use_type =
false)
23528 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
23534 const bool use_size =
false,
23535 const bool use_type =
false)
23537 std::vector<std::uint8_t> result;
23538 to_bjdata(j, result, use_size, use_type);
23545 const bool use_size =
false,
const bool use_type =
false)
23547 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type,
true,
true);
23553 const bool use_size =
false,
const bool use_type =
false)
23555 binary_writer<char>(o).write_ubjson(j, use_size, use_type,
true,
true);
23562 std::vector<std::uint8_t> result;
23571 binary_writer<std::uint8_t>(o).write_bson(j);
23578 binary_writer<char>(o).write_bson(j);
23583 template<
typename InputType>
23586 const bool strict =
true,
23587 const bool allow_exceptions =
true,
23592 auto ia = detail::input_adapter(std::forward<InputType>(i));
23593 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
23594 return res ? result :
basic_json(value_t::discarded);
23599 template<
typename IteratorType>
23602 const bool strict =
true,
23603 const bool allow_exceptions =
true,
23608 auto ia = detail::input_adapter(std::move(first), std::move(last));
23609 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
23610 return res ? result :
basic_json(value_t::discarded);
23613 template<
typename T>
23617 const
bool strict = true,
23618 const
bool allow_exceptions = true,
23621 return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
23628 const
bool strict = true,
23629 const
bool allow_exceptions = true,
23636 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
23637 return res ? result :
basic_json(value_t::discarded);
23642 template<
typename InputType>
23645 const bool strict =
true,
23646 const bool allow_exceptions =
true)
23650 auto ia = detail::input_adapter(std::forward<InputType>(i));
23651 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
23652 return res ? result :
basic_json(value_t::discarded);
23657 template<
typename IteratorType>
23660 const bool strict =
true,
23661 const bool allow_exceptions =
true)
23665 auto ia = detail::input_adapter(std::move(first), std::move(last));
23666 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
23667 return res ? result :
basic_json(value_t::discarded);
23670 template<
typename T>
23674 const
bool strict = true,
23675 const
bool allow_exceptions = true)
23677 return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
23683 const
bool strict = true,
23684 const
bool allow_exceptions = true)
23690 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
23691 return res ? result :
basic_json(value_t::discarded);
23696 template<
typename InputType>
23699 const bool strict =
true,
23700 const bool allow_exceptions =
true)
23704 auto ia = detail::input_adapter(std::forward<InputType>(i));
23705 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
23706 return res ? result :
basic_json(value_t::discarded);
23711 template<
typename IteratorType>
23714 const bool strict =
true,
23715 const bool allow_exceptions =
true)
23719 auto ia = detail::input_adapter(std::move(first), std::move(last));
23720 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
23721 return res ? result :
basic_json(value_t::discarded);
23724 template<
typename T>
23728 const
bool strict = true,
23729 const
bool allow_exceptions = true)
23731 return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
23737 const
bool strict = true,
23738 const
bool allow_exceptions = true)
23744 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
23745 return res ? result :
basic_json(value_t::discarded);
23751 template<
typename InputType>
23754 const bool strict =
true,
23755 const bool allow_exceptions =
true)
23759 auto ia = detail::input_adapter(std::forward<InputType>(i));
23760 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
23761 return res ? result :
basic_json(value_t::discarded);
23766 template<
typename IteratorType>
23769 const bool strict =
true,
23770 const bool allow_exceptions =
true)
23774 auto ia = detail::input_adapter(std::move(first), std::move(last));
23775 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
23776 return res ? result :
basic_json(value_t::discarded);
23781 template<
typename InputType>
23784 const bool strict =
true,
23785 const bool allow_exceptions =
true)
23789 auto ia = detail::input_adapter(std::forward<InputType>(i));
23790 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
23791 return res ? result :
basic_json(value_t::discarded);
23796 template<
typename IteratorType>
23799 const bool strict =
true,
23800 const bool allow_exceptions =
true)
23804 auto ia = detail::input_adapter(std::move(first), std::move(last));
23805 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
23806 return res ? result :
basic_json(value_t::discarded);
23809 template<
typename T>
23813 const
bool strict = true,
23814 const
bool allow_exceptions = true)
23816 return from_bson(ptr, ptr + len, strict, allow_exceptions);
23822 const
bool strict = true,
23823 const
bool allow_exceptions = true)
23829 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
23830 return res ? result :
basic_json(value_t::discarded);
23845 return ptr.get_unchecked(
this);
23848 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
23852 return ptr.get_unchecked(
this);
23859 return ptr.get_unchecked(
this);
23862 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
23866 return ptr.get_unchecked(
this);
23873 return ptr.get_checked(
this);
23876 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
23880 return ptr.get_checked(
this);
23887 return ptr.get_checked(
this);
23890 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
23894 return ptr.get_checked(
this);
23902 json_pointer::flatten(
"", *
this, result);
23910 return json_pointer::unflatten(*
this);
23928 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
23930 const auto get_op = [](
const std::string & op)
23934 return patch_operations::add;
23936 if (op ==
"remove")
23938 return patch_operations::remove;
23940 if (op ==
"replace")
23942 return patch_operations::replace;
23946 return patch_operations::move;
23950 return patch_operations::copy;
23954 return patch_operations::test;
23957 return patch_operations::invalid;
23972 if (top_pointer != ptr)
23974 result.
at(top_pointer);
23978 const auto last_path = ptr.
back();
23983 switch (parent.
m_data.m_type)
23985 case value_t::null:
23986 case value_t::object:
23989 parent[last_path] = val;
23993 case value_t::array:
23995 if (last_path ==
"-")
24002 const auto idx = json_pointer::template array_index<basic_json_t>(last_path);
24016 case value_t::string:
24017 case value_t::boolean:
24018 case value_t::number_integer:
24019 case value_t::number_unsigned:
24020 case value_t::number_float:
24021 case value_t::binary:
24022 case value_t::discarded:
24029 const auto operation_remove = [
this, &result](
json_pointer & ptr)
24032 const auto last_path = ptr.
back();
24040 auto it = parent.
find(last_path);
24053 parent.
erase(json_pointer::template array_index<basic_json_t>(last_path));
24064 for (
const auto& val : json_patch)
24067 const auto get_value = [&val](
const std::string & op,
24068 const std::string & member,
24072 auto it = val.
m_data.m_value.object->find(member);
24075 const auto error_msg = (op ==
"op") ?
"operation" :
detail::concat(
"operation '", op,
'\'');
24102 const auto op = get_value(
"op",
"op",
true).template get<std::string>();
24103 const auto path = get_value(op,
"path",
true).template get<std::string>();
24106 switch (get_op(op))
24108 case patch_operations::add:
24110 operation_add(ptr, get_value(
"add",
"value",
false));
24114 case patch_operations::remove:
24116 operation_remove(ptr);
24120 case patch_operations::replace:
24123 result.
at(ptr) = get_value(
"replace",
"value",
false);
24127 case patch_operations::move:
24129 const auto from_path = get_value(
"move",
"from",
true).template get<std::string>();
24139 operation_remove(from_ptr);
24140 operation_add(ptr, v);
24144 case patch_operations::copy:
24146 const auto from_path = get_value(
"copy",
"from",
true).template get<std::string>();
24155 operation_add(ptr, v);
24159 case patch_operations::test:
24161 bool success =
false;
24166 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
24182 case patch_operations::invalid:
24206 const std::string& path =
"")
24212 if (source == target)
24217 if (source.
type() != target.
type())
24222 {
"op",
"replace"}, {
"path", path}, {
"value", target}
24227 switch (source.
type())
24229 case value_t::array:
24233 while (i < source.
size() && i < target.
size())
24236 auto temp_diff =
diff(source[i], target[i],
detail::concat(path,
'/', std::to_string(i)));
24237 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
24246 while (i < source.
size())
24259 while (i < target.
size())
24265 {
"value", target[i]}
24273 case value_t::object:
24276 for (
auto it = source.
cbegin(); it != source.
cend(); ++it)
24281 if (target.
find(it.key()) != target.
end())
24284 auto temp_diff =
diff(it.value(), target[it.key()], path_key);
24285 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
24292 {
"op",
"remove"}, {
"path", path_key}
24298 for (
auto it = target.
cbegin(); it != target.
cend(); ++it)
24300 if (source.
find(it.key()) == source.
end())
24306 {
"op",
"add"}, {
"path", path_key},
24307 {
"value", it.value()}
24315 case value_t::null:
24316 case value_t::string:
24317 case value_t::boolean:
24318 case value_t::number_integer:
24319 case value_t::number_unsigned:
24320 case value_t::number_float:
24321 case value_t::binary:
24322 case value_t::discarded:
24328 {
"op",
"replace"}, {
"path", path}, {
"value", target}
24355 for (
auto it = apply_patch.
begin(); it != apply_patch.
end(); ++it)
24357 if (it.value().is_null())
24369 *
this = apply_patch;
24386inline namespace json_literals
24392inline nlohmann::
json operator "" _json(const
char* s,
std::
size_t n)
24394 return nlohmann::json::parse(s, s + n);
24402 return nlohmann::json::json_pointer(std::string(s, n));
24421 std::size_t
operator()(
const nlohmann::NLOHMANN_BASIC_JSON_TPL& j)
const
24423 return nlohmann::detail::hash(j);
24429struct less< ::nlohmann::detail::value_t>
24436 ::nlohmann::detail::value_t rhs)
const noexcept
24438#if JSON_HAS_THREE_WAY_COMPARISON
24439 return std::is_lt(lhs <=> rhs);
24441 return ::nlohmann::detail::operator<(lhs, rhs);
24447#ifndef JSON_HAS_CPP_20
24452inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC_JSON_TPL& j2)
noexcept(
24453 is_nothrow_move_constructible<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value&&
24454 is_nothrow_move_assignable<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value)
24463#if JSON_USE_GLOBAL_UDLS
24464 using nlohmann::literals::json_literals::operator
"" _json;
24465 using nlohmann::literals::json_literals::operator
"" _json_pointer;
24480#if defined(__clang__)
24481 #pragma clang diagnostic pop
24486#undef JSON_INTERNAL_CATCH
24488#undef JSON_PRIVATE_UNLESS_TESTED
24489#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
24490#undef NLOHMANN_BASIC_JSON_TPL
24491#undef JSON_EXPLICIT
24492#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
24493#undef JSON_INLINE_VARIABLE
24494#undef JSON_NO_UNIQUE_ADDRESS
24495#undef JSON_DISABLE_ENUM_SERIALIZATION
24496#undef JSON_USE_GLOBAL_UDLS
24498#ifndef JSON_TEST_KEEP_MACROS
24501 #undef JSON_HAS_CPP_11
24502 #undef JSON_HAS_CPP_14
24503 #undef JSON_HAS_CPP_17
24504 #undef JSON_HAS_CPP_20
24505 #undef JSON_HAS_FILESYSTEM
24506 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
24507 #undef JSON_HAS_THREE_WAY_COMPARISON
24508 #undef JSON_HAS_RANGES
24509 #undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
24523#undef JSON_HEDLEY_ALWAYS_INLINE
24524#undef JSON_HEDLEY_ARM_VERSION
24525#undef JSON_HEDLEY_ARM_VERSION_CHECK
24526#undef JSON_HEDLEY_ARRAY_PARAM
24527#undef JSON_HEDLEY_ASSUME
24528#undef JSON_HEDLEY_BEGIN_C_DECLS
24529#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
24530#undef JSON_HEDLEY_CLANG_HAS_BUILTIN
24531#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
24532#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
24533#undef JSON_HEDLEY_CLANG_HAS_EXTENSION
24534#undef JSON_HEDLEY_CLANG_HAS_FEATURE
24535#undef JSON_HEDLEY_CLANG_HAS_WARNING
24536#undef JSON_HEDLEY_COMPCERT_VERSION
24537#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
24538#undef JSON_HEDLEY_CONCAT
24539#undef JSON_HEDLEY_CONCAT3
24540#undef JSON_HEDLEY_CONCAT3_EX
24541#undef JSON_HEDLEY_CONCAT_EX
24542#undef JSON_HEDLEY_CONST
24543#undef JSON_HEDLEY_CONSTEXPR
24544#undef JSON_HEDLEY_CONST_CAST
24545#undef JSON_HEDLEY_CPP_CAST
24546#undef JSON_HEDLEY_CRAY_VERSION
24547#undef JSON_HEDLEY_CRAY_VERSION_CHECK
24548#undef JSON_HEDLEY_C_DECL
24549#undef JSON_HEDLEY_DEPRECATED
24550#undef JSON_HEDLEY_DEPRECATED_FOR
24551#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
24552#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
24553#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
24554#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
24555#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
24556#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
24557#undef JSON_HEDLEY_DIAGNOSTIC_POP
24558#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
24559#undef JSON_HEDLEY_DMC_VERSION
24560#undef JSON_HEDLEY_DMC_VERSION_CHECK
24561#undef JSON_HEDLEY_EMPTY_BASES
24562#undef JSON_HEDLEY_EMSCRIPTEN_VERSION
24563#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
24564#undef JSON_HEDLEY_END_C_DECLS
24565#undef JSON_HEDLEY_FLAGS
24566#undef JSON_HEDLEY_FLAGS_CAST
24567#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
24568#undef JSON_HEDLEY_GCC_HAS_BUILTIN
24569#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
24570#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
24571#undef JSON_HEDLEY_GCC_HAS_EXTENSION
24572#undef JSON_HEDLEY_GCC_HAS_FEATURE
24573#undef JSON_HEDLEY_GCC_HAS_WARNING
24574#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
24575#undef JSON_HEDLEY_GCC_VERSION
24576#undef JSON_HEDLEY_GCC_VERSION_CHECK
24577#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
24578#undef JSON_HEDLEY_GNUC_HAS_BUILTIN
24579#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
24580#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
24581#undef JSON_HEDLEY_GNUC_HAS_EXTENSION
24582#undef JSON_HEDLEY_GNUC_HAS_FEATURE
24583#undef JSON_HEDLEY_GNUC_HAS_WARNING
24584#undef JSON_HEDLEY_GNUC_VERSION
24585#undef JSON_HEDLEY_GNUC_VERSION_CHECK
24586#undef JSON_HEDLEY_HAS_ATTRIBUTE
24587#undef JSON_HEDLEY_HAS_BUILTIN
24588#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
24589#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
24590#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
24591#undef JSON_HEDLEY_HAS_EXTENSION
24592#undef JSON_HEDLEY_HAS_FEATURE
24593#undef JSON_HEDLEY_HAS_WARNING
24594#undef JSON_HEDLEY_IAR_VERSION
24595#undef JSON_HEDLEY_IAR_VERSION_CHECK
24596#undef JSON_HEDLEY_IBM_VERSION
24597#undef JSON_HEDLEY_IBM_VERSION_CHECK
24598#undef JSON_HEDLEY_IMPORT
24599#undef JSON_HEDLEY_INLINE
24600#undef JSON_HEDLEY_INTEL_CL_VERSION
24601#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
24602#undef JSON_HEDLEY_INTEL_VERSION
24603#undef JSON_HEDLEY_INTEL_VERSION_CHECK
24604#undef JSON_HEDLEY_IS_CONSTANT
24605#undef JSON_HEDLEY_IS_CONSTEXPR_
24606#undef JSON_HEDLEY_LIKELY
24607#undef JSON_HEDLEY_MALLOC
24608#undef JSON_HEDLEY_MCST_LCC_VERSION
24609#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
24610#undef JSON_HEDLEY_MESSAGE
24611#undef JSON_HEDLEY_MSVC_VERSION
24612#undef JSON_HEDLEY_MSVC_VERSION_CHECK
24613#undef JSON_HEDLEY_NEVER_INLINE
24614#undef JSON_HEDLEY_NON_NULL
24615#undef JSON_HEDLEY_NO_ESCAPE
24616#undef JSON_HEDLEY_NO_RETURN
24617#undef JSON_HEDLEY_NO_THROW
24618#undef JSON_HEDLEY_NULL
24619#undef JSON_HEDLEY_PELLES_VERSION
24620#undef JSON_HEDLEY_PELLES_VERSION_CHECK
24621#undef JSON_HEDLEY_PGI_VERSION
24622#undef JSON_HEDLEY_PGI_VERSION_CHECK
24623#undef JSON_HEDLEY_PREDICT
24624#undef JSON_HEDLEY_PRINTF_FORMAT
24625#undef JSON_HEDLEY_PRIVATE
24626#undef JSON_HEDLEY_PUBLIC
24627#undef JSON_HEDLEY_PURE
24628#undef JSON_HEDLEY_REINTERPRET_CAST
24629#undef JSON_HEDLEY_REQUIRE
24630#undef JSON_HEDLEY_REQUIRE_CONSTEXPR
24631#undef JSON_HEDLEY_REQUIRE_MSG
24632#undef JSON_HEDLEY_RESTRICT
24633#undef JSON_HEDLEY_RETURNS_NON_NULL
24634#undef JSON_HEDLEY_SENTINEL
24635#undef JSON_HEDLEY_STATIC_ASSERT
24636#undef JSON_HEDLEY_STATIC_CAST
24637#undef JSON_HEDLEY_STRINGIFY
24638#undef JSON_HEDLEY_STRINGIFY_EX
24639#undef JSON_HEDLEY_SUNPRO_VERSION
24640#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
24641#undef JSON_HEDLEY_TINYC_VERSION
24642#undef JSON_HEDLEY_TINYC_VERSION_CHECK
24643#undef JSON_HEDLEY_TI_ARMCL_VERSION
24644#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
24645#undef JSON_HEDLEY_TI_CL2000_VERSION
24646#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
24647#undef JSON_HEDLEY_TI_CL430_VERSION
24648#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
24649#undef JSON_HEDLEY_TI_CL6X_VERSION
24650#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
24651#undef JSON_HEDLEY_TI_CL7X_VERSION
24652#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
24653#undef JSON_HEDLEY_TI_CLPRU_VERSION
24654#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
24655#undef JSON_HEDLEY_TI_VERSION
24656#undef JSON_HEDLEY_TI_VERSION_CHECK
24657#undef JSON_HEDLEY_UNAVAILABLE
24658#undef JSON_HEDLEY_UNLIKELY
24659#undef JSON_HEDLEY_UNPREDICTABLE
24660#undef JSON_HEDLEY_UNREACHABLE
24661#undef JSON_HEDLEY_UNREACHABLE_RETURN
24662#undef JSON_HEDLEY_VERSION
24663#undef JSON_HEDLEY_VERSION_DECODE_MAJOR
24664#undef JSON_HEDLEY_VERSION_DECODE_MINOR
24665#undef JSON_HEDLEY_VERSION_DECODE_REVISION
24666#undef JSON_HEDLEY_VERSION_ENCODE
24667#undef JSON_HEDLEY_WARNING
24668#undef JSON_HEDLEY_WARN_UNUSED_RESULT
24669#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
24670#undef JSON_HEDLEY_FALL_THROUGH
namespace for Niels Lohmann
constexpr bool is_string() const noexcept
return whether value is a string
size_type erase(const typename object_t::key_type &key)
remove element from a JSON object given a key
reference operator[](KeyType &&key)
access specified object element
size_type size() const noexcept
returns the number of elements
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
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
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 > {}))
get a (pointer) value (explicit)
const_iterator end() const noexcept
returns an iterator to one past the last element
reference back()
access the last element
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
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
basic_json patch(const basic_json &json_patch) const
applies a JSON patch to a copy of the current object
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string
const_reference front() const
access the first element
constexpr bool is_array() const noexcept
return whether value is an array
ReturnType value(const json_pointer &ptr, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
size_type count(KeyType &&key) const
returns the number of occurrences of a key in a JSON object
iter_impl< const basic_json > const_iterator
a const iterator for a basic_json container
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
std::initializer_list< detail::json_ref< basic_json > > initializer_list_t
helper type for initializer lists of basic_json values
constexpr bool is_number_integer() const noexcept
return whether value is an integer number
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
a const reverse iterator for a basic_json container
data(size_type cnt, const basic_json &val)
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_bson(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in BSON format
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
reference operator[](const json_pointer &ptr)
access specified element via JSON Pointer
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
the type of an element const pointer
void swap(reference other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
std::size_t size_type
a type to represent container sizes
constexpr bool is_structured() const noexcept
return whether type is structured
const_reference operator[](KeyType &&key) const
access specified object element
const value_type & const_reference
the type of an element const reference
void swap(binary_t &other)
exchanges the values
ReferenceType get_ref()
get a reference value (implicit)
size_type max_size() const noexcept
returns the maximum possible number of elements
void update(const_reference j, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
ReferenceType get_ref() const
get a reference value (implicit)
constexpr bool is_discarded() const noexcept
return whether value is discarded
JSON_PRIVATE_UNLESS_TESTED const_reference rhs
reference operator+=(initializer_list_t init)
add an object to an object
void push_back(basic_json &&val)
add an object to an array
const_reference operator[](const typename object_t::key_type &key) const
access specified object element
iteration_proxy< const_iterator > items() const noexcept
helper to access iterator member functions in range-based for
const_reference back() const
access the last element
IteratorType erase(IteratorType first, IteratorType last)
remove elements given an iterator range
reference operator+=(const basic_json &val)
add an object to an array
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_ubjson(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in UBJSON format
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)
iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
inserts copies of element into array
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_bson(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in BSON format
static allocator_type get_allocator()
returns the allocator associated with the container
nlohmann::byte_container_with_subtype< BinaryType > binary_t
a type for a packed binary type
reference at(KeyType &&key)
access specified object element with bounds checking
iterator end() noexcept
returns an iterator to one past the last element
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
void update(const_iterator first, const_iterator last, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
static std::vector< std::uint8_t > to_bson(const basic_json &j)
create a BSON serialization of a given JSON value
const_reverse_iterator rbegin() const noexcept
returns an iterator to the reverse-beginning
void push_back(initializer_list_t init)
add an object to an object
detail::parser_callback_t< basic_json > parser_callback_t
per-element parser callback type
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
ValueType & get_to(ValueType &v) const
static void to_msgpack(const basic_json &j, detail::output_adapter< char > o)
create a MessagePack serialization of a given JSON value
iterator begin() noexcept
returns an iterator to the first element
JSON_PRIVATE_UNLESS_TESTED const_reference bool inverse
ReturnType value(const typename object_t::key_type &key, ValueType &&default_value) const
access specified object element with default value
const_iterator cend() const noexcept
returns an iterator to one past the last element
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_bjdata(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in BJData format
const_reference at(const json_pointer &ptr) const
access specified element via JSON Pointer
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init)
explicitly create a binary array
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
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
basic_json flatten() const
return flattened JSON value
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_ubjson(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in UBJSON format
size_type erase(KeyType &&key)
remove element from a JSON object given a key
const binary_t & get_binary() const
get a binary value
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
inserts range of elements into array
void patch_inplace(const basic_json &json_patch)
applies a JSON patch in-place without copying the object
ReturnType value(KeyType &&key, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json diff(const basic_json &source, const basic_json &target, const std::string &path="")
creates a diff as a JSON patch
const_reference operator[](const json_pointer &ptr) const
access specified element via JSON Pointer
ArrayType< basic_json, AllocatorType< basic_json > > array_t
a type for an array
value_type & reference
the type of an element reference
bool contains(KeyType &&key) const
check the existence of an element in a JSON object
static void to_cbor(const basic_json &j, detail::output_adapter< std::uint8_t > o)
create a CBOR serialization of a given JSON value
static void to_bson(const basic_json &j, detail::output_adapter< char > o)
create a BSON serialization of a given JSON value
iterator find(const typename object_t::key_type &key)
find an element in a JSON object
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(const typename binary_t::container_type &init)
explicitly create a binary array (without subtype)
const_reference at(KeyType &&key) const
access specified object element with bounds checking
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json meta()
returns version information on the library
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
const_iterator find(const typename object_t::key_type &key) const
find an element in a JSON object
static std::vector< std::uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
IteratorType erase(IteratorType pos)
remove element given an iterator
iterator insert(const_iterator pos, const basic_json &val)
inserts element into array
NumberFloatType number_float_t
a type for a number (floating-point)
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
AllocatorType< basic_json > allocator_type
the allocator type
typename std::allocator_traits< allocator_type >::pointer pointer
the type of an element pointer
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
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
ValueType & get_to(ValueType &v) const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), v)))
get a value (explicit)
reference operator[](T *key)
reference at(size_type idx)
access specified array element with bounds checking
iterator find(KeyType &&key)
find an element in a JSON object
constexpr bool is_number_float() const noexcept
return whether value is a floating-point number
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
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
reference at(const json_pointer &ptr)
access specified element via JSON Pointer
BooleanType boolean_t
a type for a boolean
std::less< StringType > default_object_comparator_t
default object key comparator type The actual object key comparator type (object_comparator_t) may be...
reference operator+=(const typename object_t::value_type &val)
add an object to an object
const_iterator cbegin() const noexcept
returns a const iterator to the first element
reference operator[](typename object_t::key_type key)
access specified object element
constexpr auto get_ptr() const noexcept -> decltype(std::declval< const basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
~basic_json() noexcept
destructor
const_reverse_iterator crend() const noexcept
returns a const reverse iterator to one before the first
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
void swap(typename binary_t::container_type &other)
exchanges the values
binary_t & get_binary()
get a binary value
const_iterator begin() const noexcept
returns an iterator to the first element
constexpr bool is_number() const noexcept
return whether value is a number
void insert(const_iterator first, const_iterator last)
inserts range of elements into object
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_msgpack(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in MessagePack format
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
const_reference operator[](T *key) const
reference operator[](size_type idx)
access specified array element
basic_json(const JsonRef &ref)
JSONSerializer< T, SFINAE > json_serializer
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
static iteration_proxy< iterator > iterator_wrapper(reference ref) noexcept
wrapper to access iterator member functions in range-based for
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
Array get_to(T(&v)[N]) const noexcept(noexcept(JSONSerializer< Array >::from_json(std::declval< const basic_json_t & >(), v)))
NumberIntegerType number_integer_t
a type for a number (integer)
auto get_ptr() noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
const_reference at(const typename object_t::key_type &key) const
access specified object element with bounds checking
constexpr bool is_binary() const noexcept
return whether value is a binary array
void swap(object_t &other)
exchanges the values
basic_json unflatten() const
unflatten a previously flattened JSON value
iterator insert(const_iterator pos, initializer_list_t ilist)
inserts elements from initializer list into array
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)
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
bool empty() const noexcept
checks whether the container is empty.
void swap(array_t &other)
exchanges the values
void erase(const size_type idx)
remove element from a JSON array given an index
reference operator+=(basic_json &&val)
add an object to an array
bool contains(const json_pointer &ptr) const
check the existence of an element in a JSON object given a JSON pointer
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
reference emplace_back(Args &&... args)
add an object to an array
ValueType value(const json_pointer &ptr, const ValueType &default_value) const
access specified object element via JSON Pointer with default value
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
StringType string_t
a type for a string
friend class ::nlohmann::detail::parser
ObjectType< StringType, basic_json, default_object_comparator_t, AllocatorType< std::pair< const StringType, basic_json > > > object_t
a type for an object
void push_back(const basic_json &val)
add an object to an array
ValueType value(KeyType &&key, const ValueType &default_value) const
access specified object element with default value
reference at(const typename object_t::key_type &key)
access specified object element with bounds checking
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_bjdata(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in BJData format
json_value m_value
the value of the current element
const_reverse_iterator crbegin() const noexcept
returns a const reverse iterator to the last element
json_sax< basic_json > json_sax_t
SAX interface type, see nlohmann::json_sax.
constexpr bool is_boolean() const noexcept
return whether value is a boolean
size_type count(const typename object_t::key_type &key) const
returns the number of occurrences of a key in a JSON object
reference front()
access the first element
constexpr bool is_primitive() const noexcept
return whether type is primitive
constexpr bool is_null() const noexcept
return whether value is null
void clear() noexcept
clears the contents
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
JSON_PRIVATE_UNLESS_TESTED const_reference bool static SAX bool sax_parse(InputType &&i, SAX *sax, input_format_t format=input_format_t::json, const bool strict=true, const bool ignore_comments=false)
basic_json(basic_json &&other) noexcept
move constructor
iter_impl< basic_json > iterator
an iterator for a basic_json container
basic_json(const value_t v)
create an empty value with a given type
const_reference operator[](size_type idx) const
access specified array element
std::ptrdiff_t difference_type
a type to represent differences between iterators
iterator insert(const_iterator pos, basic_json &&val)
inserts element into array
const_reverse_iterator rend() const noexcept
returns an iterator to the reverse-end
NumberUnsignedType number_unsigned_t
a type for a number (unsigned)
friend std::istream & operator>>(std::istream &i, basic_json &j)
deserialize from stream
static std::vector< std::uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
void swap(string_t &other)
exchanges the values
basic_json(const BasicJsonType &val)
create a JSON value from an existing one
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
a reverse iterator for a basic_json container
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 &&std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
const_reference at(size_type idx) const
access specified array element with bounds checking
detail::actual_object_comparator_t< basic_json > object_comparator_t
object key comparator type
basic_json(const basic_json &other)
copy constructor
void push_back(const typename object_t::value_type &val)
add an object to an object
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
static void to_cbor(const basic_json &j, detail::output_adapter< char > o)
create a CBOR serialization of a given JSON value
constexpr bool is_object() const noexcept
return whether value is an object
static void to_msgpack(const basic_json &j, detail::output_adapter< std::uint8_t > o)
create a MessagePack serialization of a given JSON value
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_msgpack(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in MessagePack format
iterator insert_iterator(const_iterator pos, Args &&... args)
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
friend std::istream & operator<<(basic_json &j, std::istream &i)
deserialize from stream
bool contains(const typename object_t::key_type &key) const
check the existence of an element in a JSON object
static void to_bson(const basic_json &j, detail::output_adapter< std::uint8_t > o)
create a BSON serialization of a given JSON value
const_iterator find(KeyType &&key) const
find an element in a JSON object
::nlohmann::json_pointer< StringType > json_pointer
JSON Pointer, see nlohmann::json_pointer.
an internal type for a backed binary type
bool operator!=(const byte_container_with_subtype &rhs) const
byte_container_with_subtype() noexcept(noexcept(container_type()))
std::uint64_t subtype_type
bool operator==(const byte_container_with_subtype &rhs) const
BinaryType container_type
byte_container_with_subtype(container_type &&b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))
byte_container_with_subtype(container_type &&b) noexcept(noexcept(container_type(std::move(b))))
constexpr subtype_type subtype() const noexcept
return the binary subtype
byte_container_with_subtype(const container_type &b, subtype_type subtype_) noexcept(noexcept(container_type(b)))
constexpr bool has_subtype() const noexcept
return whether the value has a subtype
byte_container_with_subtype(const container_type &b) noexcept(noexcept(container_type(b)))
void set_subtype(subtype_type subtype_) noexcept
sets the binary subtype
void clear_subtype() noexcept
clears the binary subtype
deserialization of CBOR, MessagePack, and UBJSON values
binary_reader(const binary_reader &)=delete
binary_reader(binary_reader &&)=default
binary_reader(InputAdapterType &&adapter, const input_format_t format=input_format_t::json) noexcept
create a binary reader
binary_reader & operator=(const binary_reader &)=delete
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)
binary_reader & operator=(binary_reader &&)=default
general exception of the basic_json class
const int id
the id of the exception
static std::string diagnostics(std::nullptr_t)
static std::string name(const std::string &ename, int id_)
const char * what() const noexcept override
returns the explanatory string
static std::string diagnostics(const BasicJsonType *leaf_element)
exception indicating errors with iterators
static invalid_iterator create(int id_, const std::string &what_arg, BasicJsonContext context)
a template for a bidirectional iterator for the basic_json class This class implements a both iterato...
iter_impl operator+(difference_type i) const
add to iterator
iter_impl & operator=(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting assignment
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
iter_impl(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting constructor
bool operator<(const iter_impl &other) const
comparison: smaller
bool operator<=(const iter_impl &other) const
comparison: less than or equal
iter_impl & operator-=(difference_type i)
subtract from iterator
iter_impl & operator--()
pre-decrement (–it)
const object_t::key_type & key() const
return the key of an object iterator
bool operator==(const IterImpl &other) const
comparison: equal
iter_impl operator++(int) &
post-increment (it++)
iter_impl & operator+=(difference_type i)
add to iterator
reference operator[](difference_type n) const
access to successor
typename BasicJsonType::difference_type difference_type
a type to represent differences between iterators
pointer operator->() const
dereference the iterator
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
difference_type operator-(const iter_impl &other) const
return difference
iter_impl(iter_impl &&) noexcept=default
std::bidirectional_iterator_tag iterator_category
friend iter_impl operator+(difference_type i, const iter_impl &it)
addition of distance and iterator
reference value() const
return the value of an iterator
bool operator>(const iter_impl &other) const
comparison: greater than
typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_pointer, typename BasicJsonType::pointer >::type pointer
defines a pointer to the type iterated over (value_type)
iter_impl & operator++()
pre-increment (++it)
typename BasicJsonType::value_type value_type
the type of the values when the iterator is dereferenced
reference operator*() const
return a reference to the value pointed to by the iterator
iter_impl operator-(difference_type i) const
subtract from iterator
iter_impl & operator=(const iter_impl< const BasicJsonType > &other) noexcept
converting assignment
bool operator!=(const IterImpl &other) const
comparison: not equal
iter_impl operator--(int) &
post-decrement (it–)
typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_reference, typename BasicJsonType::reference >::type reference
defines a reference to the type iterated over (value_type)
iter_impl(const iter_impl< const BasicJsonType > &other) noexcept
const copy constructor
void set_end() noexcept
set the iterator past the last value
iteration_proxy_value operator++(int) &
iteration_proxy_value(iteration_proxy_value const &)=default
bool operator==(const iteration_proxy_value &o) const
equality operator (needed for InputIterator)
bool operator!=(const iteration_proxy_value &o) const
inequality operator (needed for range-based for)
std::ptrdiff_t difference_type
iteration_proxy_value(IteratorType it, std::size_t array_index_=0) noexcept(std::is_nothrow_move_constructible< IteratorType >::value &&std::is_nothrow_default_constructible< string_type >::value)
iteration_proxy_value & operator++()
increment operator (needed for range-based for)
iteration_proxy_value()=default
iteration_proxy_value(iteration_proxy_value &&) noexcept(std::is_nothrow_move_constructible< IteratorType >::value &&std::is_nothrow_move_constructible< string_type >::value)=default
IteratorType::reference value() const
return value of the iterator
const string_type & key() const
return key of the iterator
iteration_proxy_value & operator=(iteration_proxy_value const &)=default
std::input_iterator_tag iterator_category
typename std::remove_cv< typename std::remove_reference< decltype(std::declval< IteratorType >().key()) >::type >::type string_type
proxy class for the items() function
iteration_proxy_value< IteratorType > end() const noexcept
return iterator end (needed for range-based for)
iteration_proxy(iteration_proxy const &)=default
iteration_proxy()=default
iteration_proxy(iteration_proxy &&) noexcept=default
iteration_proxy_value< IteratorType > begin() const noexcept
return iterator begin (needed for range-based for)
iteration_proxy(typename IteratorType::reference cont) noexcept
construct iteration proxy from a container
iteration_proxy & operator=(iteration_proxy const &)=default
json_ref(json_ref &&) noexcept=default
json_ref(const value_type &value)
json_ref(value_type &&value)
value_type const & operator*() const
value_type const * operator->() const
json_ref(std::initializer_list< json_ref > init)
json_ref(Args &&... args)
value_type moved_or_copied() const
a template for a reverse iterator class
json_reverse_iterator operator++(int) &
post-increment (it++)
json_reverse_iterator operator--(int) &
post-decrement (it–)
json_reverse_iterator & operator++()
pre-increment (++it)
std::ptrdiff_t difference_type
json_reverse_iterator & operator+=(difference_type i)
add to iterator
reference operator[](difference_type n) const
access to successor
auto key() const -> decltype(std::declval< Base >().key())
return the key of an object iterator
difference_type operator-(const json_reverse_iterator &other) const
return difference
typename Base::reference reference
the reference type for the pointed-to element
reference value() const
return the value of an iterator
json_reverse_iterator(const base_iterator &it) noexcept
create reverse iterator from base class
json_reverse_iterator & operator--()
pre-decrement (–it)
std::reverse_iterator< Base > base_iterator
shortcut to the reverse iterator adapter
json_reverse_iterator operator-(difference_type i) const
subtract from iterator
json_reverse_iterator(const typename base_iterator::iterator_type &it) noexcept
create reverse iterator from iterator
json_reverse_iterator operator+(difference_type i) const
add to iterator
typename BasicJsonType::number_unsigned_t number_unsigned_t
bool start_object(std::size_t=static_cast< std::size_t >(-1))
bool number_integer(number_integer_t)
bool start_array(std::size_t=static_cast< std::size_t >(-1))
bool number_unsigned(number_unsigned_t)
typename BasicJsonType::binary_t binary_t
bool number_float(number_float_t, const string_t &)
bool parse_error(std::size_t, const std::string &, const detail::exception &)
typename BasicJsonType::number_integer_t number_integer_t
typename BasicJsonType::number_float_t number_float_t
typename BasicJsonType::string_t string_t
bool parse_error(std::size_t, const std::string &, const Exception &ex)
typename BasicJsonType::string_t string_t
bool number_float(number_float_t val, const string_t &)
constexpr bool is_errored() const
bool string(string_t &val)
json_sax_dom_callback_parser & operator=(const json_sax_dom_callback_parser &)=delete
json_sax_dom_callback_parser(const json_sax_dom_callback_parser &)=delete
typename BasicJsonType::number_unsigned_t number_unsigned_t
typename BasicJsonType::binary_t binary_t
bool start_object(std::size_t len)
bool start_array(std::size_t len)
typename BasicJsonType::number_integer_t number_integer_t
json_sax_dom_callback_parser(json_sax_dom_callback_parser &&)=default
~json_sax_dom_callback_parser()=default
typename BasicJsonType::parse_event_t parse_event_t
typename BasicJsonType::parser_callback_t parser_callback_t
bool number_unsigned(number_unsigned_t val)
json_sax_dom_callback_parser & operator=(json_sax_dom_callback_parser &&)=default
json_sax_dom_callback_parser(BasicJsonType &r, const parser_callback_t cb, const bool allow_exceptions_=true)
typename BasicJsonType::number_float_t number_float_t
bool number_integer(number_integer_t val)
bool binary(binary_t &val)
SAX implementation to create a JSON value from SAX events.
json_sax_dom_parser(const json_sax_dom_parser &)=delete
json_sax_dom_parser & operator=(json_sax_dom_parser &&)=default
bool string(string_t &val)
json_sax_dom_parser(BasicJsonType &r, const bool allow_exceptions_=true)
bool parse_error(std::size_t, const std::string &, const Exception &ex)
~json_sax_dom_parser()=default
typename BasicJsonType::string_t string_t
bool start_object(std::size_t len)
typename BasicJsonType::number_unsigned_t number_unsigned_t
bool number_unsigned(number_unsigned_t val)
bool number_integer(number_integer_t val)
typename BasicJsonType::number_integer_t number_integer_t
json_sax_dom_parser & operator=(const json_sax_dom_parser &)=delete
bool binary(binary_t &val)
json_sax_dom_parser(json_sax_dom_parser &&)=default
bool number_float(number_float_t val, const string_t &)
constexpr bool is_errored() const
typename BasicJsonType::binary_t binary_t
typename BasicJsonType::number_float_t number_float_t
bool start_array(std::size_t len)
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)
token_type
token types for the parser
bool skip_bom()
skip the UTF-8 byte order mark
lexer(InputAdapterType &&adapter, bool ignore_comments_=false) noexcept
JSON_HEDLEY_RETURNS_NON_NULL constexpr const char * get_error_message() const noexcept
return syntax error message
std::string get_token_string() const
constexpr number_integer_t get_number_integer() const noexcept
return integer value
constexpr position_t get_position() const noexcept
return position of last read token
constexpr number_unsigned_t get_number_unsigned() const noexcept
return unsigned integer value
typename lexer_base< BasicJsonType >::token_type token_type
lexer & operator=(lexer &&)=default
lexer(const lexer &)=delete
lexer & operator=(lexer &)=delete
string_t & get_string()
return current string value (implicitly resets the token; useful only once)
constexpr number_float_t get_number_float() const noexcept
return floating-point value
exception indicating other library errors
static other_error create(int id_, const std::string &what_arg, BasicJsonContext context)
exception indicating access out of the defined range
static out_of_range create(int id_, const std::string &what_arg, BasicJsonContext context)
exception indicating a parse error
static parse_error create(int id_, const position_t &pos, const std::string &what_arg, BasicJsonContext context)
create a parse error exception
static parse_error create(int id_, std::size_t byte_, const std::string &what_arg, BasicJsonContext context)
const std::size_t byte
byte index of the parse error
std::array< char, 512 > string_buffer
string buffer
std::size_t bytes_after_last_accept
serializer(output_adapter_t< char > s, const char ichar, error_handler_t error_handler_=error_handler_t::strict)
JSON_PRIVATE_UNLESS_TESTED const bool ensure_ascii
std::size_t undumped_chars
const char thousands_sep
the locale's thousand separator character
const char decimal_point
the locale's decimal point character
serializer & operator=(const serializer &)=delete
const error_handler_t error_handler
error_handler how to react on decoding errors
string_t indent_string
the indentation string
const std::lconv * loc
the locale
serializer & operator=(serializer &&)=delete
std::array< char, 64 > number_buffer
a (hopefully) large enough character buffer
const char indent_char
the indentation character
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
serializer(const serializer &)=delete
serializer(serializer &&)=delete
exception indicating executing a member function with a wrong type
static type_error create(int id_, const std::string &what_arg, BasicJsonContext context)
JSON Pointer defines a string syntax for identifying a specific value within a JSON document.
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
typename string_t_helper< RefStringType >::type string_t
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
json_pointer(const string_t &s="")
create JSON pointer
bool empty() const noexcept
return whether pointer points to the root document
friend bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
compares two JSON pointers for equality
void pop_back()
remove last reference token
string_t to_string() const
return a string representation of the JSON pointer
json_pointer & operator/=(std::size_t array_idx)
append an array index at the end of this JSON pointer
void push_back(string_t &&token)
append an unescaped token at the end of the reference pointer
json_pointer & operator/=(const json_pointer &ptr)
append another JSON pointer at the end of this JSON pointer
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
json_pointer parent_pointer() const
returns the parent of this JSON pointer
friend bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
compares two JSON pointers for inequality
json_pointer & operator/=(string_t token)
append an unescaped reference token at the end of this JSON pointer
friend class json_pointer
const string_t & back() const
return last reference token
friend std::ostream & operator<<(std::ostream &o, const json_pointer &ptr)
write string representation of the JSON pointer to stream
void push_back(const string_t &token)
append an unescaped token at the end of the reference pointer
friend bool operator<(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
compares two JSON pointer for less-than
decltype(get< N >(std::declval< ::nlohmann::detail::iteration_proxy_value< IteratorType > >())) type
#define NLOHMANN_BASIC_JSON_TPL_DECLARATION
#define JSON_HEDLEY_CONST
#define JSON_HEDLEY_DIAGNOSTIC_PUSH
#define JSON_INLINE_VARIABLE
#define JSON_HEDLEY_WARN_UNUSED_RESULT
#define JSON_PRIVATE_UNLESS_TESTED
#define NLOHMANN_JSON_VERSION_PATCH
#define JSON_HEDLEY_LIKELY(expr)
#define JSON_HEDLEY_NON_NULL(...)
#define JSON_INTERNAL_CATCH(exception)
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
#define JSON_HEDLEY_RETURNS_NON_NULL
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
#define JSON_CATCH(exception)
#define JSON_THROW(exception)
#define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
#define NLOHMANN_JSON_VERSION_MAJOR
#define NLOHMANN_BASIC_JSON_TPL
#define JSON_HEDLEY_UNLIKELY(expr)
#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_
#define NLOHMANN_JSON_NAMESPACE_END
#define JSON_NO_UNIQUE_ADDRESS
bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
basic_json< nlohmann::ordered_map > ordered_json
specialization that maintains the insertion order of object keys
#define NLOHMANN_JSON_VERSION_MINOR
#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name)
#define NLOHMANN_JSON_NAMESPACE_BEGIN
#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_
basic_json<> json
default specialization
#define JSON_HEDLEY_DIAGNOSTIC_POP
#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
bool operator<(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result)
constexpr bool is_transparent()
constexpr bool is_c_string()
detail namespace with internal helper functions
void to_json_tuple_impl(BasicJsonType &j, const Tuple &t, index_sequence< Idx... >)
std::is_same< Expected, detected_t< Op, Args... > > is_detected_exact
typename make_void< Ts... >::type void_t
decltype(std::declval< StringType & >()+=std::declval< Arg && >()) string_can_append_op
OutStringType concat(Args &&... args)
is_detected< string_can_append_iter, StringType, Arg > detect_string_can_append_iter
decltype(T::to_json(std::declval< Args >()...)) to_json_function
constexpr std::array< T, sizeof...(Args)> make_array(Args &&... args)
decltype(std::declval< T >().template get< U >()) get_template_function
typename std::conditional< is_usable_as_key_type< typename BasicJsonType::object_comparator_t, typename BasicJsonType::object_t::key_type, KeyTypeCVRef, RequireTransparentComparator, ExcludeObjectKeyType >::value &&!is_json_iterator_of< BasicJsonType, KeyType >::value, std::true_type, std::false_type >::type is_usable_as_basic_json_key_type
typename T::pointer pointer_t
is_detected< string_can_append_op, StringType, Arg > detect_string_can_append_op
integer_sequence< size_t, Ints... > index_sequence
typename utility_internal::Gen< T, N >::type make_integer_sequence
typename T::value_type value_type_t
std::is_convertible< detected_t< Op, Args... >, To > is_detected_convertible
T conditional_static_cast(U value)
is_detected< string_can_append_data, StringType, Arg > detect_string_can_append_data
typename std::enable_if< B, T >::type enable_if_t
is_specialization_of<::nlohmann::json_pointer, uncvref_t< T > > is_json_pointer
typename T::mapped_type mapped_type_t
void replace_substring(StringType &s, const StringType &f, const StringType &t)
replace all occurrences of a substring by another string
enable_if_t< is_range< R >::value, result_of_begin< decltype(std::declval< R & >())> > iterator_t
auto get(const nlohmann::detail::iteration_proxy_value< IteratorType > &i) -> decltype(i.key())
conjunction< std::is_integral< Types >... > all_integral
cbor_tag_handler_t
how to treat CBOR tags
@ store
store tags as binary type
@ error
throw a parse_error exception in case of a tag
typename detected_or< Default, Op, Args... >::type detected_or_t
decltype(T::from_json(std::declval< Args >()...)) from_json_function
conjunction< std::is_unsigned< Types >... > all_unsigned
make_integer_sequence< size_t, N > make_index_sequence
std::integral_constant< bool, Value > bool_constant
void concat_into(OutStringType &)
typename T::key_type key_type_t
constexpr bool value_in_range_of(T val)
value_t
the JSON type enumeration
@ number_integer
number value (signed integer)
@ discarded
discarded by the parser callback function
@ binary
binary array (ordered collection of bytes)
@ object
object (unordered set of name/value pairs)
@ number_float
number value (floating-point)
@ number_unsigned
number value (unsigned integer)
@ array
array (ordered collection of values)
std::integral_constant< bool, all_signed< Types... >::value||all_unsigned< Types... >::value > same_sign
typename detector< nonesuch, void, Op, Args... >::type detected_t
typename std::conditional< is_comparable< Comparator, ObjectKeyType, KeyTypeCVRef >::value &&!(ExcludeObjectKeyType &&std::is_same< KeyType, ObjectKeyType >::value) &&(!RequireTransparentComparator||is_detected< detect_is_transparent, Comparator >::value) &&!is_json_pointer< KeyType >::value, std::true_type, std::false_type >::type is_usable_as_key_type
is_c_string< uncvref_t< T > > is_c_string_uncvref
decltype(std::declval< StringType & >().append(std::declval< const Arg & >().begin(), std::declval< const Arg & >().end())) string_can_append_iter
typename T::iterator_category iterator_category_t
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
typename std::conditional< is_detected< detect_erase_with_key_type, typename BasicJsonType::object_t, KeyType >::value, std::true_type, std::false_type >::type has_erase_with_key_type
error_handler_t
how to treat decoding errors
@ strict
throw a type_error exception in case of invalid UTF-8
@ ignore
ignore invalid UTF-8 sequences
@ replace
replace invalid UTF-8 sequences with U+FFFD
std::size_t concat_length()
value_type_t< iterator_traits< iterator_t< T > > > range_value_t
conjunction< std::is_signed< Types >... > all_signed
typename actual_object_comparator< BasicJsonType >::type actual_object_comparator_t
decltype(std::declval< StringType & >().append(std::declval< Arg && >())) string_can_append
void to_json(BasicJsonType &j, T b) noexcept
make_index_sequence< sizeof...(Ts)> index_sequence_for
typename T::difference_type difference_type_t
typename std::remove_cv< typename std::remove_reference< T >::type >::type uncvref_t
typename T::is_transparent detect_is_transparent
typename std::conditional< std::is_same< T, void >::value, json_default_base, T >::type json_base_class
typename T::reference reference_t
decltype(std::declval< ObjectType & >().erase(std::declval< KeyType >())) detect_erase_with_key_type
typename T::key_compare detect_key_compare
decltype(std::declval< StringType & >().append(std::declval< const Arg & >().data(), std::declval< const Arg & >().size())) string_can_append_data
typename detector< nonesuch, void, Op, Args... >::value_t is_detected
StringType escape(StringType s)
string escaping as described in RFC 6901 (Sect. 4)
void int_to_string(string_type &target, std::size_t value)
std::integral_constant< bool,(std::is_signed< OfType >::value &&(sizeof(T)< sizeof(OfType)))||(same_sign< OfType, T >::value &&sizeof(OfType)==sizeof(T)) > never_out_of_range
is_detected< string_can_append, StringType, Arg > detect_string_can_append
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
namespace for Niels Lohmann
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
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
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
typename BasicJsonType::object_t object_t
typename BasicJsonType::default_object_comparator_t object_comparator_t
typename std::conditional< has_key_compare< object_t >::value, typename object_t::key_compare, object_comparator_t >::type type
static void construct(BasicJsonType &j, const std::vector< bool > &arr)
static void construct(BasicJsonType &j, typename BasicJsonType::array_t &&arr)
static void construct(BasicJsonType &j, const typename BasicJsonType::array_t &arr)
static void construct(BasicJsonType &j, const CompatibleArrayType &arr)
static void construct(BasicJsonType &j, const std::valarray< T > &arr)
static void construct(BasicJsonType &j, const typename BasicJsonType::binary_t &b)
static void construct(BasicJsonType &j, typename BasicJsonType::binary_t &&b)
static void construct(BasicJsonType &j, typename BasicJsonType::boolean_t b) noexcept
static void construct(BasicJsonType &j, typename BasicJsonType::number_float_t val) noexcept
static void construct(BasicJsonType &j, typename BasicJsonType::number_integer_t val) noexcept
static void construct(BasicJsonType &j, typename BasicJsonType::number_unsigned_t val) noexcept
static void construct(BasicJsonType &j, const typename BasicJsonType::object_t &obj)
static void construct(BasicJsonType &j, const CompatibleObjectType &obj)
static void construct(BasicJsonType &j, typename BasicJsonType::object_t &&obj)
static void construct(BasicJsonType &j, typename BasicJsonType::string_t &&s)
static void construct(BasicJsonType &j, const CompatibleStringType &str)
static void construct(BasicJsonType &j, const typename BasicJsonType::string_t &s)
typename BasicJsonType::template json_serializer< T, void > serializer
typename BasicJsonType::template json_serializer< T, void > serializer
typename BasicJsonType::template json_serializer< T, void > serializer
static constexpr std::size_t size() noexcept
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
primitive_iterator_t primitive_iterator
generic iterator for all other types
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
std::numeric_limits< RealIntegerType > RealLimits
std::numeric_limits< CompatibleNumberIntegerType > CompatibleLimits
typename BasicJsonType::object_t object_t
static constexpr auto value
detail::is_constructible_array_type_impl< BasicJsonType, ConstructibleArrayType, enable_if_t< !std::is_same< ConstructibleArrayType, typename BasicJsonType::value_type >::value &&!is_compatible_string_type< BasicJsonType, ConstructibleArrayType >::value &&is_default_constructible< ConstructibleArrayType >::value &&(std::is_move_assignable< ConstructibleArrayType >::value||std::is_copy_assignable< ConstructibleArrayType >::value)&&is_detected< iterator_t, ConstructibleArrayType >::value &&is_iterator_traits< iterator_traits< detected_t< iterator_t, ConstructibleArrayType > > >::value &&is_detected< range_value_t, ConstructibleArrayType >::value &&!std::is_same< ConstructibleArrayType, detected_t< range_value_t, ConstructibleArrayType > >::value &&is_complete_type< detected_t< range_value_t, ConstructibleArrayType > >::value > >::value_type range_value_t< ConstructibleArrayType > value_type
typename BasicJsonType::object_t object_t
ConstructibleStringType laundered_type
static constexpr auto value
static constexpr bool value
static one test(decltype(&C::capacity))
static constexpr bool value
ptrdiff_t difference_type
std::random_access_iterator_tag iterator_category
typename It::iterator_category iterator_category
typename It::difference_type difference_type
typename It::value_type value_type
typename It::reference reference
typename It::pointer pointer
Default base class of the basic_json class.
nonesuch(nonesuch const &&)=delete
void operator=(nonesuch &&)=delete
void operator=(nonesuch const &)=delete
nonesuch(nonesuch const &)=delete
struct to capture the start position of the current token
std::size_t chars_read_current_line
the number of characters read in the current line
std::size_t lines_read
the number of lines read
std::size_t chars_read_total
the total number of characters read
static JSON_INLINE_VARIABLE constexpr T value
auto operator()(BasicJsonType &j, T &&val) const noexcept(noexcept(to_json(j, std::forward< T >(val)))) -> decltype(to_json(j, std::forward< T >(val)), void())
integer_sequence< T, Ints...,(Ints+SeqSize)... > type
integer_sequence< T, Ints...,(Ints+SeqSize)..., 2 *SeqSize > type
integer_sequence< T > type
typename Extend< typename Gen< T, N/2 >::type, N/2, N % 2 >::type type
static constexpr bool test(T val)
static constexpr bool test(T)
static constexpr bool test(T val)
static constexpr bool test(T val)
static constexpr bool test(T val)
static constexpr bool test(T val)
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
typename BasicJsonType::number_integer_t number_integer_t
typename BasicJsonType::string_t string_t
virtual bool end_array()=0
the end of an array was read
json_sax(const json_sax &)=default
virtual bool boolean(bool val)=0
a boolean value was read
virtual bool end_object()=0
the end of an object was read
typename BasicJsonType::number_float_t number_float_t
virtual bool null()=0
a null value was read
typename BasicJsonType::number_unsigned_t number_unsigned_t
json_sax(json_sax &&) noexcept=default
typename BasicJsonType::binary_t binary_t
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
std::vector< std::pair< const Key, T >, Allocator > Container
std::pair< iterator, bool > insert(value_type &&value)
typename Container::value_type value_type
std::equal_to< Key > key_compare
iterator erase(iterator pos)
ordered_map(const Allocator &alloc) noexcept(noexcept(Container(alloc)))
T & operator[](KeyType &&key)
typename Container::iterator iterator
const T & at(KeyType &&key) const
const T & operator[](KeyType &&key) const
iterator find(const key_type &key)
iterator erase(iterator first, iterator last)
const T & at(const key_type &key) const
const_iterator find(const key_type &key) const
T & operator[](const key_type &key)
size_type erase(KeyType &&key)
typename Container::size_type size_type
ordered_map() noexcept(noexcept(Container()))
void insert(InputIt first, InputIt last)
size_type count(const key_type &key) const
std::pair< iterator, bool > emplace(KeyType &&key, T &&t)
size_type erase(const key_type &key)
ordered_map(std::initializer_list< value_type > init, const Allocator &alloc=Allocator())
std::pair< iterator, bool > insert(const value_type &value)
size_type count(KeyType &&key) const
ordered_map(It first, It last, const Allocator &alloc=Allocator())
typename std::enable_if< std::is_convertible< typename std::iterator_traits< InputIt >::iterator_category, std::input_iterator_tag >::value >::type require_input_iter
const T & operator[](const key_type &key) const
iterator find(KeyType &&key)
T & at(const key_type &key)
typename Container::const_iterator const_iterator
std::pair< iterator, bool > emplace(const key_type &key, T &&t)
std::size_t operator()(const nlohmann::NLOHMANN_BASIC_JSON_TPL &j) const
bool operator()(::nlohmann::detail::value_t lhs, ::nlohmann::detail::value_t rhs) const noexcept
compare two value_t enum values