23#ifndef INCLUDE_NLOHMANN_JSON_HPP_
24#define INCLUDE_NLOHMANN_JSON_HPP_
29#include <initializer_list>
65#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
66 #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH)
67 #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0
68 #warning "Already included a different version of the library!"
73#define NLOHMANN_JSON_VERSION_MAJOR 3
74#define NLOHMANN_JSON_VERSION_MINOR 12
75#define NLOHMANN_JSON_VERSION_PATCH 0
77#ifndef JSON_DIAGNOSTICS
78 #define JSON_DIAGNOSTICS 0
81#ifndef JSON_DIAGNOSTIC_POSITIONS
82 #define JSON_DIAGNOSTIC_POSITIONS 0
85#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
86 #define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0
90 #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag
92 #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS
95#if JSON_DIAGNOSTIC_POSITIONS
96 #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS _dp
98 #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS
101#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
102 #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp
104 #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON
107#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION
108 #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0
112#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b, c) json_abi ## a ## b ## c
113#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b, c) \
114 NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b, c)
116#define NLOHMANN_JSON_ABI_TAGS \
117 NLOHMANN_JSON_ABI_TAGS_CONCAT( \
118 NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \
119 NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON, \
120 NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS)
123#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \
124 _v ## major ## _ ## minor ## _ ## patch
125#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \
126 NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch)
128#if NLOHMANN_JSON_NAMESPACE_NO_VERSION
129#define NLOHMANN_JSON_NAMESPACE_VERSION
131#define NLOHMANN_JSON_NAMESPACE_VERSION \
132 NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \
133 NLOHMANN_JSON_VERSION_MINOR, \
134 NLOHMANN_JSON_VERSION_PATCH)
138#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b
139#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \
140 NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b)
142#ifndef NLOHMANN_JSON_NAMESPACE
143#define NLOHMANN_JSON_NAMESPACE \
144 nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \
145 NLOHMANN_JSON_ABI_TAGS, \
146 NLOHMANN_JSON_NAMESPACE_VERSION)
149#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
150#define NLOHMANN_JSON_NAMESPACE_BEGIN \
153 inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \
154 NLOHMANN_JSON_ABI_TAGS, \
155 NLOHMANN_JSON_NAMESPACE_VERSION) \
159#ifndef NLOHMANN_JSON_NAMESPACE_END
160#define NLOHMANN_JSON_NAMESPACE_END \
178#include <forward_list>
183#include <type_traits>
184#include <unordered_map>
247#include <type_traits>
263NLOHMANN_JSON_NAMESPACE_BEGIN
271template<
typename ...Ts>
using void_t =
typename make_void<Ts...>::type;
274NLOHMANN_JSON_NAMESPACE_END
277NLOHMANN_JSON_NAMESPACE_BEGIN
288 void operator=(
nonesuch const&) =
delete;
289 void operator=(
nonesuch&&) =
delete;
292template<
class Default,
294 template<
class...>
class Op,
298 using value_t = std::false_type;
299 using type = Default;
302template<
class Default,
template<
class...>
class Op,
class... Args>
303struct detector<Default, void_t<Op<Args...>>, Op, Args...>
305 using value_t = std::true_type;
306 using type = Op<Args...>;
309template<
template<
class...>
class Op,
class... Args>
312template<
template<
class...>
class Op,
class... Args>
315template<
template<
class...>
class Op,
class... Args>
318template<
class Default,
template<
class...>
class Op,
class... Args>
321template<
class Default,
template<
class...>
class Op,
class... Args>
322using detected_or_t =
typename detected_or<Default, Op, Args...>::type;
324template<
class Expected,
template<
class...>
class Op,
class... Args>
325using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
327template<
class To,
template<
class...>
class Op,
class... Args>
328using is_detected_convertible =
329 std::is_convertible<detected_t<Op, Args...>, To>;
332NLOHMANN_JSON_NAMESPACE_END
350#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15)
351#if defined(JSON_HEDLEY_VERSION)
352 #undef JSON_HEDLEY_VERSION
354#define JSON_HEDLEY_VERSION 15
356#if defined(JSON_HEDLEY_STRINGIFY_EX)
357 #undef JSON_HEDLEY_STRINGIFY_EX
359#define JSON_HEDLEY_STRINGIFY_EX(x) #x
361#if defined(JSON_HEDLEY_STRINGIFY)
362 #undef JSON_HEDLEY_STRINGIFY
364#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
366#if defined(JSON_HEDLEY_CONCAT_EX)
367 #undef JSON_HEDLEY_CONCAT_EX
369#define JSON_HEDLEY_CONCAT_EX(a,b) a##b
371#if defined(JSON_HEDLEY_CONCAT)
372 #undef JSON_HEDLEY_CONCAT
374#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
376#if defined(JSON_HEDLEY_CONCAT3_EX)
377 #undef JSON_HEDLEY_CONCAT3_EX
379#define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c
381#if defined(JSON_HEDLEY_CONCAT3)
382 #undef JSON_HEDLEY_CONCAT3
384#define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c)
386#if defined(JSON_HEDLEY_VERSION_ENCODE)
387 #undef JSON_HEDLEY_VERSION_ENCODE
389#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
391#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
392 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
394#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
396#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
397 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
399#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
401#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
402 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
404#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
406#if defined(JSON_HEDLEY_GNUC_VERSION)
407 #undef JSON_HEDLEY_GNUC_VERSION
409#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
410 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
411#elif defined(__GNUC__)
412 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
415#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
416 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
418#if defined(JSON_HEDLEY_GNUC_VERSION)
419 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
421 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
424#if defined(JSON_HEDLEY_MSVC_VERSION)
425 #undef JSON_HEDLEY_MSVC_VERSION
427#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL)
428 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
429#elif defined(_MSC_FULL_VER) && !defined(__ICL)
430 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
431#elif defined(_MSC_VER) && !defined(__ICL)
432 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
435#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
436 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
438#if !defined(JSON_HEDLEY_MSVC_VERSION)
439 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
440#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
441 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
442#elif defined(_MSC_VER) && (_MSC_VER >= 1200)
443 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
445 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))
448#if defined(JSON_HEDLEY_INTEL_VERSION)
449 #undef JSON_HEDLEY_INTEL_VERSION
451#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL)
452 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
453#elif defined(__INTEL_COMPILER) && !defined(__ICL)
454 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
457#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
458 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
460#if defined(JSON_HEDLEY_INTEL_VERSION)
461 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
463 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
466#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
467 #undef JSON_HEDLEY_INTEL_CL_VERSION
469#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL)
470 #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0)
473#if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK)
474 #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
476#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
477 #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
479 #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0)
482#if defined(JSON_HEDLEY_PGI_VERSION)
483 #undef JSON_HEDLEY_PGI_VERSION
485#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
486 #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
489#if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
490 #undef JSON_HEDLEY_PGI_VERSION_CHECK
492#if defined(JSON_HEDLEY_PGI_VERSION)
493 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
495 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
498#if defined(JSON_HEDLEY_SUNPRO_VERSION)
499 #undef JSON_HEDLEY_SUNPRO_VERSION
501#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
502 #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)
503#elif defined(__SUNPRO_C)
504 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
505#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
506 #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)
507#elif defined(__SUNPRO_CC)
508 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
511#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
512 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
514#if defined(JSON_HEDLEY_SUNPRO_VERSION)
515 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
517 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
520#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
521 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
523#if defined(__EMSCRIPTEN__)
524 #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
527#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
528 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
530#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
531 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
533 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
536#if defined(JSON_HEDLEY_ARM_VERSION)
537 #undef JSON_HEDLEY_ARM_VERSION
539#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
540 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)
541#elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
542 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
545#if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
546 #undef JSON_HEDLEY_ARM_VERSION_CHECK
548#if defined(JSON_HEDLEY_ARM_VERSION)
549 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
551 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
554#if defined(JSON_HEDLEY_IBM_VERSION)
555 #undef JSON_HEDLEY_IBM_VERSION
557#if defined(__ibmxl__)
558 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
559#elif defined(__xlC__) && defined(__xlC_ver__)
560 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
561#elif defined(__xlC__)
562 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
565#if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
566 #undef JSON_HEDLEY_IBM_VERSION_CHECK
568#if defined(JSON_HEDLEY_IBM_VERSION)
569 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
571 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
574#if defined(JSON_HEDLEY_TI_VERSION)
575 #undef JSON_HEDLEY_TI_VERSION
578 defined(__TI_COMPILER_VERSION__) && \
580 defined(__TMS470__) || defined(__TI_ARM__) || \
581 defined(__MSP430__) || \
582 defined(__TMS320C2000__) \
584#if (__TI_COMPILER_VERSION__ >= 16000000)
585 #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
589#if defined(JSON_HEDLEY_TI_VERSION_CHECK)
590 #undef JSON_HEDLEY_TI_VERSION_CHECK
592#if defined(JSON_HEDLEY_TI_VERSION)
593 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
595 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
598#if defined(JSON_HEDLEY_TI_CL2000_VERSION)
599 #undef JSON_HEDLEY_TI_CL2000_VERSION
601#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
602 #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
605#if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK)
606 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
608#if defined(JSON_HEDLEY_TI_CL2000_VERSION)
609 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
611 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0)
614#if defined(JSON_HEDLEY_TI_CL430_VERSION)
615 #undef JSON_HEDLEY_TI_CL430_VERSION
617#if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__)
618 #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
621#if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK)
622 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
624#if defined(JSON_HEDLEY_TI_CL430_VERSION)
625 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
627 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0)
630#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
631 #undef JSON_HEDLEY_TI_ARMCL_VERSION
633#if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__))
634 #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
637#if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK)
638 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
640#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
641 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
643 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0)
646#if defined(JSON_HEDLEY_TI_CL6X_VERSION)
647 #undef JSON_HEDLEY_TI_CL6X_VERSION
649#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__)
650 #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
653#if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK)
654 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
656#if defined(JSON_HEDLEY_TI_CL6X_VERSION)
657 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
659 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0)
662#if defined(JSON_HEDLEY_TI_CL7X_VERSION)
663 #undef JSON_HEDLEY_TI_CL7X_VERSION
665#if defined(__TI_COMPILER_VERSION__) && defined(__C7000__)
666 #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
669#if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK)
670 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
672#if defined(JSON_HEDLEY_TI_CL7X_VERSION)
673 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
675 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0)
678#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
679 #undef JSON_HEDLEY_TI_CLPRU_VERSION
681#if defined(__TI_COMPILER_VERSION__) && defined(__PRU__)
682 #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
685#if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK)
686 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
688#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
689 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
691 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0)
694#if defined(JSON_HEDLEY_CRAY_VERSION)
695 #undef JSON_HEDLEY_CRAY_VERSION
698 #if defined(_RELEASE_PATCHLEVEL)
699 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
701 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
705#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
706 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
708#if defined(JSON_HEDLEY_CRAY_VERSION)
709 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
711 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
714#if defined(JSON_HEDLEY_IAR_VERSION)
715 #undef JSON_HEDLEY_IAR_VERSION
717#if defined(__IAR_SYSTEMS_ICC__)
719 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
721 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0)
725#if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
726 #undef JSON_HEDLEY_IAR_VERSION_CHECK
728#if defined(JSON_HEDLEY_IAR_VERSION)
729 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
731 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
734#if defined(JSON_HEDLEY_TINYC_VERSION)
735 #undef JSON_HEDLEY_TINYC_VERSION
737#if defined(__TINYC__)
738 #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
741#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
742 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
744#if defined(JSON_HEDLEY_TINYC_VERSION)
745 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
747 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
750#if defined(JSON_HEDLEY_DMC_VERSION)
751 #undef JSON_HEDLEY_DMC_VERSION
754 #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
757#if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
758 #undef JSON_HEDLEY_DMC_VERSION_CHECK
760#if defined(JSON_HEDLEY_DMC_VERSION)
761 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
763 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
766#if defined(JSON_HEDLEY_COMPCERT_VERSION)
767 #undef JSON_HEDLEY_COMPCERT_VERSION
769#if defined(__COMPCERT_VERSION__)
770 #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)
773#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
774 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
776#if defined(JSON_HEDLEY_COMPCERT_VERSION)
777 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
779 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
782#if defined(JSON_HEDLEY_PELLES_VERSION)
783 #undef JSON_HEDLEY_PELLES_VERSION
786 #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
789#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
790 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
792#if defined(JSON_HEDLEY_PELLES_VERSION)
793 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
795 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
798#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
799 #undef JSON_HEDLEY_MCST_LCC_VERSION
801#if defined(__LCC__) && defined(__LCC_MINOR__)
802 #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__)
805#if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK)
806 #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
808#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
809 #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
811 #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0)
814#if defined(JSON_HEDLEY_GCC_VERSION)
815 #undef JSON_HEDLEY_GCC_VERSION
818 defined(JSON_HEDLEY_GNUC_VERSION) && \
819 !defined(__clang__) && \
820 !defined(JSON_HEDLEY_INTEL_VERSION) && \
821 !defined(JSON_HEDLEY_PGI_VERSION) && \
822 !defined(JSON_HEDLEY_ARM_VERSION) && \
823 !defined(JSON_HEDLEY_CRAY_VERSION) && \
824 !defined(JSON_HEDLEY_TI_VERSION) && \
825 !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \
826 !defined(JSON_HEDLEY_TI_CL430_VERSION) && \
827 !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \
828 !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \
829 !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \
830 !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \
831 !defined(__COMPCERT__) && \
832 !defined(JSON_HEDLEY_MCST_LCC_VERSION)
833 #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
836#if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
837 #undef JSON_HEDLEY_GCC_VERSION_CHECK
839#if defined(JSON_HEDLEY_GCC_VERSION)
840 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
842 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
845#if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
846 #undef JSON_HEDLEY_HAS_ATTRIBUTE
849 defined(__has_attribute) && \
851 (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \
853# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
855# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
858#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
859 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
861#if defined(__has_attribute)
862 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
864 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
867#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
868 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
870#if defined(__has_attribute)
871 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
873 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
876#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
877 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
880 defined(__has_cpp_attribute) && \
881 defined(__cplusplus) && \
882 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0))
883 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
885 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
888#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
889 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
891#if !defined(__cplusplus) || !defined(__has_cpp_attribute)
892 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
894 !defined(JSON_HEDLEY_PGI_VERSION) && \
895 !defined(JSON_HEDLEY_IAR_VERSION) && \
896 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \
897 (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0))
898 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)
900 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
903#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
904 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
906#if defined(__has_cpp_attribute) && defined(__cplusplus)
907 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
909 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
912#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
913 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
915#if defined(__has_cpp_attribute) && defined(__cplusplus)
916 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
918 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
921#if defined(JSON_HEDLEY_HAS_BUILTIN)
922 #undef JSON_HEDLEY_HAS_BUILTIN
924#if defined(__has_builtin)
925 #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
927 #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
930#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
931 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
933#if defined(__has_builtin)
934 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
936 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
939#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
940 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
942#if defined(__has_builtin)
943 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
945 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
948#if defined(JSON_HEDLEY_HAS_FEATURE)
949 #undef JSON_HEDLEY_HAS_FEATURE
951#if defined(__has_feature)
952 #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
954 #define JSON_HEDLEY_HAS_FEATURE(feature) (0)
957#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
958 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
960#if defined(__has_feature)
961 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
963 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
966#if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
967 #undef JSON_HEDLEY_GCC_HAS_FEATURE
969#if defined(__has_feature)
970 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
972 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
975#if defined(JSON_HEDLEY_HAS_EXTENSION)
976 #undef JSON_HEDLEY_HAS_EXTENSION
978#if defined(__has_extension)
979 #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
981 #define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
984#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
985 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
987#if defined(__has_extension)
988 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
990 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
993#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
994 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
996#if defined(__has_extension)
997 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
999 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
1002#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
1003 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
1005#if defined(__has_declspec_attribute)
1006 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
1008 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
1011#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
1012 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
1014#if defined(__has_declspec_attribute)
1015 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
1017 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
1020#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
1021 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
1023#if defined(__has_declspec_attribute)
1024 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
1026 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
1029#if defined(JSON_HEDLEY_HAS_WARNING)
1030 #undef JSON_HEDLEY_HAS_WARNING
1032#if defined(__has_warning)
1033 #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
1035 #define JSON_HEDLEY_HAS_WARNING(warning) (0)
1038#if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
1039 #undef JSON_HEDLEY_GNUC_HAS_WARNING
1041#if defined(__has_warning)
1042 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
1044 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
1047#if defined(JSON_HEDLEY_GCC_HAS_WARNING)
1048 #undef JSON_HEDLEY_GCC_HAS_WARNING
1050#if defined(__has_warning)
1051 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
1053 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
1057 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1058 defined(__clang__) || \
1059 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1060 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1061 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1062 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
1063 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1064 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1065 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1066 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1067 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1068 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \
1069 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1070 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1071 JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
1072 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
1073 JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
1074 (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
1075 #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
1076#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1077 #define JSON_HEDLEY_PRAGMA(value) __pragma(value)
1079 #define JSON_HEDLEY_PRAGMA(value)
1082#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
1083 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
1085#if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
1086 #undef JSON_HEDLEY_DIAGNOSTIC_POP
1088#if defined(__clang__)
1089 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
1090 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
1091#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1092 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
1093 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
1094#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1095 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
1096 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
1098 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
1099 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1100 #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
1101 #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
1102#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
1103 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
1104 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
1106 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1107 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1108 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \
1109 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1110 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1111 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1112 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
1113 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
1114#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
1115 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
1116 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
1118 #define JSON_HEDLEY_DIAGNOSTIC_PUSH
1119 #define JSON_HEDLEY_DIAGNOSTIC_POP
1124#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
1125 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
1127#if defined(__cplusplus)
1128# if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
1129# if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions")
1130# if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions")
1131# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1132 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1133 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1134 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
1135 _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \
1137 JSON_HEDLEY_DIAGNOSTIC_POP
1139# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1140 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1141 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1142 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
1144 JSON_HEDLEY_DIAGNOSTIC_POP
1147# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1148 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1149 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1151 JSON_HEDLEY_DIAGNOSTIC_POP
1155#if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
1156 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
1159#if defined(JSON_HEDLEY_CONST_CAST)
1160 #undef JSON_HEDLEY_CONST_CAST
1162#if defined(__cplusplus)
1163# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
1165 JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
1166 JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \
1167 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1168# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \
1169 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1170 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
1172 JSON_HEDLEY_DIAGNOSTIC_POP \
1175# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
1178#if defined(JSON_HEDLEY_REINTERPRET_CAST)
1179 #undef JSON_HEDLEY_REINTERPRET_CAST
1181#if defined(__cplusplus)
1182 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
1184 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr))
1187#if defined(JSON_HEDLEY_STATIC_CAST)
1188 #undef JSON_HEDLEY_STATIC_CAST
1190#if defined(__cplusplus)
1191 #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
1193 #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
1196#if defined(JSON_HEDLEY_CPP_CAST)
1197 #undef JSON_HEDLEY_CPP_CAST
1199#if defined(__cplusplus)
1200# if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
1201# define JSON_HEDLEY_CPP_CAST(T, expr) \
1202 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1203 _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \
1205 JSON_HEDLEY_DIAGNOSTIC_POP
1206# elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0)
1207# define JSON_HEDLEY_CPP_CAST(T, expr) \
1208 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1209 _Pragma("diag_suppress=Pe137") \
1210 JSON_HEDLEY_DIAGNOSTIC_POP
1212# define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr))
1215# define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
1218#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
1219 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1221#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
1222 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
1223#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1224 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
1225#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1226 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786))
1227#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1228 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445")
1229#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1230 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1231#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1232 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1233#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1234 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
1235#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1236 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1238 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1239 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1240 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1241 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1242 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1243 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1244 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1245 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1246 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1247 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1248 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1249 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
1250#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
1251 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
1252#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
1253 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
1254#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1255 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
1256#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
1257 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
1259 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1262#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
1263 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1265#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1266 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
1267#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1268 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
1269#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1270 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161))
1271#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1272 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
1273#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1274 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
1275#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1276 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))
1278 JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \
1279 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1280 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1281 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)
1282 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1283#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0)
1284 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1285#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1286 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
1287#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1288 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161")
1290 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1293#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
1294 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1296#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
1297 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"")
1298#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1299 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1300#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
1301 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
1302#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1303 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292))
1304#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
1305 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))
1306#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1307 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098")
1308#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1309 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1310#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
1311 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
1313 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1314 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1315 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0)
1316 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
1317#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1318 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097")
1319#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1320 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1322 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1325#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
1326 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1328#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
1329 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
1330#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1331 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
1332#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
1333 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
1335 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1338#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION)
1339 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1341#if JSON_HEDLEY_HAS_WARNING("-Wunused-function")
1342 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"")
1343#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0)
1344 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"")
1345#elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0)
1346 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505))
1347#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1348 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142")
1350 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1353#if defined(JSON_HEDLEY_DEPRECATED)
1354 #undef JSON_HEDLEY_DEPRECATED
1356#if defined(JSON_HEDLEY_DEPRECATED_FOR)
1357 #undef JSON_HEDLEY_DEPRECATED_FOR
1360 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1361 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1362 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
1363 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
1365 (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1366 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1367 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1368 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1369 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \
1370 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1371 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1372 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \
1373 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1374 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1375 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \
1376 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1377 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
1378 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
1379#elif defined(__cplusplus) && (__cplusplus >= 201402L)
1380 #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
1381 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
1383 JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
1384 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1385 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1386 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1387 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1388 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1389 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1390 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1391 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1392 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1393 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1394 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1395 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1396 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1397 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1398 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1399 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
1400 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
1402 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1403 JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \
1404 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1405 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
1406 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
1407#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1408 #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
1409 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
1411 #define JSON_HEDLEY_DEPRECATED(since)
1412 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
1415#if defined(JSON_HEDLEY_UNAVAILABLE)
1416 #undef JSON_HEDLEY_UNAVAILABLE
1419 JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
1420 JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
1421 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1422 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1423 #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
1425 #define JSON_HEDLEY_UNAVAILABLE(available_since)
1428#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT)
1429 #undef JSON_HEDLEY_WARN_UNUSED_RESULT
1431#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG)
1432 #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
1435 JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
1436 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1437 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1438 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1439 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1440 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1441 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1442 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1443 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1444 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1445 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1446 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1447 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1448 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1449 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1450 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1451 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1452 #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
1453 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__))
1454#elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)
1455 #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1456 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
1457#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
1458 #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1459 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1460#elif defined(_Check_return_)
1461 #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_
1462 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_
1464 #define JSON_HEDLEY_WARN_UNUSED_RESULT
1465 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg)
1468#if defined(JSON_HEDLEY_SENTINEL)
1469 #undef JSON_HEDLEY_SENTINEL
1472 JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
1473 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1474 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1475 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1476 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1477 #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
1479 #define JSON_HEDLEY_SENTINEL(position)
1482#if defined(JSON_HEDLEY_NO_RETURN)
1483 #undef JSON_HEDLEY_NO_RETURN
1485#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1486 #define JSON_HEDLEY_NO_RETURN __noreturn
1488 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1489 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1490 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1491#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
1492 #define JSON_HEDLEY_NO_RETURN _Noreturn
1493#elif defined(__cplusplus) && (__cplusplus >= 201103L)
1494 #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
1496 JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
1497 JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \
1498 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1499 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1500 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1501 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1502 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1503 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1504 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1505 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1506 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1507 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1508 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1509 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1510 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1511 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1512 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1513 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1514#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1515 #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
1517 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1518 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1519 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1520#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1521 #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
1522#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1523 #define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
1524#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1525 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1527 #define JSON_HEDLEY_NO_RETURN
1530#if defined(JSON_HEDLEY_NO_ESCAPE)
1531 #undef JSON_HEDLEY_NO_ESCAPE
1533#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
1534 #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
1536 #define JSON_HEDLEY_NO_ESCAPE
1539#if defined(JSON_HEDLEY_UNREACHABLE)
1540 #undef JSON_HEDLEY_UNREACHABLE
1542#if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
1543 #undef JSON_HEDLEY_UNREACHABLE_RETURN
1545#if defined(JSON_HEDLEY_ASSUME)
1546 #undef JSON_HEDLEY_ASSUME
1549 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1550 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1551 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1552 #define JSON_HEDLEY_ASSUME(expr) __assume(expr)
1553#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
1554 #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
1556 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1557 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1558 #if defined(__cplusplus)
1559 #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
1561 #define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
1565 (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
1566 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1567 JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \
1568 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1569 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \
1570 JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \
1571 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1572 #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
1573#elif defined(JSON_HEDLEY_ASSUME)
1574 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1576#if !defined(JSON_HEDLEY_ASSUME)
1577 #if defined(JSON_HEDLEY_UNREACHABLE)
1578 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1)))
1580 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr)
1583#if defined(JSON_HEDLEY_UNREACHABLE)
1585 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1586 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1587 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))
1589 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
1592 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value)
1594#if !defined(JSON_HEDLEY_UNREACHABLE)
1595 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1598JSON_HEDLEY_DIAGNOSTIC_PUSH
1599#if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
1600 #pragma clang diagnostic ignored "-Wpedantic"
1602#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
1603 #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
1605#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0)
1606 #if defined(__clang__)
1607 #pragma clang diagnostic ignored "-Wvariadic-macros"
1608 #elif defined(JSON_HEDLEY_GCC_VERSION)
1609 #pragma GCC diagnostic ignored "-Wvariadic-macros"
1612#if defined(JSON_HEDLEY_NON_NULL)
1613 #undef JSON_HEDLEY_NON_NULL
1616 JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
1617 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1618 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1619 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1620 #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
1622 #define JSON_HEDLEY_NON_NULL(...)
1624JSON_HEDLEY_DIAGNOSTIC_POP
1626#if defined(JSON_HEDLEY_PRINTF_FORMAT)
1627 #undef JSON_HEDLEY_PRINTF_FORMAT
1629#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO)
1630 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))
1631#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO)
1632 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
1634 JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
1635 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1636 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1637 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1638 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1639 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1640 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1641 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1642 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1643 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1644 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1645 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1646 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1647 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1648 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1649 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1650 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1651 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
1652#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
1653 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
1655 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
1658#if defined(JSON_HEDLEY_CONSTEXPR)
1659 #undef JSON_HEDLEY_CONSTEXPR
1661#if defined(__cplusplus)
1662 #if __cplusplus >= 201103L
1663 #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)
1666#if !defined(JSON_HEDLEY_CONSTEXPR)
1667 #define JSON_HEDLEY_CONSTEXPR
1670#if defined(JSON_HEDLEY_PREDICT)
1671 #undef JSON_HEDLEY_PREDICT
1673#if defined(JSON_HEDLEY_LIKELY)
1674 #undef JSON_HEDLEY_LIKELY
1676#if defined(JSON_HEDLEY_UNLIKELY)
1677 #undef JSON_HEDLEY_UNLIKELY
1679#if defined(JSON_HEDLEY_UNPREDICTABLE)
1680 #undef JSON_HEDLEY_UNPREDICTABLE
1682#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
1683 #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
1686 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
1687 JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \
1688 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1689# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability))
1690# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability))
1691# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability))
1692# define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 )
1693# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 )
1695 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
1696 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1697 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1698 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1699 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1700 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1701 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1702 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1703 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1704 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1705 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1706 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1707 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1708 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \
1709 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1710 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1711# define JSON_HEDLEY_PREDICT(expr, expected, probability) \
1712 (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))
1713# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
1715 double hedley_probability_ = (probability); \
1716 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
1718# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
1720 double hedley_probability_ = (probability); \
1721 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
1723# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1724# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1726# define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))
1727# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
1728# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
1729# define JSON_HEDLEY_LIKELY(expr) (!!(expr))
1730# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
1732#if !defined(JSON_HEDLEY_UNPREDICTABLE)
1733 #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
1736#if defined(JSON_HEDLEY_MALLOC)
1737 #undef JSON_HEDLEY_MALLOC
1740 JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
1741 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1742 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1743 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1744 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1745 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1746 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1747 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1748 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1749 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1750 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1751 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1752 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1753 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1754 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1755 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1756 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1757 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1758 #define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
1759#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1760 #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
1762 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1763 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1764 #define JSON_HEDLEY_MALLOC __declspec(restrict)
1766 #define JSON_HEDLEY_MALLOC
1769#if defined(JSON_HEDLEY_PURE)
1770 #undef JSON_HEDLEY_PURE
1773 JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
1774 JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \
1775 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1776 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1777 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1778 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1779 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1780 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1781 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1782 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1783 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1784 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1785 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1786 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1787 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1788 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1789 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1790 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1791 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1792# define JSON_HEDLEY_PURE __attribute__((__pure__))
1793#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1794# define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
1795#elif defined(__cplusplus) && \
1797 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1798 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \
1799 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \
1801# define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
1803# define JSON_HEDLEY_PURE
1806#if defined(JSON_HEDLEY_CONST)
1807 #undef JSON_HEDLEY_CONST
1810 JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
1811 JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \
1812 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1813 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1814 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1815 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1816 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1817 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1818 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1819 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1820 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1821 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1822 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1823 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1824 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1825 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1826 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1827 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1828 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1829 #define JSON_HEDLEY_CONST __attribute__((__const__))
1831 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1832 #define JSON_HEDLEY_CONST _Pragma("no_side_effect")
1834 #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
1837#if defined(JSON_HEDLEY_RESTRICT)
1838 #undef JSON_HEDLEY_RESTRICT
1840#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
1841 #define JSON_HEDLEY_RESTRICT restrict
1843 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1844 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1845 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1846 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1847 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1848 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1849 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1850 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1851 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \
1852 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1853 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1854 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
1855 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1856 defined(__clang__) || \
1857 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1858 #define JSON_HEDLEY_RESTRICT __restrict
1859#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
1860 #define JSON_HEDLEY_RESTRICT _Restrict
1862 #define JSON_HEDLEY_RESTRICT
1865#if defined(JSON_HEDLEY_INLINE)
1866 #undef JSON_HEDLEY_INLINE
1869 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1870 (defined(__cplusplus) && (__cplusplus >= 199711L))
1871 #define JSON_HEDLEY_INLINE inline
1873 defined(JSON_HEDLEY_GCC_VERSION) || \
1874 JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
1875 #define JSON_HEDLEY_INLINE __inline__
1877 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1878 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1879 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1880 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \
1881 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1882 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1883 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1884 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1885 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1886 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1887 #define JSON_HEDLEY_INLINE __inline
1889 #define JSON_HEDLEY_INLINE
1892#if defined(JSON_HEDLEY_ALWAYS_INLINE)
1893 #undef JSON_HEDLEY_ALWAYS_INLINE
1896 JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
1897 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1898 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1899 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1900 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1901 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1902 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1903 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1904 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1905 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1906 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1907 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1908 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1909 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1910 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1911 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1912 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1913 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1914 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1915# define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
1917 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1918 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1919# define JSON_HEDLEY_ALWAYS_INLINE __forceinline
1920#elif defined(__cplusplus) && \
1922 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1923 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1924 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1925 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1926 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1927 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \
1929# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
1930#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1931# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
1933# define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
1936#if defined(JSON_HEDLEY_NEVER_INLINE)
1937 #undef JSON_HEDLEY_NEVER_INLINE
1940 JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
1941 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1942 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1943 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1944 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1945 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1946 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1947 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1948 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1949 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1950 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1951 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1952 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1953 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1954 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1955 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1956 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1957 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1958 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1959 #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
1961 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1962 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1963 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1964#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
1965 #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
1966#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1967 #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
1968#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1969 #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
1970#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1971 #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
1972#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1973 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1975 #define JSON_HEDLEY_NEVER_INLINE
1978#if defined(JSON_HEDLEY_PRIVATE)
1979 #undef JSON_HEDLEY_PRIVATE
1981#if defined(JSON_HEDLEY_PUBLIC)
1982 #undef JSON_HEDLEY_PUBLIC
1984#if defined(JSON_HEDLEY_IMPORT)
1985 #undef JSON_HEDLEY_IMPORT
1987#if defined(_WIN32) || defined(__CYGWIN__)
1988# define JSON_HEDLEY_PRIVATE
1989# define JSON_HEDLEY_PUBLIC __declspec(dllexport)
1990# define JSON_HEDLEY_IMPORT __declspec(dllimport)
1993 JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
1994 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1995 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1996 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1997 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1998 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
2000 defined(__TI_EABI__) && \
2002 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
2003 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \
2006 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2007# define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
2008# define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
2010# define JSON_HEDLEY_PRIVATE
2011# define JSON_HEDLEY_PUBLIC
2013# define JSON_HEDLEY_IMPORT extern
2016#if defined(JSON_HEDLEY_NO_THROW)
2017 #undef JSON_HEDLEY_NO_THROW
2020 JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
2021 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
2022 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2023 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2024 #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
2026 JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
2027 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
2028 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
2029 #define JSON_HEDLEY_NO_THROW __declspec(nothrow)
2031 #define JSON_HEDLEY_NO_THROW
2034#if defined(JSON_HEDLEY_FALL_THROUGH)
2035 #undef JSON_HEDLEY_FALL_THROUGH
2038 JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
2039 JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \
2040 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2041 #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
2042#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
2043 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
2044#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
2045 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])
2046#elif defined(__fallthrough)
2047 #define JSON_HEDLEY_FALL_THROUGH __fallthrough
2049 #define JSON_HEDLEY_FALL_THROUGH
2052#if defined(JSON_HEDLEY_RETURNS_NON_NULL)
2053 #undef JSON_HEDLEY_RETURNS_NON_NULL
2056 JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
2057 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
2058 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2059 #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__))
2060#elif defined(_Ret_notnull_)
2061 #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_
2063 #define JSON_HEDLEY_RETURNS_NON_NULL
2066#if defined(JSON_HEDLEY_ARRAY_PARAM)
2067 #undef JSON_HEDLEY_ARRAY_PARAM
2070 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
2071 !defined(__STDC_NO_VLA__) && \
2072 !defined(__cplusplus) && \
2073 !defined(JSON_HEDLEY_PGI_VERSION) && \
2074 !defined(JSON_HEDLEY_TINYC_VERSION)
2075 #define JSON_HEDLEY_ARRAY_PARAM(name) (name)
2077 #define JSON_HEDLEY_ARRAY_PARAM(name)
2080#if defined(JSON_HEDLEY_IS_CONSTANT)
2081 #undef JSON_HEDLEY_IS_CONSTANT
2083#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
2084 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
2088#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
2089 #undef JSON_HEDLEY_IS_CONSTEXPR_
2092 JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
2093 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
2094 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2095 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
2096 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
2097 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
2098 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
2099 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
2100 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
2101 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2102 #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
2104#if !defined(__cplusplus)
2106 JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
2107 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
2108 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2109 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
2110 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
2111 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
2112 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
2113#if defined(__INTPTR_TYPE__)
2114 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
2117 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
2121 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
2122 !defined(JSON_HEDLEY_SUNPRO_VERSION) && \
2123 !defined(JSON_HEDLEY_PGI_VERSION) && \
2124 !defined(JSON_HEDLEY_IAR_VERSION)) || \
2125 (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
2126 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
2127 JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
2128 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
2129 JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
2130#if defined(__INTPTR_TYPE__)
2131 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
2134 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)
2137 defined(JSON_HEDLEY_GCC_VERSION) || \
2138 defined(JSON_HEDLEY_INTEL_VERSION) || \
2139 defined(JSON_HEDLEY_TINYC_VERSION) || \
2140 defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
2141 JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \
2142 defined(JSON_HEDLEY_TI_CL2000_VERSION) || \
2143 defined(JSON_HEDLEY_TI_CL6X_VERSION) || \
2144 defined(JSON_HEDLEY_TI_CL7X_VERSION) || \
2145 defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \
2147# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
2151 ((void*) ((expr) * 0L) ) : \
2152((struct { char v[sizeof(void) * 2]; } *) 1) \
2158#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
2159 #if !defined(JSON_HEDLEY_IS_CONSTANT)
2160 #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
2162 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))
2164 #if !defined(JSON_HEDLEY_IS_CONSTANT)
2165 #define JSON_HEDLEY_IS_CONSTANT(expr) (0)
2167 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
2170#if defined(JSON_HEDLEY_BEGIN_C_DECLS)
2171 #undef JSON_HEDLEY_BEGIN_C_DECLS
2173#if defined(JSON_HEDLEY_END_C_DECLS)
2174 #undef JSON_HEDLEY_END_C_DECLS
2176#if defined(JSON_HEDLEY_C_DECL)
2177 #undef JSON_HEDLEY_C_DECL
2179#if defined(__cplusplus)
2180 #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
2181 #define JSON_HEDLEY_END_C_DECLS }
2182 #define JSON_HEDLEY_C_DECL extern "C"
2184 #define JSON_HEDLEY_BEGIN_C_DECLS
2185 #define JSON_HEDLEY_END_C_DECLS
2186 #define JSON_HEDLEY_C_DECL
2189#if defined(JSON_HEDLEY_STATIC_ASSERT)
2190 #undef JSON_HEDLEY_STATIC_ASSERT
2193 !defined(__cplusplus) && ( \
2194 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
2195 (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
2196 JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
2197 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2198 defined(_Static_assert) \
2200# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
2202 (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
2203 JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \
2204 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2205# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
2207# define JSON_HEDLEY_STATIC_ASSERT(expr, message)
2210#if defined(JSON_HEDLEY_NULL)
2211 #undef JSON_HEDLEY_NULL
2213#if defined(__cplusplus)
2214 #if __cplusplus >= 201103L
2215 #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)
2217 #define JSON_HEDLEY_NULL NULL
2219 #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
2222 #define JSON_HEDLEY_NULL NULL
2224 #define JSON_HEDLEY_NULL ((void*) 0)
2227#if defined(JSON_HEDLEY_MESSAGE)
2228 #undef JSON_HEDLEY_MESSAGE
2230#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2231# define JSON_HEDLEY_MESSAGE(msg) \
2232 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2233 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2234 JSON_HEDLEY_PRAGMA(message msg) \
2235 JSON_HEDLEY_DIAGNOSTIC_POP
2237 JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
2238 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2239# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
2240#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
2241# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
2242#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
2243# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2244#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
2245# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2247# define JSON_HEDLEY_MESSAGE(msg)
2250#if defined(JSON_HEDLEY_WARNING)
2251 #undef JSON_HEDLEY_WARNING
2253#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2254# define JSON_HEDLEY_WARNING(msg) \
2255 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2256 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2257 JSON_HEDLEY_PRAGMA(clang warning msg) \
2258 JSON_HEDLEY_DIAGNOSTIC_POP
2260 JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
2261 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
2262 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2263# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
2265 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
2266 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2267# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
2269# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
2272#if defined(JSON_HEDLEY_REQUIRE)
2273 #undef JSON_HEDLEY_REQUIRE
2275#if defined(JSON_HEDLEY_REQUIRE_MSG)
2276 #undef JSON_HEDLEY_REQUIRE_MSG
2278#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
2279# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
2280# define JSON_HEDLEY_REQUIRE(expr) \
2281 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2282 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2283 __attribute__((diagnose_if(!(expr), #expr, "error"))) \
2284 JSON_HEDLEY_DIAGNOSTIC_POP
2285# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \
2286 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2287 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2288 __attribute__((diagnose_if(!(expr), msg, "error"))) \
2289 JSON_HEDLEY_DIAGNOSTIC_POP
2291# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error")))
2292# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error")))
2295# define JSON_HEDLEY_REQUIRE(expr)
2296# define JSON_HEDLEY_REQUIRE_MSG(expr,msg)
2299#if defined(JSON_HEDLEY_FLAGS)
2300 #undef JSON_HEDLEY_FLAGS
2302#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion"))
2303 #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
2305 #define JSON_HEDLEY_FLAGS
2308#if defined(JSON_HEDLEY_FLAGS_CAST)
2309 #undef JSON_HEDLEY_FLAGS_CAST
2311#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)
2312# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \
2313 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2314 _Pragma("warning(disable:188)") \
2316 JSON_HEDLEY_DIAGNOSTIC_POP \
2319# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
2322#if defined(JSON_HEDLEY_EMPTY_BASES)
2323 #undef JSON_HEDLEY_EMPTY_BASES
2326 (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \
2327 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2328 #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
2330 #define JSON_HEDLEY_EMPTY_BASES
2335#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
2336 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
2338#if defined(__clang__)
2339 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
2341 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
2344#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
2345 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
2347#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
2349#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
2350 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
2352#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
2354#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
2355 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
2357#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
2359#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
2360 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
2362#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
2364#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
2365 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
2367#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
2369#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
2370 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
2372#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
2374#if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
2375 #undef JSON_HEDLEY_CLANG_HAS_WARNING
2377#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
2389#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
2390 #if defined(__clang__)
2391 #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
2392 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
2394 #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
2395 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
2396 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
2403#if !defined(JSON_HAS_CPP_26) && !defined(JSON_HAS_CPP_23) && !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)
2404 #if (defined(__cplusplus) && __cplusplus > 202302L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202302L)
2405 #define JSON_HAS_CPP_26
2406 #define JSON_HAS_CPP_23
2407 #define JSON_HAS_CPP_20
2408 #define JSON_HAS_CPP_17
2409 #define JSON_HAS_CPP_14
2410 #elif (defined(__cplusplus) && __cplusplus > 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202002L)
2411 #define JSON_HAS_CPP_23
2412 #define JSON_HAS_CPP_20
2413 #define JSON_HAS_CPP_17
2414 #define JSON_HAS_CPP_14
2415 #elif (defined(__cplusplus) && __cplusplus > 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG > 201703L)
2416 #define JSON_HAS_CPP_20
2417 #define JSON_HAS_CPP_17
2418 #define JSON_HAS_CPP_14
2419 #elif (defined(__cplusplus) && __cplusplus > 201402L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1)
2420 #define JSON_HAS_CPP_17
2421 #define JSON_HAS_CPP_14
2422 #elif (defined(__cplusplus) && __cplusplus > 201103L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
2423 #define JSON_HAS_CPP_14
2426 #define JSON_HAS_CPP_11
2430 #if __has_include(<version>)
2435#if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM)
2436 #ifdef JSON_HAS_CPP_17
2437 #if defined(__cpp_lib_filesystem)
2438 #define JSON_HAS_FILESYSTEM 1
2439 #elif defined(__cpp_lib_experimental_filesystem)
2440 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2441 #elif !defined(__has_include)
2442 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2443 #elif __has_include(<filesystem>)
2444 #define JSON_HAS_FILESYSTEM 1
2445 #elif __has_include(<experimental/filesystem>)
2446 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2450 #if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8
2451 #undef JSON_HAS_FILESYSTEM
2452 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2456 #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 8
2457 #undef JSON_HAS_FILESYSTEM
2458 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2462 #if defined(__clang_major__) && __clang_major__ < 7
2463 #undef JSON_HAS_FILESYSTEM
2464 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2468 #if defined(_MSC_VER) && _MSC_VER < 1914
2469 #undef JSON_HAS_FILESYSTEM
2470 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2474 #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000
2475 #undef JSON_HAS_FILESYSTEM
2476 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2480 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
2481 #undef JSON_HAS_FILESYSTEM
2482 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2487#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2488 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0
2491#ifndef JSON_HAS_FILESYSTEM
2492 #define JSON_HAS_FILESYSTEM 0
2495#ifndef JSON_HAS_THREE_WAY_COMPARISON
2496 #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L \
2497 && defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L
2498 #define JSON_HAS_THREE_WAY_COMPARISON 1
2500 #define JSON_HAS_THREE_WAY_COMPARISON 0
2504#ifndef JSON_HAS_RANGES
2506 #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427
2507 #define JSON_HAS_RANGES 0
2508 #elif defined(__cpp_lib_ranges)
2509 #define JSON_HAS_RANGES 1
2511 #define JSON_HAS_RANGES 0
2515#ifndef JSON_HAS_STATIC_RTTI
2516 #if !defined(_HAS_STATIC_RTTI) || _HAS_STATIC_RTTI != 0
2517 #define JSON_HAS_STATIC_RTTI 1
2519 #define JSON_HAS_STATIC_RTTI 0
2523#ifdef JSON_HAS_CPP_17
2524 #define JSON_INLINE_VARIABLE inline
2526 #define JSON_INLINE_VARIABLE
2529#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address)
2530 #define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]]
2532 #define JSON_NO_UNIQUE_ADDRESS
2536#if defined(__clang__)
2537 #pragma clang diagnostic push
2538 #pragma clang diagnostic ignored "-Wdocumentation"
2539 #pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
2543#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
2544 #define JSON_THROW(exception) throw exception
2545 #define JSON_TRY try
2546 #define JSON_CATCH(exception) catch(exception)
2547 #define JSON_INTERNAL_CATCH(exception) catch(exception)
2550 #define JSON_THROW(exception) std::abort()
2551 #define JSON_TRY if(true)
2552 #define JSON_CATCH(exception) if(false)
2553 #define JSON_INTERNAL_CATCH(exception) if(false)
2557#if defined(JSON_THROW_USER)
2559 #define JSON_THROW JSON_THROW_USER
2561#if defined(JSON_TRY_USER)
2563 #define JSON_TRY JSON_TRY_USER
2565#if defined(JSON_CATCH_USER)
2567 #define JSON_CATCH JSON_CATCH_USER
2568 #undef JSON_INTERNAL_CATCH
2569 #define JSON_INTERNAL_CATCH JSON_CATCH_USER
2571#if defined(JSON_INTERNAL_CATCH_USER)
2572 #undef JSON_INTERNAL_CATCH
2573 #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2577#if !defined(JSON_ASSERT)
2579 #define JSON_ASSERT(x) assert(x)
2583#if defined(JSON_TESTS_PRIVATE)
2584 #define JSON_PRIVATE_UNLESS_TESTED public
2586 #define JSON_PRIVATE_UNLESS_TESTED private
2594#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2595 template<typename BasicJsonType> \
2596 inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
2599 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2601 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2602 auto it = std::find_if(std::begin(m), std::end(m), \
2603 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2605 return ej_pair.first == e; \
2607 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2609 template<typename BasicJsonType> \
2610 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
2613 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2615 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2616 auto it = std::find_if(std::begin(m), std::end(m), \
2617 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2619 return ej_pair.second == j; \
2621 e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2627#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2628 template<template<typename, typename, typename...> class ObjectType, \
2629 template<typename, typename...> class ArrayType, \
2630 class StringType, class BooleanType, class NumberIntegerType, \
2631 class NumberUnsignedType, class NumberFloatType, \
2632 template<typename> class AllocatorType, \
2633 template<typename, typename = void> class JSONSerializer, \
2635 class CustomBaseClass>
2637#define NLOHMANN_BASIC_JSON_TPL \
2638 basic_json<ObjectType, ArrayType, StringType, BooleanType, \
2639 NumberIntegerType, NumberUnsignedType, NumberFloatType, \
2640 AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>
2644#define NLOHMANN_JSON_EXPAND( x ) x
2645#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
2646#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
2647 NLOHMANN_JSON_PASTE64, \
2648 NLOHMANN_JSON_PASTE63, \
2649 NLOHMANN_JSON_PASTE62, \
2650 NLOHMANN_JSON_PASTE61, \
2651 NLOHMANN_JSON_PASTE60, \
2652 NLOHMANN_JSON_PASTE59, \
2653 NLOHMANN_JSON_PASTE58, \
2654 NLOHMANN_JSON_PASTE57, \
2655 NLOHMANN_JSON_PASTE56, \
2656 NLOHMANN_JSON_PASTE55, \
2657 NLOHMANN_JSON_PASTE54, \
2658 NLOHMANN_JSON_PASTE53, \
2659 NLOHMANN_JSON_PASTE52, \
2660 NLOHMANN_JSON_PASTE51, \
2661 NLOHMANN_JSON_PASTE50, \
2662 NLOHMANN_JSON_PASTE49, \
2663 NLOHMANN_JSON_PASTE48, \
2664 NLOHMANN_JSON_PASTE47, \
2665 NLOHMANN_JSON_PASTE46, \
2666 NLOHMANN_JSON_PASTE45, \
2667 NLOHMANN_JSON_PASTE44, \
2668 NLOHMANN_JSON_PASTE43, \
2669 NLOHMANN_JSON_PASTE42, \
2670 NLOHMANN_JSON_PASTE41, \
2671 NLOHMANN_JSON_PASTE40, \
2672 NLOHMANN_JSON_PASTE39, \
2673 NLOHMANN_JSON_PASTE38, \
2674 NLOHMANN_JSON_PASTE37, \
2675 NLOHMANN_JSON_PASTE36, \
2676 NLOHMANN_JSON_PASTE35, \
2677 NLOHMANN_JSON_PASTE34, \
2678 NLOHMANN_JSON_PASTE33, \
2679 NLOHMANN_JSON_PASTE32, \
2680 NLOHMANN_JSON_PASTE31, \
2681 NLOHMANN_JSON_PASTE30, \
2682 NLOHMANN_JSON_PASTE29, \
2683 NLOHMANN_JSON_PASTE28, \
2684 NLOHMANN_JSON_PASTE27, \
2685 NLOHMANN_JSON_PASTE26, \
2686 NLOHMANN_JSON_PASTE25, \
2687 NLOHMANN_JSON_PASTE24, \
2688 NLOHMANN_JSON_PASTE23, \
2689 NLOHMANN_JSON_PASTE22, \
2690 NLOHMANN_JSON_PASTE21, \
2691 NLOHMANN_JSON_PASTE20, \
2692 NLOHMANN_JSON_PASTE19, \
2693 NLOHMANN_JSON_PASTE18, \
2694 NLOHMANN_JSON_PASTE17, \
2695 NLOHMANN_JSON_PASTE16, \
2696 NLOHMANN_JSON_PASTE15, \
2697 NLOHMANN_JSON_PASTE14, \
2698 NLOHMANN_JSON_PASTE13, \
2699 NLOHMANN_JSON_PASTE12, \
2700 NLOHMANN_JSON_PASTE11, \
2701 NLOHMANN_JSON_PASTE10, \
2702 NLOHMANN_JSON_PASTE9, \
2703 NLOHMANN_JSON_PASTE8, \
2704 NLOHMANN_JSON_PASTE7, \
2705 NLOHMANN_JSON_PASTE6, \
2706 NLOHMANN_JSON_PASTE5, \
2707 NLOHMANN_JSON_PASTE4, \
2708 NLOHMANN_JSON_PASTE3, \
2709 NLOHMANN_JSON_PASTE2, \
2710 NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
2711#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
2712#define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
2713#define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
2714#define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
2715#define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
2716#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)
2717#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)
2718#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)
2719#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)
2720#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)
2721#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)
2722#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)
2723#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)
2724#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)
2725#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)
2726#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)
2727#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)
2728#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)
2729#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)
2730#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)
2731#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)
2732#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)
2733#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)
2734#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)
2735#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)
2736#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)
2737#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)
2738#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)
2739#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)
2740#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)
2741#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)
2742#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)
2743#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)
2744#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)
2745#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)
2746#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)
2747#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)
2748#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)
2749#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)
2750#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)
2751#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)
2752#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)
2753#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)
2754#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)
2755#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)
2756#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)
2757#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)
2758#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)
2759#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)
2760#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)
2761#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)
2762#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)
2763#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)
2764#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)
2765#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)
2766#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)
2767#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)
2768#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)
2769#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)
2770#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)
2771#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)
2772#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)
2773#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)
2775#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2776#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2777#define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) nlohmann_json_t.v1 = !nlohmann_json_j.is_null() ? nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1) : nlohmann_json_default_obj.v1;
2785#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
2786 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2787 friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2788 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2789 friend void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2797#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \
2798 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2799 friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2800 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2801 friend void from_json(const BasicJsonType& 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__)) }
2809#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \
2810 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2811 friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) }
2819#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
2820 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2821 void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2822 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2823 void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2831#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \
2832 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2833 void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2834 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2835 void from_json(const BasicJsonType& 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__)) }
2843#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \
2844 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2845 void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) }
2853#define NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE(Type, BaseType, ...) \
2854 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2855 friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { nlohmann::to_json(nlohmann_json_j, static_cast<const BaseType &>(nlohmann_json_t)); NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2856 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2857 friend void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { nlohmann::from_json(nlohmann_json_j, static_cast<BaseType&>(nlohmann_json_t)); NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2865#define NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT(Type, BaseType, ...) \
2866 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2867 friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { nlohmann::to_json(nlohmann_json_j, static_cast<const BaseType&>(nlohmann_json_t)); NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2868 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2869 friend void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { nlohmann::from_json(nlohmann_json_j, static_cast<BaseType&>(nlohmann_json_t)); const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
2877#define NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, BaseType, ...) \
2878 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2879 friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { nlohmann::to_json(nlohmann_json_j, static_cast<const BaseType &>(nlohmann_json_t)); NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) }
2887#define NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE(Type, BaseType, ...) \
2888 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2889 void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { nlohmann::to_json(nlohmann_json_j, static_cast<const BaseType &>(nlohmann_json_t)); NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2890 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2891 void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { nlohmann::from_json(nlohmann_json_j, static_cast<BaseType&>(nlohmann_json_t)); NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2899#define NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, BaseType, ...) \
2900 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2901 void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { nlohmann::to_json(nlohmann_json_j, static_cast<const BaseType &>(nlohmann_json_t)); NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2902 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2903 void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { nlohmann::from_json(nlohmann_json_j, static_cast<BaseType&>(nlohmann_json_t)); const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
2911#define NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, BaseType, ...) \
2912 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2913 void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { nlohmann::to_json(nlohmann_json_j, static_cast<const BaseType &>(nlohmann_json_t)); NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) }
2921#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \
2922 namespace detail { \
2923 using std::std_name; \
2925 template<typename... T> \
2926 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2929 namespace detail2 { \
2930 struct std_name##_tag \
2934 template<typename... T> \
2935 std_name##_tag std_name(T&&...); \
2937 template<typename... T> \
2938 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2940 template<typename... T> \
2941 struct would_call_std_##std_name \
2943 static constexpr auto const value = ::nlohmann::detail:: \
2944 is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \
2948 template<typename... T> \
2949 struct would_call_std_##std_name : detail2::would_call_std_##std_name<T...> \
2953#ifndef JSON_USE_IMPLICIT_CONVERSIONS
2954 #define JSON_USE_IMPLICIT_CONVERSIONS 1
2957#if JSON_USE_IMPLICIT_CONVERSIONS
2958 #define JSON_EXPLICIT
2960 #define JSON_EXPLICIT explicit
2963#ifndef JSON_DISABLE_ENUM_SERIALIZATION
2964 #define JSON_DISABLE_ENUM_SERIALIZATION 0
2967#ifndef JSON_USE_GLOBAL_UDLS
2968 #define JSON_USE_GLOBAL_UDLS 1
2971#if JSON_HAS_THREE_WAY_COMPARISON
2975NLOHMANN_JSON_NAMESPACE_BEGIN
3034#if JSON_HAS_THREE_WAY_COMPARISON
3035 inline std::partial_ordering operator<=>(
const value_t lhs,
const value_t rhs)
noexcept
3040 static constexpr std::array<std::uint8_t, 9> order = {{
3047 const auto l_index =
static_cast<std::size_t
>(lhs);
3048 const auto r_index =
static_cast<std::size_t
>(rhs);
3049#if JSON_HAS_THREE_WAY_COMPARISON
3050 if (l_index < order.size() && r_index < order.size())
3052 return order[l_index] <=> order[r_index];
3054 return std::partial_ordering::unordered;
3056 return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
3064#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__)
3067 return std::is_lt(lhs <=> rhs);
3072NLOHMANN_JSON_NAMESPACE_END
3088NLOHMANN_JSON_NAMESPACE_BEGIN
3105template<
typename StringType>
3107 const StringType& t)
3109 JSON_ASSERT(!f.empty());
3110 for (
auto pos = s.find(f);
3111 pos != StringType::npos;
3112 s.replace(pos, f.size(), t),
3113 pos = s.find(f, pos + t.size()))
3124template<
typename StringType>
3139template<
typename StringType>
3147NLOHMANN_JSON_NAMESPACE_END
3165NLOHMANN_JSON_NAMESPACE_BEGIN
3180 constexpr operator size_t()
const
3187NLOHMANN_JSON_NAMESPACE_END
3205#include <type_traits>
3211NLOHMANN_JSON_NAMESPACE_BEGIN
3216using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
3218#ifdef JSON_HAS_CPP_14
3221using std::enable_if_t;
3222using std::index_sequence;
3223using std::make_index_sequence;
3224using std::index_sequence_for;
3229template<
bool B,
typename T =
void>
3230using enable_if_t =
typename std::enable_if<B, T>::type;
3256template <
typename T, T... Ints>
3259 using value_type = T;
3260 static constexpr std::size_t size()
noexcept
3262 return sizeof...(Ints);
3271template <
size_t... Ints>
3274namespace utility_internal
3277template <
typename Seq,
size_t SeqSize,
size_t Rem>
3281template <
typename T, T... Ints,
size_t SeqSize>
3287template <
typename T, T... Ints,
size_t SeqSize>
3290 using type =
integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >;
3295template <
typename T,
size_t N>
3299 typename Extend <
typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
3302template <
typename T>
3317template <
typename T, T N>
3318using make_integer_sequence =
typename utility_internal::Gen<T, N>::type;
3326using make_index_sequence = make_integer_sequence<size_t, N>;
3333template <
typename... Ts>
3334using index_sequence_for = make_index_sequence<
sizeof...(Ts)>;
3348 static JSON_INLINE_VARIABLE
constexpr T value{};
3351#ifndef JSON_HAS_CPP_17
3352 template<
typename T>
3356template<
typename T,
typename... Args>
3357constexpr std::array<T,
sizeof...(Args)> make_array(Args&& ... args)
3359 return std::array<T,
sizeof...(Args)> {{
static_cast<T
>(std::forward<Args>(args))...}};
3363NLOHMANN_JSON_NAMESPACE_END
3379#include <type_traits>
3381#if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L
3404NLOHMANN_JSON_NAMESPACE_BEGIN
3408template<
typename It,
typename =
void>
3411template<
typename It>
3414 void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
3415 typename It::reference, typename It::iterator_category >>
3417 using difference_type =
typename It::difference_type;
3418 using value_type =
typename It::value_type;
3419 using pointer =
typename It::pointer;
3420 using reference =
typename It::reference;
3421 using iterator_category =
typename It::iterator_category;
3426template<
typename T,
typename =
void>
3440 using iterator_category = std::random_access_iterator_tag;
3441 using value_type = T;
3442 using difference_type = ptrdiff_t;
3444 using reference = T&;
3448NLOHMANN_JSON_NAMESPACE_END
3466NLOHMANN_JSON_NAMESPACE_BEGIN
3468NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin);
3470NLOHMANN_JSON_NAMESPACE_END
3486NLOHMANN_JSON_NAMESPACE_BEGIN
3488NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end);
3490NLOHMANN_JSON_NAMESPACE_END
3505#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
3506 #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
3522 NLOHMANN_JSON_NAMESPACE_BEGIN
3531 template<
typename T =
void,
typename SFINAE =
void>
3536 template<
template<
typename U,
typename V,
typename... Args>
class ObjectType =
3538 template<
typename U,
typename... Args>
class ArrayType = std::vector,
3539 class StringType = std::string,
class BooleanType = bool,
3540 class NumberIntegerType = std::int64_t,
3541 class NumberUnsignedType = std::uint64_t,
3542 class NumberFloatType = double,
3543 template<
typename U>
class AllocatorType = std::allocator,
3544 template<
typename T,
typename SFINAE =
void>
class JSONSerializer =
3546 class BinaryType = std::vector<std::uint8_t>,
3547 class CustomBaseClass =
void>
3552 template<
typename RefStringType>
3563 template<
class Key,
class T,
class IgnoredLess,
class Allocator>
3570 NLOHMANN_JSON_NAMESPACE_END
3575NLOHMANN_JSON_NAMESPACE_BEGIN
3602NLOHMANN_BASIC_JSON_TPL_DECLARATION
3608template<
typename BasicJsonContext>
3610 std::integral_constant < bool,
3611 is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value
3612 || std::is_same<BasicJsonContext, std::nullptr_t>::value >
3633using mapped_type_t =
typename T::mapped_type;
3636using key_type_t =
typename T::key_type;
3639using value_type_t =
typename T::value_type;
3642using difference_type_t =
typename T::difference_type;
3645using pointer_t =
typename T::pointer;
3648using reference_t =
typename T::reference;
3651using iterator_category_t =
typename T::iterator_category;
3653template<
typename T,
typename... Args>
3654using to_json_function =
decltype(T::to_json(std::declval<Args>()...));
3656template<
typename T,
typename... Args>
3657using from_json_function =
decltype(T::from_json(std::declval<Args>()...));
3659template<
typename T,
typename U>
3660using get_template_function =
decltype(std::declval<T>().template get<U>());
3663template<
typename BasicJsonType,
typename T,
typename =
void>
3670template <
typename BasicJsonType,
typename T>
3673 static constexpr bool value = is_detected<get_template_function, const BasicJsonType&, T>::value;
3676template<
typename BasicJsonType,
typename T>
3679 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3681 static constexpr bool value =
3682 is_detected_exact<void, from_json_function, serializer,
3683 const BasicJsonType&, T&>::value;
3688template<
typename BasicJsonType,
typename T,
typename =
void>
3691template<
typename BasicJsonType,
typename T>
3694 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3696 static constexpr bool value =
3697 is_detected_exact<T, from_json_function, serializer,
3698 const BasicJsonType&>::value;
3703template<
typename BasicJsonType,
typename T,
typename =
void>
3706template<
typename BasicJsonType,
typename T>
3709 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3711 static constexpr bool value =
3712 is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
3717using detect_key_compare =
typename T::key_compare;
3720struct has_key_compare : std::integral_constant<bool, is_detected<detect_key_compare, T>::value> {};
3723template<
typename BasicJsonType>
3726 using object_t =
typename BasicJsonType::object_t;
3727 using object_comparator_t =
typename BasicJsonType::default_object_comparator_t;
3728 using type =
typename std::conditional < has_key_compare<object_t>::value,
3729 typename object_t::key_compare, object_comparator_t>::type;
3732template<
typename BasicJsonType>
3733using actual_object_comparator_t =
typename actual_object_comparator<BasicJsonType>::type;
3748 using char_type =
unsigned char;
3749 using int_type = uint64_t;
3752 static int_type to_int_type(char_type c)
noexcept
3754 return static_cast<int_type
>(c);
3757 static char_type to_char_type(int_type i)
noexcept
3759 return static_cast<char_type
>(i);
3762 static constexpr int_type eof()
noexcept
3764 return static_cast<int_type
>(std::char_traits<char>::eof());
3772 using char_type =
signed char;
3773 using int_type = uint64_t;
3776 static int_type to_int_type(char_type c)
noexcept
3778 return static_cast<int_type
>(c);
3781 static char_type to_char_type(int_type i)
noexcept
3783 return static_cast<char_type
>(i);
3786 static constexpr int_type eof()
noexcept
3788 return static_cast<int_type
>(std::char_traits<char>::eof());
3792#if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L
3794struct char_traits<std::byte> : std::char_traits<char>
3796 using char_type = std::byte;
3797 using int_type = uint64_t;
3799 static int_type to_int_type(char_type c)
noexcept
3801 return static_cast<int_type
>(std::to_integer<unsigned char>(c));
3804 static char_type to_char_type(int_type i)
noexcept
3806 return std::byte(
static_cast<unsigned char>(i));
3809 static constexpr int_type eof() noexcept
3811 return static_cast<int_type
>(std::char_traits<char>::eof());
3823template<
class B,
class... Bn>
3825: std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {};
3828template<
class B>
struct negation : std::integral_constant < bool, !B::value > { };
3833template <
typename T>
3836template <
typename T1,
typename T2>
3838 :
conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3840template <
typename T1,
typename T2>
3842 :
conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3844template <
typename... Ts>
3846 :
conjunction<is_default_constructible<Ts>...> {};
3848template <
typename... Ts>
3850 :
conjunction<is_default_constructible<Ts>...> {};
3852template <
typename T,
typename... Args>
3855template <
typename T1,
typename T2>
3858template <
typename T1,
typename T2>
3861template <
typename... Ts>
3864template <
typename... Ts>
3867template<
typename T,
typename =
void>
3877 static constexpr auto value =
3878 is_detected<value_type_t, traits>::value &&
3879 is_detected<difference_type_t, traits>::value &&
3880 is_detected<pointer_t, traits>::value &&
3881 is_detected<iterator_category_t, traits>::value &&
3882 is_detected<reference_t, traits>::value;
3889 using t_ref =
typename std::add_lvalue_reference<T>::type;
3891 using iterator = detected_t<result_of_begin, t_ref>;
3892 using sentinel = detected_t<result_of_end, t_ref>;
3897 static constexpr auto is_iterator_begin =
3901 static constexpr bool value = !std::is_same<iterator, nonesuch>::value && !std::is_same<sentinel, nonesuch>::value && is_iterator_begin;
3905using iterator_t = enable_if_t<is_range<R>::value, result_of_begin<decltype(std::declval<R&>())>>;
3908using range_value_t = value_type_t<iterator_traits<iterator_t<T>>>;
3914template<
typename T,
typename =
void>
3920template<
typename BasicJsonType,
typename CompatibleObjectType,
3924template<
typename BasicJsonType,
typename CompatibleObjectType>
3926 BasicJsonType, CompatibleObjectType,
3927 enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
3928 is_detected<key_type_t, CompatibleObjectType>::value >>
3930 using object_t =
typename BasicJsonType::object_t;
3933 static constexpr bool value =
3935 typename CompatibleObjectType::key_type>::value &&
3937 typename CompatibleObjectType::mapped_type>::value;
3940template<
typename BasicJsonType,
typename CompatibleObjectType>
3944template<
typename BasicJsonType,
typename ConstructibleObjectType,
3948template<
typename BasicJsonType,
typename ConstructibleObjectType>
3950 BasicJsonType, ConstructibleObjectType,
3951 enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&&
3952 is_detected<key_type_t, ConstructibleObjectType>::value >>
3954 using object_t =
typename BasicJsonType::object_t;
3956 static constexpr bool value =
3958 (std::is_move_assignable<ConstructibleObjectType>::value ||
3959 std::is_copy_assignable<ConstructibleObjectType>::value) &&
3961 typename object_t::key_type>::value &&
3963 typename object_t::mapped_type,
3964 typename ConstructibleObjectType::mapped_type >::value)) ||
3966 typename ConstructibleObjectType::mapped_type>::value ||
3969 typename ConstructibleObjectType::mapped_type >::value);
3972template<
typename BasicJsonType,
typename ConstructibleObjectType>
3975 ConstructibleObjectType> {};
3977template<
typename BasicJsonType,
typename CompatibleStringType>
3980 static constexpr auto value =
3984template<
typename BasicJsonType,
typename ConstructibleStringType>
3988#ifdef __INTEL_COMPILER
3989 using laundered_type =
decltype(std::declval<ConstructibleStringType>());
3991 using laundered_type = ConstructibleStringType;
3994 static constexpr auto value =
3997 is_detected_exact<
typename BasicJsonType::string_t::value_type,
3998 value_type_t, laundered_type >>::value;
4001template<
typename BasicJsonType,
typename CompatibleArrayType,
typename =
void>
4004template<
typename BasicJsonType,
typename CompatibleArrayType>
4006 BasicJsonType, CompatibleArrayType,
4008 is_detected<iterator_t, CompatibleArrayType>::value&&
4009 is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value&&
4012 !std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value >>
4014 static constexpr bool value =
4016 range_value_t<CompatibleArrayType>>::value;
4019template<
typename BasicJsonType,
typename CompatibleArrayType>
4023template<
typename BasicJsonType,
typename ConstructibleArrayType,
typename =
void>
4026template<
typename BasicJsonType,
typename ConstructibleArrayType>
4028 BasicJsonType, ConstructibleArrayType,
4029 enable_if_t<std::is_same<ConstructibleArrayType,
4030 typename BasicJsonType::value_type>::value >>
4031 : std::true_type {};
4033template<
typename BasicJsonType,
typename ConstructibleArrayType>
4035 BasicJsonType, ConstructibleArrayType,
4036 enable_if_t < !std::is_same<ConstructibleArrayType,
4037 typename BasicJsonType::value_type>::value&&
4040(std::is_move_assignable<ConstructibleArrayType>::value ||
4041 std::is_copy_assignable<ConstructibleArrayType>::value)&&
4042is_detected<iterator_t, ConstructibleArrayType>::value&&
4043is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value&&
4044is_detected<range_value_t, ConstructibleArrayType>::value&&
4047!std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>::value&&
4049detected_t<range_value_t, ConstructibleArrayType >>::value >>
4051 using value_type = range_value_t<ConstructibleArrayType>;
4053 static constexpr bool value =
4054 std::is_same<value_type,
4055 typename BasicJsonType::array_t::value_type>::value ||
4057 value_type>::value ||
4060 value_type >::value;
4063template<
typename BasicJsonType,
typename ConstructibleArrayType>
4067template<
typename RealIntegerType,
typename CompatibleNumberIntegerType,
4071template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
4073 RealIntegerType, CompatibleNumberIntegerType,
4074 enable_if_t < std::is_integral<RealIntegerType>::value&&
4075 std::is_integral<CompatibleNumberIntegerType>::value&&
4076 !std::is_same<bool, CompatibleNumberIntegerType>::value >>
4079 using RealLimits = std::numeric_limits<RealIntegerType>;
4080 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
4082 static constexpr auto value =
4084 CompatibleNumberIntegerType>::value &&
4085 CompatibleLimits::is_integer &&
4086 RealLimits::is_signed == CompatibleLimits::is_signed;
4089template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
4092 CompatibleNumberIntegerType> {};
4094template<
typename BasicJsonType,
typename CompatibleType,
typename =
void>
4097template<
typename BasicJsonType,
typename CompatibleType>
4099 BasicJsonType, CompatibleType,
4102 static constexpr bool value =
4106template<
typename BasicJsonType,
typename CompatibleType>
4110template<
typename T1,
typename T2>
4113template<
typename T1,
typename... Args>
4116template<
typename BasicJsonType,
typename T>
4119template<
typename BasicJsonType>
4122template<
typename BasicJsonType>
4127template<
template <
typename...>
class Primary,
typename T>
4130template<
template <
typename...>
class Primary,
typename... Args>
4137template<
typename Compare,
typename A,
typename B,
typename =
void>
4140template<
typename Compare,
typename A,
typename B>
4142decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())),
4143decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))
4144>> : std::true_type {};
4147using detect_is_transparent =
typename T::is_transparent;
4151template<
typename Comparator,
typename ObjectKeyType,
typename KeyTypeCVRef,
bool RequireTransparentComparator =
true,
4152 bool ExcludeObjectKeyType = RequireTransparentComparator,
typename KeyType = uncvref_t<KeyTypeCVRef>>
4153using is_usable_as_key_type =
typename std::conditional <
4155 && !(ExcludeObjectKeyType && std::is_same<KeyType,
4156 ObjectKeyType>::value)
4157 && (!RequireTransparentComparator
4158 || is_detected <detect_is_transparent, Comparator>::value)
4159 && !is_json_pointer<KeyType>::value,
4161 std::false_type >::type;
4169template<
typename BasicJsonType,
typename KeyTypeCVRef,
bool RequireTransparentComparator =
true,
4170 bool ExcludeObjectKeyType = RequireTransparentComparator,
typename KeyType = uncvref_t<KeyTypeCVRef>>
4171using is_usable_as_basic_json_key_type =
typename std::conditional <
4172 is_usable_as_key_type<
typename BasicJsonType::object_comparator_t,
4173 typename BasicJsonType::object_t::key_type, KeyTypeCVRef,
4174 RequireTransparentComparator, ExcludeObjectKeyType>::value
4177 std::false_type >::type;
4179template<
typename ObjectType,
typename KeyType>
4180using detect_erase_with_key_type =
decltype(std::declval<ObjectType&>().erase(std::declval<KeyType>()));
4183template<
typename BasicJsonType,
typename KeyType>
4184using has_erase_with_key_type =
typename std::conditional <
4186 detect_erase_with_key_type,
4187 typename BasicJsonType::object_t, KeyType >::value,
4189 std::false_type >::type;
4193template <
typename T>
4203 template <
typename C>
static one test(
decltype(&C::capacity) ) ;
4204 template <
typename C>
static two test(...);
4206 enum { value =
sizeof(test<T>(
nullptr)) ==
sizeof(
char) };
4210template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value,
int > = 0 >
4211T conditional_static_cast(U value)
4213 return static_cast<T
>(value);
4216template<typename T, typename U, enable_if_t<std::is_same<T, U>::value,
int> = 0>
4217T conditional_static_cast(U value)
4222template<
typename... Types>
4223using all_integral = conjunction<std::is_integral<Types>...>;
4225template<
typename... Types>
4226using all_signed = conjunction<std::is_signed<Types>...>;
4228template<
typename... Types>
4229using all_unsigned = conjunction<std::is_unsigned<Types>...>;
4232template<
typename... Types>
4233using same_sign = std::integral_constant < bool,
4234 all_signed<Types...>::value || all_unsigned<Types...>::value >;
4236template<
typename OfType,
typename T>
4237using never_out_of_range = std::integral_constant < bool,
4238 (std::is_signed<OfType>::value && (
sizeof(T) <
sizeof(OfType)))
4239 || (same_sign<OfType, T>::value &&
sizeof(OfType) ==
sizeof(T)) >;
4241template<
typename OfType,
typename T,
4242 bool OfTypeSigned = std::is_signed<OfType>::value,
4243 bool TSigned = std::is_signed<T>::value>
4246template<
typename OfType,
typename T>
4249 static constexpr bool test(T val)
4251 using CommonType =
typename std::common_type<OfType, T>::type;
4252 return static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4256template<
typename OfType,
typename T>
4259 static constexpr bool test(T val)
4261 using CommonType =
typename std::common_type<OfType, T>::type;
4262 return static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4266template<
typename OfType,
typename T>
4269 static constexpr bool test(T val)
4271 using CommonType =
typename std::common_type<OfType, T>::type;
4272 return val >= 0 &&
static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4276template<
typename OfType,
typename T>
4279 static constexpr bool test(T val)
4281 using CommonType =
typename std::common_type<OfType, T>::type;
4282 return static_cast<CommonType
>(val) >=
static_cast<CommonType
>((std::numeric_limits<OfType>::min)())
4283 &&
static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4287template<
typename OfType,
typename T,
4288 bool NeverOutOfRange = never_out_of_range<OfType, T>::value,
4289 typename = detail::enable_if_t<all_integral<OfType, T>::value>>
4292template<
typename OfType,
typename T>
4295 static constexpr bool test(T val)
4301template<
typename OfType,
typename T>
4304 static constexpr bool test(T )
4310template<
typename OfType,
typename T>
4311constexpr bool value_in_range_of(T val)
4317using bool_constant = std::integral_constant<bool, Value>;
4327constexpr bool is_c_string()
4329 using TUnExt =
typename std::remove_extent<T>::type;
4330 using TUnCVExt =
typename std::remove_cv<TUnExt>::type;
4331 using TUnPtr =
typename std::remove_pointer<T>::type;
4332 using TUnCVPtr =
typename std::remove_cv<TUnPtr>::type;
4334 (std::is_array<T>::value && std::is_same<TUnCVExt, char>::value)
4335 || (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value);
4357 return is_detected<detect_is_transparent, T>::value;
4369NLOHMANN_JSON_NAMESPACE_END
4391NLOHMANN_JSON_NAMESPACE_BEGIN
4395inline std::size_t concat_length()
4400template<
typename... Args>
4401inline std::size_t concat_length(
const char* cstr,
const Args& ... rest);
4403template<
typename StringType,
typename... Args>
4404inline std::size_t concat_length(
const StringType& str,
const Args& ... rest);
4406template<
typename... Args>
4407inline std::size_t concat_length(
const char ,
const Args& ... rest)
4409 return 1 + concat_length(rest...);
4412template<
typename... Args>
4413inline std::size_t concat_length(
const char* cstr,
const Args& ... rest)
4416 return ::strlen(cstr) + concat_length(rest...);
4419template<
typename StringType,
typename... Args>
4420inline std::size_t concat_length(
const StringType& str,
const Args& ... rest)
4422 return str.size() + concat_length(rest...);
4425template<
typename OutStringType>
4426inline void concat_into(OutStringType& )
4429template<
typename StringType,
typename Arg>
4430using string_can_append =
decltype(std::declval<StringType&>().append(std::declval < Arg && > ()));
4432template<
typename StringType,
typename Arg>
4433using detect_string_can_append = is_detected<string_can_append, StringType, Arg>;
4435template<
typename StringType,
typename Arg>
4436using string_can_append_op =
decltype(std::declval<StringType&>() += std::declval < Arg && > ());
4438template<
typename StringType,
typename Arg>
4439using detect_string_can_append_op = is_detected<string_can_append_op, StringType, Arg>;
4441template<
typename StringType,
typename Arg>
4442using string_can_append_iter =
decltype(std::declval<StringType&>().append(std::declval<const Arg&>().begin(), std::declval<const Arg&>().end()));
4444template<
typename StringType,
typename Arg>
4445using detect_string_can_append_iter = is_detected<string_can_append_iter, StringType, Arg>;
4447template<
typename StringType,
typename Arg>
4448using string_can_append_data =
decltype(std::declval<StringType&>().append(std::declval<const Arg&>().data(), std::declval<const Arg&>().size()));
4450template<
typename StringType,
typename Arg>
4451using detect_string_can_append_data = is_detected<string_can_append_data, StringType, Arg>;
4453template <
typename OutStringType,
typename Arg,
typename... Args,
4454 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4455 && detect_string_can_append_op<OutStringType, Arg>::value,
int > = 0 >
4456inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest);
4458template <
typename OutStringType,
typename Arg,
typename... Args,
4459 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4460 && !detect_string_can_append_op<OutStringType, Arg>::value
4461 && detect_string_can_append_iter<OutStringType, Arg>::value,
int > = 0 >
4462inline void concat_into(OutStringType& out,
const Arg& arg, Args && ... rest);
4464template <
typename OutStringType,
typename Arg,
typename... Args,
4465 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4466 && !detect_string_can_append_op<OutStringType, Arg>::value
4467 && !detect_string_can_append_iter<OutStringType, Arg>::value
4468 && detect_string_can_append_data<OutStringType, Arg>::value,
int > = 0 >
4469inline void concat_into(OutStringType& out,
const Arg& arg, Args && ... rest);
4471template<
typename OutStringType,
typename Arg,
typename... Args,
4472 enable_if_t<detect_string_can_append<OutStringType, Arg>::value,
int> = 0>
4473inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest)
4475 out.append(std::forward<Arg>(arg));
4476 concat_into(out, std::forward<Args>(rest)...);
4479template <
typename OutStringType,
typename Arg,
typename... Args,
4480 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4481 && detect_string_can_append_op<OutStringType, Arg>::value,
int > >
4482inline void concat_into(OutStringType& out, Arg&& arg, Args&& ... rest)
4484 out += std::forward<Arg>(arg);
4485 concat_into(out, std::forward<Args>(rest)...);
4488template <
typename OutStringType,
typename Arg,
typename... Args,
4489 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4490 && !detect_string_can_append_op<OutStringType, Arg>::value
4491 && detect_string_can_append_iter<OutStringType, Arg>::value,
int > >
4492inline void concat_into(OutStringType& out,
const Arg& arg, Args&& ... rest)
4494 out.append(arg.begin(), arg.end());
4495 concat_into(out, std::forward<Args>(rest)...);
4498template <
typename OutStringType,
typename Arg,
typename... Args,
4499 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4500 && !detect_string_can_append_op<OutStringType, Arg>::value
4501 && !detect_string_can_append_iter<OutStringType, Arg>::value
4502 && detect_string_can_append_data<OutStringType, Arg>::value,
int > >
4503inline void concat_into(OutStringType& out,
const Arg& arg, Args&& ... rest)
4505 out.append(arg.data(), arg.size());
4506 concat_into(out, std::forward<Args>(rest)...);
4509template<
typename OutStringType = std::string,
typename... Args>
4510inline OutStringType concat(Args && ... args)
4513 str.reserve(concat_length(args...));
4514 concat_into(str, std::forward<Args>(args)...);
4519NLOHMANN_JSON_NAMESPACE_END
4529#if defined(__clang__)
4530 #pragma clang diagnostic push
4531 #pragma clang diagnostic ignored "-Wweak-vtables"
4534NLOHMANN_JSON_NAMESPACE_BEGIN
4548 const char*
what() const noexcept
override
4557 JSON_HEDLEY_NON_NULL(3)
4558 exception(
int id_, const
char* what_arg) :
id(id_), m(what_arg) {}
4560 static std::string name(
const std::string& ename,
int id_)
4562 return concat(
"[json.exception.", ename,
'.', std::to_string(id_),
"] ");
4565 static std::string diagnostics(std::nullptr_t )
4570 template<
typename BasicJsonType>
4571 static std::string diagnostics(
const BasicJsonType* leaf_element)
4574 std::vector<std::string> tokens;
4575 for (
const auto* current = leaf_element; current !=
nullptr && current->m_parent !=
nullptr; current = current->m_parent)
4577 switch (current->m_parent->type())
4581 for (std::size_t i = 0; i < current->m_parent->m_data.m_value.array->size(); ++i)
4583 if (¤t->m_parent->m_data.m_value.array->operator[](i) == current)
4585 tokens.emplace_back(std::to_string(i));
4594 for (
const auto& element : *current->m_parent->m_data.m_value.
object)
4596 if (&element.second == current)
4598 tokens.emplace_back(element.first.c_str());
4623 auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
4624 [](
const std::string & a,
const std::string & b)
4626 return concat(a,
'/', detail::escape(b));
4629 return concat(
'(', str,
") ", get_byte_positions(leaf_element));
4631 return get_byte_positions(leaf_element);
4637 std::runtime_error m;
4638#if JSON_DIAGNOSTIC_POSITIONS
4639 template<
typename BasicJsonType>
4640 static std::string get_byte_positions(
const BasicJsonType* leaf_element)
4642 if ((leaf_element->start_pos() != std::string::npos) && (leaf_element->end_pos() != std::string::npos))
4644 return concat(
"(bytes ", std::to_string(leaf_element->start_pos()),
"-", std::to_string(leaf_element->end_pos()),
") ");
4649 template<
typename BasicJsonType>
4650 static std::string get_byte_positions(
const BasicJsonType* leaf_element)
4652 static_cast<void>(leaf_element);
4672 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4675 const std::string w = concat(exception::name(
"parse_error", id_),
"parse error",
4676 position_string(pos),
": ", exception::diagnostics(context), what_arg);
4680 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4681 static parse_error create(
int id_, std::size_t byte_,
const std::string& what_arg, BasicJsonContext context)
4683 const std::string w = concat(exception::name(
"parse_error", id_),
"parse error",
4684 (byte_ != 0 ? (concat(
" at byte ", std::to_string(byte_))) :
""),
4685 ": ",
exception::diagnostics(context), what_arg);
4686 return {id_, byte_, w.c_str()};
4701 parse_error(
int id_, std::size_t byte_,
const char* what_arg)
4704 static std::string position_string(
const position_t& pos)
4706 return concat(
" at line ", std::to_string(pos.
lines_read + 1),
4716 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4717 static invalid_iterator create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4719 const std::string w = concat(exception::name(
"invalid_iterator", id_), exception::diagnostics(context), what_arg);
4720 return {id_, w.c_str()};
4724 JSON_HEDLEY_NON_NULL(3)
4734 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4735 static type_error create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4737 const std::string w = concat(exception::name(
"type_error", id_), exception::diagnostics(context), what_arg);
4738 return {id_, w.c_str()};
4742 JSON_HEDLEY_NON_NULL(3)
4751 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4752 static out_of_range create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4754 const std::string w = concat(exception::name(
"out_of_range", id_), exception::diagnostics(context), what_arg);
4755 return {id_, w.c_str()};
4759 JSON_HEDLEY_NON_NULL(3)
4768 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4769 static other_error create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4771 const std::string w = concat(exception::name(
"other_error", id_), exception::diagnostics(context), what_arg);
4772 return {id_, w.c_str()};
4776 JSON_HEDLEY_NON_NULL(3)
4781NLOHMANN_JSON_NAMESPACE_END
4783#if defined(__clang__)
4784 #pragma clang diagnostic pop
4805NLOHMANN_JSON_NAMESPACE_BEGIN
4810template <
class T>
struct identity_tag {};
4813NLOHMANN_JSON_NAMESPACE_END
4829#if JSON_HAS_EXPERIMENTAL_FILESYSTEM
4830#include <experimental/filesystem>
4831NLOHMANN_JSON_NAMESPACE_BEGIN
4834namespace std_fs = std::experimental::filesystem;
4836NLOHMANN_JSON_NAMESPACE_END
4837#elif JSON_HAS_FILESYSTEM
4838#include <filesystem>
4839NLOHMANN_JSON_NAMESPACE_BEGIN
4842namespace std_fs = std::filesystem;
4844NLOHMANN_JSON_NAMESPACE_END
4855#ifdef JSON_HAS_CPP_17
4859#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
4860 #include <string_view>
4863NLOHMANN_JSON_NAMESPACE_BEGIN
4867template<
typename BasicJsonType>
4868inline void from_json(
const BasicJsonType& j,
typename std::nullptr_t& n)
4870 if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
4872 JSON_THROW(type_error::create(302, concat(
"type must be null, but is ", j.type_name()), &j));
4877#ifdef JSON_HAS_CPP_17
4878template<
typename BasicJsonType,
typename T>
4879void from_json(
const BasicJsonType& j, std::optional<T>& opt)
4887 opt.emplace(j.template get<T>());
4893template <
typename BasicJsonType,
typename ArithmeticType,
4894 enable_if_t < std::is_arithmetic<ArithmeticType>::value&&
4895 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4897void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val)
4899 switch (
static_cast<value_t>(j))
4903 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4908 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4913 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4925 JSON_THROW(type_error::create(302, concat(
"type must be number, but is ", j.type_name()), &j));
4929template<
typename BasicJsonType>
4930inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::boolean_t& b)
4932 if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
4934 JSON_THROW(type_error::create(302, concat(
"type must be boolean, but is ", j.type_name()), &j));
4936 b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
4939template<
typename BasicJsonType>
4940inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::string_t& s)
4942 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
4944 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
4946 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4950 typename BasicJsonType,
typename StringType,
4952 std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value
4953 && is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value
4954 && !std::is_same<typename BasicJsonType::string_t, StringType>::value
4955 && !is_json_ref<StringType>::value,
int > = 0 >
4956inline void from_json(
const BasicJsonType& j, StringType& s)
4958 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
4960 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
4963 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4966template<
typename BasicJsonType>
4967inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_float_t& val)
4969 get_arithmetic_value(j, val);
4972template<
typename BasicJsonType>
4973inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_unsigned_t& val)
4975 get_arithmetic_value(j, val);
4978template<
typename BasicJsonType>
4979inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_integer_t& val)
4981 get_arithmetic_value(j, val);
4984#if !JSON_DISABLE_ENUM_SERIALIZATION
4985template<
typename BasicJsonType,
typename EnumType,
4986 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
4987inline void from_json(
const BasicJsonType& j, EnumType& e)
4989 typename std::underlying_type<EnumType>::type val;
4990 get_arithmetic_value(j, val);
4991 e =
static_cast<EnumType
>(val);
4996template<
typename BasicJsonType,
typename T,
typename Allocator,
4997 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4998inline void from_json(
const BasicJsonType& j, std::forward_list<T, Allocator>& l)
5000 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5002 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5005 std::transform(j.rbegin(), j.rend(),
5006 std::front_inserter(l), [](
const BasicJsonType & i)
5008 return i.template get<T>();
5013template<
typename BasicJsonType,
typename T,
5014 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
5015inline void from_json(
const BasicJsonType& j, std::valarray<T>& l)
5017 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5019 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5022 std::transform(j.begin(), j.end(), std::begin(l),
5023 [](
const BasicJsonType & elem)
5025 return elem.template get<T>();
5029template<
typename BasicJsonType,
typename T, std::
size_t N>
5030auto from_json(
const BasicJsonType& j, T (&arr)[N])
5031->
decltype(j.template get<T>(), void())
5033 for (std::size_t i = 0; i < N; ++i)
5035 arr[i] = j.at(i).template get<T>();
5039template<
typename BasicJsonType,
typename T, std::
size_t N1, std::
size_t N2>
5040auto from_json(
const BasicJsonType& j, T (&arr)[N1][N2])
5041->
decltype(j.template get<T>(), void())
5043 for (std::size_t i1 = 0; i1 < N1; ++i1)
5045 for (std::size_t i2 = 0; i2 < N2; ++i2)
5047 arr[i1][i2] = j.at(i1).at(i2).template get<T>();
5052template<
typename BasicJsonType,
typename T, std::
size_t N1, std::
size_t N2, std::
size_t N3>
5053auto from_json(
const BasicJsonType& j, T (&arr)[N1][N2][N3])
5054->
decltype(j.template get<T>(), void())
5056 for (std::size_t i1 = 0; i1 < N1; ++i1)
5058 for (std::size_t i2 = 0; i2 < N2; ++i2)
5060 for (std::size_t i3 = 0; i3 < N3; ++i3)
5062 arr[i1][i2][i3] = j.at(i1).at(i2).at(i3).template get<T>();
5068template<
typename BasicJsonType,
typename T, std::
size_t N1, std::
size_t N2, std::
size_t N3, std::
size_t N4>
5069auto from_json(
const BasicJsonType& j, T (&arr)[N1][N2][N3][N4])
5070->
decltype(j.template get<T>(), void())
5072 for (std::size_t i1 = 0; i1 < N1; ++i1)
5074 for (std::size_t i2 = 0; i2 < N2; ++i2)
5076 for (std::size_t i3 = 0; i3 < N3; ++i3)
5078 for (std::size_t i4 = 0; i4 < N4; ++i4)
5080 arr[i1][i2][i3][i4] = j.at(i1).at(i2).at(i3).at(i4).template get<T>();
5087template<
typename BasicJsonType>
5088inline void from_json_array_impl(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr, priority_tag<3> )
5090 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
5093template<
typename BasicJsonType,
typename T, std::
size_t N>
5094auto from_json_array_impl(
const BasicJsonType& j, std::array<T, N>& arr,
5096->
decltype(j.template get<T>(), void())
5098 for (std::size_t i = 0; i < N; ++i)
5100 arr[i] = j.at(i).template get<T>();
5104template<
typename BasicJsonType,
typename ConstructibleArrayType,
5106 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
5108auto from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> )
5110 arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
5111 j.template get<typename ConstructibleArrayType::value_type>(),
5116 ConstructibleArrayType ret;
5117 ret.reserve(j.size());
5118 std::transform(j.begin(), j.end(),
5119 std::inserter(ret, end(ret)), [](
const BasicJsonType & i)
5123 return i.template get<typename ConstructibleArrayType::value_type>();
5125 arr = std::move(ret);
5128template<
typename BasicJsonType,
typename ConstructibleArrayType,
5130 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
5132inline void from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
5137 ConstructibleArrayType ret;
5139 j.begin(), j.end(), std::inserter(ret, end(ret)),
5140 [](
const BasicJsonType & i)
5144 return i.template get<typename ConstructibleArrayType::value_type>();
5146 arr = std::move(ret);
5149template <
typename BasicJsonType,
typename ConstructibleArrayType,
5151 is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&&
5152 !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&&
5153 !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
5154 !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&&
5155 !is_basic_json<ConstructibleArrayType>::value,
5157auto from_json(
const BasicJsonType& j, ConstructibleArrayType& arr)
5158->
decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
5159j.template get<typename ConstructibleArrayType::value_type>(),
5162 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5164 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5167 from_json_array_impl(j, arr, priority_tag<3> {});
5170template <
typename BasicJsonType,
typename T, std::size_t... Idx >
5171std::array<T,
sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j,
5172 identity_tag<std::array<T,
sizeof...(Idx)>> , index_sequence<Idx...> )
5174 return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
5177template <
typename BasicJsonType,
typename T, std::
size_t N >
5178auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag)
5179->
decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}))
5181 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5183 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5186 return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {});
5189template<
typename BasicJsonType>
5190inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::binary_t& bin)
5192 if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
5194 JSON_THROW(type_error::create(302, concat(
"type must be binary, but is ", j.type_name()), &j));
5197 bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
5200template<
typename BasicJsonType,
typename ConstructibleObjectType,
5201 enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value,
int> = 0>
5202inline void from_json(
const BasicJsonType& j, ConstructibleObjectType& obj)
5204 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
5206 JSON_THROW(type_error::create(302, concat(
"type must be object, but is ", j.type_name()), &j));
5209 ConstructibleObjectType ret;
5210 const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
5211 using value_type =
typename ConstructibleObjectType::value_type;
5213 inner_object->begin(), inner_object->end(),
5214 std::inserter(ret, ret.begin()),
5215 [](
typename BasicJsonType::object_t::value_type
const & p)
5217 return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
5219 obj = std::move(ret);
5226template <
typename BasicJsonType,
typename ArithmeticType,
5228 std::is_arithmetic<ArithmeticType>::value&&
5229 !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&&
5230 !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&&
5231 !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&&
5232 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
5234inline void from_json(
const BasicJsonType& j, ArithmeticType& val)
5236 switch (
static_cast<value_t>(j))
5240 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
5245 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
5250 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
5255 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
5266 JSON_THROW(type_error::create(302, concat(
"type must be number, but is ", j.type_name()), &j));
5270template<
typename BasicJsonType,
typename... Args, std::size_t... Idx>
5271std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<Idx...> )
5273 return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).
template get<Args>()...);
5276template<
typename BasicJsonType>
5277std::tuple<> from_json_tuple_impl_base(BasicJsonType& , index_sequence<> )
5282template <
typename BasicJsonType,
class A1,
class A2 >
5283std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> , priority_tag<0> )
5285 return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
5286 std::forward<BasicJsonType>(j).at(1).template get<A2>()};
5289template<
typename BasicJsonType,
typename A1,
typename A2>
5290inline void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> )
5292 p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {});
5295template<
typename BasicJsonType,
typename... Args>
5296std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> , priority_tag<2> )
5298 return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
5301template<
typename BasicJsonType,
typename... Args>
5302inline void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> )
5304 t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
5307template<
typename BasicJsonType,
typename TupleRelated>
5308auto from_json(BasicJsonType&& j, TupleRelated&& t)
5309->
decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}))
5311 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5313 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5316 return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {});
5319template <
typename BasicJsonType,
typename Key,
typename Value,
typename Compare,
typename Allocator,
5320 typename = enable_if_t < !std::is_constructible <
5321 typename BasicJsonType::string_t, Key >::value >>
5322inline void from_json(
const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
5324 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5326 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5329 for (
const auto& p : j)
5331 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
5333 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", p.type_name()), &j));
5335 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
5339template <
typename BasicJsonType,
typename Key,
typename Value,
typename Hash,
typename KeyEqual,
typename Allocator,
5340 typename = enable_if_t < !std::is_constructible <
5341 typename BasicJsonType::string_t, Key >::value >>
5342inline void from_json(
const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
5344 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5346 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5349 for (
const auto& p : j)
5351 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
5353 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", p.type_name()), &j));
5355 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
5359#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
5360template<
typename BasicJsonType>
5361inline void from_json(
const BasicJsonType& j, std_fs::path& p)
5363 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
5365 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
5367 const auto& s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
5371#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L)
5372 p = std_fs::path(std::u8string_view(
reinterpret_cast<const char8_t*
>(s.data()), s.size()));
5374 p = std_fs::u8path(s);
5381 template<
typename BasicJsonType,
typename T>
5382 auto operator()(
const BasicJsonType& j, T&& val)
const
5383 noexcept(
noexcept(from_json(j, std::forward<T>(val))))
5384 ->
decltype(from_json(j, std::forward<T>(val)))
5386 return from_json(j, std::forward<T>(val));
5392#ifndef JSON_HAS_CPP_17
5399JSON_INLINE_VARIABLE
constexpr const auto& from_json =
5401#ifndef JSON_HAS_CPP_17
5405NLOHMANN_JSON_NAMESPACE_END
5420#ifdef JSON_HAS_CPP_17
5429#include <type_traits>
5475NLOHMANN_JSON_NAMESPACE_BEGIN
5479template<
typename StringType>
5480void int_to_string(StringType& target, std::size_t value)
5483 using std::to_string;
5484 target = to_string(value);
5487template<
typename StringType>
5488StringType to_string(std::size_t value)
5491 int_to_string(result, value);
5496NLOHMANN_JSON_NAMESPACE_END
5501NLOHMANN_JSON_NAMESPACE_BEGIN
5508 using difference_type = std::ptrdiff_t;
5512 using iterator_category = std::forward_iterator_tag;
5513 using string_type =
typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().
key() ) >::type >::type;
5517 IteratorType anchor{};
5519 std::size_t array_index = 0;
5521 mutable std::size_t array_index_last = 0;
5523 mutable string_type array_index_str =
"0";
5525 string_type empty_str{};
5530 noexcept(std::is_nothrow_move_constructible<IteratorType>::value
5531 && std::is_nothrow_default_constructible<string_type>::value)
5532 : anchor(std::move(it))
5533 , array_index(array_index_)
5540 noexcept(std::is_nothrow_move_constructible<IteratorType>::value
5541 && std::is_nothrow_move_constructible<string_type>::value) =
default;
5543 noexcept(std::is_nothrow_move_assignable<IteratorType>::value
5544 && std::is_nothrow_move_assignable<string_type>::value) =
default;
5573 return anchor == o.anchor;
5579 return anchor != o.anchor;
5583 const string_type&
key()
const
5585 JSON_ASSERT(anchor.m_object !=
nullptr);
5587 switch (anchor.m_object->type())
5592 if (array_index != array_index_last)
5594 int_to_string( array_index_str, array_index );
5595 array_index_last = array_index;
5597 return array_index_str;
5602 return anchor.key();
5619 typename IteratorType::reference
value()
const
5621 return anchor.value();
5630 typename IteratorType::pointer container =
nullptr;
5637 : container(&cont) {}
5661template<std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
5662auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.key())
5669template<std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
5670auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.value())
5676NLOHMANN_JSON_NAMESPACE_END
5685#if defined(__clang__)
5687 #pragma clang diagnostic push
5688 #pragma clang diagnostic ignored "-Wmismatched-tags"
5690template<
typename IteratorType>
5691class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
5692 :
public std::integral_constant<std::size_t, 2> {};
5694template<std::
size_t N,
typename IteratorType>
5695class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
5698 using type =
decltype(
5699 get<N>(std::declval <
5700 ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));
5702#if defined(__clang__)
5703 #pragma clang diagnostic pop
5709 template <
typename IteratorType>
5710 inline constexpr bool ::std::ranges::enable_borrowed_range<::nlohmann::detail::iteration_proxy<IteratorType>> =
true;
5722NLOHMANN_JSON_NAMESPACE_BEGIN
5742 template<
typename BasicJsonType>
5743 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t b)
noexcept
5745 j.m_data.m_value.destroy(j.m_data.m_type);
5747 j.m_data.m_value = b;
5748 j.assert_invariant();
5755 template<
typename BasicJsonType>
5756 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t& s)
5758 j.m_data.m_value.destroy(j.m_data.m_type);
5760 j.m_data.m_value = s;
5761 j.assert_invariant();
5764 template<
typename BasicJsonType>
5765 static void construct(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
5767 j.m_data.m_value.destroy(j.m_data.m_type);
5769 j.m_data.m_value = std::move(s);
5770 j.assert_invariant();
5773 template <
typename BasicJsonType,
typename CompatibleStringType,
5774 enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
5776 static void construct(BasicJsonType& j,
const CompatibleStringType& str)
5778 j.m_data.m_value.destroy(j.m_data.m_type);
5780 j.m_data.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
5781 j.assert_invariant();
5788 template<
typename BasicJsonType>
5789 static void construct(BasicJsonType& j,
const typename BasicJsonType::binary_t& b)
5791 j.m_data.m_value.destroy(j.m_data.m_type);
5793 j.m_data.m_value =
typename BasicJsonType::binary_t(b);
5794 j.assert_invariant();
5797 template<
typename BasicJsonType>
5798 static void construct(BasicJsonType& j,
typename BasicJsonType::binary_t&& b)
5800 j.m_data.m_value.destroy(j.m_data.m_type);
5802 j.m_data.m_value =
typename BasicJsonType::binary_t(std::move(b));
5803 j.assert_invariant();
5810 template<
typename BasicJsonType>
5811 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val)
noexcept
5813 j.m_data.m_value.destroy(j.m_data.m_type);
5815 j.m_data.m_value = val;
5816 j.assert_invariant();
5823 template<
typename BasicJsonType>
5824 static void construct(BasicJsonType& j,
typename BasicJsonType::number_unsigned_t val)
noexcept
5826 j.m_data.m_value.destroy(j.m_data.m_type);
5828 j.m_data.m_value = val;
5829 j.assert_invariant();
5836 template<
typename BasicJsonType>
5837 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val)
noexcept
5839 j.m_data.m_value.destroy(j.m_data.m_type);
5841 j.m_data.m_value = val;
5842 j.assert_invariant();
5849 template<
typename BasicJsonType>
5850 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
5852 j.m_data.m_value.destroy(j.m_data.m_type);
5854 j.m_data.m_value = arr;
5856 j.assert_invariant();
5859 template<
typename BasicJsonType>
5860 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
5862 j.m_data.m_value.destroy(j.m_data.m_type);
5864 j.m_data.m_value = std::move(arr);
5866 j.assert_invariant();
5869 template <
typename BasicJsonType,
typename CompatibleArrayType,
5870 enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
5872 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
5877 j.m_data.m_value.destroy(j.m_data.m_type);
5879 j.m_data.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
5881 j.assert_invariant();
5884 template<
typename BasicJsonType>
5885 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
5887 j.m_data.m_value.destroy(j.m_data.m_type);
5890 j.m_data.m_value.array->reserve(arr.size());
5891 for (
const bool x : arr)
5893 j.m_data.m_value.array->push_back(x);
5894 j.set_parent(j.m_data.m_value.array->back());
5896 j.assert_invariant();
5899 template<
typename BasicJsonType,
typename T,
5900 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
5901 static void construct(BasicJsonType& j,
const std::valarray<T>& arr)
5903 j.m_data.m_value.destroy(j.m_data.m_type);
5906 j.m_data.m_value.array->resize(arr.size());
5909 std::copy(std::begin(arr), std::end(arr), j.m_data.m_value.array->begin());
5912 j.assert_invariant();
5919 template<
typename BasicJsonType>
5920 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
5922 j.m_data.m_value.destroy(j.m_data.m_type);
5924 j.m_data.m_value = obj;
5926 j.assert_invariant();
5929 template<
typename BasicJsonType>
5930 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
5932 j.m_data.m_value.destroy(j.m_data.m_type);
5934 j.m_data.m_value = std::move(obj);
5936 j.assert_invariant();
5939 template <
typename BasicJsonType,
typename CompatibleObjectType,
5940 enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
int > = 0 >
5941 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
5946 j.m_data.m_value.destroy(j.m_data.m_type);
5948 j.m_data.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
5950 j.assert_invariant();
5958#ifdef JSON_HAS_CPP_17
5959template<
typename BasicJsonType,
typename T,
5960 enable_if_t<std::is_constructible<BasicJsonType, T>::value,
int> = 0>
5961void to_json(BasicJsonType& j,
const std::optional<T>& opt)
noexcept
5963 if (opt.has_value())
5974template<
typename BasicJsonType,
typename T,
5975 enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value,
int> = 0>
5976inline void to_json(BasicJsonType& j, T b)
noexcept
5978 external_constructor<value_t::boolean>::construct(j, b);
5981template <
typename BasicJsonType,
typename BoolRef,
5983 ((std::is_same<std::vector<bool>::reference, BoolRef>::value
5984 && !std::is_same <std::vector<bool>::reference,
typename BasicJsonType::boolean_t&>::value)
5985 || (std::is_same<std::vector<bool>::const_reference, BoolRef>::value
5986 && !std::is_same <detail::uncvref_t<std::vector<bool>::const_reference>,
5987 typename BasicJsonType::boolean_t >::value))
5988 && std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value,
int > = 0 >
5989inline void to_json(BasicJsonType& j,
const BoolRef& b)
noexcept
5991 external_constructor<value_t::boolean>::construct(j,
static_cast<typename BasicJsonType::boolean_t
>(b));
5994template<
typename BasicJsonType,
typename CompatibleString,
5995 enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value,
int> = 0>
5996inline void to_json(BasicJsonType& j,
const CompatibleString& s)
5998 external_constructor<value_t::string>::construct(j, s);
6001template<
typename BasicJsonType>
6002inline void to_json(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
6004 external_constructor<value_t::string>::construct(j, std::move(s));
6007template<
typename BasicJsonType,
typename FloatType,
6008 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
6009inline void to_json(BasicJsonType& j, FloatType val)
noexcept
6011 external_constructor<value_t::number_float>::construct(j,
static_cast<typename BasicJsonType::number_float_t
>(val));
6014template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
6015 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value,
int> = 0>
6016inline void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val)
noexcept
6018 external_constructor<value_t::number_unsigned>::construct(j,
static_cast<typename BasicJsonType::number_unsigned_t
>(val));
6021template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
6022 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value,
int> = 0>
6023inline void to_json(BasicJsonType& j, CompatibleNumberIntegerType val)
noexcept
6025 external_constructor<value_t::number_integer>::construct(j,
static_cast<typename BasicJsonType::number_integer_t
>(val));
6028#if !JSON_DISABLE_ENUM_SERIALIZATION
6029template<
typename BasicJsonType,
typename EnumType,
6030 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
6031inline void to_json(BasicJsonType& j, EnumType e)
noexcept
6033 using underlying_type =
typename std::underlying_type<EnumType>::type;
6035 external_constructor<integral_value_t>::construct(j,
static_cast<underlying_type
>(e));
6039template<
typename BasicJsonType>
6040inline void to_json(BasicJsonType& j,
const std::vector<bool>& e)
6042 external_constructor<value_t::array>::construct(j, e);
6045template <
typename BasicJsonType,
typename CompatibleArrayType,
6046 enable_if_t < is_compatible_array_type<BasicJsonType,
6047 CompatibleArrayType>::value&&
6048 !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&&
6049 !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&&
6050 !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
6051 !is_basic_json<CompatibleArrayType>::value,
6053inline void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
6055 external_constructor<value_t::array>::construct(j, arr);
6058template<
typename BasicJsonType>
6059inline void to_json(BasicJsonType& j,
const typename BasicJsonType::binary_t& bin)
6061 external_constructor<value_t::binary>::construct(j, bin);
6064template<
typename BasicJsonType,
typename T,
6065 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
6066inline void to_json(BasicJsonType& j,
const std::valarray<T>& arr)
6068 external_constructor<value_t::array>::construct(j, std::move(arr));
6071template<
typename BasicJsonType>
6072inline void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
6074 external_constructor<value_t::array>::construct(j, std::move(arr));
6077template <
typename BasicJsonType,
typename CompatibleObjectType,
6078 enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value,
int > = 0 >
6079inline void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
6081 external_constructor<value_t::object>::construct(j, obj);
6084template<
typename BasicJsonType>
6085inline void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
6087 external_constructor<value_t::object>::construct(j, std::move(obj));
6091 typename BasicJsonType,
typename T, std::size_t N,
6092 enable_if_t < !std::is_constructible<
typename BasicJsonType::string_t,
6093 const T(&)[N]>::value,
6095inline void to_json(BasicJsonType& j,
const T(&arr)[N])
6097 external_constructor<value_t::array>::construct(j, arr);
6100template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value,
int > = 0 >
6101inline void to_json(BasicJsonType& j,
const std::pair<T1, T2>& p)
6103 j = { p.first, p.second };
6107template<
typename BasicJsonType,
typename T,
6108 enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value,
int> = 0>
6109inline void to_json(BasicJsonType& j,
const T& b)
6111 j = { {b.key(), b.value()} };
6114template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
6115inline void to_json_tuple_impl(BasicJsonType& j,
const Tuple& t, index_sequence<Idx...> )
6117 j = { std::get<Idx>(t)... };
6120template<
typename BasicJsonType,
typename Tuple>
6121inline void to_json_tuple_impl(BasicJsonType& j,
const Tuple& , index_sequence<> )
6123 using array_t =
typename BasicJsonType::array_t;
6127template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value,
int > = 0>
6128inline void to_json(BasicJsonType& j,
const T& t)
6130 to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
6133#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
6134#if defined(__cpp_lib_char8_t)
6135template<
typename BasicJsonType,
typename Tr,
typename Allocator>
6136inline void to_json(BasicJsonType& j,
const std::basic_string<char8_t, Tr, Allocator>& s)
6138 using OtherAllocator =
typename std::allocator_traits<Allocator>::template rebind_alloc<char>;
6139 j = std::basic_string<char, std::char_traits<char>, OtherAllocator>(s.begin(), s.end(), s.get_allocator());
6143template<
typename BasicJsonType>
6144inline void to_json(BasicJsonType& j,
const std_fs::path& p)
6154 template<
typename BasicJsonType,
typename T>
6155 auto operator()(BasicJsonType& j, T&& val)
const noexcept(
noexcept(to_json(j, std::forward<T>(val))))
6156 ->
decltype(to_json(j, std::forward<T>(val)), void())
6158 return to_json(j, std::forward<T>(val));
6163#ifndef JSON_HAS_CPP_17
6170JSON_INLINE_VARIABLE
constexpr const auto& to_json =
6172#ifndef JSON_HAS_CPP_17
6176NLOHMANN_JSON_NAMESPACE_END
6181NLOHMANN_JSON_NAMESPACE_BEGIN
6184template<
typename ValueType,
typename>
6189 template<
typename BasicJsonType,
typename TargetType = ValueType>
6190 static auto from_json(BasicJsonType && j, TargetType& val)
noexcept(
6191 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
6192 ->
decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
6194 ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
6199 template<
typename BasicJsonType,
typename TargetType = ValueType>
6201 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
6202 ->
decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
6204 return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
6209 template<
typename BasicJsonType,
typename TargetType = ValueType>
6210 static auto to_json(BasicJsonType& j, TargetType && val)
noexcept(
6211 noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
6212 ->
decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
6214 ::nlohmann::to_json(j, std::forward<TargetType>(val));
6218NLOHMANN_JSON_NAMESPACE_END
6238NLOHMANN_JSON_NAMESPACE_BEGIN
6242template<
typename BinaryType>
6246 using container_type = BinaryType;
6247 using subtype_type = std::uint64_t;
6261 : container_type(std::move(b))
6267 , m_subtype(subtype_)
6268 , m_has_subtype(
true)
6273 : container_type(std::move(b))
6274 , m_subtype(subtype_)
6275 , m_has_subtype(
true)
6280 return std::tie(
static_cast<const BinaryType&
>(*
this), m_subtype, m_has_subtype) ==
6281 std::tie(
static_cast<const BinaryType&
>(rhs), rhs.m_subtype, rhs.m_has_subtype);
6286 return !(rhs == *
this);
6293 m_subtype = subtype_;
6294 m_has_subtype =
true;
6301 return m_has_subtype ? m_subtype :
static_cast<subtype_type
>(-1);
6308 return m_has_subtype;
6316 m_has_subtype =
false;
6320 subtype_type m_subtype = 0;
6321 bool m_has_subtype =
false;
6324NLOHMANN_JSON_NAMESPACE_END
6345#include <functional>
6352NLOHMANN_JSON_NAMESPACE_BEGIN
6357inline std::size_t combine(std::size_t seed, std::size_t h)
noexcept
6359 seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
6374template<
typename BasicJsonType>
6375std::size_t hash(
const BasicJsonType& j)
6377 using string_t =
typename BasicJsonType::string_t;
6378 using number_integer_t =
typename BasicJsonType::number_integer_t;
6379 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6380 using number_float_t =
typename BasicJsonType::number_float_t;
6382 const auto type =
static_cast<std::size_t
>(j.type());
6385 case BasicJsonType::value_t::null:
6386 case BasicJsonType::value_t::discarded:
6388 return combine(type, 0);
6391 case BasicJsonType::value_t::object:
6393 auto seed = combine(type, j.size());
6394 for (
const auto& element : j.items())
6396 const auto h = std::hash<string_t> {}(element.key());
6397 seed = combine(seed, h);
6398 seed = combine(seed, hash(element.value()));
6403 case BasicJsonType::value_t::array:
6405 auto seed = combine(type, j.size());
6406 for (
const auto& element : j)
6408 seed = combine(seed, hash(element));
6413 case BasicJsonType::value_t::string:
6415 const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
6416 return combine(type, h);
6419 case BasicJsonType::value_t::boolean:
6421 const auto h = std::hash<bool> {}(j.template get<bool>());
6422 return combine(type, h);
6425 case BasicJsonType::value_t::number_integer:
6427 const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
6428 return combine(type, h);
6431 case BasicJsonType::value_t::number_unsigned:
6433 const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
6434 return combine(type, h);
6437 case BasicJsonType::value_t::number_float:
6439 const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
6440 return combine(type, h);
6443 case BasicJsonType::value_t::binary:
6445 auto seed = combine(type, j.get_binary().size());
6446 const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
6447 seed = combine(seed, h);
6448 seed = combine(seed,
static_cast<std::size_t
>(j.get_binary().subtype()));
6449 for (
const auto byte : j.get_binary())
6451 seed = combine(seed, std::hash<std::uint8_t> {}(byte));
6463NLOHMANN_JSON_NAMESPACE_END
6488#ifdef __cpp_lib_byteswap
6513#include <type_traits>
6530NLOHMANN_JSON_NAMESPACE_BEGIN
6535enum class input_format_t {
json, cbor, msgpack, ubjson, bson, bjdata };
6546class file_input_adapter
6549 using char_type = char;
6551 JSON_HEDLEY_NON_NULL(2)
6552 explicit file_input_adapter(std::FILE* f) noexcept
6555 JSON_ASSERT(m_file !=
nullptr);
6559 file_input_adapter(
const file_input_adapter&) =
delete;
6560 file_input_adapter(file_input_adapter&&) noexcept = default;
6561 file_input_adapter& operator=(const file_input_adapter&) = delete;
6562 file_input_adapter& operator=(file_input_adapter&&) = delete;
6563 ~file_input_adapter() = default;
6565 std::char_traits<
char>::int_type get_character() noexcept
6567 return std::fgetc(m_file);
6572 std::size_t get_elements(T* dest, std::size_t count = 1)
6574 return fread(dest, 1,
sizeof(T) * count, m_file);
6591class input_stream_adapter
6594 using char_type = char;
6596 ~input_stream_adapter()
6602 is->clear(is->rdstate() & std::ios::eofbit);
6606 explicit input_stream_adapter(std::istream& i)
6607 : is(&i), sb(i.rdbuf())
6611 input_stream_adapter(
const input_stream_adapter&) =
delete;
6612 input_stream_adapter& operator=(input_stream_adapter&) =
delete;
6613 input_stream_adapter& operator=(input_stream_adapter&&) =
delete;
6615 input_stream_adapter(input_stream_adapter&& rhs) noexcept
6616 : is(rhs.is), sb(rhs.sb)
6625 std::char_traits<char>::int_type get_character()
6627 auto res = sb->sbumpc();
6629 if (JSON_HEDLEY_UNLIKELY(res == std::char_traits<char>::eof()))
6631 is->clear(is->rdstate() | std::ios::eofbit);
6637 std::size_t get_elements(T* dest, std::size_t count = 1)
6639 auto res =
static_cast<std::size_t
>(sb->sgetn(
reinterpret_cast<char*
>(dest),
static_cast<std::streamsize
>(count *
sizeof(T))));
6640 if (JSON_HEDLEY_UNLIKELY(res < count *
sizeof(T)))
6642 is->clear(is->rdstate() | std::ios::eofbit);
6649 std::istream* is =
nullptr;
6650 std::streambuf* sb =
nullptr;
6656template<
typename IteratorType>
6657class iterator_input_adapter
6660 using char_type =
typename std::iterator_traits<IteratorType>::value_type;
6662 iterator_input_adapter(IteratorType first, IteratorType last)
6663 : current(std::move(first)), end(std::move(last))
6666 typename char_traits<char_type>::int_type get_character()
6668 if (JSON_HEDLEY_LIKELY(current != end))
6670 auto result = char_traits<char_type>::to_int_type(*current);
6671 std::advance(current, 1);
6675 return char_traits<char_type>::eof();
6680 std::size_t get_elements(T* dest, std::size_t count = 1)
6682 auto* ptr =
reinterpret_cast<char*
>(dest);
6683 for (std::size_t read_index = 0; read_index < count *
sizeof(T); ++read_index)
6685 if (JSON_HEDLEY_LIKELY(current != end))
6687 ptr[read_index] =
static_cast<char>(*current);
6688 std::advance(current, 1);
6695 return count *
sizeof(T);
6699 IteratorType current;
6702 template<
typename BaseInputAdapter,
size_t T>
6703 friend struct wide_string_input_helper;
6707 return current == end;
6711template<
typename BaseInputAdapter,
size_t T>
6712struct wide_string_input_helper;
6714template<
typename BaseInputAdapter>
6715struct wide_string_input_helper<BaseInputAdapter, 4>
6718 static void fill_buffer(BaseInputAdapter& input,
6719 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
6720 size_t& utf8_bytes_index,
6721 size_t& utf8_bytes_filled)
6723 utf8_bytes_index = 0;
6725 if (JSON_HEDLEY_UNLIKELY(input.empty()))
6727 utf8_bytes[0] = std::char_traits<char>::eof();
6728 utf8_bytes_filled = 1;
6733 const auto wc = input.get_character();
6738 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6739 utf8_bytes_filled = 1;
6741 else if (wc <= 0x7FF)
6743 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
6744 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6745 utf8_bytes_filled = 2;
6747 else if (wc <= 0xFFFF)
6749 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
6750 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6751 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6752 utf8_bytes_filled = 3;
6754 else if (wc <= 0x10FFFF)
6756 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | ((
static_cast<unsigned int>(wc) >> 18u) & 0x07u));
6757 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
6758 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6759 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6760 utf8_bytes_filled = 4;
6765 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6766 utf8_bytes_filled = 1;
6772template<
typename BaseInputAdapter>
6773struct wide_string_input_helper<BaseInputAdapter, 2>
6776 static void fill_buffer(BaseInputAdapter& input,
6777 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
6778 size_t& utf8_bytes_index,
6779 size_t& utf8_bytes_filled)
6781 utf8_bytes_index = 0;
6783 if (JSON_HEDLEY_UNLIKELY(input.empty()))
6785 utf8_bytes[0] = std::char_traits<char>::eof();
6786 utf8_bytes_filled = 1;
6791 const auto wc = input.get_character();
6796 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6797 utf8_bytes_filled = 1;
6799 else if (wc <= 0x7FF)
6801 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u)));
6802 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6803 utf8_bytes_filled = 2;
6805 else if (0xD800 > wc || wc >= 0xE000)
6807 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u)));
6808 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6809 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6810 utf8_bytes_filled = 3;
6814 if (JSON_HEDLEY_UNLIKELY(!input.empty()))
6816 const auto wc2 =
static_cast<unsigned int>(input.get_character());
6817 const auto charcode = 0x10000u + (((
static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
6818 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | (charcode >> 18u));
6819 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 12u) & 0x3Fu));
6820 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 6u) & 0x3Fu));
6821 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (charcode & 0x3Fu));
6822 utf8_bytes_filled = 4;
6826 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6827 utf8_bytes_filled = 1;
6835template<
typename BaseInputAdapter,
typename W
ideCharType>
6836class wide_string_input_adapter
6839 using char_type = char;
6841 wide_string_input_adapter(BaseInputAdapter base)
6842 : base_adapter(base) {}
6844 typename std::char_traits<char>::int_type get_character() noexcept
6847 if (utf8_bytes_index == utf8_bytes_filled)
6849 fill_buffer<sizeof(WideCharType)>();
6851 JSON_ASSERT(utf8_bytes_filled > 0);
6852 JSON_ASSERT(utf8_bytes_index == 0);
6856 JSON_ASSERT(utf8_bytes_filled > 0);
6857 JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);
6858 return utf8_bytes[utf8_bytes_index++];
6863 std::size_t get_elements(T* , std::size_t = 1)
6865 JSON_THROW(
parse_error::create(112, 1,
"wide string type cannot be interpreted as binary data",
nullptr));
6869 BaseInputAdapter base_adapter;
6874 wide_string_input_helper<BaseInputAdapter, T>::fill_buffer(base_adapter, utf8_bytes, utf8_bytes_index, utf8_bytes_filled);
6878 std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
6881 std::size_t utf8_bytes_index = 0;
6883 std::size_t utf8_bytes_filled = 0;
6886template<
typename IteratorType,
typename Enable =
void>
6887struct iterator_input_adapter_factory
6889 using iterator_type = IteratorType;
6890 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
6891 using adapter_type = iterator_input_adapter<iterator_type>;
6893 static adapter_type create(IteratorType first, IteratorType last)
6895 return adapter_type(std::move(first), std::move(last));
6900struct is_iterator_of_multibyte
6902 using value_type =
typename std::iterator_traits<T>::value_type;
6905 value =
sizeof(value_type) > 1
6909template<
typename IteratorType>
6910struct iterator_input_adapter_factory<IteratorType, enable_if_t<is_iterator_of_multibyte<IteratorType>::value>>
6912 using iterator_type = IteratorType;
6913 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
6914 using base_adapter_type = iterator_input_adapter<iterator_type>;
6915 using adapter_type = wide_string_input_adapter<base_adapter_type, char_type>;
6917 static adapter_type create(IteratorType first, IteratorType last)
6919 return adapter_type(base_adapter_type(std::move(first), std::move(last)));
6924template<
typename IteratorType>
6925typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapter(IteratorType first, IteratorType last)
6927 using factory_type = iterator_input_adapter_factory<IteratorType>;
6928 return factory_type::create(first, last);
6935namespace container_input_adapter_factory_impl
6941template<
typename ContainerType,
typename Enable =
void>
6944template<
typename ContainerType>
6946 void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
6948 using adapter_type =
decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
6950 static adapter_type create(
const ContainerType& container)
6952 return input_adapter(begin(container), end(container));
6958template<
typename ContainerType>
6965using string_input_adapter_type =
decltype(input_adapter(std::declval<std::string>()));
6969inline file_input_adapter input_adapter(std::FILE* file)
6971 if (file ==
nullptr)
6973 JSON_THROW(
parse_error::create(101, 0,
"attempting to parse an empty input; check that your input string or stream contains the expected JSON",
nullptr));
6975 return file_input_adapter(file);
6978inline input_stream_adapter input_adapter(std::istream& stream)
6980 return input_stream_adapter(stream);
6983inline input_stream_adapter input_adapter(std::istream&& stream)
6985 return input_stream_adapter(stream);
6989using contiguous_bytes_input_adapter =
decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
6992template <
typename CharT,
6993 typename std::enable_if <
6994 std::is_pointer<CharT>::value&&
6995 !std::is_array<CharT>::value&&
6996 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
6997 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
6999contiguous_bytes_input_adapter input_adapter(CharT b)
7003 JSON_THROW(
parse_error::create(101, 0,
"attempting to parse an empty input; check that your input string or stream contains the expected JSON",
nullptr));
7005 auto length = std::strlen(
reinterpret_cast<const char*
>(b));
7006 const auto* ptr =
reinterpret_cast<const char*
>(b);
7007 return input_adapter(ptr, ptr + length);
7010template<
typename T, std::
size_t N>
7011auto input_adapter(T (&
array)[N]) ->
decltype(input_adapter(
array,
array + N))
7019class span_input_adapter
7022 template <
typename CharT,
7023 typename std::enable_if <
7024 std::is_pointer<CharT>::value&&
7025 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
7026 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
7028 span_input_adapter(CharT b, std::size_t l)
7029 : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {}
7031 template<
class IteratorType,
7032 typename std::enable_if<
7033 std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
7035 span_input_adapter(IteratorType first, IteratorType last)
7036 : ia(input_adapter(first, last)) {}
7038 contiguous_bytes_input_adapter&& get()
7040 return std::move(ia);
7044 contiguous_bytes_input_adapter ia;
7048NLOHMANN_JSON_NAMESPACE_END
7063#include <type_traits>
7085#include <initializer_list>
7099NLOHMANN_JSON_NAMESPACE_BEGIN
7107template<
typename BasicJsonType>
7112 enum class token_type
7134 JSON_HEDLEY_RETURNS_NON_NULL
7136 static const char* token_type_name(
const token_type t)
noexcept
7140 case token_type::uninitialized:
7141 return "<uninitialized>";
7142 case token_type::literal_true:
7143 return "true literal";
7144 case token_type::literal_false:
7145 return "false literal";
7146 case token_type::literal_null:
7147 return "null literal";
7148 case token_type::value_string:
7149 return "string literal";
7150 case token_type::value_unsigned:
7151 case token_type::value_integer:
7152 case token_type::value_float:
7153 return "number literal";
7154 case token_type::begin_array:
7156 case token_type::begin_object:
7158 case token_type::end_array:
7160 case token_type::end_object:
7162 case token_type::name_separator:
7164 case token_type::value_separator:
7166 case token_type::parse_error:
7167 return "<parse error>";
7168 case token_type::end_of_input:
7169 return "end of input";
7170 case token_type::literal_or_value:
7171 return "'[', '{', or a literal";
7174 return "unknown token";
7184template<
typename BasicJsonType,
typename InputAdapterType>
7185class lexer :
public lexer_base<BasicJsonType>
7187 using number_integer_t =
typename BasicJsonType::number_integer_t;
7188 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7189 using number_float_t =
typename BasicJsonType::number_float_t;
7190 using string_t =
typename BasicJsonType::string_t;
7191 using char_type =
typename InputAdapterType::char_type;
7192 using char_int_type =
typename char_traits<char_type>::int_type;
7195 using token_type =
typename lexer_base<BasicJsonType>::token_type;
7197 explicit lexer(InputAdapterType&& adapter,
bool ignore_comments_ =
false) noexcept
7198 : ia(std::move(adapter))
7199 , ignore_comments(ignore_comments_)
7200 , decimal_point_char(static_cast<char_int_type>(get_decimal_point()))
7204 lexer(
const lexer&) =
delete;
7205 lexer(lexer&&) =
default;
7206 lexer& operator=(lexer&) =
delete;
7207 lexer& operator=(lexer&&) =
default;
7217 static char get_decimal_point() noexcept
7219 const auto* loc = localeconv();
7220 JSON_ASSERT(loc !=
nullptr);
7221 return (loc->decimal_point ==
nullptr) ?
'.' : *(loc->decimal_point);
7246 JSON_ASSERT(current ==
'u');
7249 const auto factors = { 12u, 8u, 4u, 0u };
7250 for (
const auto factor : factors)
7254 if (current >=
'0' && current <=
'9')
7256 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x30u) << factor);
7258 else if (current >=
'A' && current <=
'F')
7260 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x37u) << factor);
7262 else if (current >=
'a' && current <=
'f')
7264 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x57u) << factor);
7272 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
7291 bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
7293 JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
7296 for (
auto range = ranges.begin(); range != ranges.end(); ++range)
7299 if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range)))
7305 error_message =
"invalid string: ill-formed UTF-8 byte";
7328 token_type scan_string()
7334 JSON_ASSERT(current ==
'\"');
7342 case char_traits<char_type>::eof():
7344 error_message =
"invalid string: missing closing quote";
7345 return token_type::parse_error;
7351 return token_type::value_string;
7395 const int codepoint1 = get_codepoint();
7396 int codepoint = codepoint1;
7398 if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
7400 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7401 return token_type::parse_error;
7405 if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
7408 if (JSON_HEDLEY_LIKELY(get() ==
'\\' && get() ==
'u'))
7410 const int codepoint2 = get_codepoint();
7412 if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
7414 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7415 return token_type::parse_error;
7419 if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))
7422 codepoint =
static_cast<int>(
7424 (
static_cast<unsigned int>(codepoint1) << 10u)
7426 +
static_cast<unsigned int>(codepoint2)
7434 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
7435 return token_type::parse_error;
7440 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
7441 return token_type::parse_error;
7446 if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))
7448 error_message =
"invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
7449 return token_type::parse_error;
7454 JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
7457 if (codepoint < 0x80)
7460 add(
static_cast<char_int_type
>(codepoint));
7462 else if (codepoint <= 0x7FF)
7465 add(
static_cast<char_int_type
>(0xC0u | (
static_cast<unsigned int>(codepoint) >> 6u)));
7466 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7468 else if (codepoint <= 0xFFFF)
7471 add(
static_cast<char_int_type
>(0xE0u | (
static_cast<unsigned int>(codepoint) >> 12u)));
7472 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7473 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7478 add(
static_cast<char_int_type
>(0xF0u | (
static_cast<unsigned int>(codepoint) >> 18u)));
7479 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
7480 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7481 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7489 error_message =
"invalid string: forbidden character after backslash";
7490 return token_type::parse_error;
7499 error_message =
"invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
7500 return token_type::parse_error;
7505 error_message =
"invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
7506 return token_type::parse_error;
7511 error_message =
"invalid string: control character U+0002 (STX) must be escaped to \\u0002";
7512 return token_type::parse_error;
7517 error_message =
"invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
7518 return token_type::parse_error;
7523 error_message =
"invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
7524 return token_type::parse_error;
7529 error_message =
"invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
7530 return token_type::parse_error;
7535 error_message =
"invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
7536 return token_type::parse_error;
7541 error_message =
"invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
7542 return token_type::parse_error;
7547 error_message =
"invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
7548 return token_type::parse_error;
7553 error_message =
"invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
7554 return token_type::parse_error;
7559 error_message =
"invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
7560 return token_type::parse_error;
7565 error_message =
"invalid string: control character U+000B (VT) must be escaped to \\u000B";
7566 return token_type::parse_error;
7571 error_message =
"invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
7572 return token_type::parse_error;
7577 error_message =
"invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
7578 return token_type::parse_error;
7583 error_message =
"invalid string: control character U+000E (SO) must be escaped to \\u000E";
7584 return token_type::parse_error;
7589 error_message =
"invalid string: control character U+000F (SI) must be escaped to \\u000F";
7590 return token_type::parse_error;
7595 error_message =
"invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
7596 return token_type::parse_error;
7601 error_message =
"invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
7602 return token_type::parse_error;
7607 error_message =
"invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
7608 return token_type::parse_error;
7613 error_message =
"invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
7614 return token_type::parse_error;
7619 error_message =
"invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
7620 return token_type::parse_error;
7625 error_message =
"invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
7626 return token_type::parse_error;
7631 error_message =
"invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
7632 return token_type::parse_error;
7637 error_message =
"invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
7638 return token_type::parse_error;
7643 error_message =
"invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
7644 return token_type::parse_error;
7649 error_message =
"invalid string: control character U+0019 (EM) must be escaped to \\u0019";
7650 return token_type::parse_error;
7655 error_message =
"invalid string: control character U+001A (SUB) must be escaped to \\u001A";
7656 return token_type::parse_error;
7661 error_message =
"invalid string: control character U+001B (ESC) must be escaped to \\u001B";
7662 return token_type::parse_error;
7667 error_message =
"invalid string: control character U+001C (FS) must be escaped to \\u001C";
7668 return token_type::parse_error;
7673 error_message =
"invalid string: control character U+001D (GS) must be escaped to \\u001D";
7674 return token_type::parse_error;
7679 error_message =
"invalid string: control character U+001E (RS) must be escaped to \\u001E";
7680 return token_type::parse_error;
7685 error_message =
"invalid string: control character U+001F (US) must be escaped to \\u001F";
7686 return token_type::parse_error;
7821 if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
7823 return token_type::parse_error;
7831 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
7833 return token_type::parse_error;
7855 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
7857 return token_type::parse_error;
7865 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
7867 return token_type::parse_error;
7875 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7877 return token_type::parse_error;
7887 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7889 return token_type::parse_error;
7897 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
7899 return token_type::parse_error;
7907 error_message =
"invalid string: ill-formed UTF-8 byte";
7908 return token_type::parse_error;
7931 case char_traits<char_type>::eof():
7948 case char_traits<char_type>::eof():
7951 error_message =
"invalid comment; missing closing '*/'";
7979 error_message =
"invalid comment; expecting '/' or '*' after '/'";
7985 JSON_HEDLEY_NON_NULL(2)
7986 static
void strtof(
float& f, const
char* str,
char** endptr) noexcept
7988 f = std::strtof(str, endptr);
7991 JSON_HEDLEY_NON_NULL(2)
7992 static
void strtof(
double& f, const
char* str,
char** endptr) noexcept
7994 f = std::strtod(str, endptr);
7997 JSON_HEDLEY_NON_NULL(2)
7998 static
void strtof(
long double& f, const
char* str,
char** endptr) noexcept
8000 f = std::strtold(str, endptr);
8043 token_type scan_number()
8050 token_type number_type = token_type::value_unsigned;
8058 goto scan_number_minus;
8064 goto scan_number_zero;
8078 goto scan_number_any1;
8088 number_type = token_type::value_integer;
8094 goto scan_number_zero;
8108 goto scan_number_any1;
8113 error_message =
"invalid number; expected digit after '-'";
8114 return token_type::parse_error;
8124 add(decimal_point_char);
8125 decimal_point_position = token_buffer.size() - 1;
8126 goto scan_number_decimal1;
8133 goto scan_number_exponent;
8137 goto scan_number_done;
8156 goto scan_number_any1;
8161 add(decimal_point_char);
8162 decimal_point_position = token_buffer.size() - 1;
8163 goto scan_number_decimal1;
8170 goto scan_number_exponent;
8174 goto scan_number_done;
8177scan_number_decimal1:
8179 number_type = token_type::value_float;
8194 goto scan_number_decimal2;
8199 error_message =
"invalid number; expected digit after '.'";
8200 return token_type::parse_error;
8204scan_number_decimal2:
8220 goto scan_number_decimal2;
8227 goto scan_number_exponent;
8231 goto scan_number_done;
8234scan_number_exponent:
8236 number_type = token_type::value_float;
8243 goto scan_number_sign;
8258 goto scan_number_any2;
8264 "invalid number; expected '+', '-', or digit after exponent";
8265 return token_type::parse_error;
8285 goto scan_number_any2;
8290 error_message =
"invalid number; expected digit after exponent sign";
8291 return token_type::parse_error;
8311 goto scan_number_any2;
8315 goto scan_number_done;
8323 char* endptr =
nullptr;
8327 if (number_type == token_type::value_unsigned)
8329 const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
8332 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8334 if (errno != ERANGE)
8336 value_unsigned =
static_cast<number_unsigned_t
>(x);
8337 if (value_unsigned == x)
8339 return token_type::value_unsigned;
8343 else if (number_type == token_type::value_integer)
8345 const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
8348 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8350 if (errno != ERANGE)
8352 value_integer =
static_cast<number_integer_t
>(x);
8353 if (value_integer == x)
8355 return token_type::value_integer;
8362 strtof(value_float, token_buffer.data(), &endptr);
8365 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8367 return token_type::value_float;
8375 JSON_HEDLEY_NON_NULL(2)
8376 token_type scan_literal(const char_type* literal_text, const std::
size_t length,
8377 token_type return_type)
8379 JSON_ASSERT(char_traits<char_type>::to_char_type(current) == literal_text[0]);
8380 for (std::size_t i = 1; i < length; ++i)
8382 if (JSON_HEDLEY_UNLIKELY(char_traits<char_type>::to_char_type(get()) != literal_text[i]))
8384 error_message =
"invalid literal";
8385 return token_type::parse_error;
8396 void reset() noexcept
8398 token_buffer.clear();
8399 token_string.clear();
8400 decimal_point_position = std::string::npos;
8401 token_string.push_back(char_traits<char_type>::to_char_type(current));
8416 ++position.chars_read_total;
8417 ++position.chars_read_current_line;
8426 current = ia.get_character();
8429 if (JSON_HEDLEY_LIKELY(current != char_traits<char_type>::eof()))
8431 token_string.push_back(char_traits<char_type>::to_char_type(current));
8434 if (current ==
'\n')
8436 ++position.lines_read;
8437 position.chars_read_current_line = 0;
8455 --position.chars_read_total;
8458 if (position.chars_read_current_line == 0)
8460 if (position.lines_read > 0)
8462 --position.lines_read;
8467 --position.chars_read_current_line;
8470 if (JSON_HEDLEY_LIKELY(current != char_traits<char_type>::eof()))
8472 JSON_ASSERT(!token_string.empty());
8473 token_string.pop_back();
8478 void add(char_int_type c)
8480 token_buffer.push_back(
static_cast<typename string_t::value_type
>(c));
8489 constexpr number_integer_t get_number_integer() const noexcept
8491 return value_integer;
8495 constexpr number_unsigned_t get_number_unsigned() const noexcept
8497 return value_unsigned;
8501 constexpr number_float_t get_number_float() const noexcept
8507 string_t& get_string()
8510 if (decimal_point_char !=
'.' && decimal_point_position != std::string::npos)
8512 token_buffer[decimal_point_position] =
'.';
8514 return token_buffer;
8522 constexpr position_t get_position() const noexcept
8530 std::string get_token_string()
const
8534 for (
const auto c : token_string)
8536 if (
static_cast<unsigned char>(c) <=
'\x1F')
8539 std::array<char, 9> cs{{}};
8540 static_cast<void>((std::snprintf)(cs.data(), cs.size(),
"<U+%.4X>",
static_cast<unsigned char>(c)));
8541 result += cs.data();
8546 result.push_back(
static_cast<std::string::value_type
>(c));
8554 JSON_HEDLEY_RETURNS_NON_NULL
8555 constexpr const char* get_error_message() const noexcept
8557 return error_message;
8573 return get() == 0xBB && get() == 0xBF;
8582 void skip_whitespace()
8588 while (current ==
' ' || current ==
'\t' || current ==
'\n' || current ==
'\r');
8594 if (position.chars_read_total == 0 && !skip_bom())
8596 error_message =
"invalid BOM; must be 0xEF 0xBB 0xBF if given";
8597 return token_type::parse_error;
8604 while (ignore_comments && current ==
'/')
8606 if (!scan_comment())
8608 return token_type::parse_error;
8619 return token_type::begin_array;
8621 return token_type::end_array;
8623 return token_type::begin_object;
8625 return token_type::end_object;
8627 return token_type::name_separator;
8629 return token_type::value_separator;
8634 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')}};
8635 return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
8639 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')}};
8640 return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
8644 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')}};
8645 return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
8650 return scan_string();
8664 return scan_number();
8669 case char_traits<char_type>::eof():
8670 return token_type::end_of_input;
8674 error_message =
"invalid literal";
8675 return token_type::parse_error;
8681 InputAdapterType ia;
8684 const bool ignore_comments =
false;
8687 char_int_type current = char_traits<char_type>::eof();
8690 bool next_unget =
false;
8693 position_t position {};
8696 std::vector<char_type> token_string {};
8699 string_t token_buffer {};
8702 const char* error_message =
"";
8705 number_integer_t value_integer = 0;
8706 number_unsigned_t value_unsigned = 0;
8707 number_float_t value_float = 0;
8710 const char_int_type decimal_point_char =
'.';
8712 std::size_t decimal_point_position = std::string::npos;
8716NLOHMANN_JSON_NAMESPACE_END
8722NLOHMANN_JSON_NAMESPACE_BEGIN
8732template<
typename BasicJsonType>
8735 using number_integer_t =
typename BasicJsonType::number_integer_t;
8736 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8737 using number_float_t =
typename BasicJsonType::number_float_t;
8738 using string_t =
typename BasicJsonType::string_t;
8739 using binary_t =
typename BasicJsonType::binary_t;
8806 virtual bool key(string_t& val) = 0;
8836 const std::string& last_token,
8849constexpr std::size_t unknown_size()
8851 return (std::numeric_limits<std::size_t>::max)();
8867template<
typename BasicJsonType,
typename InputAdapterType>
8871 using number_integer_t =
typename BasicJsonType::number_integer_t;
8872 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8873 using number_float_t =
typename BasicJsonType::number_float_t;
8874 using string_t =
typename BasicJsonType::string_t;
8875 using binary_t =
typename BasicJsonType::binary_t;
8876 using lexer_t = lexer<BasicJsonType, InputAdapterType>;
8883 explicit json_sax_dom_parser(BasicJsonType& r,
const bool allow_exceptions_ =
true, lexer_t* lexer_ =
nullptr)
8884 : root(r), allow_exceptions(allow_exceptions_), m_lexer_ref(lexer_)
8896 handle_value(
nullptr);
8900 bool boolean(
bool val)
8918 bool number_float(number_float_t val,
const string_t& )
8924 bool string(string_t& val)
8930 bool binary(binary_t& val)
8932 handle_value(std::move(val));
8936 bool start_object(std::size_t len)
8938 ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
8940#if JSON_DIAGNOSTIC_POSITIONS
8947 ref_stack.back()->start_position = m_lexer_ref->get_position() - 1;
8951 if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
8953 JSON_THROW(out_of_range::create(408, concat(
"excessive object size: ", std::to_string(len)), ref_stack.back()));
8959 bool key(string_t& val)
8961 JSON_ASSERT(!ref_stack.empty());
8962 JSON_ASSERT(ref_stack.back()->is_object());
8965 object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val));
8971 JSON_ASSERT(!ref_stack.empty());
8972 JSON_ASSERT(ref_stack.back()->is_object());
8974#if JSON_DIAGNOSTIC_POSITIONS
8978 ref_stack.back()->end_position = m_lexer_ref->get_position();
8982 ref_stack.back()->set_parents();
8983 ref_stack.pop_back();
8987 bool start_array(std::size_t len)
8989 ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
8991#if JSON_DIAGNOSTIC_POSITIONS
8996 ref_stack.back()->start_position = m_lexer_ref->get_position() - 1;
9000 if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
9002 JSON_THROW(out_of_range::create(408, concat(
"excessive array size: ", std::to_string(len)), ref_stack.back()));
9010 JSON_ASSERT(!ref_stack.empty());
9011 JSON_ASSERT(ref_stack.back()->is_array());
9013#if JSON_DIAGNOSTIC_POSITIONS
9017 ref_stack.back()->end_position = m_lexer_ref->get_position();
9021 ref_stack.back()->set_parents();
9022 ref_stack.pop_back();
9026 template<
class Exception>
9027 bool parse_error(std::size_t ,
const std::string& ,
9028 const Exception& ex)
9031 static_cast<void>(ex);
9032 if (allow_exceptions)
9039 constexpr bool is_errored()
const
9046#if JSON_DIAGNOSTIC_POSITIONS
9047 void handle_diagnostic_positions_for_json_value(BasicJsonType& v)
9054 v.end_position = m_lexer_ref->get_position();
9058 case value_t::boolean:
9061 v.start_position = v.end_position - (v.m_data.m_value.boolean ? 4 : 5);
9068 v.start_position = v.end_position - 4;
9072 case value_t::string:
9075 v.start_position = v.end_position - v.m_data.m_value.string->size() - 2;
9084 case value_t::discarded:
9086 v.end_position = std::string::npos;
9087 v.start_position = v.end_position;
9091 case value_t::binary:
9092 case value_t::number_integer:
9093 case value_t::number_unsigned:
9094 case value_t::number_float:
9096 v.start_position = v.end_position - m_lexer_ref->get_string().size();
9099 case value_t::object:
9100 case value_t::array:
9120 template<
typename Value>
9121 JSON_HEDLEY_RETURNS_NON_NULL
9122 BasicJsonType* handle_value(Value&& v)
9124 if (ref_stack.empty())
9126 root = BasicJsonType(std::forward<Value>(v));
9128#if JSON_DIAGNOSTIC_POSITIONS
9129 handle_diagnostic_positions_for_json_value(root);
9135 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
9137 if (ref_stack.back()->is_array())
9139 ref_stack.back()->m_data.m_value.array->emplace_back(std::forward<Value>(v));
9141#if JSON_DIAGNOSTIC_POSITIONS
9142 handle_diagnostic_positions_for_json_value(ref_stack.back()->m_data.m_value.array->back());
9145 return &(ref_stack.back()->m_data.m_value.array->back());
9148 JSON_ASSERT(ref_stack.back()->is_object());
9149 JSON_ASSERT(object_element);
9150 *object_element = BasicJsonType(std::forward<Value>(v));
9152#if JSON_DIAGNOSTIC_POSITIONS
9153 handle_diagnostic_positions_for_json_value(*object_element);
9156 return object_element;
9160 BasicJsonType& root;
9162 std::vector<BasicJsonType*> ref_stack {};
9164 BasicJsonType* object_element =
nullptr;
9166 bool errored =
false;
9168 const bool allow_exceptions =
true;
9170 lexer_t* m_lexer_ref =
nullptr;
9173template<
typename BasicJsonType,
typename InputAdapterType>
9177 using number_integer_t =
typename BasicJsonType::number_integer_t;
9178 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9179 using number_float_t =
typename BasicJsonType::number_float_t;
9180 using string_t =
typename BasicJsonType::string_t;
9181 using binary_t =
typename BasicJsonType::binary_t;
9182 using parser_callback_t =
typename BasicJsonType::parser_callback_t;
9183 using parse_event_t =
typename BasicJsonType::parse_event_t;
9184 using lexer_t = lexer<BasicJsonType, InputAdapterType>;
9187 parser_callback_t cb,
9188 const bool allow_exceptions_ =
true,
9189 lexer_t* lexer_ =
nullptr)
9190 : root(r), callback(std::move(cb)), allow_exceptions(allow_exceptions_), m_lexer_ref(lexer_)
9192 keep_stack.push_back(
true);
9204 handle_value(
nullptr);
9226 bool number_float(number_float_t val,
const string_t& )
9232 bool string(string_t& val)
9238 bool binary(binary_t& val)
9240 handle_value(std::move(val));
9244 bool start_object(std::size_t len)
9247 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::object_start,
discarded);
9248 keep_stack.push_back(keep);
9250 auto val = handle_value(BasicJsonType::value_t::object,
true);
9251 ref_stack.push_back(val.second);
9253 if (ref_stack.back())
9256#if JSON_DIAGNOSTIC_POSITIONS
9263 ref_stack.back()->start_position = m_lexer_ref->get_position() - 1;
9268 if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
9270 JSON_THROW(out_of_range::create(408, concat(
"excessive object size: ", std::to_string(len)), ref_stack.back()));
9276 bool key(string_t& val)
9278 BasicJsonType k = BasicJsonType(val);
9281 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::key, k);
9282 key_keep_stack.push_back(keep);
9285 if (keep && ref_stack.back())
9287 object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val) =
discarded);
9295 if (ref_stack.back())
9297 if (!callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
9302#if JSON_DIAGNOSTIC_POSITIONS
9304 handle_diagnostic_positions_for_json_value(*ref_stack.back());
9310#if JSON_DIAGNOSTIC_POSITIONS
9314 ref_stack.back()->end_position = m_lexer_ref->get_position();
9318 ref_stack.back()->set_parents();
9322 JSON_ASSERT(!ref_stack.empty());
9323 JSON_ASSERT(!keep_stack.empty());
9324 ref_stack.pop_back();
9325 keep_stack.pop_back();
9327 if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
9330 for (
auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
9332 if (it->is_discarded())
9334 ref_stack.back()->erase(it);
9343 bool start_array(std::size_t len)
9345 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::array_start,
discarded);
9346 keep_stack.push_back(keep);
9348 auto val = handle_value(BasicJsonType::value_t::array,
true);
9349 ref_stack.push_back(val.second);
9351 if (ref_stack.back())
9354#if JSON_DIAGNOSTIC_POSITIONS
9361 ref_stack.back()->start_position = m_lexer_ref->get_position() - 1;
9366 if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
9368 JSON_THROW(out_of_range::create(408, concat(
"excessive array size: ", std::to_string(len)), ref_stack.back()));
9379 if (ref_stack.back())
9381 keep = callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
9385#if JSON_DIAGNOSTIC_POSITIONS
9389 ref_stack.back()->end_position = m_lexer_ref->get_position();
9393 ref_stack.back()->set_parents();
9400#if JSON_DIAGNOSTIC_POSITIONS
9402 handle_diagnostic_positions_for_json_value(*ref_stack.back());
9407 JSON_ASSERT(!ref_stack.empty());
9408 JSON_ASSERT(!keep_stack.empty());
9409 ref_stack.pop_back();
9410 keep_stack.pop_back();
9413 if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
9415 ref_stack.back()->m_data.m_value.array->pop_back();
9421 template<
class Exception>
9422 bool parse_error(std::size_t ,
const std::string& ,
9423 const Exception& ex)
9426 static_cast<void>(ex);
9427 if (allow_exceptions)
9434 constexpr bool is_errored()
const
9441#if JSON_DIAGNOSTIC_POSITIONS
9442 void handle_diagnostic_positions_for_json_value(BasicJsonType& v)
9449 v.end_position = m_lexer_ref->get_position();
9453 case value_t::boolean:
9456 v.start_position = v.end_position - (v.m_data.m_value.boolean ? 4 : 5);
9463 v.start_position = v.end_position - 4;
9467 case value_t::string:
9470 v.start_position = v.end_position - v.m_data.m_value.string->size() - 2;
9474 case value_t::discarded:
9476 v.end_position = std::string::npos;
9477 v.start_position = v.end_position;
9481 case value_t::binary:
9482 case value_t::number_integer:
9483 case value_t::number_unsigned:
9484 case value_t::number_float:
9486 v.start_position = v.end_position - m_lexer_ref->get_string().size();
9490 case value_t::object:
9491 case value_t::array:
9520 template<
typename Value>
9521 std::pair<bool, BasicJsonType*> handle_value(Value&& v,
const bool skip_callback =
false)
9523 JSON_ASSERT(!keep_stack.empty());
9527 if (!keep_stack.back())
9529 return {
false,
nullptr};
9533 auto value = BasicJsonType(std::forward<Value>(v));
9535#if JSON_DIAGNOSTIC_POSITIONS
9536 handle_diagnostic_positions_for_json_value(value);
9540 const bool keep = skip_callback || callback(
static_cast<int>(ref_stack.size()), parse_event_t::value, value);
9545 return {
false,
nullptr};
9548 if (ref_stack.empty())
9550 root = std::move(value);
9551 return {
true, & root};
9556 if (!ref_stack.back())
9558 return {
false,
nullptr};
9562 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
9565 if (ref_stack.back()->is_array())
9567 ref_stack.back()->m_data.m_value.array->emplace_back(std::move(value));
9568 return {
true, & (ref_stack.back()->m_data.m_value.array->back())};
9572 JSON_ASSERT(ref_stack.back()->is_object());
9574 JSON_ASSERT(!key_keep_stack.empty());
9575 const bool store_element = key_keep_stack.back();
9576 key_keep_stack.pop_back();
9580 return {
false,
nullptr};
9583 JSON_ASSERT(object_element);
9584 *object_element = std::move(value);
9585 return {
true, object_element};
9589 BasicJsonType& root;
9591 std::vector<BasicJsonType*> ref_stack {};
9593 std::vector<bool> keep_stack {};
9595 std::vector<bool> key_keep_stack {};
9597 BasicJsonType* object_element =
nullptr;
9599 bool errored =
false;
9601 const parser_callback_t callback =
nullptr;
9603 const bool allow_exceptions =
true;
9605 BasicJsonType
discarded = BasicJsonType::value_t::discarded;
9607 lexer_t* m_lexer_ref =
nullptr;
9610template<
typename BasicJsonType>
9614 using number_integer_t =
typename BasicJsonType::number_integer_t;
9615 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9616 using number_float_t =
typename BasicJsonType::number_float_t;
9617 using string_t =
typename BasicJsonType::string_t;
9618 using binary_t =
typename BasicJsonType::binary_t;
9655 bool start_object(std::size_t = detail::unknown_size())
9660 bool key(string_t& )
9670 bool start_array(std::size_t = detail::unknown_size())
9687NLOHMANN_JSON_NAMESPACE_END
9715NLOHMANN_JSON_NAMESPACE_BEGIN
9720using null_function_t =
decltype(std::declval<T&>().null());
9723using boolean_function_t =
9724 decltype(std::declval<T&>().boolean(std::declval<bool>()));
9726template<
typename T,
typename Integer>
9727using number_integer_function_t =
9728 decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
9730template<
typename T,
typename Un
signed>
9731using number_unsigned_function_t =
9732 decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
9734template<
typename T,
typename Float,
typename String>
9735using number_float_function_t =
decltype(std::declval<T&>().number_float(
9736 std::declval<Float>(), std::declval<const String&>()));
9738template<
typename T,
typename String>
9739using string_function_t =
9740 decltype(std::declval<T&>().string(std::declval<String&>()));
9742template<
typename T,
typename Binary>
9743using binary_function_t =
9744 decltype(std::declval<T&>().binary(std::declval<Binary&>()));
9747using start_object_function_t =
9748 decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
9750template<
typename T,
typename String>
9751using key_function_t =
9752 decltype(std::declval<T&>().key(std::declval<String&>()));
9755using end_object_function_t =
decltype(std::declval<T&>().end_object());
9758using start_array_function_t =
9759 decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
9762using end_array_function_t =
decltype(std::declval<T&>().end_array());
9764template<
typename T,
typename Exception>
9765using parse_error_function_t =
decltype(std::declval<T&>().parse_error(
9766 std::declval<std::size_t>(), std::declval<const std::string&>(),
9767 std::declval<const Exception&>()));
9769template<
typename SAX,
typename BasicJsonType>
9774 "BasicJsonType must be of type basic_json<...>");
9776 using number_integer_t =
typename BasicJsonType::number_integer_t;
9777 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9778 using number_float_t =
typename BasicJsonType::number_float_t;
9779 using string_t =
typename BasicJsonType::string_t;
9780 using binary_t =
typename BasicJsonType::binary_t;
9781 using exception_t =
typename BasicJsonType::exception;
9784 static constexpr bool value =
9785 is_detected_exact<bool, null_function_t, SAX>::value &&
9786 is_detected_exact<bool, boolean_function_t, SAX>::value &&
9787 is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
9788 is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
9789 is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
9790 is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
9791 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
9792 is_detected_exact<bool, start_object_function_t, SAX>::value &&
9793 is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
9794 is_detected_exact<bool, end_object_function_t, SAX>::value &&
9795 is_detected_exact<bool, start_array_function_t, SAX>::value &&
9796 is_detected_exact<bool, end_array_function_t, SAX>::value &&
9797 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
9800template<
typename SAX,
typename BasicJsonType>
9805 "BasicJsonType must be of type basic_json<...>");
9807 using number_integer_t =
typename BasicJsonType::number_integer_t;
9808 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9809 using number_float_t =
typename BasicJsonType::number_float_t;
9810 using string_t =
typename BasicJsonType::string_t;
9811 using binary_t =
typename BasicJsonType::binary_t;
9812 using exception_t =
typename BasicJsonType::exception;
9815 static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
9816 "Missing/invalid function: bool null()");
9817 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
9818 "Missing/invalid function: bool boolean(bool)");
9819 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
9820 "Missing/invalid function: bool boolean(bool)");
9822 is_detected_exact<bool, number_integer_function_t, SAX,
9823 number_integer_t>::value,
9824 "Missing/invalid function: bool number_integer(number_integer_t)");
9826 is_detected_exact<bool, number_unsigned_function_t, SAX,
9827 number_unsigned_t>::value,
9828 "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
9829 static_assert(is_detected_exact<bool, number_float_function_t, SAX,
9830 number_float_t, string_t>::value,
9831 "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
9833 is_detected_exact<bool, string_function_t, SAX, string_t>::value,
9834 "Missing/invalid function: bool string(string_t&)");
9836 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
9837 "Missing/invalid function: bool binary(binary_t&)");
9838 static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
9839 "Missing/invalid function: bool start_object(std::size_t)");
9840 static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
9841 "Missing/invalid function: bool key(string_t&)");
9842 static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
9843 "Missing/invalid function: bool end_object()");
9844 static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
9845 "Missing/invalid function: bool start_array(std::size_t)");
9846 static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
9847 "Missing/invalid function: bool end_array()");
9849 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
9850 "Missing/invalid function: bool parse_error(std::size_t, const "
9851 "std::string&, const exception&)");
9855NLOHMANN_JSON_NAMESPACE_END
9864NLOHMANN_JSON_NAMESPACE_BEGIN
9885 return *
reinterpret_cast<char*
>(&num) == 1;
9895template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX = json_sax_dom_parser<BasicJsonType, InputAdapterType>>
9898 using number_integer_t =
typename BasicJsonType::number_integer_t;
9899 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9900 using number_float_t =
typename BasicJsonType::number_float_t;
9901 using string_t =
typename BasicJsonType::string_t;
9902 using binary_t =
typename BasicJsonType::binary_t;
9903 using json_sax_t = SAX;
9904 using char_type =
typename InputAdapterType::char_type;
9913 explicit binary_reader(InputAdapterType&& adapter,
const input_format_t format = input_format_t::json) noexcept : ia(std::move(adapter)), input_format(format)
9933 JSON_HEDLEY_NON_NULL(3)
9934 bool sax_parse(const input_format_t format,
9936 const
bool strict = true,
9940 bool result =
false;
9944 case input_format_t::bson:
9945 result = parse_bson_internal();
9948 case input_format_t::cbor:
9949 result = parse_cbor_internal(
true, tag_handler);
9952 case input_format_t::msgpack:
9953 result = parse_msgpack_internal();
9956 case input_format_t::ubjson:
9957 case input_format_t::bjdata:
9958 result = parse_ubjson_internal();
9961 case input_format_t::json:
9969 if (input_format == input_format_t::ubjson || input_format == input_format_t::bjdata)
9980 return sax->parse_error(chars_read, get_token_string(), parse_error::create(110, chars_read,
9981 exception_message(input_format, concat(
"expected end of input; last byte: 0x", get_token_string()),
"value"),
nullptr));
9997 bool parse_bson_internal()
9999 std::int32_t document_size{};
10000 get_number<std::int32_t, true>(input_format_t::bson, document_size);
10002 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
10007 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
false)))
10012 return sax->end_object();
10022 bool get_bson_cstr(string_t& result)
10024 auto out = std::back_inserter(result);
10028 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"cstring")))
10032 if (current == 0x00)
10036 *out++ =
static_cast<typename string_t::value_type
>(current);
10051 template<
typename NumberType>
10052 bool get_bson_string(
const NumberType len, string_t& result)
10054 if (JSON_HEDLEY_UNLIKELY(len < 1))
10056 auto last_token = get_token_string();
10057 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
10058 exception_message(input_format_t::bson, concat(
"string length must be at least 1, is ", std::to_string(len)),
"string"),
nullptr));
10061 return get_string(input_format_t::bson, len -
static_cast<NumberType
>(1), result) && get() != char_traits<char_type>::eof();
10073 template<
typename NumberType>
10074 bool get_bson_binary(
const NumberType len, binary_t& result)
10076 if (JSON_HEDLEY_UNLIKELY(len < 0))
10078 auto last_token = get_token_string();
10079 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
10080 exception_message(input_format_t::bson, concat(
"byte array length cannot be negative, is ", std::to_string(len)),
"binary"),
nullptr));
10084 std::uint8_t subtype{};
10085 get_number<std::uint8_t>(input_format_t::bson, subtype);
10086 result.set_subtype(subtype);
10088 return get_binary(input_format_t::bson, len, result);
10101 bool parse_bson_element_internal(
const char_int_type element_type,
10102 const std::size_t element_type_parse_position)
10104 switch (element_type)
10109 return get_number<double, true>(input_format_t::bson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10114 std::int32_t len{};
10116 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
10121 return parse_bson_internal();
10126 return parse_bson_array();
10131 std::int32_t len{};
10133 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
10138 return sax->boolean(get() != 0);
10143 return sax->null();
10148 std::int32_t value{};
10149 return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
10154 std::int64_t value{};
10155 return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
10160 std::uint64_t value{};
10161 return get_number<std::uint64_t, true>(input_format_t::bson, value) && sax->number_unsigned(value);
10166 std::array<char, 3> cr{{}};
10167 static_cast<void>((std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(element_type)));
10168 const std::string cr_str{cr.data()};
10169 return sax->parse_error(element_type_parse_position, cr_str,
10170 parse_error::create(114, element_type_parse_position, concat(
"Unsupported BSON record type 0x", cr_str),
nullptr));
10187 bool parse_bson_element_list(
const bool is_array)
10191 while (
auto element_type = get())
10193 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"element list")))
10198 const std::size_t element_type_parse_position = chars_read;
10199 if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key)))
10204 if (!is_array && !sax->key(key))
10209 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
10225 bool parse_bson_array()
10227 std::int32_t document_size{};
10228 get_number<std::int32_t, true>(input_format_t::bson, document_size);
10230 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
10235 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
true)))
10240 return sax->end_array();
10255 bool parse_cbor_internal(
const bool get_char,
10256 const cbor_tag_handler_t tag_handler)
10258 switch (get_char ? get() : current)
10261 case char_traits<char_type>::eof():
10262 return unexpect_eof(input_format_t::cbor,
"value");
10289 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
10293 std::uint8_t number{};
10294 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
10299 std::uint16_t number{};
10300 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
10305 std::uint32_t number{};
10306 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
10311 std::uint64_t number{};
10312 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
10340 return sax->number_integer(
static_cast<std::int8_t
>(0x20 - 1 - current));
10344 std::uint8_t number{};
10345 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
10350 std::uint16_t number{};
10351 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
10356 std::uint32_t number{};
10357 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
10362 std::uint64_t number{};
10363 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1)
10364 -
static_cast<number_integer_t
>(number));
10399 return get_cbor_binary(b) && sax->binary(b);
10434 return get_cbor_string(s) && sax->string(s);
10462 return get_cbor_array(
10463 conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
10467 std::uint8_t len{};
10468 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
10473 std::uint16_t len{};
10474 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
10479 std::uint32_t len{};
10480 return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
10485 std::uint64_t len{};
10486 return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
10490 return get_cbor_array(detail::unknown_size(), tag_handler);
10517 return get_cbor_object(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
10521 std::uint8_t len{};
10522 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
10527 std::uint16_t len{};
10528 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
10533 std::uint32_t len{};
10534 return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
10539 std::uint64_t len{};
10540 return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
10544 return get_cbor_object(detail::unknown_size(), tag_handler);
10566 switch (tag_handler)
10568 case cbor_tag_handler_t::error:
10570 auto last_token = get_token_string();
10571 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
10572 exception_message(input_format_t::cbor, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
10575 case cbor_tag_handler_t::ignore:
10582 std::uint8_t subtype_to_ignore{};
10583 get_number(input_format_t::cbor, subtype_to_ignore);
10588 std::uint16_t subtype_to_ignore{};
10589 get_number(input_format_t::cbor, subtype_to_ignore);
10594 std::uint32_t subtype_to_ignore{};
10595 get_number(input_format_t::cbor, subtype_to_ignore);
10600 std::uint64_t subtype_to_ignore{};
10601 get_number(input_format_t::cbor, subtype_to_ignore);
10607 return parse_cbor_internal(
true, tag_handler);
10610 case cbor_tag_handler_t::store:
10618 std::uint8_t subtype{};
10619 get_number(input_format_t::cbor, subtype);
10620 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
10625 std::uint16_t subtype{};
10626 get_number(input_format_t::cbor, subtype);
10627 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
10632 std::uint32_t subtype{};
10633 get_number(input_format_t::cbor, subtype);
10634 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
10639 std::uint64_t subtype{};
10640 get_number(input_format_t::cbor, subtype);
10641 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
10645 return parse_cbor_internal(
true, tag_handler);
10648 return get_cbor_binary(b) && sax->binary(b);
10652 JSON_ASSERT(
false);
10658 return sax->boolean(
false);
10661 return sax->boolean(
true);
10664 return sax->null();
10668 const auto byte1_raw = get();
10669 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
10673 const auto byte2_raw = get();
10674 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
10679 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
10680 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
10690 const auto half =
static_cast<unsigned int>((byte1 << 8u) + byte2);
10691 const double val = [&half]
10693 const int exp = (half >> 10u) & 0x1Fu;
10694 const unsigned int mant = half & 0x3FFu;
10695 JSON_ASSERT(0 <= exp&& exp <= 32);
10696 JSON_ASSERT(mant <= 1024);
10700 return std::ldexp(mant, -24);
10703 ? std::numeric_limits<double>::infinity()
10704 : std::numeric_limits<double>::quiet_NaN();
10706 return std::ldexp(mant + 1024, exp - 25);
10709 return sax->number_float((half & 0x8000u) != 0
10710 ?
static_cast<number_float_t
>(-val)
10711 : static_cast<number_float_t>(val),
"");
10717 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10723 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10728 auto last_token = get_token_string();
10729 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
10730 exception_message(input_format_t::cbor, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
10746 bool get_cbor_string(string_t& result)
10748 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"string")))
10781 return get_string(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
10786 std::uint8_t len{};
10787 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10792 std::uint16_t len{};
10793 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10798 std::uint32_t len{};
10799 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10804 std::uint64_t len{};
10805 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10810 while (get() != 0xFF)
10813 if (!get_cbor_string(chunk))
10817 result.append(chunk);
10824 auto last_token = get_token_string();
10825 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
10826 exception_message(input_format_t::cbor, concat(
"expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token),
"string"),
nullptr));
10842 bool get_cbor_binary(binary_t& result)
10844 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"binary")))
10877 return get_binary(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
10882 std::uint8_t len{};
10883 return get_number(input_format_t::cbor, len) &&
10884 get_binary(input_format_t::cbor, len, result);
10889 std::uint16_t len{};
10890 return get_number(input_format_t::cbor, len) &&
10891 get_binary(input_format_t::cbor, len, result);
10896 std::uint32_t len{};
10897 return get_number(input_format_t::cbor, len) &&
10898 get_binary(input_format_t::cbor, len, result);
10903 std::uint64_t len{};
10904 return get_number(input_format_t::cbor, len) &&
10905 get_binary(input_format_t::cbor, len, result);
10910 while (get() != 0xFF)
10913 if (!get_cbor_binary(chunk))
10917 result.insert(result.end(), chunk.begin(), chunk.end());
10924 auto last_token = get_token_string();
10925 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
10926 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));
10937 bool get_cbor_array(
const std::size_t len,
10938 const cbor_tag_handler_t tag_handler)
10940 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
10945 if (len != detail::unknown_size())
10947 for (std::size_t i = 0; i < len; ++i)
10949 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
10957 while (get() != 0xFF)
10959 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
false, tag_handler)))
10966 return sax->end_array();
10975 bool get_cbor_object(
const std::size_t len,
10976 const cbor_tag_handler_t tag_handler)
10978 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
10986 if (len != detail::unknown_size())
10988 for (std::size_t i = 0; i < len; ++i)
10991 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
10996 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
11005 while (get() != 0xFF)
11007 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
11012 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
11021 return sax->end_object();
11031 bool parse_msgpack_internal()
11036 case char_traits<char_type>::eof():
11037 return unexpect_eof(input_format_t::msgpack,
"value");
11168 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
11187 return get_msgpack_object(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x0Fu));
11206 return get_msgpack_array(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x0Fu));
11246 return get_msgpack_string(s) && sax->string(s);
11250 return sax->null();
11253 return sax->boolean(
false);
11256 return sax->boolean(
true);
11271 return get_msgpack_binary(b) && sax->binary(b);
11277 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
11283 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
11288 std::uint8_t number{};
11289 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
11294 std::uint16_t number{};
11295 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
11300 std::uint32_t number{};
11301 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
11306 std::uint64_t number{};
11307 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
11312 std::int8_t number{};
11313 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
11318 std::int16_t number{};
11319 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
11324 std::int32_t number{};
11325 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
11330 std::int64_t number{};
11331 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
11336 std::uint16_t len{};
11337 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
11342 std::uint32_t len{};
11343 return get_number(input_format_t::msgpack, len) && get_msgpack_array(conditional_static_cast<std::size_t>(len));
11348 std::uint16_t len{};
11349 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
11354 std::uint32_t len{};
11355 return get_number(input_format_t::msgpack, len) && get_msgpack_object(conditional_static_cast<std::size_t>(len));
11391 return sax->number_integer(
static_cast<std::int8_t
>(current));
11395 auto last_token = get_token_string();
11396 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
11397 exception_message(input_format_t::msgpack, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
11412 bool get_msgpack_string(string_t& result)
11414 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack,
"string")))
11455 return get_string(input_format_t::msgpack,
static_cast<unsigned int>(current) & 0x1Fu, result);
11460 std::uint8_t len{};
11461 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
11466 std::uint16_t len{};
11467 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
11472 std::uint32_t len{};
11473 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
11478 auto last_token = get_token_string();
11479 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
11480 exception_message(input_format_t::msgpack, concat(
"expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token),
"string"),
nullptr));
11495 bool get_msgpack_binary(binary_t& result)
11498 auto assign_and_return_true = [&result](std::int8_t subtype)
11500 result.set_subtype(
static_cast<std::uint8_t
>(subtype));
11508 std::uint8_t len{};
11509 return get_number(input_format_t::msgpack, len) &&
11510 get_binary(input_format_t::msgpack, len, result);
11515 std::uint16_t len{};
11516 return get_number(input_format_t::msgpack, len) &&
11517 get_binary(input_format_t::msgpack, len, result);
11522 std::uint32_t len{};
11523 return get_number(input_format_t::msgpack, len) &&
11524 get_binary(input_format_t::msgpack, len, result);
11529 std::uint8_t len{};
11530 std::int8_t subtype{};
11531 return get_number(input_format_t::msgpack, len) &&
11532 get_number(input_format_t::msgpack, subtype) &&
11533 get_binary(input_format_t::msgpack, len, result) &&
11534 assign_and_return_true(subtype);
11539 std::uint16_t len{};
11540 std::int8_t subtype{};
11541 return get_number(input_format_t::msgpack, len) &&
11542 get_number(input_format_t::msgpack, subtype) &&
11543 get_binary(input_format_t::msgpack, len, result) &&
11544 assign_and_return_true(subtype);
11549 std::uint32_t len{};
11550 std::int8_t subtype{};
11551 return get_number(input_format_t::msgpack, len) &&
11552 get_number(input_format_t::msgpack, subtype) &&
11553 get_binary(input_format_t::msgpack, len, result) &&
11554 assign_and_return_true(subtype);
11559 std::int8_t subtype{};
11560 return get_number(input_format_t::msgpack, subtype) &&
11561 get_binary(input_format_t::msgpack, 1, result) &&
11562 assign_and_return_true(subtype);
11567 std::int8_t subtype{};
11568 return get_number(input_format_t::msgpack, subtype) &&
11569 get_binary(input_format_t::msgpack, 2, result) &&
11570 assign_and_return_true(subtype);
11575 std::int8_t subtype{};
11576 return get_number(input_format_t::msgpack, subtype) &&
11577 get_binary(input_format_t::msgpack, 4, result) &&
11578 assign_and_return_true(subtype);
11583 std::int8_t subtype{};
11584 return get_number(input_format_t::msgpack, subtype) &&
11585 get_binary(input_format_t::msgpack, 8, result) &&
11586 assign_and_return_true(subtype);
11591 std::int8_t subtype{};
11592 return get_number(input_format_t::msgpack, subtype) &&
11593 get_binary(input_format_t::msgpack, 16, result) &&
11594 assign_and_return_true(subtype);
11606 bool get_msgpack_array(
const std::size_t len)
11608 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
11613 for (std::size_t i = 0; i < len; ++i)
11615 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
11621 return sax->end_array();
11628 bool get_msgpack_object(
const std::size_t len)
11630 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
11636 for (std::size_t i = 0; i < len; ++i)
11639 if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key)))
11644 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
11651 return sax->end_object();
11665 bool parse_ubjson_internal(
const bool get_char =
true)
11667 return get_ubjson_value(get_char ? get_ignore_noop() : current);
11684 bool get_ubjson_string(string_t& result,
const bool get_char =
true)
11691 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"value")))
11700 std::uint8_t len{};
11701 return get_number(input_format, len) && get_string(input_format, len, result);
11707 return get_number(input_format, len) && get_string(input_format, len, result);
11712 std::int16_t len{};
11713 return get_number(input_format, len) && get_string(input_format, len, result);
11718 std::int32_t len{};
11719 return get_number(input_format, len) && get_string(input_format, len, result);
11724 std::int64_t len{};
11725 return get_number(input_format, len) && get_string(input_format, len, result);
11730 if (input_format != input_format_t::bjdata)
11734 std::uint16_t len{};
11735 return get_number(input_format, len) && get_string(input_format, len, result);
11740 if (input_format != input_format_t::bjdata)
11744 std::uint32_t len{};
11745 return get_number(input_format, len) && get_string(input_format, len, result);
11750 if (input_format != input_format_t::bjdata)
11754 std::uint64_t len{};
11755 return get_number(input_format, len) && get_string(input_format, len, result);
11761 auto last_token = get_token_string();
11762 std::string message;
11764 if (input_format != input_format_t::bjdata)
11766 message =
"expected length type specification (U, i, I, l, L); last byte: 0x" + last_token;
11770 message =
"expected length type specification (U, i, u, I, m, l, M, L); last byte: 0x" + last_token;
11772 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message,
"string"),
nullptr));
11779 bool get_ubjson_ndarray_size(std::vector<size_t>& dim)
11781 std::pair<std::size_t, char_int_type> size_and_type;
11783 bool no_ndarray =
true;
11785 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type, no_ndarray)))
11790 if (size_and_type.first != npos)
11792 if (size_and_type.second != 0)
11794 if (size_and_type.second !=
'N')
11796 for (std::size_t i = 0; i < size_and_type.first; ++i)
11798 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, size_and_type.second)))
11802 dim.push_back(dimlen);
11808 for (std::size_t i = 0; i < size_and_type.first; ++i)
11810 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray)))
11814 dim.push_back(dimlen);
11820 while (current !=
']')
11822 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, current)))
11826 dim.push_back(dimlen);
11844 bool get_ubjson_size_value(std::size_t& result,
bool& is_ndarray, char_int_type prefix = 0)
11848 prefix = get_ignore_noop();
11855 std::uint8_t number{};
11856 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11860 result =
static_cast<std::size_t
>(number);
11866 std::int8_t number{};
11867 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11873 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11874 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11876 result =
static_cast<std::size_t
>(number);
11882 std::int16_t number{};
11883 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11889 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11890 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11892 result =
static_cast<std::size_t
>(number);
11898 std::int32_t number{};
11899 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11905 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11906 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11908 result =
static_cast<std::size_t
>(number);
11914 std::int64_t number{};
11915 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11921 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11922 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11924 if (!value_in_range_of<std::size_t>(number))
11926 return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,
11927 exception_message(input_format,
"integer value overflow",
"size"),
nullptr));
11929 result =
static_cast<std::size_t
>(number);
11935 if (input_format != input_format_t::bjdata)
11939 std::uint16_t number{};
11940 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11944 result =
static_cast<std::size_t
>(number);
11950 if (input_format != input_format_t::bjdata)
11954 std::uint32_t number{};
11955 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11959 result = conditional_static_cast<std::size_t>(number);
11965 if (input_format != input_format_t::bjdata)
11969 std::uint64_t number{};
11970 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11974 if (!value_in_range_of<std::size_t>(number))
11976 return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,
11977 exception_message(input_format,
"integer value overflow",
"size"),
nullptr));
11979 result = detail::conditional_static_cast<std::size_t>(number);
11985 if (input_format != input_format_t::bjdata)
11991 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));
11993 std::vector<size_t> dim;
11994 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_ndarray_size(dim)))
11998 if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1))
12000 result = dim.at(dim.size() - 1);
12014 string_t key =
"_ArraySize_";
12015 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(3) || !sax->key(key) || !sax->start_array(dim.size())))
12025 if (JSON_HEDLEY_UNLIKELY(i > 0 && result > (std::numeric_limits<std::size_t>::max)() / i))
12027 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));
12031 if (result == 0 || result == npos)
12033 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));
12035 if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(
static_cast<number_unsigned_t
>(i))))
12041 return sax->end_array();
12050 auto last_token = get_token_string();
12051 std::string message;
12053 if (input_format != input_format_t::bjdata)
12055 message =
"expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token;
12059 message =
"expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x" + last_token;
12061 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message,
"size"),
nullptr));
12075 bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result,
bool inside_ndarray =
false)
12077 result.first = npos;
12079 bool is_ndarray =
false;
12083 if (current ==
'$')
12085 result.second = get();
12086 if (input_format == input_format_t::bjdata
12087 && JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second)))
12089 auto last_token = get_token_string();
12090 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
12091 exception_message(input_format, concat(
"marker 0x", last_token,
" is not a permitted optimized array type"),
"type"),
nullptr));
12094 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"type")))
12100 if (JSON_HEDLEY_UNLIKELY(current !=
'#'))
12102 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"value")))
12106 auto last_token = get_token_string();
12107 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
12108 exception_message(input_format, concat(
"expected '#' after type information; last byte: 0x", last_token),
"size"),
nullptr));
12111 const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
12112 if (input_format == input_format_t::bjdata && is_ndarray)
12114 if (inside_ndarray)
12116 return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
12117 exception_message(input_format,
"ndarray can not be recursive",
"size"),
nullptr));
12119 result.second |= (1 << 8);
12124 if (current ==
'#')
12126 const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
12127 if (input_format == input_format_t::bjdata && is_ndarray)
12129 return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
12130 exception_message(input_format,
"ndarray requires both type and size",
"size"),
nullptr));
12142 bool get_ubjson_value(
const char_int_type prefix)
12146 case char_traits<char_type>::eof():
12147 return unexpect_eof(input_format,
"value");
12150 return sax->boolean(
true);
12152 return sax->boolean(
false);
12155 return sax->null();
12159 if (input_format != input_format_t::bjdata)
12163 std::uint8_t number{};
12164 return get_number(input_format, number) && sax->number_unsigned(number);
12169 std::uint8_t number{};
12170 return get_number(input_format, number) && sax->number_unsigned(number);
12175 std::int8_t number{};
12176 return get_number(input_format, number) && sax->number_integer(number);
12181 std::int16_t number{};
12182 return get_number(input_format, number) && sax->number_integer(number);
12187 std::int32_t number{};
12188 return get_number(input_format, number) && sax->number_integer(number);
12193 std::int64_t number{};
12194 return get_number(input_format, number) && sax->number_integer(number);
12199 if (input_format != input_format_t::bjdata)
12203 std::uint16_t number{};
12204 return get_number(input_format, number) && sax->number_unsigned(number);
12209 if (input_format != input_format_t::bjdata)
12213 std::uint32_t number{};
12214 return get_number(input_format, number) && sax->number_unsigned(number);
12219 if (input_format != input_format_t::bjdata)
12223 std::uint64_t number{};
12224 return get_number(input_format, number) && sax->number_unsigned(number);
12229 if (input_format != input_format_t::bjdata)
12233 const auto byte1_raw = get();
12234 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
12238 const auto byte2_raw = get();
12239 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
12244 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
12245 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
12255 const auto half =
static_cast<unsigned int>((byte2 << 8u) + byte1);
12256 const double val = [&half]
12258 const int exp = (half >> 10u) & 0x1Fu;
12259 const unsigned int mant = half & 0x3FFu;
12260 JSON_ASSERT(0 <= exp&& exp <= 32);
12261 JSON_ASSERT(mant <= 1024);
12265 return std::ldexp(mant, -24);
12268 ? std::numeric_limits<double>::infinity()
12269 : std::numeric_limits<double>::quiet_NaN();
12271 return std::ldexp(mant + 1024, exp - 25);
12274 return sax->number_float((half & 0x8000u) != 0
12275 ?
static_cast<number_float_t
>(-val)
12276 : static_cast<number_float_t>(val),
"");
12282 return get_number(input_format, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
12288 return get_number(input_format, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
12293 return get_ubjson_high_precision_number();
12299 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"char")))
12303 if (JSON_HEDLEY_UNLIKELY(current > 127))
12305 auto last_token = get_token_string();
12306 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
12307 exception_message(input_format, concat(
"byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token),
"char"),
nullptr));
12309 string_t s(1,
static_cast<typename string_t::value_type
>(current));
12310 return sax->string(s);
12316 return get_ubjson_string(s) && sax->string(s);
12320 return get_ubjson_array();
12323 return get_ubjson_object();
12328 auto last_token = get_token_string();
12329 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));
12335 bool get_ubjson_array()
12337 std::pair<std::size_t, char_int_type> size_and_type;
12338 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
12346 if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
12348 size_and_type.second &= ~(
static_cast<char_int_type
>(1) << 8);
12349 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)
12351 return p.first < t;
12353 string_t key =
"_ArrayType_";
12354 if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second))
12356 auto last_token = get_token_string();
12357 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
12358 exception_message(input_format,
"invalid byte: 0x" + last_token,
"type"),
nullptr));
12361 string_t type = it->second;
12362 if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type)))
12367 if (size_and_type.second ==
'C' || size_and_type.second ==
'B')
12369 size_and_type.second =
'U';
12372 key =
"_ArrayData_";
12373 if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->start_array(size_and_type.first) ))
12378 for (std::size_t i = 0; i < size_and_type.first; ++i)
12380 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
12386 return (sax->end_array() && sax->end_object());
12390 if (input_format == input_format_t::bjdata && size_and_type.first != npos && size_and_type.second ==
'B')
12393 return get_binary(input_format, size_and_type.first, result) && sax->binary(result);
12396 if (size_and_type.first != npos)
12398 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
12403 if (size_and_type.second != 0)
12405 if (size_and_type.second !=
'N')
12407 for (std::size_t i = 0; i < size_and_type.first; ++i)
12409 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
12418 for (std::size_t i = 0; i < size_and_type.first; ++i)
12420 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
12429 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
12434 while (current !=
']')
12436 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(
false)))
12444 return sax->end_array();
12450 bool get_ubjson_object()
12452 std::pair<std::size_t, char_int_type> size_and_type;
12453 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
12459 if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
12461 auto last_token = get_token_string();
12462 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
12463 exception_message(input_format,
"BJData object does not support ND-array size in optimized format",
"object"),
nullptr));
12467 if (size_and_type.first != npos)
12469 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))
12474 if (size_and_type.second != 0)
12476 for (std::size_t i = 0; i < size_and_type.first; ++i)
12478 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
12482 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
12491 for (std::size_t i = 0; i < size_and_type.first; ++i)
12493 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
12497 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
12507 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
12512 while (current !=
'}')
12514 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key,
false) || !sax->key(key)))
12518 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
12527 return sax->end_object();
12533 bool get_ubjson_high_precision_number()
12536 std::size_t size{};
12537 bool no_ndarray =
true;
12538 auto res = get_ubjson_size_value(size, no_ndarray);
12539 if (JSON_HEDLEY_UNLIKELY(!res))
12545 std::vector<char> number_vector;
12546 for (std::size_t i = 0; i < size; ++i)
12549 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
12553 number_vector.push_back(
static_cast<char>(current));
12557 using ia_type =
decltype(detail::input_adapter(number_vector));
12558 auto number_lexer = detail::lexer<BasicJsonType, ia_type>(detail::input_adapter(number_vector),
false);
12559 const auto result_number = number_lexer.scan();
12560 const auto number_string = number_lexer.get_token_string();
12561 const auto result_remainder = number_lexer.scan();
12563 using token_type =
typename detail::lexer_base<BasicJsonType>::token_type;
12565 if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
12567 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
12568 exception_message(input_format, concat(
"invalid number text: ", number_lexer.get_token_string()),
"high-precision number"),
nullptr));
12571 switch (result_number)
12573 case token_type::value_integer:
12574 return sax->number_integer(number_lexer.get_number_integer());
12575 case token_type::value_unsigned:
12576 return sax->number_unsigned(number_lexer.get_number_unsigned());
12577 case token_type::value_float:
12578 return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
12579 case token_type::uninitialized:
12580 case token_type::literal_true:
12581 case token_type::literal_false:
12582 case token_type::literal_null:
12583 case token_type::value_string:
12584 case token_type::begin_array:
12585 case token_type::begin_object:
12586 case token_type::end_array:
12587 case token_type::end_object:
12588 case token_type::name_separator:
12589 case token_type::value_separator:
12590 case token_type::parse_error:
12591 case token_type::end_of_input:
12592 case token_type::literal_or_value:
12594 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
12595 exception_message(input_format, concat(
"invalid number text: ", number_lexer.get_token_string()),
"high-precision number"),
nullptr));
12612 char_int_type get()
12615 return current = ia.get_character();
12627 bool get_to(T& dest,
const input_format_t format,
const char* context)
12629 auto new_chars_read = ia.get_elements(&dest);
12630 chars_read += new_chars_read;
12631 if (JSON_HEDLEY_UNLIKELY(new_chars_read <
sizeof(T)))
12635 sax->parse_error(chars_read,
"<end of file>", parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context),
nullptr));
12644 char_int_type get_ignore_noop()
12650 while (current ==
'N');
12655 template<
class NumberType>
12656 static void byte_swap(NumberType& number)
12658 constexpr std::size_t sz =
sizeof(number);
12659#ifdef __cpp_lib_byteswap
12660 if constexpr (sz == 1)
12664 else if constexpr(std::is_integral_v<NumberType>)
12666 number = std::byteswap(number);
12672 auto* ptr =
reinterpret_cast<std::uint8_t*
>(&number);
12673 for (std::size_t i = 0; i < sz / 2; ++i)
12677#ifdef __cpp_lib_byteswap
12697 template<
typename NumberType,
bool InputIsLittleEndian = false>
12698 bool get_number(
const input_format_t format, NumberType& result)
12702 if (JSON_HEDLEY_UNLIKELY(!get_to(result, format,
"number")))
12706 if (is_little_endian != (InputIsLittleEndian || format == input_format_t::bjdata))
12727 template<
typename NumberType>
12728 bool get_string(
const input_format_t format,
12729 const NumberType len,
12732 bool success =
true;
12733 for (NumberType i = 0; i < len; i++)
12736 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"string")))
12741 result.push_back(
static_cast<typename string_t::value_type
>(current));
12760 template<
typename NumberType>
12761 bool get_binary(
const input_format_t format,
12762 const NumberType len,
12765 bool success =
true;
12766 for (NumberType i = 0; i < len; i++)
12769 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"binary")))
12774 result.push_back(
static_cast<typename binary_t::value_type
>(current));
12784 JSON_HEDLEY_NON_NULL(3)
12785 bool unexpect_eof(const input_format_t format, const
char* context)
const
12787 if (JSON_HEDLEY_UNLIKELY(current == char_traits<char_type>::eof()))
12789 return sax->parse_error(chars_read,
"<end of file>",
12790 parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context),
nullptr));
12798 std::string get_token_string()
const
12800 std::array<char, 3> cr{{}};
12801 static_cast<void>((std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(current)));
12802 return std::string{cr.data()};
12811 std::string exception_message(
const input_format_t format,
12812 const std::string&
detail,
12813 const std::string& context)
const
12815 std::string error_msg =
"syntax error while parsing ";
12819 case input_format_t::cbor:
12820 error_msg +=
"CBOR";
12823 case input_format_t::msgpack:
12824 error_msg +=
"MessagePack";
12827 case input_format_t::ubjson:
12828 error_msg +=
"UBJSON";
12831 case input_format_t::bson:
12832 error_msg +=
"BSON";
12835 case input_format_t::bjdata:
12836 error_msg +=
"BJData";
12839 case input_format_t::json:
12841 JSON_ASSERT(
false);
12844 return concat(error_msg,
' ', context,
": ",
detail);
12848 static JSON_INLINE_VARIABLE
constexpr std::size_t npos = detail::unknown_size();
12851 InputAdapterType ia;
12854 char_int_type current = char_traits<char_type>::eof();
12857 std::size_t chars_read = 0;
12863 const input_format_t input_format = input_format_t::json;
12866 json_sax_t* sax =
nullptr;
12869#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ \
12870 make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
12872#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
12873 make_array<bjd_type>( \
12874 bjd_type{'B', "byte"}, \
12875 bjd_type{'C', "char"}, \
12876 bjd_type{'D', "double"}, \
12877 bjd_type{'I', "int16"}, \
12878 bjd_type{'L', "int64"}, \
12879 bjd_type{'M', "uint64"}, \
12880 bjd_type{'U', "uint8"}, \
12881 bjd_type{'d', "single"}, \
12882 bjd_type{'i', "int8"}, \
12883 bjd_type{'l', "int32"}, \
12884 bjd_type{'m', "uint32"}, \
12885 bjd_type{'u', "uint16"})
12887 JSON_PRIVATE_UNLESS_TESTED:
12890 const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers =
12891 JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_;
12893 using bjd_type = std::pair<char_int_type, string_t>;
12895 const decltype(JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_) bjd_types_map =
12896 JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_;
12898#undef JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_
12899#undef JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_
12902#ifndef JSON_HAS_CPP_17
12903 template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX>
12904 constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos;
12908NLOHMANN_JSON_NAMESPACE_END
12927#include <functional>
12949NLOHMANN_JSON_NAMESPACE_BEGIN
12956enum class parse_event_t : std::uint8_t
12972template<
typename BasicJsonType>
12973using parser_callback_t =
12974 std::function<bool(
int , parse_event_t , BasicJsonType& )>;
12981template<
typename BasicJsonType,
typename InputAdapterType>
12984 using number_integer_t =
typename BasicJsonType::number_integer_t;
12985 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
12986 using number_float_t =
typename BasicJsonType::number_float_t;
12987 using string_t =
typename BasicJsonType::string_t;
12988 using lexer_t = lexer<BasicJsonType, InputAdapterType>;
12989 using token_type =
typename lexer_t::token_type;
12993 explicit parser(InputAdapterType&& adapter,
12994 parser_callback_t<BasicJsonType> cb =
nullptr,
12995 const bool allow_exceptions_ =
true,
12996 const bool ignore_comments =
false,
12997 const bool ignore_trailing_commas_ =
false)
12998 : callback(std::move(cb))
12999 , m_lexer(std::move(adapter), ignore_comments)
13000 , allow_exceptions(allow_exceptions_)
13001 , ignore_trailing_commas(ignore_trailing_commas_)
13017 void parse(
const bool strict, BasicJsonType& result)
13021 json_sax_dom_callback_parser<BasicJsonType, InputAdapterType> sdp(result, callback, allow_exceptions, &m_lexer);
13022 sax_parse_internal(&sdp);
13025 if (strict && (get_token() != token_type::end_of_input))
13027 sdp.parse_error(m_lexer.get_position(),
13028 m_lexer.get_token_string(),
13029 parse_error::create(101, m_lexer.get_position(),
13030 exception_message(token_type::end_of_input,
"value"),
nullptr));
13034 if (sdp.is_errored())
13036 result = value_t::discarded;
13042 if (result.is_discarded())
13049 json_sax_dom_parser<BasicJsonType, InputAdapterType> sdp(result, allow_exceptions, &m_lexer);
13050 sax_parse_internal(&sdp);
13053 if (strict && (get_token() != token_type::end_of_input))
13055 sdp.parse_error(m_lexer.get_position(),
13056 m_lexer.get_token_string(),
13057 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"),
nullptr));
13061 if (sdp.is_errored())
13063 result = value_t::discarded;
13068 result.assert_invariant();
13077 bool accept(
const bool strict =
true)
13079 json_sax_acceptor<BasicJsonType> sax_acceptor;
13080 return sax_parse(&sax_acceptor, strict);
13083 template<
typename SAX>
13084 JSON_HEDLEY_NON_NULL(2)
13085 bool sax_parse(SAX* sax, const
bool strict = true)
13088 const bool result = sax_parse_internal(sax);
13091 if (result && strict && (get_token() != token_type::end_of_input))
13093 return sax->parse_error(m_lexer.get_position(),
13094 m_lexer.get_token_string(),
13095 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"),
nullptr));
13102 template<
typename SAX>
13103 JSON_HEDLEY_NON_NULL(2)
13104 bool sax_parse_internal(SAX* sax)
13108 std::vector<bool> states;
13110 bool skip_to_state_evaluation =
false;
13114 if (!skip_to_state_evaluation)
13117 switch (last_token)
13119 case token_type::begin_object:
13121 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
13127 if (get_token() == token_type::end_object)
13129 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
13137 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
13139 return sax->parse_error(m_lexer.get_position(),
13140 m_lexer.get_token_string(),
13141 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"),
nullptr));
13143 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
13149 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
13151 return sax->parse_error(m_lexer.get_position(),
13152 m_lexer.get_token_string(),
13153 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"),
nullptr));
13157 states.push_back(
false);
13164 case token_type::begin_array:
13166 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
13172 if (get_token() == token_type::end_array)
13174 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
13182 states.push_back(
true);
13188 case token_type::value_float:
13190 const auto res = m_lexer.get_number_float();
13192 if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))
13194 return sax->parse_error(m_lexer.get_position(),
13195 m_lexer.get_token_string(),
13196 out_of_range::create(406, concat(
"number overflow parsing '", m_lexer.get_token_string(),
'\''),
nullptr));
13199 if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
13207 case token_type::literal_false:
13209 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
false)))
13216 case token_type::literal_null:
13218 if (JSON_HEDLEY_UNLIKELY(!sax->null()))
13225 case token_type::literal_true:
13227 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
true)))
13234 case token_type::value_integer:
13236 if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer())))
13243 case token_type::value_string:
13245 if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))
13252 case token_type::value_unsigned:
13254 if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned())))
13261 case token_type::parse_error:
13264 return sax->parse_error(m_lexer.get_position(),
13265 m_lexer.get_token_string(),
13266 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized,
"value"),
nullptr));
13268 case token_type::end_of_input:
13270 if (JSON_HEDLEY_UNLIKELY(m_lexer.get_position().chars_read_total == 1))
13272 return sax->parse_error(m_lexer.get_position(),
13273 m_lexer.get_token_string(),
13274 parse_error::create(101, m_lexer.get_position(),
13275 "attempting to parse an empty input; check that your input string or stream contains the expected JSON",
nullptr));
13278 return sax->parse_error(m_lexer.get_position(),
13279 m_lexer.get_token_string(),
13280 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value,
"value"),
nullptr));
13282 case token_type::uninitialized:
13283 case token_type::end_array:
13284 case token_type::end_object:
13285 case token_type::name_separator:
13286 case token_type::value_separator:
13287 case token_type::literal_or_value:
13290 return sax->parse_error(m_lexer.get_position(),
13291 m_lexer.get_token_string(),
13292 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value,
"value"),
nullptr));
13298 skip_to_state_evaluation =
false;
13302 if (states.empty())
13312 if (get_token() == token_type::value_separator)
13318 if (!(ignore_trailing_commas && last_token == token_type::end_array))
13325 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
13327 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
13336 JSON_ASSERT(!states.empty());
13338 skip_to_state_evaluation =
true;
13342 return sax->parse_error(m_lexer.get_position(),
13343 m_lexer.get_token_string(),
13344 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array,
"array"),
nullptr));
13351 if (get_token() == token_type::value_separator)
13356 if (!(ignore_trailing_commas && last_token == token_type::end_object))
13359 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
13361 return sax->parse_error(m_lexer.get_position(),
13362 m_lexer.get_token_string(),
13363 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"),
nullptr));
13366 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
13372 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
13374 return sax->parse_error(m_lexer.get_position(),
13375 m_lexer.get_token_string(),
13376 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"),
nullptr));
13386 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
13388 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
13397 JSON_ASSERT(!states.empty());
13399 skip_to_state_evaluation =
true;
13403 return sax->parse_error(m_lexer.get_position(),
13404 m_lexer.get_token_string(),
13405 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object,
"object"),
nullptr));
13410 token_type get_token()
13412 return last_token = m_lexer.scan();
13415 std::string exception_message(
const token_type expected,
const std::string& context)
13417 std::string error_msg =
"syntax error ";
13419 if (!context.empty())
13421 error_msg += concat(
"while parsing ", context,
' ');
13426 if (last_token == token_type::parse_error)
13428 error_msg += concat(m_lexer.get_error_message(),
"; last read: '",
13429 m_lexer.get_token_string(),
'\'');
13433 error_msg += concat(
"unexpected ", lexer_t::token_type_name(last_token));
13436 if (expected != token_type::uninitialized)
13438 error_msg += concat(
"; expected ", lexer_t::token_type_name(expected));
13446 const parser_callback_t<BasicJsonType> callback =
nullptr;
13448 token_type last_token = token_type::uninitialized;
13452 const bool allow_exceptions =
true;
13454 const bool ignore_trailing_commas =
false;
13458NLOHMANN_JSON_NAMESPACE_END
13490NLOHMANN_JSON_NAMESPACE_BEGIN
13503class primitive_iterator_t
13506 using difference_type = std::ptrdiff_t;
13507 static constexpr difference_type begin_value = 0;
13508 static constexpr difference_type end_value = begin_value + 1;
13510 JSON_PRIVATE_UNLESS_TESTED:
13512 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
13515 constexpr difference_type get_value() const noexcept
13521 void set_begin() noexcept
13523 m_it = begin_value;
13527 void set_end() noexcept
13533 constexpr bool is_begin() const noexcept
13535 return m_it == begin_value;
13539 constexpr bool is_end() const noexcept
13541 return m_it == end_value;
13544 friend constexpr bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
13546 return lhs.m_it == rhs.m_it;
13549 friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
13551 return lhs.m_it < rhs.m_it;
13554 primitive_iterator_t operator+(difference_type n)
noexcept
13556 auto result = *
this;
13561 friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
13563 return lhs.m_it - rhs.m_it;
13566 primitive_iterator_t& operator++() noexcept
13572 primitive_iterator_t operator++(
int)&
noexcept
13574 auto result = *
this;
13579 primitive_iterator_t& operator--() noexcept
13585 primitive_iterator_t operator--(
int)&
noexcept
13587 auto result = *
this;
13592 primitive_iterator_t& operator+=(difference_type n)
noexcept
13598 primitive_iterator_t& operator-=(difference_type n)
noexcept
13606NLOHMANN_JSON_NAMESPACE_END
13609NLOHMANN_JSON_NAMESPACE_BEGIN
13622 typename BasicJsonType::object_t::iterator object_iterator {};
13624 typename BasicJsonType::array_t::iterator array_iterator {};
13626 primitive_iterator_t primitive_iterator {};
13630NLOHMANN_JSON_NAMESPACE_END
13644#include <type_traits>
13661NLOHMANN_JSON_NAMESPACE_BEGIN
13666template<
typename IteratorType>
class iteration_proxy;
13667template<
typename IteratorType>
class iteration_proxy_value;
13685template<
typename BasicJsonType>
13691 friend other_iter_impl;
13692 friend BasicJsonType;
13696 using object_t =
typename BasicJsonType::object_t;
13697 using array_t =
typename BasicJsonType::array_t;
13700 "iter_impl only accepts (const) basic_json");
13702 static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value
13703 && std::is_base_of<std::bidirectional_iterator_tag, typename std::iterator_traits<typename array_t::iterator>::iterator_category>::value,
13704 "basic_json iterator assumes array and object type iterators satisfy the LegacyBidirectionalIterator named requirement.");
13719 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
13720 typename BasicJsonType::const_pointer,
13721 typename BasicJsonType::pointer>::type;
13724 typename std::conditional<std::is_const<BasicJsonType>::value,
13725 typename BasicJsonType::const_reference,
13726 typename BasicJsonType::reference>::type;
13741 JSON_ASSERT(m_object !=
nullptr);
13743 switch (m_object->m_data.m_type)
13745 case value_t::object:
13747 m_it.object_iterator =
typename object_t::iterator();
13751 case value_t::array:
13753 m_it.array_iterator =
typename array_t::iterator();
13757 case value_t::null:
13758 case value_t::string:
13759 case value_t::boolean:
13760 case value_t::number_integer:
13761 case value_t::number_unsigned:
13762 case value_t::number_float:
13763 case value_t::binary:
13764 case value_t::discarded:
13767 m_it.primitive_iterator = primitive_iterator_t();
13790 : m_object(other.m_object), m_it(other.m_it)
13801 if (&other !=
this)
13803 m_object = other.m_object;
13815 : m_object(other.m_object), m_it(other.m_it)
13826 m_object = other.m_object;
13831 JSON_PRIVATE_UNLESS_TESTED:
13836 void set_begin() noexcept
13838 JSON_ASSERT(m_object !=
nullptr);
13840 switch (m_object->m_data.m_type)
13842 case value_t::object:
13844 m_it.object_iterator = m_object->m_data.m_value.object->begin();
13848 case value_t::array:
13850 m_it.array_iterator = m_object->m_data.m_value.array->begin();
13854 case value_t::null:
13857 m_it.primitive_iterator.set_end();
13861 case value_t::string:
13862 case value_t::boolean:
13863 case value_t::number_integer:
13864 case value_t::number_unsigned:
13865 case value_t::number_float:
13866 case value_t::binary:
13867 case value_t::discarded:
13870 m_it.primitive_iterator.set_begin();
13882 JSON_ASSERT(m_object !=
nullptr);
13884 switch (m_object->m_data.m_type)
13886 case value_t::object:
13888 m_it.object_iterator = m_object->m_data.m_value.object->end();
13892 case value_t::array:
13894 m_it.array_iterator = m_object->m_data.m_value.array->end();
13898 case value_t::null:
13899 case value_t::string:
13900 case value_t::boolean:
13901 case value_t::number_integer:
13902 case value_t::number_unsigned:
13903 case value_t::number_float:
13904 case value_t::binary:
13905 case value_t::discarded:
13908 m_it.primitive_iterator.set_end();
13921 JSON_ASSERT(m_object !=
nullptr);
13923 switch (m_object->m_data.m_type)
13925 case value_t::object:
13927 JSON_ASSERT(m_it.object_iterator != m_object->m_data.m_value.object->end());
13928 return m_it.object_iterator->second;
13931 case value_t::array:
13933 JSON_ASSERT(m_it.array_iterator != m_object->m_data.m_value.array->end());
13934 return *m_it.array_iterator;
13937 case value_t::null:
13938 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13940 case value_t::string:
13941 case value_t::boolean:
13942 case value_t::number_integer:
13943 case value_t::number_unsigned:
13944 case value_t::number_float:
13945 case value_t::binary:
13946 case value_t::discarded:
13949 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
13954 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13965 JSON_ASSERT(m_object !=
nullptr);
13967 switch (m_object->m_data.m_type)
13969 case value_t::object:
13971 JSON_ASSERT(m_it.object_iterator != m_object->m_data.m_value.object->end());
13972 return &(m_it.object_iterator->second);
13975 case value_t::array:
13977 JSON_ASSERT(m_it.array_iterator != m_object->m_data.m_value.array->end());
13978 return &*m_it.array_iterator;
13981 case value_t::null:
13982 case value_t::string:
13983 case value_t::boolean:
13984 case value_t::number_integer:
13985 case value_t::number_unsigned:
13986 case value_t::number_float:
13987 case value_t::binary:
13988 case value_t::discarded:
13991 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
13996 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
14007 auto result = *
this;
14018 JSON_ASSERT(m_object !=
nullptr);
14020 switch (m_object->m_data.m_type)
14022 case value_t::object:
14024 std::advance(m_it.object_iterator, 1);
14028 case value_t::array:
14030 std::advance(m_it.array_iterator, 1);
14034 case value_t::null:
14035 case value_t::string:
14036 case value_t::boolean:
14037 case value_t::number_integer:
14038 case value_t::number_unsigned:
14039 case value_t::number_float:
14040 case value_t::binary:
14041 case value_t::discarded:
14044 ++m_it.primitive_iterator;
14058 auto result = *
this;
14069 JSON_ASSERT(m_object !=
nullptr);
14071 switch (m_object->m_data.m_type)
14073 case value_t::object:
14075 std::advance(m_it.object_iterator, -1);
14079 case value_t::array:
14081 std::advance(m_it.array_iterator, -1);
14085 case value_t::null:
14086 case value_t::string:
14087 case value_t::boolean:
14088 case value_t::number_integer:
14089 case value_t::number_unsigned:
14090 case value_t::number_float:
14091 case value_t::binary:
14092 case value_t::discarded:
14095 --m_it.primitive_iterator;
14107 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 >
14111 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
14113 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", m_object));
14117 if (m_object ==
nullptr)
14122 switch (m_object->m_data.m_type)
14124 case value_t::object:
14125 return (m_it.object_iterator == other.m_it.object_iterator);
14127 case value_t::array:
14128 return (m_it.array_iterator == other.m_it.array_iterator);
14130 case value_t::null:
14131 case value_t::string:
14132 case value_t::boolean:
14133 case value_t::number_integer:
14134 case value_t::number_unsigned:
14135 case value_t::number_float:
14136 case value_t::binary:
14137 case value_t::discarded:
14139 return (m_it.primitive_iterator == other.m_it.primitive_iterator);
14147 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 >
14160 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
14162 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", m_object));
14166 if (m_object ==
nullptr)
14172 switch (m_object->m_data.m_type)
14174 case value_t::object:
14175 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators", m_object));
14177 case value_t::array:
14180 case value_t::null:
14181 case value_t::string:
14182 case value_t::boolean:
14183 case value_t::number_integer:
14184 case value_t::number_unsigned:
14185 case value_t::number_float:
14186 case value_t::binary:
14187 case value_t::discarded:
14199 return !other.operator < (*this);
14208 return !operator<=(other);
14226 JSON_ASSERT(m_object !=
nullptr);
14228 switch (m_object->m_data.m_type)
14230 case value_t::object:
14231 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", m_object));
14233 case value_t::array:
14235 std::advance(m_it.array_iterator, i);
14239 case value_t::null:
14240 case value_t::string:
14241 case value_t::boolean:
14242 case value_t::number_integer:
14243 case value_t::number_unsigned:
14244 case value_t::number_float:
14245 case value_t::binary:
14246 case value_t::discarded:
14249 m_it.primitive_iterator += i;
14263 return operator+=(-i);
14272 auto result = *
this;
14294 auto result = *
this;
14305 JSON_ASSERT(m_object !=
nullptr);
14307 switch (m_object->m_data.m_type)
14309 case value_t::object:
14310 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", m_object));
14312 case value_t::array:
14315 case value_t::null:
14316 case value_t::string:
14317 case value_t::boolean:
14318 case value_t::number_integer:
14319 case value_t::number_unsigned:
14320 case value_t::number_float:
14321 case value_t::binary:
14322 case value_t::discarded:
14334 JSON_ASSERT(m_object !=
nullptr);
14336 switch (m_object->m_data.m_type)
14338 case value_t::object:
14339 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators", m_object));
14341 case value_t::array:
14342 return *std::next(m_it.array_iterator, n);
14344 case value_t::null:
14345 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
14347 case value_t::string:
14348 case value_t::boolean:
14349 case value_t::number_integer:
14350 case value_t::number_unsigned:
14351 case value_t::number_float:
14352 case value_t::binary:
14353 case value_t::discarded:
14356 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n))
14361 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
14370 const typename object_t::key_type&
key()
const
14372 JSON_ASSERT(m_object !=
nullptr);
14374 if (JSON_HEDLEY_LIKELY(m_object->is_object()))
14376 return m_it.object_iterator->first;
14379 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators", m_object));
14388 return operator*();
14391 JSON_PRIVATE_UNLESS_TESTED:
14393 pointer m_object =
nullptr;
14399NLOHMANN_JSON_NAMESPACE_END
14421NLOHMANN_JSON_NAMESPACE_BEGIN
14447template<
typename Base>
14451 using difference_type = std::ptrdiff_t;
14515 return *(this->operator+(n));
14519 auto key() const -> decltype(std::declval<Base>().key())
14521 auto it = --this->base();
14528 auto it = --this->base();
14529 return it.operator * ();
14534NLOHMANN_JSON_NAMESPACE_END
14549#include <type_traits>
14554NLOHMANN_JSON_NAMESPACE_BEGIN
14571using json_base_class =
typename std::conditional <
14572 std::is_same<T, void>::value,
14578NLOHMANN_JSON_NAMESPACE_END
14591#include <algorithm>
14615NLOHMANN_JSON_NAMESPACE_BEGIN
14619template<
typename RefStringType>
14623 NLOHMANN_BASIC_JSON_TPL_DECLARATION
14629 template<
typename T>
14630 struct string_t_helper
14635 NLOHMANN_BASIC_JSON_TPL_DECLARATION
14636 struct string_t_helper<NLOHMANN_BASIC_JSON_TPL>
14638 using type = StringType;
14643 using string_t =
typename string_t_helper<RefStringType>::type;
14648 : reference_tokens(split(s))
14655 return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
14657 [](
const string_t& a,
const string_t& b)
14659 return detail::concat(a,
'/', detail::escape(b));
14665 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, to_string())
14666 operator string_t()
const
14668 return to_string();
14685 reference_tokens.insert(reference_tokens.end(),
14686 ptr.reference_tokens.begin(),
14687 ptr.reference_tokens.end());
14695 push_back(std::move(token));
14703 return *
this /= std::to_string(array_idx);
14746 if (JSON_HEDLEY_UNLIKELY(empty()))
14748 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
14751 reference_tokens.pop_back();
14758 if (JSON_HEDLEY_UNLIKELY(empty()))
14760 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
14763 return reference_tokens.back();
14770 reference_tokens.push_back(token);
14777 reference_tokens.push_back(std::move(token));
14784 return reference_tokens.empty();
14798 template<
typename BasicJsonType>
14799 static typename BasicJsonType::size_type array_index(
const string_t& s)
14801 using size_type =
typename BasicJsonType::size_type;
14804 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] ==
'0'))
14810 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >=
'1' && s[0] <=
'9')))
14815 const char* p = s.c_str();
14816 char* p_end =
nullptr;
14818 const unsigned long long res = std::strtoull(p, &p_end, 10);
14821 || JSON_HEDLEY_UNLIKELY(
static_cast<std::size_t
>(p_end - p) != s.size()))
14823 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", s,
"'"),
nullptr));
14828 if (res >=
static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))
14830 JSON_THROW(detail::out_of_range::create(410, detail::concat(
"array index ", s,
" exceeds size_type"),
nullptr));
14833 return static_cast<size_type
>(res);
14836 JSON_PRIVATE_UNLESS_TESTED:
14839 if (JSON_HEDLEY_UNLIKELY(empty()))
14841 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
14845 result.reference_tokens = {reference_tokens[0]};
14858 template<
typename BasicJsonType>
14859 BasicJsonType& get_and_create(BasicJsonType& j)
const
14865 for (
const auto& reference_token : reference_tokens)
14867 switch (result->type())
14871 if (reference_token ==
"0")
14874 result = &result->operator[](0);
14879 result = &result->operator[](reference_token);
14887 result = &result->operator[](reference_token);
14894 result = &result->operator[](array_index<BasicJsonType>(reference_token));
14912 JSON_THROW(detail::type_error::create(313,
"invalid value to unflatten", &j));
14938 template<
typename BasicJsonType>
14939 BasicJsonType& get_unchecked(BasicJsonType* ptr)
const
14941 for (
const auto& reference_token : reference_tokens)
14944 if (ptr->is_null())
14948 std::all_of(reference_token.begin(), reference_token.end(),
14949 [](
const unsigned char x)
14951 return std::isdigit(x);
14955 *ptr = (nums || reference_token ==
"-")
14960 switch (ptr->type())
14965 ptr = &ptr->operator[](reference_token);
14971 if (reference_token ==
"-")
14974 ptr = &ptr->operator[](ptr->m_data.m_value.array->size());
14979 ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));
14993 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
15006 template<
typename BasicJsonType>
15007 BasicJsonType& get_checked(BasicJsonType* ptr)
const
15009 for (
const auto& reference_token : reference_tokens)
15011 switch (ptr->type())
15016 ptr = &ptr->at(reference_token);
15022 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
15025 JSON_THROW(detail::out_of_range::create(402, detail::concat(
15026 "array index '-' (", std::to_string(ptr->m_data.m_value.array->size()),
15027 ") is out of range"), ptr));
15031 ptr = &ptr->at(array_index<BasicJsonType>(reference_token));
15044 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
15064 template<
typename BasicJsonType>
15065 const BasicJsonType& get_unchecked(
const BasicJsonType* ptr)
const
15067 for (
const auto& reference_token : reference_tokens)
15069 switch (ptr->type())
15074 ptr = &ptr->operator[](reference_token);
15080 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
15083 JSON_THROW(detail::out_of_range::create(402, detail::concat(
"array index '-' (", std::to_string(ptr->m_data.m_value.array->size()),
") is out of range"), ptr));
15087 ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));
15100 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
15113 template<
typename BasicJsonType>
15114 const BasicJsonType& get_checked(
const BasicJsonType* ptr)
const
15116 for (
const auto& reference_token : reference_tokens)
15118 switch (ptr->type())
15123 ptr = &ptr->at(reference_token);
15129 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
15132 JSON_THROW(detail::out_of_range::create(402, detail::concat(
15133 "array index '-' (", std::to_string(ptr->m_data.m_value.array->size()),
15134 ") is out of range"), ptr));
15138 ptr = &ptr->at(array_index<BasicJsonType>(reference_token));
15151 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
15162 template<
typename BasicJsonType>
15163 bool contains(
const BasicJsonType* ptr)
const
15165 for (
const auto& reference_token : reference_tokens)
15167 switch (ptr->type())
15171 if (!ptr->contains(reference_token))
15177 ptr = &ptr->operator[](reference_token);
15183 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
15188 if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !(
"0" <= reference_token && reference_token <=
"9")))
15193 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
15195 if (JSON_HEDLEY_UNLIKELY(!(
'1' <= reference_token[0] && reference_token[0] <=
'9')))
15200 for (std::size_t i = 1; i < reference_token.size(); i++)
15202 if (JSON_HEDLEY_UNLIKELY(!(
'0' <= reference_token[i] && reference_token[i] <=
'9')))
15210 const auto idx = array_index<BasicJsonType>(reference_token);
15211 if (idx >= ptr->size())
15217 ptr = &ptr->operator[](idx);
15251 static std::vector<string_t> split(
const string_t& reference_string)
15253 std::vector<string_t> result;
15256 if (reference_string.empty())
15262 if (JSON_HEDLEY_UNLIKELY(reference_string[0] !=
'/'))
15264 JSON_THROW(
detail::parse_error::create(107, 1, detail::concat(
"JSON pointer must be empty or begin with '/' - was: '", reference_string,
"'"),
nullptr));
15272 std::size_t slash = reference_string.find_first_of(
'/', 1),
15279 start = (slash == string_t::npos) ? 0 : slash + 1,
15281 slash = reference_string.find_first_of(
'/', start))
15285 auto reference_token = reference_string.substr(start, slash - start);
15288 for (std::size_t pos = reference_token.find_first_of(
'~');
15289 pos != string_t::npos;
15290 pos = reference_token.find_first_of(
'~', pos + 1))
15292 JSON_ASSERT(reference_token[pos] ==
'~');
15295 if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
15296 (reference_token[pos + 1] !=
'0' &&
15297 reference_token[pos + 1] !=
'1')))
15305 result.push_back(reference_token);
15319 template<
typename BasicJsonType>
15320 static void flatten(
const string_t& reference_string,
15321 const BasicJsonType& value,
15322 BasicJsonType& result)
15324 switch (value.type())
15328 if (value.m_data.m_value.array->empty())
15331 result[reference_string] =
nullptr;
15336 for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i)
15338 flatten(detail::concat<string_t>(reference_string,
'/', std::to_string(i)),
15339 value.m_data.m_value.array->operator[](i), result);
15347 if (value.m_data.m_value.object->empty())
15350 result[reference_string] =
nullptr;
15355 for (
const auto& element : *value.m_data.m_value.
object)
15357 flatten(detail::concat<string_t>(reference_string,
'/',
detail::escape(element.first)), element.second, result);
15374 result[reference_string] = value;
15390 template<
typename BasicJsonType>
15391 static BasicJsonType
15392 unflatten(
const BasicJsonType& value)
15394 if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
15396 JSON_THROW(detail::type_error::create(314,
"only objects can be unflattened", &value));
15399 BasicJsonType result;
15402 for (
const auto& element : *value.m_data.m_value.
object)
15404 if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
15406 JSON_THROW(detail::type_error::create(315,
"values in object must be primitive", &element.second));
15413 json_pointer(element.first).get_and_create(result) = element.second;
15423 result.reference_tokens = reference_tokens;
15430 result.reference_tokens = std::move(reference_tokens);
15435#if JSON_HAS_THREE_WAY_COMPARISON
15438 template<
typename RefStringTypeRhs>
15441 return reference_tokens == rhs.reference_tokens;
15446 JSON_HEDLEY_DEPRECATED_FOR(3.11.2,
operator==(
json_pointer))
15453 template<
typename RefStringTypeRhs>
15456 return reference_tokens <=> rhs.reference_tokens;
15461 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15468 template<
typename RefStringTypeLhs,
typename StringType>
15471 const StringType& rhs);
15475 template<
typename RefStringTypeRhs,
typename StringType>
15477 friend bool operator==(
const StringType& lhs,
15482 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15489 template<
typename RefStringTypeLhs,
typename StringType>
15492 const StringType& rhs);
15496 template<
typename RefStringTypeRhs,
typename StringType>
15498 friend bool operator!=(
const StringType& lhs,
15502 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15510 std::vector<string_t> reference_tokens;
15513#if !JSON_HAS_THREE_WAY_COMPARISON
15515template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15519 return lhs.reference_tokens == rhs.reference_tokens;
15522template<
typename RefStringTypeLhs,
15523 typename StringType =
typename json_pointer<RefStringTypeLhs>::string_t>
15526 const StringType& rhs)
15531template<
typename RefStringTypeRhs,
15532 typename StringType =
typename json_pointer<RefStringTypeRhs>::string_t>
15534inline
bool operator==(const StringType& lhs,
15540template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15544 return !(lhs == rhs);
15547template<
typename RefStringTypeLhs,
15548 typename StringType =
typename json_pointer<RefStringTypeLhs>::string_t>
15551 const StringType& rhs)
15553 return !(lhs == rhs);
15556template<
typename RefStringTypeRhs,
15557 typename StringType =
typename json_pointer<RefStringTypeRhs>::string_t>
15559inline
bool operator!=(const StringType& lhs,
15562 return !(lhs == rhs);
15565template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15569 return lhs.reference_tokens < rhs.reference_tokens;
15573NLOHMANN_JSON_NAMESPACE_END
15586#include <initializer_list>
15594NLOHMANN_JSON_NAMESPACE_BEGIN
15598template<
typename BasicJsonType>
15602 using value_type = BasicJsonType;
15605 : owned_value(std::move(value))
15609 : value_ref(&value)
15612 json_ref(std::initializer_list<json_ref> init)
15613 : owned_value(init)
15618 enable_if_t<std::is_constructible<value_type, Args...>::value,
int> = 0 >
15620 : owned_value(std::forward<Args>(args)...)
15630 value_type moved_or_copied()
const
15632 if (value_ref ==
nullptr)
15634 return std::move(owned_value);
15639 value_type
const& operator*()
const
15641 return value_ref ? *value_ref : owned_value;
15644 value_type
const* operator->()
const
15650 mutable value_type owned_value =
nullptr;
15651 value_type
const* value_ref =
nullptr;
15655NLOHMANN_JSON_NAMESPACE_END
15680#include <algorithm>
15706#include <algorithm>
15721NLOHMANN_JSON_NAMESPACE_BEGIN
15726template<
typename CharType>
struct output_adapter_protocol
15728 virtual void write_character(CharType c) = 0;
15729 virtual void write_characters(
const CharType* s, std::size_t length) = 0;
15730 virtual ~output_adapter_protocol() =
default;
15732 output_adapter_protocol() =
default;
15733 output_adapter_protocol(
const output_adapter_protocol&) =
default;
15734 output_adapter_protocol(output_adapter_protocol&&) noexcept = default;
15735 output_adapter_protocol& operator=(const output_adapter_protocol&) = default;
15736 output_adapter_protocol& operator=(output_adapter_protocol&&) noexcept = default;
15740template<typename CharType>
15741using output_adapter_t = std::shared_ptr<output_adapter_protocol<CharType>>;
15744template<typename CharType, typename AllocatorType = std::allocator<CharType>>
15745class output_vector_adapter : public output_adapter_protocol<CharType>
15748 explicit output_vector_adapter(std::vector<CharType, AllocatorType>& vec) noexcept
15752 void write_character(CharType c)
override
15757 JSON_HEDLEY_NON_NULL(2)
15758 void write_characters(const CharType* s, std::
size_t length)
override
15760 v.insert(v.end(), s, s + length);
15764 std::vector<CharType, AllocatorType>& v;
15769template<
typename CharType>
15770class output_stream_adapter :
public output_adapter_protocol<CharType>
15773 explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
15777 void write_character(CharType c)
override
15782 JSON_HEDLEY_NON_NULL(2)
15783 void write_characters(const CharType* s, std::
size_t length)
override
15785 stream.write(s,
static_cast<std::streamsize
>(length));
15789 std::basic_ostream<CharType>& stream;
15794template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
15795class output_string_adapter :
public output_adapter_protocol<CharType>
15798 explicit output_string_adapter(StringType& s) noexcept
15802 void write_character(CharType c)
override
15807 JSON_HEDLEY_NON_NULL(2)
15808 void write_characters(const CharType* s, std::
size_t length)
override
15810 str.append(s, length);
15817template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
15818class output_adapter
15821 template<
typename AllocatorType = std::allocator<CharType>>
15822 output_adapter(std::vector<CharType, AllocatorType>& vec)
15823 : oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) {}
15826 output_adapter(std::basic_ostream<CharType>& s)
15827 : oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
15830 output_adapter(StringType& s)
15831 : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
15833 operator output_adapter_t<CharType>()
15839 output_adapter_t<CharType> oa =
nullptr;
15843NLOHMANN_JSON_NAMESPACE_END
15848NLOHMANN_JSON_NAMESPACE_BEGIN
15853enum class bjdata_version_t
15866template<
typename BasicJsonType,
typename CharType>
15869 using string_t =
typename BasicJsonType::string_t;
15870 using binary_t =
typename BasicJsonType::binary_t;
15871 using number_float_t =
typename BasicJsonType::number_float_t;
15879 explicit binary_writer(output_adapter_t<CharType> adapter) : oa(std::move(adapter))
15888 void write_bson(
const BasicJsonType& j)
15892 case value_t::object:
15894 write_bson_object(*j.m_data.m_value.object);
15898 case value_t::null:
15899 case value_t::array:
15900 case value_t::string:
15901 case value_t::boolean:
15902 case value_t::number_integer:
15903 case value_t::number_unsigned:
15904 case value_t::number_float:
15905 case value_t::binary:
15906 case value_t::discarded:
15909 JSON_THROW(type_error::create(317, concat(
"to serialize to BSON, top-level type must be object, but is ", j.type_name()), &j));
15917 void write_cbor(
const BasicJsonType& j)
15921 case value_t::null:
15923 oa->write_character(to_char_type(0xF6));
15927 case value_t::boolean:
15929 oa->write_character(j.m_data.m_value.boolean
15930 ? to_char_type(0xF5)
15931 : to_char_type(0xF4));
15935 case value_t::number_integer:
15937 if (j.m_data.m_value.number_integer >= 0)
15942 if (j.m_data.m_value.number_integer <= 0x17)
15944 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15946 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
15948 oa->write_character(to_char_type(0x18));
15949 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15951 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
15953 oa->write_character(to_char_type(0x19));
15954 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
15956 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
15958 oa->write_character(to_char_type(0x1A));
15959 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
15963 oa->write_character(to_char_type(0x1B));
15964 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
15971 const auto positive_number = -1 - j.m_data.m_value.number_integer;
15972 if (j.m_data.m_value.number_integer >= -24)
15974 write_number(
static_cast<std::uint8_t
>(0x20 + positive_number));
15976 else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
15978 oa->write_character(to_char_type(0x38));
15979 write_number(
static_cast<std::uint8_t
>(positive_number));
15981 else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
15983 oa->write_character(to_char_type(0x39));
15984 write_number(
static_cast<std::uint16_t
>(positive_number));
15986 else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
15988 oa->write_character(to_char_type(0x3A));
15989 write_number(
static_cast<std::uint32_t
>(positive_number));
15993 oa->write_character(to_char_type(0x3B));
15994 write_number(
static_cast<std::uint64_t
>(positive_number));
16000 case value_t::number_unsigned:
16002 if (j.m_data.m_value.number_unsigned <= 0x17)
16004 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_unsigned));
16006 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
16008 oa->write_character(to_char_type(0x18));
16009 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_unsigned));
16011 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
16013 oa->write_character(to_char_type(0x19));
16014 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_unsigned));
16016 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
16018 oa->write_character(to_char_type(0x1A));
16019 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_unsigned));
16023 oa->write_character(to_char_type(0x1B));
16024 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_unsigned));
16029 case value_t::number_float:
16031 if (std::isnan(j.m_data.m_value.number_float))
16034 oa->write_character(to_char_type(0xF9));
16035 oa->write_character(to_char_type(0x7E));
16036 oa->write_character(to_char_type(0x00));
16038 else if (std::isinf(j.m_data.m_value.number_float))
16041 oa->write_character(to_char_type(0xf9));
16042 oa->write_character(j.m_data.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
16043 oa->write_character(to_char_type(0x00));
16047 write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::cbor);
16052 case value_t::string:
16055 const auto N = j.m_data.m_value.string->size();
16058 write_number(
static_cast<std::uint8_t
>(0x60 + N));
16060 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
16062 oa->write_character(to_char_type(0x78));
16063 write_number(
static_cast<std::uint8_t
>(N));
16065 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16067 oa->write_character(to_char_type(0x79));
16068 write_number(
static_cast<std::uint16_t
>(N));
16070 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16072 oa->write_character(to_char_type(0x7A));
16073 write_number(
static_cast<std::uint32_t
>(N));
16076 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
16078 oa->write_character(to_char_type(0x7B));
16079 write_number(
static_cast<std::uint64_t
>(N));
16084 oa->write_characters(
16085 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
16086 j.m_data.m_value.string->size());
16090 case value_t::array:
16093 const auto N = j.m_data.m_value.array->size();
16096 write_number(
static_cast<std::uint8_t
>(0x80 + N));
16098 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
16100 oa->write_character(to_char_type(0x98));
16101 write_number(
static_cast<std::uint8_t
>(N));
16103 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16105 oa->write_character(to_char_type(0x99));
16106 write_number(
static_cast<std::uint16_t
>(N));
16108 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16110 oa->write_character(to_char_type(0x9A));
16111 write_number(
static_cast<std::uint32_t
>(N));
16114 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
16116 oa->write_character(to_char_type(0x9B));
16117 write_number(
static_cast<std::uint64_t
>(N));
16122 for (
const auto& el : *j.m_data.m_value.
array)
16129 case value_t::binary:
16131 if (j.m_data.m_value.binary->has_subtype())
16133 if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)())
16135 write_number(
static_cast<std::uint8_t
>(0xd8));
16136 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.binary->subtype()));
16138 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint16_t>::max)())
16140 write_number(
static_cast<std::uint8_t
>(0xd9));
16141 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.binary->subtype()));
16143 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint32_t>::max)())
16145 write_number(
static_cast<std::uint8_t
>(0xda));
16146 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.binary->subtype()));
16148 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint64_t>::max)())
16150 write_number(
static_cast<std::uint8_t
>(0xdb));
16151 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.binary->subtype()));
16156 const auto N = j.m_data.m_value.binary->size();
16159 write_number(
static_cast<std::uint8_t
>(0x40 + N));
16161 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
16163 oa->write_character(to_char_type(0x58));
16164 write_number(
static_cast<std::uint8_t
>(N));
16166 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16168 oa->write_character(to_char_type(0x59));
16169 write_number(
static_cast<std::uint16_t
>(N));
16171 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16173 oa->write_character(to_char_type(0x5A));
16174 write_number(
static_cast<std::uint32_t
>(N));
16177 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
16179 oa->write_character(to_char_type(0x5B));
16180 write_number(
static_cast<std::uint64_t
>(N));
16185 oa->write_characters(
16186 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
16192 case value_t::object:
16195 const auto N = j.m_data.m_value.object->size();
16198 write_number(
static_cast<std::uint8_t
>(0xA0 + N));
16200 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
16202 oa->write_character(to_char_type(0xB8));
16203 write_number(
static_cast<std::uint8_t
>(N));
16205 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16207 oa->write_character(to_char_type(0xB9));
16208 write_number(
static_cast<std::uint16_t
>(N));
16210 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16212 oa->write_character(to_char_type(0xBA));
16213 write_number(
static_cast<std::uint32_t
>(N));
16216 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
16218 oa->write_character(to_char_type(0xBB));
16219 write_number(
static_cast<std::uint64_t
>(N));
16224 for (
const auto& el : *j.m_data.m_value.
object)
16226 write_cbor(el.first);
16227 write_cbor(el.second);
16232 case value_t::discarded:
16241 void write_msgpack(
const BasicJsonType& j)
16245 case value_t::null:
16247 oa->write_character(to_char_type(0xC0));
16251 case value_t::boolean:
16253 oa->write_character(j.m_data.m_value.boolean
16254 ? to_char_type(0xC3)
16255 : to_char_type(0xC2));
16259 case value_t::number_integer:
16261 if (j.m_data.m_value.number_integer >= 0)
16266 if (j.m_data.m_value.number_unsigned < 128)
16269 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
16271 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
16274 oa->write_character(to_char_type(0xCC));
16275 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
16277 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
16280 oa->write_character(to_char_type(0xCD));
16281 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
16283 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
16286 oa->write_character(to_char_type(0xCE));
16287 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
16289 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
16292 oa->write_character(to_char_type(0xCF));
16293 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
16298 if (j.m_data.m_value.number_integer >= -32)
16301 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.number_integer));
16303 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&
16304 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
16307 oa->write_character(to_char_type(0xD0));
16308 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.number_integer));
16310 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&
16311 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
16314 oa->write_character(to_char_type(0xD1));
16315 write_number(
static_cast<std::int16_t
>(j.m_data.m_value.number_integer));
16317 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&
16318 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
16321 oa->write_character(to_char_type(0xD2));
16322 write_number(
static_cast<std::int32_t
>(j.m_data.m_value.number_integer));
16324 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&
16325 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
16328 oa->write_character(to_char_type(0xD3));
16329 write_number(
static_cast<std::int64_t
>(j.m_data.m_value.number_integer));
16335 case value_t::number_unsigned:
16337 if (j.m_data.m_value.number_unsigned < 128)
16340 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
16342 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
16345 oa->write_character(to_char_type(0xCC));
16346 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
16348 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
16351 oa->write_character(to_char_type(0xCD));
16352 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
16354 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
16357 oa->write_character(to_char_type(0xCE));
16358 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
16360 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
16363 oa->write_character(to_char_type(0xCF));
16364 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
16369 case value_t::number_float:
16371 write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::msgpack);
16375 case value_t::string:
16378 const auto N = j.m_data.m_value.string->size();
16382 write_number(
static_cast<std::uint8_t
>(0xA0 | N));
16384 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
16387 oa->write_character(to_char_type(0xD9));
16388 write_number(
static_cast<std::uint8_t
>(N));
16390 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16393 oa->write_character(to_char_type(0xDA));
16394 write_number(
static_cast<std::uint16_t
>(N));
16396 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16399 oa->write_character(to_char_type(0xDB));
16400 write_number(
static_cast<std::uint32_t
>(N));
16404 oa->write_characters(
16405 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
16406 j.m_data.m_value.string->size());
16410 case value_t::array:
16413 const auto N = j.m_data.m_value.array->size();
16417 write_number(
static_cast<std::uint8_t
>(0x90 | N));
16419 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16422 oa->write_character(to_char_type(0xDC));
16423 write_number(
static_cast<std::uint16_t
>(N));
16425 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16428 oa->write_character(to_char_type(0xDD));
16429 write_number(
static_cast<std::uint32_t
>(N));
16433 for (
const auto& el : *j.m_data.m_value.
array)
16440 case value_t::binary:
16444 const bool use_ext = j.m_data.m_value.binary->has_subtype();
16447 const auto N = j.m_data.m_value.binary->size();
16448 if (N <= (std::numeric_limits<std::uint8_t>::max)())
16450 std::uint8_t output_type{};
16457 output_type = 0xD4;
16460 output_type = 0xD5;
16463 output_type = 0xD6;
16466 output_type = 0xD7;
16469 output_type = 0xD8;
16472 output_type = 0xC7;
16480 output_type = 0xC4;
16484 oa->write_character(to_char_type(output_type));
16487 write_number(
static_cast<std::uint8_t
>(N));
16490 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16492 const std::uint8_t output_type = use_ext
16496 oa->write_character(to_char_type(output_type));
16497 write_number(
static_cast<std::uint16_t
>(N));
16499 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16501 const std::uint8_t output_type = use_ext
16505 oa->write_character(to_char_type(output_type));
16506 write_number(
static_cast<std::uint32_t
>(N));
16512 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.binary->subtype()));
16516 oa->write_characters(
16517 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
16523 case value_t::object:
16526 const auto N = j.m_data.m_value.object->size();
16530 write_number(
static_cast<std::uint8_t
>(0x80 | (N & 0xF)));
16532 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16535 oa->write_character(to_char_type(0xDE));
16536 write_number(
static_cast<std::uint16_t
>(N));
16538 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16541 oa->write_character(to_char_type(0xDF));
16542 write_number(
static_cast<std::uint32_t
>(N));
16546 for (
const auto& el : *j.m_data.m_value.
object)
16548 write_msgpack(el.first);
16549 write_msgpack(el.second);
16554 case value_t::discarded:
16568 void write_ubjson(
const BasicJsonType& j,
const bool use_count,
16569 const bool use_type,
const bool add_prefix =
true,
16570 const bool use_bjdata =
false,
const bjdata_version_t bjdata_version = bjdata_version_t::draft2)
16572 const bool bjdata_draft3 = use_bjdata && bjdata_version == bjdata_version_t::draft3;
16576 case value_t::null:
16580 oa->write_character(to_char_type(
'Z'));
16585 case value_t::boolean:
16589 oa->write_character(j.m_data.m_value.boolean
16590 ? to_char_type(
'T')
16591 : to_char_type(
'F'));
16596 case value_t::number_integer:
16598 write_number_with_ubjson_prefix(j.m_data.m_value.number_integer, add_prefix, use_bjdata);
16602 case value_t::number_unsigned:
16604 write_number_with_ubjson_prefix(j.m_data.m_value.number_unsigned, add_prefix, use_bjdata);
16608 case value_t::number_float:
16610 write_number_with_ubjson_prefix(j.m_data.m_value.number_float, add_prefix, use_bjdata);
16614 case value_t::string:
16618 oa->write_character(to_char_type(
'S'));
16620 write_number_with_ubjson_prefix(j.m_data.m_value.string->size(),
true, use_bjdata);
16621 oa->write_characters(
16622 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
16623 j.m_data.m_value.string->size());
16627 case value_t::array:
16631 oa->write_character(to_char_type(
'['));
16634 bool prefix_required =
true;
16635 if (use_type && !j.m_data.m_value.array->empty())
16637 JSON_ASSERT(use_count);
16638 const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
16639 const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
16640 [
this, first_prefix, use_bjdata](
const BasicJsonType & v)
16642 return ubjson_prefix(v, use_bjdata) == first_prefix;
16645 std::vector<CharType> bjdx = {
'[',
'{',
'S',
'H',
'T',
'F',
'N',
'Z'};
16647 if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
16649 prefix_required =
false;
16650 oa->write_character(to_char_type(
'$'));
16651 oa->write_character(first_prefix);
16657 oa->write_character(to_char_type(
'#'));
16658 write_number_with_ubjson_prefix(j.m_data.m_value.array->size(),
true, use_bjdata);
16661 for (
const auto& el : *j.m_data.m_value.
array)
16663 write_ubjson(el, use_count, use_type, prefix_required, use_bjdata, bjdata_version);
16668 oa->write_character(to_char_type(
']'));
16674 case value_t::binary:
16678 oa->write_character(to_char_type(
'['));
16681 if (use_type && (bjdata_draft3 || !j.m_data.m_value.binary->empty()))
16683 JSON_ASSERT(use_count);
16684 oa->write_character(to_char_type(
'$'));
16685 oa->write_character(bjdata_draft3 ?
'B' :
'U');
16690 oa->write_character(to_char_type(
'#'));
16691 write_number_with_ubjson_prefix(j.m_data.m_value.binary->size(),
true, use_bjdata);
16696 oa->write_characters(
16697 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
16698 j.m_data.m_value.binary->size());
16702 for (
size_t i = 0; i < j.m_data.m_value.binary->size(); ++i)
16704 oa->write_character(to_char_type(bjdata_draft3 ?
'B' :
'U'));
16705 oa->write_character(j.m_data.m_value.binary->data()[i]);
16711 oa->write_character(to_char_type(
']'));
16717 case value_t::object:
16719 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())
16721 if (!write_bjdata_ndarray(*j.m_data.m_value.object, use_count, use_type, bjdata_version))
16729 oa->write_character(to_char_type(
'{'));
16732 bool prefix_required =
true;
16733 if (use_type && !j.m_data.m_value.object->empty())
16735 JSON_ASSERT(use_count);
16736 const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
16737 const bool same_prefix = std::all_of(j.begin(), j.end(),
16738 [
this, first_prefix, use_bjdata](
const BasicJsonType & v)
16740 return ubjson_prefix(v, use_bjdata) == first_prefix;
16743 std::vector<CharType> bjdx = {
'[',
'{',
'S',
'H',
'T',
'F',
'N',
'Z'};
16745 if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
16747 prefix_required =
false;
16748 oa->write_character(to_char_type(
'$'));
16749 oa->write_character(first_prefix);
16755 oa->write_character(to_char_type(
'#'));
16756 write_number_with_ubjson_prefix(j.m_data.m_value.object->size(),
true, use_bjdata);
16759 for (
const auto& el : *j.m_data.m_value.
object)
16761 write_number_with_ubjson_prefix(el.first.size(),
true, use_bjdata);
16762 oa->write_characters(
16763 reinterpret_cast<const CharType*
>(el.first.c_str()),
16765 write_ubjson(el.second, use_count, use_type, prefix_required, use_bjdata, bjdata_version);
16770 oa->write_character(to_char_type(
'}'));
16776 case value_t::discarded:
16791 static std::size_t calc_bson_entry_header_size(
const string_t& name,
const BasicJsonType& j)
16793 const auto it = name.find(
static_cast<typename string_t::value_type
>(0));
16794 if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
16796 JSON_THROW(out_of_range::create(409, concat(
"BSON key cannot contain code point U+0000 (at byte ", std::to_string(it),
")"), &j));
16799 static_cast<void>(j);
16800 return 1ul + name.size() + 1u;
16806 void write_bson_entry_header(
const string_t& name,
16807 const std::uint8_t element_type)
16809 oa->write_character(to_char_type(element_type));
16810 oa->write_characters(
16811 reinterpret_cast<const CharType*
>(name.c_str()),
16818 void write_bson_boolean(
const string_t& name,
16821 write_bson_entry_header(name, 0x08);
16822 oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
16828 void write_bson_double(
const string_t& name,
16829 const double value)
16831 write_bson_entry_header(name, 0x01);
16832 write_number<double>(value,
true);
16838 static std::size_t calc_bson_string_size(
const string_t& value)
16840 return sizeof(std::int32_t) + value.size() + 1ul;
16846 void write_bson_string(
const string_t& name,
16847 const string_t& value)
16849 write_bson_entry_header(name, 0x02);
16851 write_number<std::int32_t>(
static_cast<std::int32_t
>(value.size() + 1ul),
true);
16852 oa->write_characters(
16853 reinterpret_cast<const CharType*
>(value.c_str()),
16860 void write_bson_null(
const string_t& name)
16862 write_bson_entry_header(name, 0x0A);
16868 static std::size_t calc_bson_integer_size(
const std::int64_t value)
16870 return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()
16871 ?
sizeof(std::int32_t)
16872 :
sizeof(std::int64_t);
16878 void write_bson_integer(
const string_t& name,
16879 const std::int64_t value)
16881 if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
16883 write_bson_entry_header(name, 0x10);
16884 write_number<std::int32_t>(
static_cast<std::int32_t
>(value),
true);
16888 write_bson_entry_header(name, 0x12);
16889 write_number<std::int64_t>(
static_cast<std::int64_t
>(value),
true);
16896 static constexpr std::size_t calc_bson_unsigned_size(
const std::uint64_t value)
noexcept
16898 return (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16899 ?
sizeof(std::int32_t)
16900 : sizeof(std::int64_t);
16906 void write_bson_unsigned(
const string_t& name,
16907 const BasicJsonType& j)
16909 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16911 write_bson_entry_header(name, 0x10 );
16912 write_number<std::int32_t>(
static_cast<std::int32_t
>(j.m_data.m_value.number_unsigned),
true);
16914 else if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
16916 write_bson_entry_header(name, 0x12 );
16917 write_number<std::int64_t>(
static_cast<std::int64_t
>(j.m_data.m_value.number_unsigned),
true);
16921 write_bson_entry_header(name, 0x11 );
16922 write_number<std::uint64_t>(
static_cast<std::uint64_t
>(j.m_data.m_value.number_unsigned),
true);
16929 void write_bson_object_entry(
const string_t& name,
16930 const typename BasicJsonType::object_t& value)
16932 write_bson_entry_header(name, 0x03);
16933 write_bson_object(value);
16939 static std::size_t calc_bson_array_size(
const typename BasicJsonType::array_t& value)
16941 std::size_t array_index = 0ul;
16943 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)
16945 return result + calc_bson_element_size(std::to_string(array_index++), el);
16948 return sizeof(std::int32_t) + embedded_document_size + 1ul;
16954 static std::size_t calc_bson_binary_size(
const typename BasicJsonType::binary_t& value)
16956 return sizeof(std::int32_t) + value.size() + 1ul;
16962 void write_bson_array(
const string_t& name,
16963 const typename BasicJsonType::array_t& value)
16965 write_bson_entry_header(name, 0x04);
16966 write_number<std::int32_t>(
static_cast<std::int32_t
>(calc_bson_array_size(value)),
true);
16968 std::size_t array_index = 0ul;
16970 for (
const auto& el : value)
16972 write_bson_element(std::to_string(array_index++), el);
16975 oa->write_character(to_char_type(0x00));
16981 void write_bson_binary(
const string_t& name,
16982 const binary_t& value)
16984 write_bson_entry_header(name, 0x05);
16986 write_number<std::int32_t>(
static_cast<std::int32_t
>(value.size()),
true);
16987 write_number(value.has_subtype() ?
static_cast<std::uint8_t
>(value.subtype()) : static_cast<std::uint8_t>(0x00));
16989 oa->write_characters(
reinterpret_cast<const CharType*
>(value.data()), value.size());
16996 static std::size_t calc_bson_element_size(
const string_t& name,
16997 const BasicJsonType& j)
16999 const auto header_size = calc_bson_entry_header_size(name, j);
17002 case value_t::object:
17003 return header_size + calc_bson_object_size(*j.m_data.m_value.object);
17005 case value_t::array:
17006 return header_size + calc_bson_array_size(*j.m_data.m_value.array);
17008 case value_t::binary:
17009 return header_size + calc_bson_binary_size(*j.m_data.m_value.binary);
17011 case value_t::boolean:
17012 return header_size + 1ul;
17014 case value_t::number_float:
17015 return header_size + 8ul;
17017 case value_t::number_integer:
17018 return header_size + calc_bson_integer_size(j.m_data.m_value.number_integer);
17020 case value_t::number_unsigned:
17021 return header_size + calc_bson_unsigned_size(j.m_data.m_value.number_unsigned);
17023 case value_t::string:
17024 return header_size + calc_bson_string_size(*j.m_data.m_value.string);
17026 case value_t::null:
17027 return header_size + 0ul;
17030 case value_t::discarded:
17032 JSON_ASSERT(
false);
17044 void write_bson_element(
const string_t& name,
17045 const BasicJsonType& j)
17049 case value_t::object:
17050 return write_bson_object_entry(name, *j.m_data.m_value.object);
17052 case value_t::array:
17053 return write_bson_array(name, *j.m_data.m_value.array);
17055 case value_t::binary:
17056 return write_bson_binary(name, *j.m_data.m_value.binary);
17058 case value_t::boolean:
17059 return write_bson_boolean(name, j.m_data.m_value.boolean);
17061 case value_t::number_float:
17062 return write_bson_double(name, j.m_data.m_value.number_float);
17064 case value_t::number_integer:
17065 return write_bson_integer(name, j.m_data.m_value.number_integer);
17067 case value_t::number_unsigned:
17068 return write_bson_unsigned(name, j);
17070 case value_t::string:
17071 return write_bson_string(name, *j.m_data.m_value.string);
17073 case value_t::null:
17074 return write_bson_null(name);
17077 case value_t::discarded:
17079 JSON_ASSERT(
false);
17091 static std::size_t calc_bson_object_size(
const typename BasicJsonType::object_t& value)
17093 const std::size_t document_size = std::accumulate(value.begin(), value.end(),
static_cast<std::size_t
>(0),
17094 [](
size_t result,
const typename BasicJsonType::object_t::value_type & el)
17096 return result += calc_bson_element_size(el.first, el.second);
17099 return sizeof(std::int32_t) + document_size + 1ul;
17106 void write_bson_object(
const typename BasicJsonType::object_t& value)
17108 write_number<std::int32_t>(
static_cast<std::int32_t
>(calc_bson_object_size(value)),
true);
17110 for (
const auto& el : value)
17112 write_bson_element(el.first, el.second);
17115 oa->write_character(to_char_type(0x00));
17122 static constexpr CharType get_cbor_float_prefix(
float )
17124 return to_char_type(0xFA);
17127 static constexpr CharType get_cbor_float_prefix(
double )
17129 return to_char_type(0xFB);
17136 static constexpr CharType get_msgpack_float_prefix(
float )
17138 return to_char_type(0xCA);
17141 static constexpr CharType get_msgpack_float_prefix(
double )
17143 return to_char_type(0xCB);
17151 template<
typename NumberType,
typename std::enable_if<
17152 std::is_floating_point<NumberType>::value,
int>::type = 0>
17153 void write_number_with_ubjson_prefix(
const NumberType n,
17154 const bool add_prefix,
17155 const bool use_bjdata)
17159 oa->write_character(get_ubjson_float_prefix(n));
17161 write_number(n, use_bjdata);
17165 template<
typename NumberType,
typename std::enable_if<
17166 std::is_unsigned<NumberType>::value,
int>::type = 0>
17167 void write_number_with_ubjson_prefix(
const NumberType n,
17168 const bool add_prefix,
17169 const bool use_bjdata)
17171 if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
17175 oa->write_character(to_char_type(
'i'));
17177 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
17179 else if (n <= (std::numeric_limits<std::uint8_t>::max)())
17183 oa->write_character(to_char_type(
'U'));
17185 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
17187 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
17191 oa->write_character(to_char_type(
'I'));
17193 write_number(
static_cast<std::int16_t
>(n), use_bjdata);
17195 else if (use_bjdata && n <=
static_cast<uint64_t
>((std::numeric_limits<uint16_t>::max)()))
17199 oa->write_character(to_char_type(
'u'));
17201 write_number(
static_cast<std::uint16_t
>(n), use_bjdata);
17203 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
17207 oa->write_character(to_char_type(
'l'));
17209 write_number(
static_cast<std::int32_t
>(n), use_bjdata);
17211 else if (use_bjdata && n <=
static_cast<uint64_t
>((std::numeric_limits<uint32_t>::max)()))
17215 oa->write_character(to_char_type(
'm'));
17217 write_number(
static_cast<std::uint32_t
>(n), use_bjdata);
17219 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
17223 oa->write_character(to_char_type(
'L'));
17225 write_number(
static_cast<std::int64_t
>(n), use_bjdata);
17227 else if (use_bjdata && n <= (std::numeric_limits<uint64_t>::max)())
17231 oa->write_character(to_char_type(
'M'));
17233 write_number(
static_cast<std::uint64_t
>(n), use_bjdata);
17239 oa->write_character(to_char_type(
'H'));
17242 const auto number = BasicJsonType(n).dump();
17243 write_number_with_ubjson_prefix(number.size(),
true, use_bjdata);
17244 for (std::size_t i = 0; i < number.size(); ++i)
17246 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
17252 template <
typename NumberType,
typename std::enable_if <
17253 std::is_signed<NumberType>::value&&
17254 !std::is_floating_point<NumberType>::value,
int >::type = 0 >
17255 void write_number_with_ubjson_prefix(
const NumberType n,
17256 const bool add_prefix,
17257 const bool use_bjdata)
17259 if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
17263 oa->write_character(to_char_type(
'i'));
17265 write_number(
static_cast<std::int8_t
>(n), use_bjdata);
17267 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)()))
17271 oa->write_character(to_char_type(
'U'));
17273 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
17275 else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
17279 oa->write_character(to_char_type(
'I'));
17281 write_number(
static_cast<std::int16_t
>(n), use_bjdata);
17283 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)())))
17287 oa->write_character(to_char_type(
'u'));
17289 write_number(
static_cast<uint16_t
>(n), use_bjdata);
17291 else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
17295 oa->write_character(to_char_type(
'l'));
17297 write_number(
static_cast<std::int32_t
>(n), use_bjdata);
17299 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)())))
17303 oa->write_character(to_char_type(
'm'));
17305 write_number(
static_cast<uint32_t
>(n), use_bjdata);
17307 else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
17311 oa->write_character(to_char_type(
'L'));
17313 write_number(
static_cast<std::int64_t
>(n), use_bjdata);
17320 oa->write_character(to_char_type(
'H'));
17323 const auto number = BasicJsonType(n).dump();
17324 write_number_with_ubjson_prefix(number.size(),
true, use_bjdata);
17325 for (std::size_t i = 0; i < number.size(); ++i)
17327 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
17336 CharType ubjson_prefix(
const BasicJsonType& j,
const bool use_bjdata)
const noexcept
17340 case value_t::null:
17343 case value_t::boolean:
17344 return j.m_data.m_value.boolean ?
'T' :
'F';
17346 case value_t::number_integer:
17348 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)())
17352 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)())
17356 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)())
17360 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)()))
17364 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)())
17368 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)()))
17372 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)())
17380 case value_t::number_unsigned:
17382 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
17386 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint8_t>::max)()))
17390 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
17394 if (use_bjdata && j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint16_t>::max)()))
17398 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
17402 if (use_bjdata && j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint32_t>::max)()))
17406 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
17410 if (use_bjdata && j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
17418 case value_t::number_float:
17419 return get_ubjson_float_prefix(j.m_data.m_value.number_float);
17421 case value_t::string:
17424 case value_t::array:
17425 case value_t::binary:
17428 case value_t::object:
17431 case value_t::discarded:
17437 static constexpr CharType get_ubjson_float_prefix(
float )
17442 static constexpr CharType get_ubjson_float_prefix(
double )
17450 bool write_bjdata_ndarray(
const typename BasicJsonType::object_t& value,
const bool use_count,
const bool use_type,
const bjdata_version_t bjdata_version)
17452 std::map<string_t, CharType> bjdtype = {{
"uint8",
'U'}, {
"int8",
'i'}, {
"uint16",
'u'}, {
"int16",
'I'},
17453 {
"uint32",
'm'}, {
"int32",
'l'}, {
"uint64",
'M'}, {
"int64",
'L'}, {
"single",
'd'}, {
"double",
'D'},
17454 {
"char",
'C'}, {
"byte",
'B'}
17457 string_t
key =
"_ArrayType_";
17458 auto it = bjdtype.find(
static_cast<string_t
>(value.at(
key)));
17459 if (it == bjdtype.end())
17463 CharType dtype = it->second;
17465 key =
"_ArraySize_";
17466 std::size_t len = (value.at(
key).empty() ? 0 : 1);
17467 for (
const auto& el : value.at(
key))
17469 len *=
static_cast<std::size_t
>(el.m_data.m_value.number_unsigned);
17472 key =
"_ArrayData_";
17473 if (value.at(
key).size() != len)
17478 oa->write_character(
'[');
17479 oa->write_character(
'$');
17480 oa->write_character(dtype);
17481 oa->write_character(
'#');
17483 key =
"_ArraySize_";
17484 write_ubjson(value.at(
key), use_count, use_type,
true,
true, bjdata_version);
17486 key =
"_ArrayData_";
17487 if (dtype ==
'U' || dtype ==
'C' || dtype ==
'B')
17489 for (
const auto& el : value.at(
key))
17491 write_number(
static_cast<std::uint8_t
>(el.m_data.m_value.number_unsigned),
true);
17494 else if (dtype ==
'i')
17496 for (
const auto& el : value.at(
key))
17498 write_number(
static_cast<std::int8_t
>(el.m_data.m_value.number_integer),
true);
17501 else if (dtype ==
'u')
17503 for (
const auto& el : value.at(
key))
17505 write_number(
static_cast<std::uint16_t
>(el.m_data.m_value.number_unsigned),
true);
17508 else if (dtype ==
'I')
17510 for (
const auto& el : value.at(
key))
17512 write_number(
static_cast<std::int16_t
>(el.m_data.m_value.number_integer),
true);
17515 else if (dtype ==
'm')
17517 for (
const auto& el : value.at(
key))
17519 write_number(
static_cast<std::uint32_t
>(el.m_data.m_value.number_unsigned),
true);
17522 else if (dtype ==
'l')
17524 for (
const auto& el : value.at(
key))
17526 write_number(
static_cast<std::int32_t
>(el.m_data.m_value.number_integer),
true);
17529 else if (dtype ==
'M')
17531 for (
const auto& el : value.at(
key))
17533 write_number(
static_cast<std::uint64_t
>(el.m_data.m_value.number_unsigned),
true);
17536 else if (dtype ==
'L')
17538 for (
const auto& el : value.at(
key))
17540 write_number(
static_cast<std::int64_t
>(el.m_data.m_value.number_integer),
true);
17543 else if (dtype ==
'd')
17545 for (
const auto& el : value.at(
key))
17547 write_number(
static_cast<float>(el.m_data.m_value.number_float),
true);
17550 else if (dtype ==
'D')
17552 for (
const auto& el : value.at(
key))
17554 write_number(
static_cast<double>(el.m_data.m_value.number_float),
true);
17577 template<
typename NumberType>
17578 void write_number(
const NumberType n,
const bool OutputIsLittleEndian =
false)
17581 std::array<CharType,
sizeof(NumberType)> vec{};
17582 std::memcpy(vec.data(), &n,
sizeof(NumberType));
17585 if (is_little_endian != OutputIsLittleEndian)
17588 std::reverse(vec.begin(), vec.end());
17591 oa->write_characters(vec.data(),
sizeof(NumberType));
17594 void write_compact_float(
const number_float_t n, detail::input_format_t format)
17597#pragma GCC diagnostic push
17598#pragma GCC diagnostic ignored "-Wfloat-equal"
17600 if (!std::isfinite(n) || ((
static_cast<double>(n) >=
static_cast<double>(std::numeric_limits<float>::lowest()) &&
17601 static_cast<double>(n) <=
static_cast<double>((std::numeric_limits<float>::max)()) &&
17602 static_cast<double>(
static_cast<float>(n)) ==
static_cast<double>(n))))
17604 oa->write_character(format == detail::input_format_t::cbor
17605 ? get_cbor_float_prefix(
static_cast<float>(n))
17606 : get_msgpack_float_prefix(static_cast<float>(n)));
17607 write_number(
static_cast<float>(n));
17611 oa->write_character(format == detail::input_format_t::cbor
17612 ? get_cbor_float_prefix(n)
17613 : get_msgpack_float_prefix(n));
17617#pragma GCC diagnostic pop
17626 template <
typename C = CharType,
17627 enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * =
nullptr >
17628 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
17630 return *
reinterpret_cast<char*
>(&x);
17633 template <
typename C = CharType,
17634 enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * =
nullptr >
17635 static CharType to_char_type(std::uint8_t x)
noexcept
17644#ifdef JSON_HAS_CPP_26
17645 static_assert(std::is_trivially_copyable<CharType>::value,
"CharType must be trivially copyable");
17646 static_assert(std::is_trivially_default_constructible<CharType>::value,
"CharType must be trivially default constructible");
17648 static_assert(std::is_trivial<CharType>::value,
"CharType must be trivial");
17651 static_assert(
sizeof(std::uint8_t) ==
sizeof(CharType),
"size of CharType must be equal to std::uint8_t");
17653 std::memcpy(&result, &x,
sizeof(x));
17657 template<
typename C = CharType,
17658 enable_if_t<std::is_unsigned<C>::value>* =
nullptr>
17659 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
17664 template <
typename InputCharType,
typename C = CharType,
17666 std::is_signed<C>::value &&
17667 std::is_signed<char>::value &&
17668 std::is_same<char, typename std::remove_cv<InputCharType>::type>::value
17670 static constexpr CharType to_char_type(InputCharType x)
noexcept
17680 output_adapter_t<CharType> oa =
nullptr;
17684NLOHMANN_JSON_NAMESPACE_END
17700#include <algorithm>
17710#include <type_traits>
17730#include <type_traits>
17735NLOHMANN_JSON_NAMESPACE_BEGIN
17761template<
typename Target,
typename Source>
17762Target reinterpret_bits(
const Source source)
17764 static_assert(
sizeof(Target) ==
sizeof(Source),
"size mismatch");
17767 std::memcpy(&target, &source,
sizeof(Source));
17773 static constexpr int kPrecision = 64;
17775 std::uint64_t f = 0;
17778 constexpr diyfp(std::uint64_t f_,
int e_) noexcept : f(f_), e(e_) {}
17784 static diyfp sub(
const diyfp& x,
const diyfp& y)
noexcept
17786 JSON_ASSERT(x.e == y.e);
17787 JSON_ASSERT(x.f >= y.f);
17789 return {x.f - y.f, x.e};
17796 static diyfp mul(
const diyfp& x,
const diyfp& y)
noexcept
17798 static_assert(kPrecision == 64,
"internal error");
17823 const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
17824 const std::uint64_t u_hi = x.f >> 32u;
17825 const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
17826 const std::uint64_t v_hi = y.f >> 32u;
17828 const std::uint64_t p0 = u_lo * v_lo;
17829 const std::uint64_t p1 = u_lo * v_hi;
17830 const std::uint64_t p2 = u_hi * v_lo;
17831 const std::uint64_t p3 = u_hi * v_hi;
17833 const std::uint64_t p0_hi = p0 >> 32u;
17834 const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
17835 const std::uint64_t p1_hi = p1 >> 32u;
17836 const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
17837 const std::uint64_t p2_hi = p2 >> 32u;
17839 std::uint64_t Q = p0_hi + p1_lo + p2_lo;
17850 Q += std::uint64_t{1} << (64u - 32u - 1u);
17852 const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
17854 return {h, x.e + y.e + 64};
17861 static diyfp normalize(diyfp x)
noexcept
17863 JSON_ASSERT(x.f != 0);
17865 while ((x.f >> 63u) == 0)
17878 static diyfp normalize_to(
const diyfp& x,
const int target_exponent)
noexcept
17880 const int delta = x.e - target_exponent;
17882 JSON_ASSERT(delta >= 0);
17883 JSON_ASSERT(((x.f << delta) >> delta) == x.f);
17885 return {x.f << delta, target_exponent};
17902template<
typename FloatType>
17903boundaries compute_boundaries(FloatType value)
17905 JSON_ASSERT(std::isfinite(value));
17906 JSON_ASSERT(value > 0);
17915 static_assert(std::numeric_limits<FloatType>::is_iec559,
17916 "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
17918 constexpr int kPrecision = std::numeric_limits<FloatType>::digits;
17919 constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
17920 constexpr int kMinExp = 1 - kBias;
17921 constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
17923 using bits_type =
typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
17925 const auto bits =
static_cast<std::uint64_t
>(reinterpret_bits<bits_type>(value));
17926 const std::uint64_t E = bits >> (kPrecision - 1);
17927 const std::uint64_t F = bits & (kHiddenBit - 1);
17929 const bool is_denormal = E == 0;
17930 const diyfp v = is_denormal
17931 ? diyfp(F, kMinExp)
17932 : diyfp(F + kHiddenBit,
static_cast<int>(E) - kBias);
17955 const bool lower_boundary_is_closer = F == 0 && E > 1;
17956 const diyfp m_plus = diyfp((2 * v.f) + 1, v.e - 1);
17957 const diyfp m_minus = lower_boundary_is_closer
17958 ? diyfp((4 * v.f) - 1, v.e - 2)
17959 : diyfp((2 * v.f) - 1, v.e - 1);
17962 const diyfp w_plus = diyfp::normalize(m_plus);
17965 const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
17967 return {diyfp::normalize(v), w_minus, w_plus};
18025constexpr int kAlpha = -60;
18026constexpr int kGamma = -32;
18042inline cached_power get_cached_power_for_binary_exponent(
int e)
18094 constexpr int kCachedPowersMinDecExp = -300;
18095 constexpr int kCachedPowersDecStep = 8;
18097 static constexpr std::array<cached_power, 79> kCachedPowers =
18100 { 0xAB70FE17C79AC6CA, -1060, -300 },
18101 { 0xFF77B1FCBEBCDC4F, -1034, -292 },
18102 { 0xBE5691EF416BD60C, -1007, -284 },
18103 { 0x8DD01FAD907FFC3C, -980, -276 },
18104 { 0xD3515C2831559A83, -954, -268 },
18105 { 0x9D71AC8FADA6C9B5, -927, -260 },
18106 { 0xEA9C227723EE8BCB, -901, -252 },
18107 { 0xAECC49914078536D, -874, -244 },
18108 { 0x823C12795DB6CE57, -847, -236 },
18109 { 0xC21094364DFB5637, -821, -228 },
18110 { 0x9096EA6F3848984F, -794, -220 },
18111 { 0xD77485CB25823AC7, -768, -212 },
18112 { 0xA086CFCD97BF97F4, -741, -204 },
18113 { 0xEF340A98172AACE5, -715, -196 },
18114 { 0xB23867FB2A35B28E, -688, -188 },
18115 { 0x84C8D4DFD2C63F3B, -661, -180 },
18116 { 0xC5DD44271AD3CDBA, -635, -172 },
18117 { 0x936B9FCEBB25C996, -608, -164 },
18118 { 0xDBAC6C247D62A584, -582, -156 },
18119 { 0xA3AB66580D5FDAF6, -555, -148 },
18120 { 0xF3E2F893DEC3F126, -529, -140 },
18121 { 0xB5B5ADA8AAFF80B8, -502, -132 },
18122 { 0x87625F056C7C4A8B, -475, -124 },
18123 { 0xC9BCFF6034C13053, -449, -116 },
18124 { 0x964E858C91BA2655, -422, -108 },
18125 { 0xDFF9772470297EBD, -396, -100 },
18126 { 0xA6DFBD9FB8E5B88F, -369, -92 },
18127 { 0xF8A95FCF88747D94, -343, -84 },
18128 { 0xB94470938FA89BCF, -316, -76 },
18129 { 0x8A08F0F8BF0F156B, -289, -68 },
18130 { 0xCDB02555653131B6, -263, -60 },
18131 { 0x993FE2C6D07B7FAC, -236, -52 },
18132 { 0xE45C10C42A2B3B06, -210, -44 },
18133 { 0xAA242499697392D3, -183, -36 },
18134 { 0xFD87B5F28300CA0E, -157, -28 },
18135 { 0xBCE5086492111AEB, -130, -20 },
18136 { 0x8CBCCC096F5088CC, -103, -12 },
18137 { 0xD1B71758E219652C, -77, -4 },
18138 { 0x9C40000000000000, -50, 4 },
18139 { 0xE8D4A51000000000, -24, 12 },
18140 { 0xAD78EBC5AC620000, 3, 20 },
18141 { 0x813F3978F8940984, 30, 28 },
18142 { 0xC097CE7BC90715B3, 56, 36 },
18143 { 0x8F7E32CE7BEA5C70, 83, 44 },
18144 { 0xD5D238A4ABE98068, 109, 52 },
18145 { 0x9F4F2726179A2245, 136, 60 },
18146 { 0xED63A231D4C4FB27, 162, 68 },
18147 { 0xB0DE65388CC8ADA8, 189, 76 },
18148 { 0x83C7088E1AAB65DB, 216, 84 },
18149 { 0xC45D1DF942711D9A, 242, 92 },
18150 { 0x924D692CA61BE758, 269, 100 },
18151 { 0xDA01EE641A708DEA, 295, 108 },
18152 { 0xA26DA3999AEF774A, 322, 116 },
18153 { 0xF209787BB47D6B85, 348, 124 },
18154 { 0xB454E4A179DD1877, 375, 132 },
18155 { 0x865B86925B9BC5C2, 402, 140 },
18156 { 0xC83553C5C8965D3D, 428, 148 },
18157 { 0x952AB45CFA97A0B3, 455, 156 },
18158 { 0xDE469FBD99A05FE3, 481, 164 },
18159 { 0xA59BC234DB398C25, 508, 172 },
18160 { 0xF6C69A72A3989F5C, 534, 180 },
18161 { 0xB7DCBF5354E9BECE, 561, 188 },
18162 { 0x88FCF317F22241E2, 588, 196 },
18163 { 0xCC20CE9BD35C78A5, 614, 204 },
18164 { 0x98165AF37B2153DF, 641, 212 },
18165 { 0xE2A0B5DC971F303A, 667, 220 },
18166 { 0xA8D9D1535CE3B396, 694, 228 },
18167 { 0xFB9B7CD9A4A7443C, 720, 236 },
18168 { 0xBB764C4CA7A44410, 747, 244 },
18169 { 0x8BAB8EEFB6409C1A, 774, 252 },
18170 { 0xD01FEF10A657842C, 800, 260 },
18171 { 0x9B10A4E5E9913129, 827, 268 },
18172 { 0xE7109BFBA19C0C9D, 853, 276 },
18173 { 0xAC2820D9623BF429, 880, 284 },
18174 { 0x80444B5E7AA7CF85, 907, 292 },
18175 { 0xBF21E44003ACDD2D, 933, 300 },
18176 { 0x8E679C2F5E44FF8F, 960, 308 },
18177 { 0xD433179D9C8CB841, 986, 316 },
18178 { 0x9E19DB92B4E31BA9, 1013, 324 },
18186 JSON_ASSERT(e >= -1500);
18187 JSON_ASSERT(e <= 1500);
18188 const int f = kAlpha - e - 1;
18189 const int k = ((f * 78913) / (1 << 18)) +
static_cast<int>(f > 0);
18191 const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
18192 JSON_ASSERT(index >= 0);
18193 JSON_ASSERT(
static_cast<std::size_t
>(index) < kCachedPowers.size());
18195 const cached_power cached = kCachedPowers[
static_cast<std::size_t
>(index)];
18196 JSON_ASSERT(kAlpha <= cached.e + e + 64);
18197 JSON_ASSERT(kGamma >= cached.e + e + 64);
18206inline int find_largest_pow10(
const std::uint32_t n, std::uint32_t& pow10)
18209 if (n >= 1000000000)
18211 pow10 = 1000000000;
18215 if (n >= 100000000)
18260inline void grisu2_round(
char* buf,
int len, std::uint64_t dist, std::uint64_t delta,
18261 std::uint64_t rest, std::uint64_t ten_k)
18263 JSON_ASSERT(len >= 1);
18264 JSON_ASSERT(dist <= delta);
18265 JSON_ASSERT(rest <= delta);
18266 JSON_ASSERT(ten_k > 0);
18288 && delta - rest >= ten_k
18289 && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
18291 JSON_ASSERT(buf[len - 1] !=
'0');
18301inline void grisu2_digit_gen(
char* buffer,
int& length,
int& decimal_exponent,
18302 diyfp M_minus, diyfp w, diyfp M_plus)
18304 static_assert(kAlpha >= -60,
"internal error");
18305 static_assert(kGamma <= -32,
"internal error");
18319 JSON_ASSERT(M_plus.e >= kAlpha);
18320 JSON_ASSERT(M_plus.e <= kGamma);
18322 std::uint64_t delta = diyfp::sub(M_plus, M_minus).f;
18323 std::uint64_t dist = diyfp::sub(M_plus, w ).f;
18332 const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
18334 auto p1 =
static_cast<std::uint32_t
>(M_plus.f >> -one.e);
18335 std::uint64_t p2 = M_plus.f & (one.f - 1);
18341 JSON_ASSERT(p1 > 0);
18343 std::uint32_t pow10{};
18344 const int k = find_largest_pow10(p1, pow10);
18371 const std::uint32_t d = p1 / pow10;
18372 const std::uint32_t r = p1 % pow10;
18377 JSON_ASSERT(d <= 9);
18378 buffer[length++] =
static_cast<char>(
'0' + d);
18397 const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
18402 decimal_exponent += n;
18413 const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
18414 grisu2_round(buffer, length, dist, delta, rest, ten_n);
18464 JSON_ASSERT(p2 > delta);
18475 JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
18477 const std::uint64_t d = p2 >> -one.e;
18478 const std::uint64_t r = p2 & (one.f - 1);
18484 JSON_ASSERT(d <= 9);
18485 buffer[length++] =
static_cast<char>(
'0' + d);
18510 decimal_exponent -= m;
18518 const std::uint64_t ten_m = one.f;
18519 grisu2_round(buffer, length, dist, delta, p2, ten_m);
18541JSON_HEDLEY_NON_NULL(1)
18542inline void grisu2(
char* buf,
int& len,
int& decimal_exponent,
18543 diyfp m_minus, diyfp v, diyfp m_plus)
18545 JSON_ASSERT(m_plus.e == m_minus.e);
18546 JSON_ASSERT(m_plus.e == v.e);
18557 const cached_power cached = get_cached_power_for_binary_exponent(m_plus.e);
18559 const diyfp c_minus_k(cached.f, cached.e);
18562 const diyfp w = diyfp::mul(v, c_minus_k);
18563 const diyfp w_minus = diyfp::mul(m_minus, c_minus_k);
18564 const diyfp w_plus = diyfp::mul(m_plus, c_minus_k);
18587 const diyfp M_minus(w_minus.f + 1, w_minus.e);
18588 const diyfp M_plus (w_plus.f - 1, w_plus.e );
18590 decimal_exponent = -cached.k;
18592 grisu2_digit_gen(buf, len, decimal_exponent, M_minus, w, M_plus);
18600template<
typename FloatType>
18601JSON_HEDLEY_NON_NULL(1)
18602void grisu2(
char* buf,
int& len,
int& decimal_exponent, FloatType value)
18604 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
18605 "internal error: not enough precision");
18607 JSON_ASSERT(std::isfinite(value));
18608 JSON_ASSERT(value > 0);
18627 const boundaries w = compute_boundaries(
static_cast<double>(value));
18629 const boundaries w = compute_boundaries(value);
18632 grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
18640JSON_HEDLEY_NON_NULL(1)
18641JSON_HEDLEY_RETURNS_NON_NULL
18642inline char* append_exponent(
char* buf,
int e)
18644 JSON_ASSERT(e > -1000);
18645 JSON_ASSERT(e < 1000);
18657 auto k =
static_cast<std::uint32_t
>(e);
18663 *buf++ =
static_cast<char>(
'0' + k);
18667 *buf++ =
static_cast<char>(
'0' + (k / 10));
18669 *buf++ =
static_cast<char>(
'0' + k);
18673 *buf++ =
static_cast<char>(
'0' + (k / 100));
18675 *buf++ =
static_cast<char>(
'0' + (k / 10));
18677 *buf++ =
static_cast<char>(
'0' + k);
18692JSON_HEDLEY_NON_NULL(1)
18693JSON_HEDLEY_RETURNS_NON_NULL
18694inline char* format_buffer(
char* buf,
int len,
int decimal_exponent,
18695 int min_exp,
int max_exp)
18697 JSON_ASSERT(min_exp < 0);
18698 JSON_ASSERT(max_exp > 0);
18701 const int n = len + decimal_exponent;
18707 if (k <= n && n <= max_exp)
18712 std::memset(buf + k,
'0',
static_cast<size_t>(n) -
static_cast<size_t>(k));
18716 return buf + (
static_cast<size_t>(n) + 2);
18719 if (0 < n && n <= max_exp)
18724 JSON_ASSERT(k > n);
18726 std::memmove(buf + (
static_cast<size_t>(n) + 1), buf + n,
static_cast<size_t>(k) -
static_cast<size_t>(n));
18728 return buf + (
static_cast<size_t>(k) + 1U);
18731 if (min_exp < n && n <= 0)
18736 std::memmove(buf + (2 +
static_cast<size_t>(-n)), buf,
static_cast<size_t>(k));
18739 std::memset(buf + 2,
'0',
static_cast<size_t>(-n));
18740 return buf + (2U +
static_cast<size_t>(-n) +
static_cast<size_t>(k));
18755 std::memmove(buf + 2, buf + 1,
static_cast<size_t>(k) - 1);
18757 buf += 1 +
static_cast<size_t>(k);
18761 return append_exponent(buf, n - 1);
18776template<
typename FloatType>
18777JSON_HEDLEY_NON_NULL(1, 2)
18778JSON_HEDLEY_RETURNS_NON_NULL
18779char* to_chars(
char* first, const
char* last, FloatType value)
18781 static_cast<void>(last);
18782 JSON_ASSERT(std::isfinite(value));
18785 if (std::signbit(value))
18792#pragma GCC diagnostic push
18793#pragma GCC diagnostic ignored "-Wfloat-equal"
18804#pragma GCC diagnostic pop
18807 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
18814 int decimal_exponent = 0;
18815 dtoa_impl::grisu2(first, len, decimal_exponent, value);
18817 JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
18820 constexpr int kMinExp = -4;
18822 constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10;
18824 JSON_ASSERT(last - first >= kMaxExp + 2);
18825 JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
18826 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
18828 return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);
18832NLOHMANN_JSON_NAMESPACE_END
18849NLOHMANN_JSON_NAMESPACE_BEGIN
18865template<
typename BasicJsonType>
18868 using string_t =
typename BasicJsonType::string_t;
18869 using number_float_t =
typename BasicJsonType::number_float_t;
18870 using number_integer_t =
typename BasicJsonType::number_integer_t;
18871 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
18872 using binary_char_t =
typename BasicJsonType::binary_t::value_type;
18873 static constexpr std::uint8_t UTF8_ACCEPT = 0;
18874 static constexpr std::uint8_t UTF8_REJECT = 1;
18885 , loc(std::localeconv())
18886 , thousands_sep(loc->thousands_sep == nullptr ?
'\0' : std::
char_traits<char>::to_char_type(* (loc->thousands_sep)))
18887 , decimal_point(loc->decimal_point == nullptr ?
'\0' : std::
char_traits<char>::to_char_type(* (loc->decimal_point)))
18888 , indent_char(ichar)
18889 , indent_string(512, indent_char)
18890 , error_handler(error_handler_)
18923 const bool pretty_print,
18924 const bool ensure_ascii,
18925 const unsigned int indent_step,
18926 const unsigned int current_indent = 0)
18928 switch (val.m_data.m_type)
18930 case value_t::object:
18932 if (val.m_data.m_value.object->empty())
18934 o->write_characters(
"{}", 2);
18940 o->write_characters(
"{\n", 2);
18943 const auto new_indent = current_indent + indent_step;
18944 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
18946 indent_string.resize(indent_string.size() * 2,
' ');
18950 auto i = val.m_data.m_value.object->cbegin();
18951 for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)
18953 o->write_characters(indent_string.c_str(), new_indent);
18954 o->write_character(
'\"');
18955 dump_escaped(i->first, ensure_ascii);
18956 o->write_characters(
"\": ", 3);
18957 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
18958 o->write_characters(
",\n", 2);
18962 JSON_ASSERT(i != val.m_data.m_value.object->cend());
18963 JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
18964 o->write_characters(indent_string.c_str(), new_indent);
18965 o->write_character(
'\"');
18966 dump_escaped(i->first, ensure_ascii);
18967 o->write_characters(
"\": ", 3);
18968 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
18970 o->write_character(
'\n');
18971 o->write_characters(indent_string.c_str(), current_indent);
18972 o->write_character(
'}');
18976 o->write_character(
'{');
18979 auto i = val.m_data.m_value.object->cbegin();
18980 for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)
18982 o->write_character(
'\"');
18983 dump_escaped(i->first, ensure_ascii);
18984 o->write_characters(
"\":", 2);
18985 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
18986 o->write_character(
',');
18990 JSON_ASSERT(i != val.m_data.m_value.object->cend());
18991 JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
18992 o->write_character(
'\"');
18993 dump_escaped(i->first, ensure_ascii);
18994 o->write_characters(
"\":", 2);
18995 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
18997 o->write_character(
'}');
19003 case value_t::array:
19005 if (val.m_data.m_value.array->empty())
19007 o->write_characters(
"[]", 2);
19013 o->write_characters(
"[\n", 2);
19016 const auto new_indent = current_indent + indent_step;
19017 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
19019 indent_string.resize(indent_string.size() * 2,
' ');
19023 for (
auto i = val.m_data.m_value.array->cbegin();
19024 i != val.m_data.m_value.array->cend() - 1; ++i)
19026 o->write_characters(indent_string.c_str(), new_indent);
19027 dump(*i,
true, ensure_ascii, indent_step, new_indent);
19028 o->write_characters(
",\n", 2);
19032 JSON_ASSERT(!val.m_data.m_value.array->empty());
19033 o->write_characters(indent_string.c_str(), new_indent);
19034 dump(val.m_data.m_value.array->back(),
true, ensure_ascii, indent_step, new_indent);
19036 o->write_character(
'\n');
19037 o->write_characters(indent_string.c_str(), current_indent);
19038 o->write_character(
']');
19042 o->write_character(
'[');
19045 for (
auto i = val.m_data.m_value.array->cbegin();
19046 i != val.m_data.m_value.array->cend() - 1; ++i)
19048 dump(*i,
false, ensure_ascii, indent_step, current_indent);
19049 o->write_character(
',');
19053 JSON_ASSERT(!val.m_data.m_value.array->empty());
19054 dump(val.m_data.m_value.array->back(),
false, ensure_ascii, indent_step, current_indent);
19056 o->write_character(
']');
19062 case value_t::string:
19064 o->write_character(
'\"');
19065 dump_escaped(*val.m_data.m_value.string, ensure_ascii);
19066 o->write_character(
'\"');
19070 case value_t::binary:
19074 o->write_characters(
"{\n", 2);
19077 const auto new_indent = current_indent + indent_step;
19078 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
19080 indent_string.resize(indent_string.size() * 2,
' ');
19083 o->write_characters(indent_string.c_str(), new_indent);
19085 o->write_characters(
"\"bytes\": [", 10);
19087 if (!val.m_data.m_value.binary->empty())
19089 for (
auto i = val.m_data.m_value.binary->cbegin();
19090 i != val.m_data.m_value.binary->cend() - 1; ++i)
19093 o->write_characters(
", ", 2);
19095 dump_integer(val.m_data.m_value.binary->back());
19098 o->write_characters(
"],\n", 3);
19099 o->write_characters(indent_string.c_str(), new_indent);
19101 o->write_characters(
"\"subtype\": ", 11);
19102 if (val.m_data.m_value.binary->has_subtype())
19104 dump_integer(val.m_data.m_value.binary->subtype());
19108 o->write_characters(
"null", 4);
19110 o->write_character(
'\n');
19111 o->write_characters(indent_string.c_str(), current_indent);
19112 o->write_character(
'}');
19116 o->write_characters(
"{\"bytes\":[", 10);
19118 if (!val.m_data.m_value.binary->empty())
19120 for (
auto i = val.m_data.m_value.binary->cbegin();
19121 i != val.m_data.m_value.binary->cend() - 1; ++i)
19124 o->write_character(
',');
19126 dump_integer(val.m_data.m_value.binary->back());
19129 o->write_characters(
"],\"subtype\":", 12);
19130 if (val.m_data.m_value.binary->has_subtype())
19132 dump_integer(val.m_data.m_value.binary->subtype());
19133 o->write_character(
'}');
19137 o->write_characters(
"null}", 5);
19143 case value_t::boolean:
19145 if (val.m_data.m_value.boolean)
19147 o->write_characters(
"true", 4);
19151 o->write_characters(
"false", 5);
19156 case value_t::number_integer:
19158 dump_integer(val.m_data.m_value.number_integer);
19162 case value_t::number_unsigned:
19164 dump_integer(val.m_data.m_value.number_unsigned);
19168 case value_t::number_float:
19170 dump_float(val.m_data.m_value.number_float);
19174 case value_t::discarded:
19176 o->write_characters(
"<discarded>", 11);
19180 case value_t::null:
19182 o->write_characters(
"null", 4);
19187 JSON_ASSERT(
false);
19191 JSON_PRIVATE_UNLESS_TESTED:
19206 void dump_escaped(
const string_t& s,
const bool ensure_ascii)
19208 std::uint32_t codepoint{};
19209 std::uint8_t state = UTF8_ACCEPT;
19210 std::size_t bytes = 0;
19213 std::size_t bytes_after_last_accept = 0;
19214 std::size_t undumped_chars = 0;
19216 for (std::size_t i = 0; i < s.size(); ++i)
19218 const auto byte =
static_cast<std::uint8_t
>(s[i]);
19220 switch (decode(state, codepoint,
byte))
19228 string_buffer[bytes++] =
'\\';
19229 string_buffer[bytes++] =
'b';
19235 string_buffer[bytes++] =
'\\';
19236 string_buffer[bytes++] =
't';
19242 string_buffer[bytes++] =
'\\';
19243 string_buffer[bytes++] =
'n';
19249 string_buffer[bytes++] =
'\\';
19250 string_buffer[bytes++] =
'f';
19256 string_buffer[bytes++] =
'\\';
19257 string_buffer[bytes++] =
'r';
19263 string_buffer[bytes++] =
'\\';
19264 string_buffer[bytes++] =
'\"';
19270 string_buffer[bytes++] =
'\\';
19271 string_buffer[bytes++] =
'\\';
19279 if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
19281 if (codepoint <= 0xFFFF)
19284 static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 7,
"\\u%04x",
19285 static_cast<std::uint16_t
>(codepoint)));
19291 static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 13,
"\\u%04x\\u%04x",
19292 static_cast<std::uint16_t
>(0xD7C0u + (codepoint >> 10u)),
19293 static_cast<std::uint16_t
>(0xDC00u + (codepoint & 0x3FFu))));
19301 string_buffer[bytes++] = s[i];
19310 if (string_buffer.size() - bytes < 13)
19312 o->write_characters(string_buffer.data(), bytes);
19317 bytes_after_last_accept = bytes;
19318 undumped_chars = 0;
19324 switch (error_handler)
19326 case error_handler_t::strict:
19328 JSON_THROW(type_error::create(316, concat(
"invalid UTF-8 byte at index ", std::to_string(i),
": 0x", hex_bytes(
byte | 0)),
nullptr));
19331 case error_handler_t::ignore:
19332 case error_handler_t::replace:
19338 if (undumped_chars > 0)
19345 bytes = bytes_after_last_accept;
19347 if (error_handler == error_handler_t::replace)
19352 string_buffer[bytes++] =
'\\';
19353 string_buffer[bytes++] =
'u';
19354 string_buffer[bytes++] =
'f';
19355 string_buffer[bytes++] =
'f';
19356 string_buffer[bytes++] =
'f';
19357 string_buffer[bytes++] =
'd';
19361 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xEF');
19362 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBF');
19363 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBD');
19369 if (string_buffer.size() - bytes < 13)
19371 o->write_characters(string_buffer.data(), bytes);
19375 bytes_after_last_accept = bytes;
19378 undumped_chars = 0;
19381 state = UTF8_ACCEPT;
19386 JSON_ASSERT(
false);
19396 string_buffer[bytes++] = s[i];
19405 if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
19410 o->write_characters(string_buffer.data(), bytes);
19416 switch (error_handler)
19418 case error_handler_t::strict:
19420 JSON_THROW(type_error::create(316, concat(
"incomplete UTF-8 string; last byte: 0x", hex_bytes(
static_cast<std::uint8_t
>(s.back() | 0))),
nullptr));
19423 case error_handler_t::ignore:
19426 o->write_characters(string_buffer.data(), bytes_after_last_accept);
19430 case error_handler_t::replace:
19433 o->write_characters(string_buffer.data(), bytes_after_last_accept);
19437 o->write_characters(
"\\ufffd", 6);
19441 o->write_characters(
"\xEF\xBF\xBD", 3);
19447 JSON_ASSERT(
false);
19461 unsigned int count_digits(number_unsigned_t x)
noexcept
19463 unsigned int n_digits = 1;
19472 return n_digits + 1;
19476 return n_digits + 2;
19480 return n_digits + 3;
19492 static std::string hex_bytes(std::uint8_t
byte)
19494 std::string result =
"FF";
19495 constexpr const char* nibble_to_hex =
"0123456789ABCDEF";
19496 result[0] = nibble_to_hex[
byte / 16];
19497 result[1] = nibble_to_hex[
byte % 16];
19502 template <typename NumberType, enable_if_t<std::is_signed<NumberType>::value,
int> = 0>
19503 bool is_negative_number(NumberType x)
19508 template < typename NumberType, enable_if_t <std::is_unsigned<NumberType>::value,
int > = 0 >
19509 bool is_negative_number(NumberType )
19523 template <
typename NumberType, detail::enable_if_t <
19524 std::is_integral<NumberType>::value ||
19525 std::is_same<NumberType, number_unsigned_t>::value ||
19526 std::is_same<NumberType, number_integer_t>::value ||
19527 std::is_same<NumberType, binary_char_t>::value,
19529 void dump_integer(NumberType x)
19531 static constexpr std::array<std::array<char, 2>, 100> digits_to_99
19534 {{
'0',
'0'}}, {{
'0',
'1'}}, {{
'0',
'2'}}, {{
'0',
'3'}}, {{
'0',
'4'}}, {{
'0',
'5'}}, {{
'0',
'6'}}, {{
'0',
'7'}}, {{
'0',
'8'}}, {{
'0',
'9'}},
19535 {{
'1',
'0'}}, {{
'1',
'1'}}, {{
'1',
'2'}}, {{
'1',
'3'}}, {{
'1',
'4'}}, {{
'1',
'5'}}, {{
'1',
'6'}}, {{
'1',
'7'}}, {{
'1',
'8'}}, {{
'1',
'9'}},
19536 {{
'2',
'0'}}, {{
'2',
'1'}}, {{
'2',
'2'}}, {{
'2',
'3'}}, {{
'2',
'4'}}, {{
'2',
'5'}}, {{
'2',
'6'}}, {{
'2',
'7'}}, {{
'2',
'8'}}, {{
'2',
'9'}},
19537 {{
'3',
'0'}}, {{
'3',
'1'}}, {{
'3',
'2'}}, {{
'3',
'3'}}, {{
'3',
'4'}}, {{
'3',
'5'}}, {{
'3',
'6'}}, {{
'3',
'7'}}, {{
'3',
'8'}}, {{
'3',
'9'}},
19538 {{
'4',
'0'}}, {{
'4',
'1'}}, {{
'4',
'2'}}, {{
'4',
'3'}}, {{
'4',
'4'}}, {{
'4',
'5'}}, {{
'4',
'6'}}, {{
'4',
'7'}}, {{
'4',
'8'}}, {{
'4',
'9'}},
19539 {{
'5',
'0'}}, {{
'5',
'1'}}, {{
'5',
'2'}}, {{
'5',
'3'}}, {{
'5',
'4'}}, {{
'5',
'5'}}, {{
'5',
'6'}}, {{
'5',
'7'}}, {{
'5',
'8'}}, {{
'5',
'9'}},
19540 {{
'6',
'0'}}, {{
'6',
'1'}}, {{
'6',
'2'}}, {{
'6',
'3'}}, {{
'6',
'4'}}, {{
'6',
'5'}}, {{
'6',
'6'}}, {{
'6',
'7'}}, {{
'6',
'8'}}, {{
'6',
'9'}},
19541 {{
'7',
'0'}}, {{
'7',
'1'}}, {{
'7',
'2'}}, {{
'7',
'3'}}, {{
'7',
'4'}}, {{
'7',
'5'}}, {{
'7',
'6'}}, {{
'7',
'7'}}, {{
'7',
'8'}}, {{
'7',
'9'}},
19542 {{
'8',
'0'}}, {{
'8',
'1'}}, {{
'8',
'2'}}, {{
'8',
'3'}}, {{
'8',
'4'}}, {{
'8',
'5'}}, {{
'8',
'6'}}, {{
'8',
'7'}}, {{
'8',
'8'}}, {{
'8',
'9'}},
19543 {{
'9',
'0'}}, {{
'9',
'1'}}, {{
'9',
'2'}}, {{
'9',
'3'}}, {{
'9',
'4'}}, {{
'9',
'5'}}, {{
'9',
'6'}}, {{
'9',
'7'}}, {{
'9',
'8'}}, {{
'9',
'9'}},
19550 o->write_character(
'0');
19555 auto buffer_ptr = number_buffer.begin();
19557 number_unsigned_t abs_value;
19559 unsigned int n_chars{};
19561 if (is_negative_number(x))
19564 abs_value = remove_sign(
static_cast<number_integer_t
>(x));
19567 n_chars = 1 + count_digits(abs_value);
19571 abs_value =
static_cast<number_unsigned_t
>(x);
19572 n_chars = count_digits(abs_value);
19576 JSON_ASSERT(n_chars < number_buffer.size() - 1);
19580 buffer_ptr +=
static_cast<typename decltype(number_buffer)::difference_type
>(n_chars);
19584 while (abs_value >= 100)
19586 const auto digits_index =
static_cast<unsigned>((abs_value % 100));
19588 *(--buffer_ptr) = digits_to_99[digits_index][1];
19589 *(--buffer_ptr) = digits_to_99[digits_index][0];
19592 if (abs_value >= 10)
19594 const auto digits_index =
static_cast<unsigned>(abs_value);
19595 *(--buffer_ptr) = digits_to_99[digits_index][1];
19596 *(--buffer_ptr) = digits_to_99[digits_index][0];
19600 *(--buffer_ptr) =
static_cast<char>(
'0' + abs_value);
19603 o->write_characters(number_buffer.data(), n_chars);
19614 void dump_float(number_float_t x)
19617 if (!std::isfinite(x))
19619 o->write_characters(
"null", 4);
19628 static constexpr bool is_ieee_single_or_double
19629 = (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) ||
19630 (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);
19632 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
19635 void dump_float(number_float_t x, std::true_type )
19637 auto* begin = number_buffer.data();
19638 auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
19640 o->write_characters(begin,
static_cast<size_t>(end - begin));
19643 void dump_float(number_float_t x, std::false_type )
19646 static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
19650 std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(),
"%.*g", d, x);
19653 JSON_ASSERT(len > 0);
19655 JSON_ASSERT(
static_cast<std::size_t
>(len) < number_buffer.size());
19658 if (thousands_sep !=
'\0')
19661 const auto end = std::remove(number_buffer.begin(), number_buffer.begin() + len, thousands_sep);
19662 std::fill(end, number_buffer.end(),
'\0');
19663 JSON_ASSERT((end - number_buffer.begin()) <= len);
19664 len = (end - number_buffer.begin());
19668 if (decimal_point !=
'\0' && decimal_point !=
'.')
19671 const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
19672 if (dec_pos != number_buffer.end())
19678 o->write_characters(number_buffer.data(),
static_cast<std::size_t
>(len));
19681 const bool value_is_int_like =
19682 std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
19685 return c ==
'.' || c ==
'e';
19688 if (value_is_int_like)
19690 o->write_characters(
".0", 2);
19715 static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep,
const std::uint8_t
byte)
noexcept
19717 static const std::array<std::uint8_t, 400> utf8d =
19720 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,
19721 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,
19722 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,
19723 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,
19724 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,
19725 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,
19726 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,
19727 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3,
19728 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
19729 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1,
19730 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,
19731 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,
19732 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,
19733 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
19737 JSON_ASSERT(
byte < utf8d.size());
19738 const std::uint8_t type = utf8d[byte];
19740 codep = (state != UTF8_ACCEPT)
19741 ? (
byte & 0x3fu) | (codep << 6u)
19742 : (0xFFu >> type) & (byte);
19744 const std::size_t index = 256u + (
static_cast<size_t>(state) * 16u) +
static_cast<size_t>(type);
19745 JSON_ASSERT(index < utf8d.size());
19746 state = utf8d[index];
19755 number_unsigned_t remove_sign(number_unsigned_t x)
19757 JSON_ASSERT(
false);
19770 number_unsigned_t remove_sign(number_integer_t x)
noexcept
19772 JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)());
19773 return static_cast<number_unsigned_t
>(-(x + 1)) + 1;
19778 output_adapter_t<char> o =
nullptr;
19781 std::array<char, 64> number_buffer{{}};
19784 const std::lconv* loc =
nullptr;
19786 const char thousands_sep =
'\0';
19788 const char decimal_point =
'\0';
19791 std::array<char, 512> string_buffer{{}};
19803NLOHMANN_JSON_NAMESPACE_END
19820#include <functional>
19821#include <initializer_list>
19824#include <stdexcept>
19825#include <type_traits>
19834NLOHMANN_JSON_NAMESPACE_BEGIN
19838template <
class Key,
class T,
class IgnoredLess = std::less<Key>,
19839 class Allocator = std::allocator<std::pair<const Key, T>>>
19842 using key_type = Key;
19843 using mapped_type = T;
19844 using Container = std::vector<std::pair<const Key, T>, Allocator>;
19845 using iterator =
typename Container::iterator;
19846 using const_iterator =
typename Container::const_iterator;
19847 using size_type =
typename Container::size_type;
19848 using value_type =
typename Container::value_type;
19849#ifdef JSON_HAS_CPP_14
19850 using key_compare = std::equal_to<>;
19852 using key_compare = std::equal_to<Key>;
19857 ordered_map()
noexcept(
noexcept(Container())) : Container{} {}
19858 explicit ordered_map(
const Allocator& alloc)
noexcept(
noexcept(Container(alloc))) : Container{alloc} {}
19859 template <
class It>
19860 ordered_map(It first, It last,
const Allocator& alloc = Allocator())
19861 : Container{first, last, alloc} {}
19862 ordered_map(std::initializer_list<value_type> init,
const Allocator& alloc = Allocator() )
19863 : Container{init, alloc} {}
19865 std::pair<iterator, bool> emplace(
const key_type& key, T&& t)
19867 for (
auto it = this->begin(); it != this->end(); ++it)
19869 if (m_compare(it->first, key))
19871 return {it,
false};
19874 Container::emplace_back(key, std::forward<T>(t));
19875 return {std::prev(this->end()),
true};
19878 template<
class KeyType, detail::enable_if_t<
19879 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19880 std::pair<iterator, bool> emplace(KeyType && key, T && t)
19882 for (
auto it = this->begin(); it != this->end(); ++it)
19884 if (m_compare(it->first, key))
19886 return {it,
false};
19889 Container::emplace_back(std::forward<KeyType>(key), std::forward<T>(t));
19890 return {std::prev(this->end()),
true};
19893 T& operator[](
const key_type& key)
19895 return emplace(key, T{}).first->second;
19898 template<
class KeyType, detail::enable_if_t<
19899 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19900 T & operator[](KeyType && key)
19902 return emplace(std::forward<KeyType>(key), T{}).first->second;
19905 const T& operator[](
const key_type& key)
const
19910 template<
class KeyType, detail::enable_if_t<
19911 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19912 const T & operator[](KeyType && key)
const
19914 return at(std::forward<KeyType>(key));
19917 T& at(
const key_type& key)
19919 for (
auto it = this->begin(); it != this->end(); ++it)
19921 if (m_compare(it->first, key))
19927 JSON_THROW(std::out_of_range(
"key not found"));
19930 template<
class KeyType, detail::enable_if_t<
19931 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19932 T & at(KeyType && key)
19934 for (
auto it = this->begin(); it != this->end(); ++it)
19936 if (m_compare(it->first, key))
19942 JSON_THROW(std::out_of_range(
"key not found"));
19945 const T& at(
const key_type& key)
const
19947 for (
auto it = this->begin(); it != this->end(); ++it)
19949 if (m_compare(it->first, key))
19955 JSON_THROW(std::out_of_range(
"key not found"));
19958 template<
class KeyType, detail::enable_if_t<
19959 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19960 const T & at(KeyType && key)
const
19962 for (
auto it = this->begin(); it != this->end(); ++it)
19964 if (m_compare(it->first, key))
19970 JSON_THROW(std::out_of_range(
"key not found"));
19973 size_type erase(
const key_type& key)
19975 for (
auto it = this->begin(); it != this->end(); ++it)
19977 if (m_compare(it->first, key))
19980 for (
auto next = it; ++next != this->end(); ++it)
19983 new (&*it) value_type{std::move(*next)};
19985 Container::pop_back();
19992 template<
class KeyType, detail::enable_if_t<
19993 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19994 size_type erase(KeyType && key)
19996 for (
auto it = this->begin(); it != this->end(); ++it)
19998 if (m_compare(it->first, key))
20001 for (
auto next = it; ++next != this->end(); ++it)
20004 new (&*it) value_type{std::move(*next)};
20006 Container::pop_back();
20013 iterator erase(iterator pos)
20015 return erase(pos, std::next(pos));
20018 iterator erase(iterator first, iterator last)
20025 const auto elements_affected = std::distance(first, last);
20026 const auto offset = std::distance(Container::begin(), first);
20048 for (
auto it = first; std::next(it, elements_affected) != Container::end(); ++it)
20051 new (&*it) value_type{std::move(*std::next(it, elements_affected))};
20059 Container::resize(this->size() -
static_cast<size_type
>(elements_affected));
20068 return Container::begin() + offset;
20071 size_type count(
const key_type& key)
const
20073 for (
auto it = this->begin(); it != this->end(); ++it)
20075 if (m_compare(it->first, key))
20083 template<
class KeyType, detail::enable_if_t<
20084 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
20085 size_type count(KeyType && key)
const
20087 for (
auto it = this->begin(); it != this->end(); ++it)
20089 if (m_compare(it->first, key))
20097 iterator find(
const key_type& key)
20099 for (
auto it = this->begin(); it != this->end(); ++it)
20101 if (m_compare(it->first, key))
20106 return Container::end();
20109 template<
class KeyType, detail::enable_if_t<
20110 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
20111 iterator find(KeyType && key)
20113 for (
auto it = this->begin(); it != this->end(); ++it)
20115 if (m_compare(it->first, key))
20120 return Container::end();
20123 const_iterator find(
const key_type& key)
const
20125 for (
auto it = this->begin(); it != this->end(); ++it)
20127 if (m_compare(it->first, key))
20132 return Container::end();
20135 std::pair<iterator, bool> insert( value_type&& value )
20137 return emplace(value.first, std::move(value.second));
20140 std::pair<iterator, bool> insert(
const value_type& value )
20142 for (
auto it = this->begin(); it != this->end(); ++it)
20144 if (m_compare(it->first, value.first))
20146 return {it,
false};
20149 Container::push_back(value);
20150 return {--this->end(),
true};
20153 template<
typename InputIt>
20154 using require_input_iter =
typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
20155 std::input_iterator_tag>::value>::type;
20157 template<
typename InputIt,
typename = require_input_iter<InputIt>>
20158 void insert(InputIt first, InputIt last)
20160 for (
auto it = first; it != last; ++it)
20167 JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare();
20170NLOHMANN_JSON_NAMESPACE_END
20173#if defined(JSON_HAS_CPP_17)
20174 #if JSON_HAS_STATIC_RTTI
20177 #include <string_view>
20185NLOHMANN_JSON_NAMESPACE_BEGIN
20205NLOHMANN_BASIC_JSON_TPL_DECLARATION
20207 :
public ::nlohmann::detail::json_base_class<CustomBaseClass>
20213 friend class ::nlohmann::json_pointer;
20217 template<
typename BasicJsonType,
typename InputType>
20218 friend class ::nlohmann::detail::parser;
20219 friend ::nlohmann::detail::serializer<basic_json>;
20220 template<
typename BasicJsonType>
20221 friend class ::nlohmann::detail::iter_impl;
20222 template<
typename BasicJsonType,
typename CharType>
20223 friend class ::nlohmann::detail::binary_writer;
20224 template<
typename BasicJsonType,
typename InputType,
typename SAX>
20225 friend class ::nlohmann::detail::binary_reader;
20226 template<
typename BasicJsonType,
typename InputAdapterType>
20227 friend class ::nlohmann::detail::json_sax_dom_parser;
20228 template<
typename BasicJsonType,
typename InputAdapterType>
20229 friend class ::nlohmann::detail::json_sax_dom_callback_parser;
20230 friend class ::nlohmann::detail::exception;
20233 using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
20234 using json_base_class_t = ::nlohmann::detail::json_base_class<CustomBaseClass>;
20236 JSON_PRIVATE_UNLESS_TESTED:
20238 using lexer = ::nlohmann::detail::lexer_base<basic_json>;
20240 template<
typename InputAdapterType>
20241 static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
20242 InputAdapterType adapter,
20243 detail::parser_callback_t<basic_json>cb =
nullptr,
20244 const bool allow_exceptions =
true,
20245 const bool ignore_comments =
false,
20246 const bool ignore_trailing_commas =
false
20249 return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
20250 std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas);
20254 using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
20255 template<
typename BasicJsonType>
20256 using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
20257 template<
typename BasicJsonType>
20258 using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>;
20259 template<
typename Iterator>
20260 using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>;
20261 template<
typename Base>
using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>;
20263 template<
typename CharType>
20264 using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>;
20266 template<
typename InputType>
20267 using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
20268 template<
typename CharType>
using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
20270 JSON_PRIVATE_UNLESS_TESTED:
20271 using serializer = ::nlohmann::detail::serializer<basic_json>;
20277 template<
typename T,
typename SFINAE>
20278 using json_serializer = JSONSerializer<T, SFINAE>;
20284 using bjdata_version_t = detail::bjdata_version_t;
20288 using input_format_t = detail::input_format_t;
20335 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
20337 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
20359 JSON_HEDLEY_WARN_UNUSED_RESULT
20364 result[
"copyright"] =
"(C) 2013-2025 Niels Lohmann";
20365 result[
"name"] =
"JSON for Modern C++";
20366 result[
"url"] =
"https://github.com/nlohmann/json";
20367 result[
"version"][
"string"] =
20368 detail::concat(std::to_string(NLOHMANN_JSON_VERSION_MAJOR),
'.',
20369 std::to_string(NLOHMANN_JSON_VERSION_MINOR),
'.',
20370 std::to_string(NLOHMANN_JSON_VERSION_PATCH));
20371 result[
"version"][
"major"] = NLOHMANN_JSON_VERSION_MAJOR;
20372 result[
"version"][
"minor"] = NLOHMANN_JSON_VERSION_MINOR;
20373 result[
"version"][
"patch"] = NLOHMANN_JSON_VERSION_PATCH;
20376 result[
"platform"] =
"win32";
20377#elif defined __linux__
20378 result[
"platform"] =
"linux";
20379#elif defined __APPLE__
20380 result[
"platform"] =
"apple";
20381#elif defined __unix__
20382 result[
"platform"] =
"unix";
20384 result[
"platform"] =
"unknown";
20387#if defined(__ICC) || defined(__INTEL_COMPILER)
20388 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
20389#elif defined(__clang__)
20390 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
20391#elif defined(__GNUC__) || defined(__GNUG__)
20392 result[
"compiler"] = {{
"family",
"gcc"}, {
"version", detail::concat(
20393 std::to_string(__GNUC__),
'.',
20394 std::to_string(__GNUC_MINOR__),
'.',
20395 std::to_string(__GNUC_PATCHLEVEL__))
20398#elif defined(__HP_cc) || defined(__HP_aCC)
20399 result[
"compiler"] =
"hp"
20400#elif defined(__IBMCPP__)
20401 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
20402#elif defined(_MSC_VER)
20403 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
20404#elif defined(__PGI)
20405 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
20406#elif defined(__SUNPRO_CC)
20407 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
20409 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
20412#if defined(_MSVC_LANG)
20413 result[
"compiler"][
"c++"] = std::to_string(_MSVC_LANG);
20414#elif defined(__cplusplus)
20415 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
20417 result[
"compiler"][
"c++"] =
"unknown";
20435#if defined(JSON_HAS_CPP_14)
20438 using default_object_comparator_t = std::less<>;
20448 AllocatorType<std::pair<
const StringType,
20453 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
20477 using binary_t = nlohmann::byte_container_with_subtype<BinaryType>;
20488 template<
typename T,
typename... Args>
20489 JSON_HEDLEY_RETURNS_NON_NULL
20490 static T* create(Args&& ... args)
20492 AllocatorType<T> alloc;
20493 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
20495 auto deleter = [&](T * obj)
20497 AllocatorTraits::deallocate(alloc, obj, 1);
20499 std::unique_ptr<T,
decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
20500 AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
20501 JSON_ASSERT(obj !=
nullptr);
20502 return obj.release();
20509 JSON_PRIVATE_UNLESS_TESTED:
20548 number_integer_t number_integer;
20550 number_unsigned_t number_unsigned;
20552 number_float_t number_float;
20555 json_value() =
default;
20557 json_value(boolean_t v) noexcept : boolean(v) {}
20563 json_value(number_float_t v) noexcept :
number_float(v) {}
20565 json_value(value_t t)
20569 case value_t::object:
20571 object = create<object_t>();
20575 case value_t::array:
20577 array = create<array_t>();
20581 case value_t::string:
20583 string = create<string_t>(
"");
20587 case value_t::binary:
20589 binary = create<binary_t>();
20593 case value_t::boolean:
20595 boolean =
static_cast<boolean_t
>(
false);
20599 case value_t::number_integer:
20605 case value_t::number_unsigned:
20611 case value_t::number_float:
20617 case value_t::null:
20623 case value_t::discarded:
20627 if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
20629 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.12.0",
nullptr));
20637 json_value(
const string_t& value) :
string(create<string_t>(value)) {}
20640 json_value(string_t&& value) :
string(create<string_t>(std::move(value))) {}
20643 json_value(
const object_t& value) :
object(create<object_t>(value)) {}
20646 json_value(object_t&& value) :
object(create<object_t>(std::move(value))) {}
20649 json_value(
const array_t& value) :
array(create<array_t>(value)) {}
20652 json_value(array_t&& value) :
array(create<array_t>(std::move(value))) {}
20655 json_value(
const typename binary_t::container_type& value) :
binary(create<binary_t>(value)) {}
20658 json_value(
typename binary_t::container_type&& value) :
binary(create<binary_t>(std::move(value))) {}
20661 json_value(
const binary_t& value) :
binary(create<binary_t>(value)) {}
20664 json_value(binary_t&& value) :
binary(create<binary_t>(std::move(value))) {}
20666 void destroy(value_t t)
20669 (t == value_t::object &&
object ==
nullptr) ||
20670 (t == value_t::array && array ==
nullptr) ||
20671 (t == value_t::string &&
string ==
nullptr) ||
20672 (t == value_t::binary && binary ==
nullptr)
20678 if (t == value_t::array || t == value_t::object)
20681 std::vector<basic_json> stack;
20684 if (t == value_t::array)
20686 stack.reserve(
array->size());
20687 std::move(
array->begin(),
array->end(), std::back_inserter(stack));
20691 stack.reserve(
object->size());
20692 for (
auto&& it : *
object)
20694 stack.push_back(std::move(it.second));
20698 while (!stack.empty())
20701 basic_json current_item(std::move(stack.back()));
20706 if (current_item.is_array())
20708 std::move(current_item.m_data.m_value.array->begin(), current_item.m_data.m_value.array->end(), std::back_inserter(stack));
20710 current_item.m_data.m_value.array->clear();
20712 else if (current_item.is_object())
20714 for (
auto&& it : *current_item.m_data.m_value.
object)
20716 stack.push_back(std::move(it.second));
20719 current_item.m_data.m_value.object->clear();
20729 case value_t::object:
20731 AllocatorType<object_t> alloc;
20732 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
object);
20733 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
object, 1);
20737 case value_t::array:
20739 AllocatorType<array_t> alloc;
20740 std::allocator_traits<
decltype(alloc)>::destroy(alloc, array);
20741 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, array, 1);
20745 case value_t::string:
20747 AllocatorType<string_t> alloc;
20748 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
string);
20749 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
string, 1);
20753 case value_t::binary:
20755 AllocatorType<binary_t> alloc;
20756 std::allocator_traits<
decltype(alloc)>::destroy(alloc, binary);
20757 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, binary, 1);
20761 case value_t::null:
20762 case value_t::boolean:
20763 case value_t::number_integer:
20764 case value_t::number_unsigned:
20765 case value_t::number_float:
20766 case value_t::discarded:
20794 void assert_invariant(
bool check_parents =
true) const noexcept
20796 JSON_ASSERT(m_data.m_type != value_t::object || m_data.m_value.object !=
nullptr);
20797 JSON_ASSERT(m_data.m_type != value_t::array || m_data.m_value.array !=
nullptr);
20798 JSON_ASSERT(m_data.m_type != value_t::string || m_data.m_value.string !=
nullptr);
20799 JSON_ASSERT(m_data.m_type != value_t::binary || m_data.m_value.binary !=
nullptr);
20801#if JSON_DIAGNOSTICS
20805 JSON_ASSERT(!check_parents || !is_structured() || std::all_of(begin(), end(), [
this](
const basic_json & j)
20807 return j.m_parent ==
this;
20812 static_cast<void>(check_parents);
20817#if JSON_DIAGNOSTICS
20818 switch (m_data.m_type)
20820 case value_t::array:
20822 for (
auto& element : *m_data.m_value.
array)
20824 element.m_parent =
this;
20829 case value_t::object:
20831 for (
auto& element : *m_data.m_value.
object)
20833 element.second.m_parent =
this;
20838 case value_t::null:
20839 case value_t::string:
20840 case value_t::boolean:
20841 case value_t::number_integer:
20842 case value_t::number_unsigned:
20843 case value_t::number_float:
20844 case value_t::binary:
20845 case value_t::discarded:
20852 iterator set_parents(iterator it,
typename iterator::difference_type count_set_parents)
20854#if JSON_DIAGNOSTICS
20855 for (
typename iterator::difference_type i = 0; i < count_set_parents; ++i)
20857 (it + i)->m_parent =
this;
20860 static_cast<void>(count_set_parents);
20865 reference set_parent(reference j, std::size_t old_capacity = detail::unknown_size())
20867#if JSON_DIAGNOSTICS
20868 if (old_capacity != detail::unknown_size())
20871 JSON_ASSERT(type() == value_t::array);
20872 if (JSON_HEDLEY_UNLIKELY(m_data.m_value.array->capacity() != old_capacity))
20882#ifdef JSON_HEDLEY_MSVC_VERSION
20883#pragma warning(push )
20884#pragma warning(disable : 4127)
20891#ifdef JSON_HEDLEY_MSVC_VERSION
20892#pragma warning( pop )
20897 static_cast<void>(j);
20898 static_cast<void>(old_capacity);
20910 using parse_event_t = detail::parse_event_t;
20930 assert_invariant();
20938 assert_invariant();
20943 template <
typename CompatibleType,
20944 typename U = detail::uncvref_t<CompatibleType>,
20945 detail::enable_if_t <
20948 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
20949 std::forward<CompatibleType>(val))))
20951 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
20953 assert_invariant();
20958 template <
typename BasicJsonType,
20959 detail::enable_if_t <
20962#if JSON_DIAGNOSTIC_POSITIONS
20963 : start_position(val.start_pos()),
20964 end_position(val.end_pos())
20967 using other_boolean_t =
typename BasicJsonType::boolean_t;
20968 using other_number_float_t =
typename BasicJsonType::number_float_t;
20969 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
20970 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
20971 using other_string_t =
typename BasicJsonType::string_t;
20972 using other_object_t =
typename BasicJsonType::object_t;
20973 using other_array_t =
typename BasicJsonType::array_t;
20974 using other_binary_t =
typename BasicJsonType::binary_t;
20976 switch (val.type())
20978 case value_t::boolean:
20979 JSONSerializer<other_boolean_t>::to_json(*
this, val.template get<other_boolean_t>());
20981 case value_t::number_float:
20982 JSONSerializer<other_number_float_t>::to_json(*
this, val.template get<other_number_float_t>());
20984 case value_t::number_integer:
20985 JSONSerializer<other_number_integer_t>::to_json(*
this, val.template get<other_number_integer_t>());
20987 case value_t::number_unsigned:
20988 JSONSerializer<other_number_unsigned_t>::to_json(*
this, val.template get<other_number_unsigned_t>());
20990 case value_t::string:
20991 JSONSerializer<other_string_t>::to_json(*
this, val.template get_ref<const other_string_t&>());
20993 case value_t::object:
20994 JSONSerializer<other_object_t>::to_json(*
this, val.template get_ref<const other_object_t&>());
20996 case value_t::array:
20997 JSONSerializer<other_array_t>::to_json(*
this, val.template get_ref<const other_array_t&>());
20999 case value_t::binary:
21000 JSONSerializer<other_binary_t>::to_json(*
this, val.template get_ref<const other_binary_t&>());
21002 case value_t::null:
21005 case value_t::discarded:
21006 m_data.m_type = value_t::discarded;
21009 JSON_ASSERT(
false);
21011 JSON_ASSERT(m_data.m_type == val.type());
21014 assert_invariant();
21020 bool type_deduction =
true,
21021 value_t manual_type = value_t::array)
21025 bool is_an_object = std::all_of(init.begin(), init.end(),
21031 return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[static_cast<size_type>(0)].is_string();
21035 if (!type_deduction)
21038 if (manual_type == value_t::array)
21040 is_an_object =
false;
21044 if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))
21046 JSON_THROW(type_error::create(301,
"cannot create object from initializer list",
nullptr));
21053 m_data.m_type = value_t::object;
21054 m_data.m_value = value_t::object;
21056 for (
auto& element_ref : init)
21058 auto element = element_ref.moved_or_copied();
21059 m_data.m_value.object->emplace(
21060 std::move(*((*element.m_data.m_value.array)[0].m_data.m_value.string)),
21061 std::move((*element.m_data.m_value.array)[1]));
21067 m_data.m_type = value_t::array;
21068 m_data.m_value.array = create<array_t>(init.begin(), init.end());
21072 assert_invariant();
21077 JSON_HEDLEY_WARN_UNUSED_RESULT
21081 res.m_data.m_type = value_t::binary;
21082 res.m_data.m_value = init;
21088 JSON_HEDLEY_WARN_UNUSED_RESULT
21089 static basic_json binary(
const typename binary_t::container_type& init,
typename binary_t::subtype_type subtype)
21092 res.m_data.m_type = value_t::binary;
21093 res.m_data.m_value =
binary_t(init, subtype);
21099 JSON_HEDLEY_WARN_UNUSED_RESULT
21103 res.m_data.m_type = value_t::binary;
21104 res.m_data.m_value = std::move(init);
21110 JSON_HEDLEY_WARN_UNUSED_RESULT
21111 static basic_json binary(
typename binary_t::container_type&& init,
typename binary_t::subtype_type subtype)
21114 res.m_data.m_type = value_t::binary;
21115 res.m_data.m_value =
binary_t(std::move(init), subtype);
21121 JSON_HEDLEY_WARN_UNUSED_RESULT
21124 return basic_json(init,
false, value_t::array);
21129 JSON_HEDLEY_WARN_UNUSED_RESULT
21132 return basic_json(init,
false, value_t::object);
21141 assert_invariant();
21146 template <
class InputIT,
typename std::enable_if <
21147 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
21148 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int >::type = 0 >
21151 JSON_ASSERT(first.m_object !=
nullptr);
21152 JSON_ASSERT(last.m_object !=
nullptr);
21155 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
21157 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible",
nullptr));
21161 m_data.m_type = first.m_object->m_data.m_type;
21164 switch (m_data.m_type)
21166 case value_t::boolean:
21167 case value_t::number_float:
21168 case value_t::number_integer:
21169 case value_t::number_unsigned:
21170 case value_t::string:
21172 if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
21173 || !last.m_it.primitive_iterator.is_end()))
21175 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", first.m_object));
21180 case value_t::null:
21181 case value_t::object:
21182 case value_t::array:
21183 case value_t::binary:
21184 case value_t::discarded:
21189 switch (m_data.m_type)
21191 case value_t::number_integer:
21193 m_data.m_value.number_integer = first.m_object->m_data.m_value.number_integer;
21197 case value_t::number_unsigned:
21199 m_data.m_value.number_unsigned = first.m_object->m_data.m_value.number_unsigned;
21203 case value_t::number_float:
21205 m_data.m_value.number_float = first.m_object->m_data.m_value.number_float;
21209 case value_t::boolean:
21211 m_data.m_value.boolean = first.m_object->m_data.m_value.boolean;
21215 case value_t::string:
21217 m_data.m_value = *first.m_object->m_data.m_value.string;
21221 case value_t::object:
21223 m_data.m_value.object = create<object_t>(first.m_it.object_iterator,
21224 last.m_it.object_iterator);
21228 case value_t::array:
21230 m_data.m_value.array = create<array_t>(first.m_it.array_iterator,
21231 last.m_it.array_iterator);
21235 case value_t::binary:
21237 m_data.m_value = *first.m_object->m_data.m_value.binary;
21241 case value_t::null:
21242 case value_t::discarded:
21244 JSON_THROW(invalid_iterator::create(206, detail::concat(
"cannot construct with iterators from ", first.m_object->type_name()), first.m_object));
21248 assert_invariant();
21255 template<
typename JsonRef,
21256 detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
21257 std::is_same<typename JsonRef::value_type, basic_json>>::value,
int> = 0 >
21263 : json_base_class_t(other)
21264#if JSON_DIAGNOSTIC_POSITIONS
21265 , start_position(other.start_position)
21266 , end_position(other.end_position)
21269 m_data.m_type = other.m_data.m_type;
21271 other.assert_invariant();
21273 switch (m_data.m_type)
21275 case value_t::object:
21277 m_data.m_value = *other.m_data.m_value.object;
21281 case value_t::array:
21283 m_data.m_value = *other.m_data.m_value.array;
21287 case value_t::string:
21289 m_data.m_value = *other.m_data.m_value.string;
21293 case value_t::boolean:
21295 m_data.m_value = other.m_data.m_value.boolean;
21299 case value_t::number_integer:
21301 m_data.m_value = other.m_data.m_value.number_integer;
21305 case value_t::number_unsigned:
21307 m_data.m_value = other.m_data.m_value.number_unsigned;
21311 case value_t::number_float:
21313 m_data.m_value = other.m_data.m_value.number_float;
21317 case value_t::binary:
21319 m_data.m_value = *other.m_data.m_value.binary;
21323 case value_t::null:
21324 case value_t::discarded:
21330 assert_invariant();
21336 : json_base_class_t(std::forward<json_base_class_t>(other)),
21337 m_data(std::move(other.m_data))
21338#if JSON_DIAGNOSTIC_POSITIONS
21339 , start_position(other.start_position)
21340 , end_position(other.end_position)
21344 other.assert_invariant(
false);
21347 other.m_data.m_type = value_t::null;
21348 other.m_data.m_value = {};
21350#if JSON_DIAGNOSTIC_POSITIONS
21351 other.start_position = std::string::npos;
21352 other.end_position = std::string::npos;
21356 assert_invariant();
21362 std::is_nothrow_move_constructible<value_t>::value&&
21363 std::is_nothrow_move_assignable<value_t>::value&&
21364 std::is_nothrow_move_constructible<json_value>::value&&
21365 std::is_nothrow_move_assignable<json_value>::value&&
21366 std::is_nothrow_move_assignable<json_base_class_t>::value
21370 other.assert_invariant();
21373 swap(m_data.m_type, other.m_data.m_type);
21374 swap(m_data.m_value, other.m_data.m_value);
21376#if JSON_DIAGNOSTIC_POSITIONS
21377 swap(start_position, other.start_position);
21378 swap(end_position, other.end_position);
21381 json_base_class_t::operator=(std::move(other));
21384 assert_invariant();
21392 assert_invariant(
false);
21409 const char indent_char =
' ',
21410 const bool ensure_ascii =
false,
21414 serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler);
21418 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
21422 s.dump(*
this,
false, ensure_ascii, 0);
21432 return m_data.m_type;
21439 return is_null() || is_string() || is_boolean() || is_number() || is_binary();
21446 return is_array() || is_object();
21453 return m_data.m_type == value_t::null;
21460 return m_data.m_type == value_t::boolean;
21467 return is_number_integer() || is_number_float();
21474 return m_data.m_type == value_t::number_integer || m_data.m_type == value_t::number_unsigned;
21481 return m_data.m_type == value_t::number_unsigned;
21488 return m_data.m_type == value_t::number_float;
21495 return m_data.m_type == value_t::object;
21502 return m_data.m_type == value_t::array;
21509 return m_data.m_type == value_t::string;
21516 return m_data.m_type == value_t::binary;
21523 return m_data.m_type == value_t::discarded;
21530 return m_data.m_type;
21541 boolean_t get_impl(boolean_t* )
const
21543 if (JSON_HEDLEY_LIKELY(is_boolean()))
21545 return m_data.m_value.boolean;
21548 JSON_THROW(type_error::create(302, detail::concat(
"type must be boolean, but is ", type_name()),
this));
21552 object_t* get_impl_ptr(object_t* )
noexcept
21554 return is_object() ? m_data.m_value.object :
nullptr;
21558 constexpr const object_t* get_impl_ptr(
const object_t* )
const noexcept
21560 return is_object() ? m_data.m_value.object :
nullptr;
21564 array_t* get_impl_ptr(array_t* )
noexcept
21566 return is_array() ? m_data.m_value.array :
nullptr;
21570 constexpr const array_t* get_impl_ptr(
const array_t* )
const noexcept
21572 return is_array() ? m_data.m_value.array :
nullptr;
21576 string_t* get_impl_ptr(string_t* )
noexcept
21578 return is_string() ? m_data.m_value.string :
nullptr;
21582 constexpr const string_t* get_impl_ptr(
const string_t* )
const noexcept
21584 return is_string() ? m_data.m_value.string :
nullptr;
21588 boolean_t* get_impl_ptr(boolean_t* )
noexcept
21590 return is_boolean() ? &m_data.m_value.boolean :
nullptr;
21594 constexpr const boolean_t* get_impl_ptr(
const boolean_t* )
const noexcept
21596 return is_boolean() ? &m_data.m_value.boolean :
nullptr;
21600 number_integer_t* get_impl_ptr(number_integer_t* )
noexcept
21602 return m_data.m_type == value_t::number_integer ? &m_data.m_value.number_integer :
nullptr;
21606 constexpr const number_integer_t* get_impl_ptr(
const number_integer_t* )
const noexcept
21608 return m_data.m_type == value_t::number_integer ? &m_data.m_value.number_integer :
nullptr;
21612 number_unsigned_t* get_impl_ptr(number_unsigned_t* )
noexcept
21614 return is_number_unsigned() ? &m_data.m_value.number_unsigned :
nullptr;
21618 constexpr const number_unsigned_t* get_impl_ptr(
const number_unsigned_t* )
const noexcept
21620 return is_number_unsigned() ? &m_data.m_value.number_unsigned :
nullptr;
21624 number_float_t* get_impl_ptr(number_float_t* )
noexcept
21626 return is_number_float() ? &m_data.m_value.number_float :
nullptr;
21630 constexpr const number_float_t* get_impl_ptr(
const number_float_t* )
const noexcept
21632 return is_number_float() ? &m_data.m_value.number_float :
nullptr;
21636 binary_t* get_impl_ptr(binary_t* )
noexcept
21638 return is_binary() ? m_data.m_value.binary :
nullptr;
21642 constexpr const binary_t* get_impl_ptr(
const binary_t* )
const noexcept
21644 return is_binary() ? m_data.m_value.binary :
nullptr;
21658 template<
typename ReferenceType,
typename ThisType>
21659 static ReferenceType get_ref_impl(ThisType& obj)
21662 auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
21664 if (JSON_HEDLEY_LIKELY(ptr !=
nullptr))
21669 JSON_THROW(type_error::create(303, detail::concat(
"incompatible ReferenceType for get_ref, actual type is ", obj.type_name()), &obj));
21679 template<
typename PointerType,
typename std::enable_if<
21680 std::is_pointer<PointerType>::value,
int>::type = 0>
21681 auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
21684 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
21689 template <
typename PointerType,
typename std::enable_if <
21690 std::is_pointer<PointerType>::value&&
21691 std::is_const<typename std::remove_pointer<PointerType>::type>::value,
int >::type = 0 >
21692 constexpr auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
21695 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
21737 template <
typename ValueType,
21738 detail::enable_if_t <
21743 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
21745 auto ret = ValueType();
21746 JSONSerializer<ValueType>::from_json(*
this, ret);
21780 template <
typename ValueType,
21781 detail::enable_if_t <
21785 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
21787 return JSONSerializer<ValueType>::from_json(*
this);
21805 template <
typename BasicJsonType,
21806 detail::enable_if_t <
21828 template<
typename BasicJsonType,
21829 detail::enable_if_t<
21830 std::is_same<BasicJsonType, basic_json_t>::value,
21841 template<
typename PointerType,
21842 detail::enable_if_t<
21843 std::is_pointer<PointerType>::value,
21846 ->
decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>())
21849 return get_ptr<PointerType>();
21876 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>>
21877#if defined(JSON_HAS_CPP_14)
21881 noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(
detail::priority_tag<4> {})))
21887 static_assert(!std::is_reference<ValueTypeCV>::value,
21888 "get() cannot be used with reference types, you might want to use get_ref()");
21919 template<
typename PointerType,
typename std::enable_if<
21920 std::is_pointer<PointerType>::value,
int>::type = 0>
21921 auto get() noexcept -> decltype(std::declval<basic_json_t&>().template get_ptr<PointerType>())
21924 return get_ptr<PointerType>();
21929 template <
typename ValueType,
21930 detail::enable_if_t <
21934 ValueType &
get_to(ValueType& v)
const noexcept(
noexcept(
21935 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
21937 JSONSerializer<ValueType>::from_json(*
this, v);
21943 template<
typename ValueType,
21944 detail::enable_if_t <
21947 ValueType & get_to(ValueType& v)
const
21954 typename T, std::size_t N,
21955 typename Array = T (&)[N],
21956 detail::enable_if_t <
21958 Array get_to(T (&v)[N])
const
21959 noexcept(
noexcept(JSONSerializer<Array>::from_json(
21960 std::declval<const basic_json_t&>(), v)))
21962 JSONSerializer<Array>::from_json(*
this, v);
21968 template<
typename ReferenceType,
typename std::enable_if<
21969 std::is_reference<ReferenceType>::value,
int>::type = 0>
21973 return get_ref_impl<ReferenceType>(*
this);
21978 template <
typename ReferenceType,
typename std::enable_if <
21979 std::is_reference<ReferenceType>::value&&
21980 std::is_const<typename std::remove_reference<ReferenceType>::type>::value,
int >::type = 0 >
21984 return get_ref_impl<ReferenceType>(*
this);
22016 template <
typename ValueType,
typename std::enable_if <
22024#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
22027#if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI
22031 >::value,
int >::type = 0 >
22032 JSON_EXPLICIT
operator ValueType()
const
22035 return get<ValueType>();
22044 JSON_THROW(type_error::create(302, detail::concat(
"type must be binary, but is ", type_name()),
this));
22047 return *get_ptr<binary_t*>();
22056 JSON_THROW(type_error::create(302, detail::concat(
"type must be binary, but is ", type_name()),
this));
22059 return *get_ptr<const binary_t*>();
22077 if (JSON_HEDLEY_LIKELY(is_array()))
22081 return set_parent(m_data.m_value.array->at(idx));
22083 JSON_CATCH (std::out_of_range&)
22086 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
22091 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
22100 if (JSON_HEDLEY_LIKELY(is_array()))
22104 return m_data.m_value.array->at(idx);
22106 JSON_CATCH (std::out_of_range&)
22109 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
22114 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
22123 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22125 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
22128 auto it = m_data.m_value.object->find(key);
22129 if (it == m_data.m_value.object->end())
22131 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", key,
"' not found"),
this));
22133 return set_parent(it->second);
22138 template<
class KeyType, detail::enable_if_t<
22139 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22143 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22145 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
22148 auto it = m_data.m_value.object->find(std::forward<KeyType>(key));
22149 if (it == m_data.m_value.object->end())
22151 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
string_t(std::forward<KeyType>(key)),
"' not found"),
this));
22153 return set_parent(it->second);
22161 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22163 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
22166 auto it = m_data.m_value.object->find(key);
22167 if (it == m_data.m_value.object->end())
22169 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", key,
"' not found"),
this));
22176 template<
class KeyType, detail::enable_if_t<
22177 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22181 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22183 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
22186 auto it = m_data.m_value.object->find(std::forward<KeyType>(key));
22187 if (it == m_data.m_value.object->end())
22189 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
string_t(std::forward<KeyType>(key)),
"' not found"),
this));
22201 m_data.m_type = value_t::array;
22202 m_data.
m_value.array = create<array_t>();
22203 assert_invariant();
22207 if (JSON_HEDLEY_LIKELY(is_array()))
22210 if (idx >= m_data.m_value.array->size())
22212#if JSON_DIAGNOSTICS
22214 const auto old_size = m_data.m_value.array->size();
22215 const auto old_capacity = m_data.m_value.array->capacity();
22217 m_data.m_value.array->resize(idx + 1);
22219#if JSON_DIAGNOSTICS
22220 if (JSON_HEDLEY_UNLIKELY(m_data.m_value.array->capacity() != old_capacity))
22228 set_parents(begin() +
static_cast<typename iterator::difference_type
>(old_size),
static_cast<typename iterator::difference_type
>(idx + 1 - old_size));
22231 assert_invariant();
22234 return m_data.m_value.array->operator[](idx);
22237 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a numeric argument with ", type_name()),
this));
22245 if (JSON_HEDLEY_LIKELY(is_array()))
22247 return m_data.
m_value.array->operator[](idx);
22250 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a numeric argument with ", type_name()),
this));
22260 m_data.m_type = value_t::object;
22261 m_data.
m_value.object = create<object_t>();
22262 assert_invariant();
22266 if (JSON_HEDLEY_LIKELY(is_object()))
22268 auto result = m_data.m_value.object->emplace(std::move(key),
nullptr);
22269 return set_parent(result.first->second);
22272 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
22280 if (JSON_HEDLEY_LIKELY(is_object()))
22282 auto it = m_data.
m_value.object->find(key);
22283 JSON_ASSERT(it != m_data.m_value.object->end());
22287 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
22292 template<
typename T>
22293 reference operator[](T* key)
22295 return operator[](
typename object_t::key_type(key));
22298 template<
typename T>
22299 const_reference operator[](T* key)
const
22301 return operator[](
typename object_t::key_type(key));
22306 template<
class KeyType, detail::enable_if_t<
22307 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int > = 0 >
22313 m_data.m_type = value_t::object;
22314 m_data.
m_value.object = create<object_t>();
22315 assert_invariant();
22319 if (JSON_HEDLEY_LIKELY(is_object()))
22321 auto result = m_data.m_value.object->emplace(std::forward<KeyType>(key),
nullptr);
22322 return set_parent(result.first->second);
22325 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
22330 template<
class KeyType, detail::enable_if_t<
22331 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int > = 0 >
22335 if (JSON_HEDLEY_LIKELY(is_object()))
22337 auto it = m_data.
m_value.object->find(std::forward<KeyType>(key));
22338 JSON_ASSERT(it != m_data.m_value.object->end());
22342 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
22346 template<
typename KeyType>
22348 object_comparator_t,
const typename object_t::key_type&, KeyType >;
22350 template<
typename ValueType>
22351 using value_return_type = std::conditional <
22352 detail::is_c_string_uncvref<ValueType>::value,
22353 string_t,
typename std::decay<ValueType>::type >;
22358 template <
class ValueType, detail::enable_if_t <
22361 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22362 ValueType
value(
const typename object_t::key_type& key,
const ValueType& default_value)
const
22365 if (JSON_HEDLEY_LIKELY(is_object()))
22368 const auto it = find(key);
22371 return it->template get<ValueType>();
22374 return default_value;
22377 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
22382 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
22383 detail::enable_if_t <
22386 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22387 ReturnType
value(
const typename object_t::key_type& key, ValueType && default_value)
const
22390 if (JSON_HEDLEY_LIKELY(is_object()))
22393 const auto it = find(key);
22396 return it->template get<ReturnType>();
22399 return std::forward<ValueType>(default_value);
22402 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
22407 template <
class ValueType,
class KeyType, detail::enable_if_t <
22409 && !detail::is_json_pointer<KeyType>::value
22410 && is_comparable_with_object_key<KeyType>::value
22412 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22413 ValueType
value(KeyType && key,
const ValueType& default_value)
const
22416 if (JSON_HEDLEY_LIKELY(is_object()))
22419 const auto it = find(std::forward<KeyType>(key));
22422 return it->template get<ValueType>();
22425 return default_value;
22428 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
22433 template < class ValueType, class KeyType, class ReturnType = typename value_return_type<ValueType>::type,
22434 detail::enable_if_t <
22436 && !detail::is_json_pointer<KeyType>::value
22437 && is_comparable_with_object_key<KeyType>::value
22439 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22440 ReturnType
value(KeyType && key, ValueType && default_value)
const
22443 if (JSON_HEDLEY_LIKELY(is_object()))
22446 const auto it = find(std::forward<KeyType>(key));
22449 return it->template get<ReturnType>();
22452 return std::forward<ValueType>(default_value);
22455 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
22460 template <
class ValueType, detail::enable_if_t <
22462 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22466 if (JSON_HEDLEY_LIKELY(is_object()))
22472 return ptr.get_checked(
this).template get<ValueType>();
22476 return default_value;
22480 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
22485 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
22486 detail::enable_if_t <
22488 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22492 if (JSON_HEDLEY_LIKELY(is_object()))
22498 return ptr.get_checked(
this).template get<ReturnType>();
22502 return std::forward<ValueType>(default_value);
22506 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
22509 template <
class ValueType,
class BasicJsonType, detail::enable_if_t <
22512 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22514 ValueType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr,
const ValueType& default_value)
const
22516 return value(ptr.convert(), default_value);
22519 template < class ValueType, class BasicJsonType, class ReturnType = typename value_return_type<ValueType>::type,
22520 detail::enable_if_t <
22523 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22525 ReturnType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, ValueType && default_value)
const
22527 return value(ptr.convert(), std::forward<ValueType>(default_value));
22564 template <
class IteratorType, detail::enable_if_t <
22565 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
22566 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
22570 if (JSON_HEDLEY_UNLIKELY(
this != pos.m_object))
22572 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
22575 IteratorType result = end();
22577 switch (m_data.m_type)
22579 case value_t::boolean:
22580 case value_t::number_float:
22581 case value_t::number_integer:
22582 case value_t::number_unsigned:
22583 case value_t::string:
22584 case value_t::binary:
22586 if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
22588 JSON_THROW(invalid_iterator::create(205,
"iterator out of range",
this));
22593 AllocatorType<string_t> alloc;
22594 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.string);
22595 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.string, 1);
22596 m_data.m_value.string =
nullptr;
22598 else if (is_binary())
22600 AllocatorType<binary_t> alloc;
22601 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.binary);
22602 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.binary, 1);
22603 m_data.m_value.binary =
nullptr;
22606 m_data.m_type = value_t::null;
22607 assert_invariant();
22611 case value_t::object:
22613 result.m_it.object_iterator = m_data.m_value.object->erase(pos.m_it.object_iterator);
22617 case value_t::array:
22619 result.m_it.array_iterator = m_data.m_value.array->erase(pos.m_it.array_iterator);
22623 case value_t::null:
22624 case value_t::discarded:
22626 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
22634 template <
class IteratorType, detail::enable_if_t <
22635 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
22636 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
22637 IteratorType
erase(IteratorType first, IteratorType last)
22640 if (JSON_HEDLEY_UNLIKELY(
this != first.m_object ||
this != last.m_object))
22642 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value",
this));
22645 IteratorType result = end();
22647 switch (m_data.m_type)
22649 case value_t::boolean:
22650 case value_t::number_float:
22651 case value_t::number_integer:
22652 case value_t::number_unsigned:
22653 case value_t::string:
22654 case value_t::binary:
22656 if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
22657 || !last.m_it.primitive_iterator.is_end()))
22659 JSON_THROW(invalid_iterator::create(204,
"iterators out of range",
this));
22664 AllocatorType<string_t> alloc;
22665 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.string);
22666 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.string, 1);
22667 m_data.m_value.string =
nullptr;
22669 else if (is_binary())
22671 AllocatorType<binary_t> alloc;
22672 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.binary);
22673 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.binary, 1);
22674 m_data.m_value.binary =
nullptr;
22677 m_data.m_type = value_t::null;
22678 assert_invariant();
22682 case value_t::object:
22684 result.m_it.object_iterator = m_data.m_value.object->erase(first.m_it.object_iterator,
22685 last.m_it.object_iterator);
22689 case value_t::array:
22691 result.m_it.array_iterator = m_data.m_value.array->erase(first.m_it.array_iterator,
22692 last.m_it.array_iterator);
22696 case value_t::null:
22697 case value_t::discarded:
22699 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
22706 template <
typename KeyType, detail::enable_if_t <
22707 detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int > = 0 >
22708 size_type erase_internal(KeyType && key)
22711 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22713 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
22716 return m_data.m_value.object->erase(std::forward<KeyType>(key));
22719 template <
typename KeyType, detail::enable_if_t <
22720 !detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int > = 0 >
22721 size_type erase_internal(KeyType && key)
22724 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22726 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
22729 const auto it = m_data.m_value.object->find(std::forward<KeyType>(key));
22730 if (it != m_data.m_value.object->end())
22732 m_data.m_value.object->erase(it);
22746 return erase_internal(key);
22751 template<
class KeyType, detail::enable_if_t<
22752 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22755 return erase_internal(std::forward<KeyType>(key));
22763 if (JSON_HEDLEY_LIKELY(is_array()))
22765 if (JSON_HEDLEY_UNLIKELY(idx >= size()))
22767 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
22770 m_data.m_value.array->erase(m_data.m_value.array->begin() +
static_cast<difference_type>(idx));
22774 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
22791 auto result = end();
22795 result.m_it.object_iterator = m_data.m_value.object->find(key);
22805 auto result = cend();
22809 result.m_it.object_iterator = m_data.m_value.object->find(key);
22817 template<
class KeyType, detail::enable_if_t<
22818 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22821 auto result = end();
22825 result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(key));
22833 template<
class KeyType, detail::enable_if_t<
22834 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22837 auto result = cend();
22841 result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(key));
22852 return is_object() ? m_data.m_value.object->count(key) : 0;
22857 template<
class KeyType, detail::enable_if_t<
22858 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22862 return is_object() ? m_data.m_value.object->count(std::forward<KeyType>(key)) : 0;
22867 bool contains(
const typename object_t::key_type& key)
const
22869 return is_object() && m_data.m_value.object->find(key) != m_data.m_value.object->end();
22874 template<
class KeyType, detail::enable_if_t<
22875 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22878 return is_object() && m_data.m_value.object->find(std::forward<KeyType>(key)) != m_data.m_value.object->end();
22885 return ptr.contains(
this);
22888 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
22890 bool contains(
const typename ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
22892 return ptr.contains(
this);
22909 result.set_begin();
22925 result.set_begin();
23002 JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
23005 return ref.items();
23013 JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
23016 return ref.items();
23023 return iteration_proxy<iterator>(*
this);
23028 iteration_proxy<const_iterator>
items() const noexcept
23030 return iteration_proxy<const_iterator>(*
this);
23046 switch (m_data.m_type)
23048 case value_t::null:
23054 case value_t::array:
23057 return m_data.m_value.array->empty();
23060 case value_t::object:
23063 return m_data.m_value.object->empty();
23066 case value_t::string:
23067 case value_t::boolean:
23068 case value_t::number_integer:
23069 case value_t::number_unsigned:
23070 case value_t::number_float:
23071 case value_t::binary:
23072 case value_t::discarded:
23085 switch (m_data.m_type)
23087 case value_t::null:
23093 case value_t::array:
23096 return m_data.m_value.array->size();
23099 case value_t::object:
23102 return m_data.m_value.object->size();
23105 case value_t::string:
23106 case value_t::boolean:
23107 case value_t::number_integer:
23108 case value_t::number_unsigned:
23109 case value_t::number_float:
23110 case value_t::binary:
23111 case value_t::discarded:
23124 switch (m_data.m_type)
23126 case value_t::array:
23129 return m_data.m_value.array->max_size();
23132 case value_t::object:
23135 return m_data.m_value.object->max_size();
23138 case value_t::null:
23139 case value_t::string:
23140 case value_t::boolean:
23141 case value_t::number_integer:
23142 case value_t::number_unsigned:
23143 case value_t::number_float:
23144 case value_t::binary:
23145 case value_t::discarded:
23167 switch (m_data.m_type)
23169 case value_t::number_integer:
23171 m_data.m_value.number_integer = 0;
23175 case value_t::number_unsigned:
23177 m_data.m_value.number_unsigned = 0;
23181 case value_t::number_float:
23183 m_data.m_value.number_float = 0.0;
23187 case value_t::boolean:
23189 m_data.m_value.boolean =
false;
23193 case value_t::string:
23195 m_data.m_value.string->clear();
23199 case value_t::binary:
23201 m_data.m_value.binary->clear();
23205 case value_t::array:
23207 m_data.m_value.array->clear();
23211 case value_t::object:
23213 m_data.m_value.object->clear();
23217 case value_t::null:
23218 case value_t::discarded:
23229 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
23231 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
23237 m_data.m_type = value_t::array;
23238 m_data.m_value = value_t::array;
23239 assert_invariant();
23243 const auto old_capacity = m_data.m_value.array->capacity();
23244 m_data.m_value.array->push_back(std::move(val));
23245 set_parent(m_data.m_value.array->back(), old_capacity);
23253 push_back(std::move(val));
23262 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
23264 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
23270 m_data.m_type = value_t::array;
23271 m_data.m_value = value_t::array;
23272 assert_invariant();
23276 const auto old_capacity = m_data.m_value.array->capacity();
23277 m_data.m_value.array->push_back(val);
23278 set_parent(m_data.m_value.array->back(), old_capacity);
23294 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
23296 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
23302 m_data.m_type = value_t::object;
23303 m_data.m_value = value_t::object;
23304 assert_invariant();
23308 auto res = m_data.m_value.object->insert(val);
23309 set_parent(res.first->second);
23324 if (is_object() && init.size() == 2 && (*init.begin())->is_string())
23326 basic_json&& key = init.begin()->moved_or_copied();
23327 push_back(
typename object_t::value_type(
23328 std::move(key.get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
23346 template<
class... Args>
23350 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
23352 JSON_THROW(type_error::create(311, detail::concat(
"cannot use emplace_back() with ", type_name()),
this));
23358 m_data.m_type = value_t::array;
23359 m_data.m_value = value_t::array;
23360 assert_invariant();
23364 const auto old_capacity = m_data.m_value.array->capacity();
23365 m_data.m_value.array->emplace_back(std::forward<Args>(args)...);
23366 return set_parent(m_data.m_value.array->back(), old_capacity);
23371 template<
class... Args>
23375 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
23377 JSON_THROW(type_error::create(311, detail::concat(
"cannot use emplace() with ", type_name()),
this));
23383 m_data.m_type = value_t::object;
23384 m_data.m_value = value_t::object;
23385 assert_invariant();
23389 auto res = m_data.m_value.object->emplace(std::forward<Args>(args)...);
23390 set_parent(res.first->second);
23394 it.m_it.object_iterator = res.first;
23397 return {it, res.second};
23403 template<
typename... Args>
23407 JSON_ASSERT(m_data.m_value.array !=
nullptr);
23409 auto insert_pos = std::distance(m_data.m_value.array->begin(), pos.m_it.array_iterator);
23410 m_data.m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
23411 result.m_it.array_iterator = m_data.m_value.array->begin() + insert_pos;
23426 if (JSON_HEDLEY_LIKELY(is_array()))
23429 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23431 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
23435 return insert_iterator(pos, val);
23438 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
23445 return insert(pos, val);
23453 if (JSON_HEDLEY_LIKELY(is_array()))
23456 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23458 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
23462 return insert_iterator(pos, cnt, val);
23465 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
23473 if (JSON_HEDLEY_UNLIKELY(!is_array()))
23475 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
23479 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23481 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
23485 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23487 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
23490 if (JSON_HEDLEY_UNLIKELY(first.m_object ==
this))
23492 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container",
this));
23496 return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
23504 if (JSON_HEDLEY_UNLIKELY(!is_array()))
23506 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
23510 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23512 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
23516 return insert_iterator(pos, ilist.begin(), ilist.end());
23524 if (JSON_HEDLEY_UNLIKELY(!is_object()))
23526 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
23530 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23532 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
23536 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
23538 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects",
this));
23541 m_data.m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
23549 update(j.
begin(), j.
end(), merge_objects);
23559 m_data.m_type = value_t::object;
23560 m_data.m_value.object = create<object_t>();
23561 assert_invariant();
23564 if (JSON_HEDLEY_UNLIKELY(!is_object()))
23566 JSON_THROW(type_error::create(312, detail::concat(
"cannot use update() with ", type_name()),
this));
23570 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23572 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
23576 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
23578 JSON_THROW(type_error::create(312, detail::concat(
"cannot use update() with ", first.m_object->type_name()), first.m_object));
23581 for (
auto it = first; it != last; ++it)
23583 if (merge_objects && it.value().is_object())
23585 auto it2 = m_data.m_value.object->find(it.key());
23586 if (it2 != m_data.m_value.object->end())
23588 it2->second.update(it.value(),
true);
23592 m_data.m_value.object->operator[](it.key()) = it.value();
23593#if JSON_DIAGNOSTICS
23594 m_data.m_value.object->operator[](it.key()).m_parent =
this;
23602 std::is_nothrow_move_constructible<value_t>::value&&
23603 std::is_nothrow_move_assignable<value_t>::value&&
23604 std::is_nothrow_move_constructible<json_value>::value&&
23605 std::is_nothrow_move_assignable<json_value>::value
23608 std::swap(m_data.m_type, other.m_data.m_type);
23609 std::swap(m_data.m_value, other.m_data.m_value);
23612 other.set_parents();
23613 assert_invariant();
23619 std::is_nothrow_move_constructible<value_t>::value&&
23620 std::is_nothrow_move_assignable<value_t>::value&&
23621 std::is_nothrow_move_constructible<json_value>::value&&
23622 std::is_nothrow_move_assignable<json_value>::value
23633 if (JSON_HEDLEY_LIKELY(is_array()))
23636 swap(*(m_data.m_value.array), other);
23640 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(array_t&) with ", type_name()),
this));
23649 if (JSON_HEDLEY_LIKELY(is_object()))
23652 swap(*(m_data.m_value.object), other);
23656 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(object_t&) with ", type_name()),
this));
23665 if (JSON_HEDLEY_LIKELY(is_string()))
23668 swap(*(m_data.m_value.string), other);
23672 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(string_t&) with ", type_name()),
this));
23681 if (JSON_HEDLEY_LIKELY(is_binary()))
23684 swap(*(m_data.m_value.binary), other);
23688 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(binary_t&) with ", type_name()),
this));
23694 void swap(
typename binary_t::container_type& other)
23697 if (JSON_HEDLEY_LIKELY(is_binary()))
23700 swap(*(m_data.m_value.binary), other);
23704 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(binary_t::container_type&) with ", type_name()),
this));
23719#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result) \
23720 const auto lhs_type = lhs.type(); \
23721 const auto rhs_type = rhs.type(); \
23723 if (lhs_type == rhs_type) \
23725 switch (lhs_type) \
23727 case value_t::array: \
23728 return (*lhs.m_data.m_value.array) op (*rhs.m_data.m_value.array); \
23730 case value_t::object: \
23731 return (*lhs.m_data.m_value.object) op (*rhs.m_data.m_value.object); \
23733 case value_t::null: \
23734 return (null_result); \
23736 case value_t::string: \
23737 return (*lhs.m_data.m_value.string) op (*rhs.m_data.m_value.string); \
23739 case value_t::boolean: \
23740 return (lhs.m_data.m_value.boolean) op (rhs.m_data.m_value.boolean); \
23742 case value_t::number_integer: \
23743 return (lhs.m_data.m_value.number_integer) op (rhs.m_data.m_value.number_integer); \
23745 case value_t::number_unsigned: \
23746 return (lhs.m_data.m_value.number_unsigned) op (rhs.m_data.m_value.number_unsigned); \
23748 case value_t::number_float: \
23749 return (lhs.m_data.m_value.number_float) op (rhs.m_data.m_value.number_float); \
23751 case value_t::binary: \
23752 return (*lhs.m_data.m_value.binary) op (*rhs.m_data.m_value.binary); \
23754 case value_t::discarded: \
23756 return (unordered_result); \
23759 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) \
23761 return static_cast<number_float_t>(lhs.m_data.m_value.number_integer) op rhs.m_data.m_value.number_float; \
23763 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) \
23765 return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_integer); \
23767 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) \
23769 return static_cast<number_float_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_float; \
23771 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) \
23773 return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_unsigned); \
23775 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) \
23777 return static_cast<number_integer_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_integer; \
23779 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) \
23781 return lhs.m_data.m_value.number_integer op static_cast<number_integer_t>(rhs.m_data.m_value.number_unsigned); \
23783 else if(compares_unordered(lhs, rhs))\
23785 return (unordered_result);\
23788 return (default_result);
23790 JSON_PRIVATE_UNLESS_TESTED:
23796 static bool compares_unordered(const_reference lhs, const_reference rhs,
bool inverse =
false) noexcept
23798 if ((lhs.is_number_float() && std::isnan(lhs.m_data.m_value.number_float) && rhs.is_number())
23799 || (rhs.is_number_float() && std::isnan(rhs.m_data.m_value.number_float) && lhs.is_number()))
23803#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
23804 return (lhs.is_discarded() || rhs.is_discarded()) && !inverse;
23806 static_cast<void>(inverse);
23807 return lhs.is_discarded() || rhs.is_discarded();
23812 bool compares_unordered(const_reference rhs,
bool inverse =
false) const noexcept
23814 return compares_unordered(*
this, rhs, inverse);
23818#if JSON_HAS_THREE_WAY_COMPARISON
23821 bool operator==(const_reference rhs)
const noexcept
23824#pragma GCC diagnostic push
23825#pragma GCC diagnostic ignored "-Wfloat-equal"
23827 const_reference lhs = *
this;
23828 JSON_IMPLEMENT_OPERATOR( ==,
true,
false,
false)
23830#pragma GCC diagnostic pop
23836 template<
typename ScalarType>
23837 requires std::is_scalar_v<ScalarType>
23838 bool operator==(ScalarType rhs)
const noexcept
23845 bool operator!=(const_reference rhs)
const noexcept
23847 if (compares_unordered(rhs,
true))
23856 std::partial_ordering operator<=>(const_reference rhs)
const noexcept
23858 const_reference lhs = *
this;
23861 JSON_IMPLEMENT_OPERATOR(<=>,
23862 std::partial_ordering::equivalent,
23863 std::partial_ordering::unordered,
23864 lhs_type <=> rhs_type)
23869 template<
typename ScalarType>
23870 requires std::is_scalar_v<ScalarType>
23871 std::partial_ordering operator<=>(ScalarType rhs)
const noexcept
23876#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
23882 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON)
23883 bool operator<=(const_reference rhs)
const noexcept
23885 if (compares_unordered(rhs,
true))
23889 return !(rhs < *
this);
23894 template<
typename ScalarType>
23895 requires std::is_scalar_v<ScalarType>
23896 bool operator<=(ScalarType rhs)
const noexcept
23903 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON)
23904 bool operator>=(const_reference rhs)
const noexcept
23906 if (compares_unordered(rhs,
true))
23910 return !(*
this < rhs);
23915 template<
typename ScalarType>
23916 requires std::is_scalar_v<ScalarType>
23917 bool operator>=(ScalarType rhs)
const noexcept
23925 friend bool operator==(const_reference lhs, const_reference rhs)
noexcept
23928#pragma GCC diagnostic push
23929#pragma GCC diagnostic ignored "-Wfloat-equal"
23931 JSON_IMPLEMENT_OPERATOR( ==,
true,
false,
false)
23933#pragma GCC diagnostic pop
23939 template<
typename ScalarType,
typename std::enable_if<
23940 std::is_scalar<ScalarType>::value,
int>::type = 0>
23941 friend bool operator==(const_reference lhs, ScalarType rhs)
noexcept
23948 template<
typename ScalarType,
typename std::enable_if<
23949 std::is_scalar<ScalarType>::value,
int>::type = 0>
23950 friend bool operator==(ScalarType lhs, const_reference rhs)
noexcept
23957 friend bool operator!=(const_reference lhs, const_reference rhs)
noexcept
23959 if (compares_unordered(lhs, rhs,
true))
23963 return !(lhs == rhs);
23968 template<
typename ScalarType,
typename std::enable_if<
23969 std::is_scalar<ScalarType>::value,
int>::type = 0>
23970 friend bool operator!=(const_reference lhs, ScalarType rhs)
noexcept
23977 template<
typename ScalarType,
typename std::enable_if<
23978 std::is_scalar<ScalarType>::value,
int>::type = 0>
23979 friend bool operator!=(ScalarType lhs, const_reference rhs)
noexcept
23986 friend bool operator<(const_reference lhs, const_reference rhs)
noexcept
23991 JSON_IMPLEMENT_OPERATOR( <,
false,
false,
operator<(lhs_type, rhs_type))
23996 template<
typename ScalarType,
typename std::enable_if<
23997 std::is_scalar<ScalarType>::value,
int>::type = 0>
23998 friend bool operator<(const_reference lhs, ScalarType rhs)
noexcept
24005 template<
typename ScalarType,
typename std::enable_if<
24006 std::is_scalar<ScalarType>::value,
int>::type = 0>
24007 friend bool operator<(ScalarType lhs, const_reference rhs)
noexcept
24014 friend bool operator<=(const_reference lhs, const_reference rhs)
noexcept
24016 if (compares_unordered(lhs, rhs,
true))
24020 return !(rhs < lhs);
24025 template<
typename ScalarType,
typename std::enable_if<
24026 std::is_scalar<ScalarType>::value,
int>::type = 0>
24027 friend bool operator<=(const_reference lhs, ScalarType rhs)
noexcept
24034 template<
typename ScalarType,
typename std::enable_if<
24035 std::is_scalar<ScalarType>::value,
int>::type = 0>
24036 friend bool operator<=(ScalarType lhs, const_reference rhs)
noexcept
24043 friend bool operator>(const_reference lhs, const_reference rhs)
noexcept
24046 if (compares_unordered(lhs, rhs))
24050 return !(lhs <= rhs);
24055 template<
typename ScalarType,
typename std::enable_if<
24056 std::is_scalar<ScalarType>::value,
int>::type = 0>
24057 friend bool operator>(const_reference lhs, ScalarType rhs)
noexcept
24064 template<
typename ScalarType,
typename std::enable_if<
24065 std::is_scalar<ScalarType>::value,
int>::type = 0>
24066 friend bool operator>(ScalarType lhs, const_reference rhs)
noexcept
24073 friend bool operator>=(const_reference lhs, const_reference rhs)
noexcept
24075 if (compares_unordered(lhs, rhs,
true))
24079 return !(lhs < rhs);
24084 template<
typename ScalarType,
typename std::enable_if<
24085 std::is_scalar<ScalarType>::value,
int>::type = 0>
24086 friend bool operator>=(const_reference lhs, ScalarType rhs)
noexcept
24093 template<
typename ScalarType,
typename std::enable_if<
24094 std::is_scalar<ScalarType>::value,
int>::type = 0>
24095 friend bool operator>=(ScalarType lhs, const_reference rhs)
noexcept
24101#undef JSON_IMPLEMENT_OPERATOR
24114 friend std::ostream& operator<<(std::ostream& o,
const basic_json& j)
24117 const bool pretty_print = o.width() > 0;
24118 const auto indentation = pretty_print ? o.width() : 0;
24124 serializer s(detail::output_adapter<char>(o), o.fill());
24125 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
24135 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator<<(std::ostream&,
const basic_json&))
24136 friend std::ostream& operator>>(
const basic_json& j, std::ostream& o)
24152 template<
typename InputType>
24153 JSON_HEDLEY_WARN_UNUSED_RESULT
24155 parser_callback_t cb =
nullptr,
24156 const bool allow_exceptions =
true,
24157 const bool ignore_comments =
false,
24158 const bool ignore_trailing_commas =
false)
24161 parser(detail::input_adapter(std::forward<InputType>(i)), std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas).parse(
true, result);
24167 template<
typename IteratorType>
24168 JSON_HEDLEY_WARN_UNUSED_RESULT
24171 parser_callback_t cb =
nullptr,
24172 const bool allow_exceptions =
true,
24173 const bool ignore_comments =
false,
24174 const bool ignore_trailing_commas =
false)
24177 parser(detail::input_adapter(std::move(first), std::move(last)), std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas).parse(
true, result);
24181 JSON_HEDLEY_WARN_UNUSED_RESULT
24182 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len))
24183 static basic_json parse(detail::span_input_adapter&& i,
24184 parser_callback_t cb =
nullptr,
24185 const bool allow_exceptions =
true,
24186 const bool ignore_comments =
false,
24187 const bool ignore_trailing_commas =
false)
24190 parser(i.get(), std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas).parse(
true, result);
24196 template<
typename InputType>
24197 static bool accept(InputType&& i,
24198 const bool ignore_comments =
false,
24199 const bool ignore_trailing_commas =
false)
24201 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false, ignore_comments, ignore_trailing_commas).accept(
true);
24206 template<
typename IteratorType>
24207 static bool accept(IteratorType first, IteratorType last,
24208 const bool ignore_comments =
false,
24209 const bool ignore_trailing_commas =
false)
24211 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false, ignore_comments, ignore_trailing_commas).accept(
true);
24214 JSON_HEDLEY_WARN_UNUSED_RESULT
24215 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len))
24216 static bool accept(detail::span_input_adapter&& i,
24217 const bool ignore_comments =
false,
24218 const bool ignore_trailing_commas =
false)
24220 return parser(i.get(),
nullptr,
false, ignore_comments, ignore_trailing_commas).accept(
true);
24225 template <
typename InputType,
typename SAX>
24226 JSON_HEDLEY_NON_NULL(2)
24227 static
bool sax_parse(InputType&& i, SAX* sax,
24228 input_format_t format = input_format_t::
json,
24229 const
bool strict = true,
24230 const
bool ignore_comments = false,
24231 const
bool ignore_trailing_commas = false)
24233 auto ia = detail::input_adapter(std::forward<InputType>(i));
24234 return format == input_format_t::json
24235 ? parser(std::move(ia),
nullptr,
true, ignore_comments, ignore_trailing_commas).sax_parse(sax, strict)
24241 template<
class IteratorType,
class SAX>
24242 JSON_HEDLEY_NON_NULL(3)
24243 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
24244 input_format_t format = input_format_t::
json,
24245 const
bool strict = true,
24246 const
bool ignore_comments = false,
24247 const
bool ignore_trailing_commas = false)
24249 auto ia = detail::input_adapter(std::move(first), std::move(last));
24250 return format == input_format_t::json
24251 ? parser(std::move(ia),
nullptr,
true, ignore_comments, ignore_trailing_commas).sax_parse(sax, strict)
24260 template <
typename SAX>
24261 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, sax_parse(ptr, ptr + len, ...))
24262 JSON_HEDLEY_NON_NULL(2)
24263 static
bool sax_parse(
detail::span_input_adapter&& i, SAX* sax,
24264 input_format_t format = input_format_t::
json,
24265 const
bool strict = true,
24266 const
bool ignore_comments = false,
24267 const
bool ignore_trailing_commas = false)
24270 return format == input_format_t::json
24272 ? parser(std::move(ia),
nullptr,
true, ignore_comments, ignore_trailing_commas).sax_parse(sax, strict)
24283 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator>>(std::istream&,
basic_json&))
24286 return operator>>(i, j);
24293 parser(detail::input_adapter(i)).parse(
false, j);
24305 JSON_HEDLEY_RETURNS_NON_NULL
24308 switch (m_data.m_type)
24310 case value_t::null:
24312 case value_t::object:
24314 case value_t::array:
24316 case value_t::string:
24318 case value_t::boolean:
24320 case value_t::binary:
24322 case value_t::discarded:
24323 return "discarded";
24324 case value_t::number_integer:
24325 case value_t::number_unsigned:
24326 case value_t::number_float:
24333 JSON_PRIVATE_UNLESS_TESTED:
24341 value_t m_type = value_t::null;
24344 json_value m_value = {};
24346 data(
const value_t v)
24347 : m_type(v), m_value(v)
24354 m_value.array = create<array_t>(cnt, val);
24357 data() noexcept = default;
24358 data(data&&) noexcept = default;
24359 data(const data&) noexcept = delete;
24360 data& operator=(data&&) noexcept = delete;
24361 data& operator=(const data&) noexcept = delete;
24365 m_value.destroy(m_type);
24371#if JSON_DIAGNOSTICS
24376#if JSON_DIAGNOSTIC_POSITIONS
24378 std::size_t start_position = std::string::npos;
24380 std::size_t end_position = std::string::npos;
24382 constexpr std::size_t start_pos() const noexcept
24384 return start_position;
24387 constexpr std::size_t end_pos() const noexcept
24389 return end_position;
24405 std::vector<std::uint8_t> result;
24406 to_cbor(j, result);
24414 binary_writer<std::uint8_t>(o).write_cbor(j);
24421 binary_writer<char>(o).write_cbor(j);
24428 std::vector<std::uint8_t> result;
24429 to_msgpack(j, result);
24437 binary_writer<std::uint8_t>(o).write_msgpack(j);
24444 binary_writer<char>(o).write_msgpack(j);
24450 const bool use_size =
false,
24451 const bool use_type =
false)
24453 std::vector<std::uint8_t> result;
24454 to_ubjson(j, result, use_size, use_type);
24461 const bool use_size =
false,
const bool use_type =
false)
24463 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);
24469 const bool use_size =
false,
const bool use_type =
false)
24471 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
24477 const bool use_size =
false,
24478 const bool use_type =
false,
24479 const bjdata_version_t version = bjdata_version_t::draft2)
24481 std::vector<std::uint8_t> result;
24482 to_bjdata(j, result, use_size, use_type, version);
24489 const bool use_size =
false,
const bool use_type =
false,
24490 const bjdata_version_t version = bjdata_version_t::draft2)
24492 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type,
true,
true, version);
24498 const bool use_size =
false,
const bool use_type =
false,
24499 const bjdata_version_t version = bjdata_version_t::draft2)
24501 binary_writer<char>(o).write_ubjson(j, use_size, use_type,
true,
true, version);
24508 std::vector<std::uint8_t> result;
24509 to_bson(j, result);
24517 binary_writer<std::uint8_t>(o).write_bson(j);
24524 binary_writer<char>(o).write_bson(j);
24529 template<
typename InputType>
24530 JSON_HEDLEY_WARN_UNUSED_RESULT
24532 const bool strict =
true,
24533 const bool allow_exceptions =
true,
24537 auto ia = detail::input_adapter(std::forward<InputType>(i));
24539 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24540 return res ? result :
basic_json(value_t::discarded);
24545 template<
typename IteratorType>
24546 JSON_HEDLEY_WARN_UNUSED_RESULT
24548 const bool strict =
true,
24549 const bool allow_exceptions =
true,
24553 auto ia = detail::input_adapter(std::move(first), std::move(last));
24555 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24556 return res ? result :
basic_json(value_t::discarded);
24559 template<
typename T>
24560 JSON_HEDLEY_WARN_UNUSED_RESULT
24561 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
24562 static basic_json from_cbor(
const T* ptr, std::size_t len,
24563 const bool strict =
true,
24564 const bool allow_exceptions =
true,
24565 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24567 return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
24570 JSON_HEDLEY_WARN_UNUSED_RESULT
24571 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
24572 static basic_json from_cbor(detail::span_input_adapter&& i,
24573 const bool strict =
true,
24574 const bool allow_exceptions =
true,
24575 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24581 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24582 return res ? result :
basic_json(value_t::discarded);
24587 template<
typename InputType>
24588 JSON_HEDLEY_WARN_UNUSED_RESULT
24590 const bool strict =
true,
24591 const bool allow_exceptions =
true)
24594 auto ia = detail::input_adapter(std::forward<InputType>(i));
24596 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
24597 return res ? result :
basic_json(value_t::discarded);
24602 template<
typename IteratorType>
24603 JSON_HEDLEY_WARN_UNUSED_RESULT
24605 const bool strict =
true,
24606 const bool allow_exceptions =
true)
24609 auto ia = detail::input_adapter(std::move(first), std::move(last));
24611 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
24612 return res ? result :
basic_json(value_t::discarded);
24615 template<
typename T>
24616 JSON_HEDLEY_WARN_UNUSED_RESULT
24617 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
24618 static basic_json from_msgpack(
const T* ptr, std::size_t len,
24619 const bool strict =
true,
24620 const bool allow_exceptions =
true)
24622 return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
24625 JSON_HEDLEY_WARN_UNUSED_RESULT
24626 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
24627 static basic_json from_msgpack(detail::span_input_adapter&& i,
24628 const bool strict =
true,
24629 const bool allow_exceptions =
true)
24635 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
24636 return res ? result :
basic_json(value_t::discarded);
24641 template<
typename InputType>
24642 JSON_HEDLEY_WARN_UNUSED_RESULT
24644 const bool strict =
true,
24645 const bool allow_exceptions =
true)
24648 auto ia = detail::input_adapter(std::forward<InputType>(i));
24650 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
24651 return res ? result :
basic_json(value_t::discarded);
24656 template<
typename IteratorType>
24657 JSON_HEDLEY_WARN_UNUSED_RESULT
24659 const bool strict =
true,
24660 const bool allow_exceptions =
true)
24663 auto ia = detail::input_adapter(std::move(first), std::move(last));
24665 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
24666 return res ? result :
basic_json(value_t::discarded);
24669 template<
typename T>
24670 JSON_HEDLEY_WARN_UNUSED_RESULT
24671 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
24672 static basic_json from_ubjson(
const T* ptr, std::size_t len,
24673 const bool strict =
true,
24674 const bool allow_exceptions =
true)
24676 return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
24679 JSON_HEDLEY_WARN_UNUSED_RESULT
24680 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
24681 static basic_json from_ubjson(detail::span_input_adapter&& i,
24682 const bool strict =
true,
24683 const bool allow_exceptions =
true)
24689 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
24690 return res ? result :
basic_json(value_t::discarded);
24695 template<
typename InputType>
24696 JSON_HEDLEY_WARN_UNUSED_RESULT
24698 const bool strict =
true,
24699 const bool allow_exceptions =
true)
24702 auto ia = detail::input_adapter(std::forward<InputType>(i));
24704 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
24705 return res ? result :
basic_json(value_t::discarded);
24710 template<
typename IteratorType>
24711 JSON_HEDLEY_WARN_UNUSED_RESULT
24713 const bool strict =
true,
24714 const bool allow_exceptions =
true)
24717 auto ia = detail::input_adapter(std::move(first), std::move(last));
24719 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
24720 return res ? result :
basic_json(value_t::discarded);
24725 template<
typename InputType>
24726 JSON_HEDLEY_WARN_UNUSED_RESULT
24728 const bool strict =
true,
24729 const bool allow_exceptions =
true)
24732 auto ia = detail::input_adapter(std::forward<InputType>(i));
24734 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
24735 return res ? result :
basic_json(value_t::discarded);
24740 template<
typename IteratorType>
24741 JSON_HEDLEY_WARN_UNUSED_RESULT
24743 const bool strict =
true,
24744 const bool allow_exceptions =
true)
24747 auto ia = detail::input_adapter(std::move(first), std::move(last));
24749 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
24750 return res ? result :
basic_json(value_t::discarded);
24753 template<
typename T>
24754 JSON_HEDLEY_WARN_UNUSED_RESULT
24755 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
24756 static basic_json from_bson(
const T* ptr, std::size_t len,
24757 const bool strict =
true,
24758 const bool allow_exceptions =
true)
24760 return from_bson(ptr, ptr + len, strict, allow_exceptions);
24763 JSON_HEDLEY_WARN_UNUSED_RESULT
24764 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
24765 static basic_json from_bson(detail::span_input_adapter&& i,
24766 const bool strict =
true,
24767 const bool allow_exceptions =
true)
24773 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
24774 return res ? result :
basic_json(value_t::discarded);
24789 return ptr.get_unchecked(
this);
24792 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
24794 reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr)
24796 return ptr.get_unchecked(
this);
24803 return ptr.get_unchecked(
this);
24806 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
24808 const_reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
24810 return ptr.get_unchecked(
this);
24817 return ptr.get_checked(
this);
24820 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
24822 reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr)
24824 return ptr.get_checked(
this);
24831 return ptr.get_checked(
this);
24834 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
24836 const_reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
24838 return ptr.get_checked(
this);
24846 json_pointer::flatten(
"", *
this, result);
24854 return json_pointer::unflatten(*
this);
24872 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
24874 const auto get_op = [](
const string_t& op)
24878 return patch_operations::add;
24880 if (op ==
"remove")
24882 return patch_operations::remove;
24884 if (op ==
"replace")
24886 return patch_operations::replace;
24890 return patch_operations::move;
24894 return patch_operations::copy;
24898 return patch_operations::test;
24901 return patch_operations::invalid;
24916 if (top_pointer != ptr)
24918 result.
at(top_pointer);
24922 const auto last_path = ptr.
back();
24927 switch (parent.m_data.m_type)
24929 case value_t::null:
24930 case value_t::object:
24933 parent[last_path] = val;
24937 case value_t::array:
24939 if (last_path ==
"-")
24946 const auto idx = json_pointer::template array_index<basic_json_t>(last_path);
24947 if (JSON_HEDLEY_UNLIKELY(idx > parent.
size()))
24950 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"), &parent));
24960 case value_t::string:
24961 case value_t::boolean:
24962 case value_t::number_integer:
24963 case value_t::number_unsigned:
24964 case value_t::number_float:
24965 case value_t::binary:
24966 case value_t::discarded:
24968 JSON_ASSERT(
false);
24973 const auto operation_remove = [
this, & result](
json_pointer & ptr)
24976 const auto last_path = ptr.
back();
24984 auto it = parent.
find(last_path);
24985 if (JSON_HEDLEY_LIKELY(it != parent.
end()))
24991 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", last_path,
"' not found"),
this));
24997 parent.
erase(json_pointer::template array_index<basic_json_t>(last_path));
25002 if (JSON_HEDLEY_UNLIKELY(!json_patch.
is_array()))
25004 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", &json_patch));
25008 for (
const auto& val : json_patch)
25011 const auto get_value = [&val](
const string_t& op,
25016 auto it = val.m_data.m_value.object->find(member);
25019 const auto error_msg = (op ==
"op") ?
"operation" : detail::concat(
"operation '", op,
'\'');
25022 if (JSON_HEDLEY_UNLIKELY(it == val.m_data.m_value.object->end()))
25025 JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg,
" must have member '", member,
"'"), &val));
25029 if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
25032 JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg,
" must have string member '", member,
"'"), &val));
25040 if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
25042 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", &val));
25046 const auto op = get_value(
"op",
"op",
true).template get<string_t>();
25047 const auto path = get_value(op,
"path",
true).template get<string_t>();
25050 switch (get_op(op))
25052 case patch_operations::add:
25054 operation_add(ptr, get_value(
"add",
"value",
false));
25058 case patch_operations::remove:
25060 operation_remove(ptr);
25064 case patch_operations::replace:
25067 result.
at(ptr) = get_value(
"replace",
"value",
false);
25071 case patch_operations::move:
25073 const auto from_path = get_value(
"move",
"from",
true).template get<string_t>();
25083 operation_remove(from_ptr);
25084 operation_add(ptr, v);
25088 case patch_operations::copy:
25090 const auto from_path = get_value(
"copy",
"from",
true).template get<string_t>();
25099 operation_add(ptr, v);
25103 case patch_operations::test:
25105 bool success =
false;
25110 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
25118 if (JSON_HEDLEY_UNLIKELY(!success))
25120 JSON_THROW(other_error::create(501, detail::concat(
"unsuccessful: ", val.dump()), &val));
25126 case patch_operations::invalid:
25131 JSON_THROW(parse_error::create(105, 0, detail::concat(
"operation value '", op,
"' is invalid"), &val));
25148 JSON_HEDLEY_WARN_UNUSED_RESULT
25156 if (source == target)
25161 if (source.
type() != target.
type())
25166 {
"op",
"replace"}, {
"path", path}, {
"value", target}
25171 switch (source.
type())
25173 case value_t::array:
25177 while (i < source.
size() && i < target.
size())
25180 auto temp_diff = diff(source[i], target[i], detail::concat<string_t>(path,
'/', detail::to_string<string_t>(i)));
25181 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
25190 while (i < source.
size())
25194 result.
insert(result.
begin() + end_index, object(
25197 {
"path", detail::concat<string_t>(path,
'/', detail::to_string<string_t>(i))}
25203 while (i < target.
size())
25208 {
"path", detail::concat<string_t>(path,
"/-")},
25209 {
"value", target[i]}
25217 case value_t::object:
25220 for (
auto it = source.
cbegin(); it != source.
cend(); ++it)
25223 const auto path_key = detail::concat<string_t>(path,
'/',
detail::escape(it.key()));
25225 if (target.
find(it.key()) != target.
end())
25228 auto temp_diff = diff(it.value(), target[it.key()], path_key);
25229 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
25236 {
"op",
"remove"}, {
"path", path_key}
25242 for (
auto it = target.
cbegin(); it != target.
cend(); ++it)
25244 if (source.
find(it.key()) == source.
end())
25247 const auto path_key = detail::concat<string_t>(path,
'/',
detail::escape(it.key()));
25250 {
"op",
"add"}, {
"path", path_key},
25251 {
"value", it.value()}
25259 case value_t::null:
25260 case value_t::string:
25261 case value_t::boolean:
25262 case value_t::number_integer:
25263 case value_t::number_unsigned:
25264 case value_t::number_float:
25265 case value_t::binary:
25266 case value_t::discarded:
25272 {
"op",
"replace"}, {
"path", path}, {
"value", target}
25299 for (
auto it = apply_patch.
begin(); it != apply_patch.
end(); ++it)
25301 if (it.value().is_null())
25307 operator[](it.key()).merge_patch(it.value());
25313 *
this = apply_patch;
25322NLOHMANN_BASIC_JSON_TPL_DECLARATION
25323std::string to_string(
const NLOHMANN_BASIC_JSON_TPL& j)
25328inline namespace literals
25330inline namespace json_literals
25335JSON_HEDLEY_NON_NULL(1)
25336#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
25337 inline nlohmann::json
operator ""_json(
const char* s, std::size_t n)
25339 inline nlohmann::json
operator "" _json(
const char* s, std::size_t n)
25342 return nlohmann::json::parse(s, s + n);
25347JSON_HEDLEY_NON_NULL(1)
25348#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
25349 inline nlohmann::json::json_pointer
operator ""_json_pointer(
const char* s, std::size_t n)
25351 inline nlohmann::json::json_pointer
operator "" _json_pointer(
const char* s, std::size_t n)
25354 return nlohmann::json::json_pointer(std::string(s, n));
25359NLOHMANN_JSON_NAMESPACE_END
25370NLOHMANN_BASIC_JSON_TPL_DECLARATION
25371struct hash<nlohmann::NLOHMANN_BASIC_JSON_TPL>
25373 std::size_t operator()(
const nlohmann::NLOHMANN_BASIC_JSON_TPL& j)
const
25375 return nlohmann::detail::hash(j);
25381struct less< ::nlohmann::detail::value_t>
25388 ::nlohmann::detail::value_t rhs)
const noexcept
25390#if JSON_HAS_THREE_WAY_COMPARISON
25391 return std::is_lt(lhs <=> rhs);
25393 return ::nlohmann::detail::operator<(lhs, rhs);
25399#ifndef JSON_HAS_CPP_20
25403NLOHMANN_BASIC_JSON_TPL_DECLARATION
25404inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC_JSON_TPL& j2)
noexcept(
25405 is_nothrow_move_constructible<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value&&
25406 is_nothrow_move_assignable<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value)
25415#if JSON_USE_GLOBAL_UDLS
25416 #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
25417 using nlohmann::literals::json_literals::operator
""_json;
25418 using nlohmann::literals::json_literals::operator
""_json_pointer;
25420 using nlohmann::literals::json_literals::operator
"" _json;
25421 using nlohmann::literals::json_literals::operator
"" _json_pointer;
25437#if defined(__clang__)
25438 #pragma clang diagnostic pop
25443#undef JSON_INTERNAL_CATCH
25445#undef JSON_PRIVATE_UNLESS_TESTED
25446#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
25447#undef NLOHMANN_BASIC_JSON_TPL
25448#undef JSON_EXPLICIT
25449#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
25450#undef JSON_INLINE_VARIABLE
25451#undef JSON_NO_UNIQUE_ADDRESS
25452#undef JSON_DISABLE_ENUM_SERIALIZATION
25453#undef JSON_USE_GLOBAL_UDLS
25455#ifndef JSON_TEST_KEEP_MACROS
25458 #undef JSON_HAS_CPP_11
25459 #undef JSON_HAS_CPP_14
25460 #undef JSON_HAS_CPP_17
25461 #undef JSON_HAS_CPP_20
25462 #undef JSON_HAS_CPP_23
25463 #undef JSON_HAS_CPP_26
25464 #undef JSON_HAS_FILESYSTEM
25465 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
25466 #undef JSON_HAS_THREE_WAY_COMPARISON
25467 #undef JSON_HAS_RANGES
25468 #undef JSON_HAS_STATIC_RTTI
25469 #undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
25483#undef JSON_HEDLEY_ALWAYS_INLINE
25484#undef JSON_HEDLEY_ARM_VERSION
25485#undef JSON_HEDLEY_ARM_VERSION_CHECK
25486#undef JSON_HEDLEY_ARRAY_PARAM
25487#undef JSON_HEDLEY_ASSUME
25488#undef JSON_HEDLEY_BEGIN_C_DECLS
25489#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
25490#undef JSON_HEDLEY_CLANG_HAS_BUILTIN
25491#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
25492#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
25493#undef JSON_HEDLEY_CLANG_HAS_EXTENSION
25494#undef JSON_HEDLEY_CLANG_HAS_FEATURE
25495#undef JSON_HEDLEY_CLANG_HAS_WARNING
25496#undef JSON_HEDLEY_COMPCERT_VERSION
25497#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
25498#undef JSON_HEDLEY_CONCAT
25499#undef JSON_HEDLEY_CONCAT3
25500#undef JSON_HEDLEY_CONCAT3_EX
25501#undef JSON_HEDLEY_CONCAT_EX
25502#undef JSON_HEDLEY_CONST
25503#undef JSON_HEDLEY_CONSTEXPR
25504#undef JSON_HEDLEY_CONST_CAST
25505#undef JSON_HEDLEY_CPP_CAST
25506#undef JSON_HEDLEY_CRAY_VERSION
25507#undef JSON_HEDLEY_CRAY_VERSION_CHECK
25508#undef JSON_HEDLEY_C_DECL
25509#undef JSON_HEDLEY_DEPRECATED
25510#undef JSON_HEDLEY_DEPRECATED_FOR
25511#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
25512#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
25513#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
25514#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
25515#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
25516#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
25517#undef JSON_HEDLEY_DIAGNOSTIC_POP
25518#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
25519#undef JSON_HEDLEY_DMC_VERSION
25520#undef JSON_HEDLEY_DMC_VERSION_CHECK
25521#undef JSON_HEDLEY_EMPTY_BASES
25522#undef JSON_HEDLEY_EMSCRIPTEN_VERSION
25523#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
25524#undef JSON_HEDLEY_END_C_DECLS
25525#undef JSON_HEDLEY_FLAGS
25526#undef JSON_HEDLEY_FLAGS_CAST
25527#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
25528#undef JSON_HEDLEY_GCC_HAS_BUILTIN
25529#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
25530#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
25531#undef JSON_HEDLEY_GCC_HAS_EXTENSION
25532#undef JSON_HEDLEY_GCC_HAS_FEATURE
25533#undef JSON_HEDLEY_GCC_HAS_WARNING
25534#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
25535#undef JSON_HEDLEY_GCC_VERSION
25536#undef JSON_HEDLEY_GCC_VERSION_CHECK
25537#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
25538#undef JSON_HEDLEY_GNUC_HAS_BUILTIN
25539#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
25540#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
25541#undef JSON_HEDLEY_GNUC_HAS_EXTENSION
25542#undef JSON_HEDLEY_GNUC_HAS_FEATURE
25543#undef JSON_HEDLEY_GNUC_HAS_WARNING
25544#undef JSON_HEDLEY_GNUC_VERSION
25545#undef JSON_HEDLEY_GNUC_VERSION_CHECK
25546#undef JSON_HEDLEY_HAS_ATTRIBUTE
25547#undef JSON_HEDLEY_HAS_BUILTIN
25548#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
25549#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
25550#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
25551#undef JSON_HEDLEY_HAS_EXTENSION
25552#undef JSON_HEDLEY_HAS_FEATURE
25553#undef JSON_HEDLEY_HAS_WARNING
25554#undef JSON_HEDLEY_IAR_VERSION
25555#undef JSON_HEDLEY_IAR_VERSION_CHECK
25556#undef JSON_HEDLEY_IBM_VERSION
25557#undef JSON_HEDLEY_IBM_VERSION_CHECK
25558#undef JSON_HEDLEY_IMPORT
25559#undef JSON_HEDLEY_INLINE
25560#undef JSON_HEDLEY_INTEL_CL_VERSION
25561#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
25562#undef JSON_HEDLEY_INTEL_VERSION
25563#undef JSON_HEDLEY_INTEL_VERSION_CHECK
25564#undef JSON_HEDLEY_IS_CONSTANT
25565#undef JSON_HEDLEY_IS_CONSTEXPR_
25566#undef JSON_HEDLEY_LIKELY
25567#undef JSON_HEDLEY_MALLOC
25568#undef JSON_HEDLEY_MCST_LCC_VERSION
25569#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
25570#undef JSON_HEDLEY_MESSAGE
25571#undef JSON_HEDLEY_MSVC_VERSION
25572#undef JSON_HEDLEY_MSVC_VERSION_CHECK
25573#undef JSON_HEDLEY_NEVER_INLINE
25574#undef JSON_HEDLEY_NON_NULL
25575#undef JSON_HEDLEY_NO_ESCAPE
25576#undef JSON_HEDLEY_NO_RETURN
25577#undef JSON_HEDLEY_NO_THROW
25578#undef JSON_HEDLEY_NULL
25579#undef JSON_HEDLEY_PELLES_VERSION
25580#undef JSON_HEDLEY_PELLES_VERSION_CHECK
25581#undef JSON_HEDLEY_PGI_VERSION
25582#undef JSON_HEDLEY_PGI_VERSION_CHECK
25583#undef JSON_HEDLEY_PREDICT
25584#undef JSON_HEDLEY_PRINTF_FORMAT
25585#undef JSON_HEDLEY_PRIVATE
25586#undef JSON_HEDLEY_PUBLIC
25587#undef JSON_HEDLEY_PURE
25588#undef JSON_HEDLEY_REINTERPRET_CAST
25589#undef JSON_HEDLEY_REQUIRE
25590#undef JSON_HEDLEY_REQUIRE_CONSTEXPR
25591#undef JSON_HEDLEY_REQUIRE_MSG
25592#undef JSON_HEDLEY_RESTRICT
25593#undef JSON_HEDLEY_RETURNS_NON_NULL
25594#undef JSON_HEDLEY_SENTINEL
25595#undef JSON_HEDLEY_STATIC_ASSERT
25596#undef JSON_HEDLEY_STATIC_CAST
25597#undef JSON_HEDLEY_STRINGIFY
25598#undef JSON_HEDLEY_STRINGIFY_EX
25599#undef JSON_HEDLEY_SUNPRO_VERSION
25600#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
25601#undef JSON_HEDLEY_TINYC_VERSION
25602#undef JSON_HEDLEY_TINYC_VERSION_CHECK
25603#undef JSON_HEDLEY_TI_ARMCL_VERSION
25604#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
25605#undef JSON_HEDLEY_TI_CL2000_VERSION
25606#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
25607#undef JSON_HEDLEY_TI_CL430_VERSION
25608#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
25609#undef JSON_HEDLEY_TI_CL6X_VERSION
25610#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
25611#undef JSON_HEDLEY_TI_CL7X_VERSION
25612#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
25613#undef JSON_HEDLEY_TI_CLPRU_VERSION
25614#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
25615#undef JSON_HEDLEY_TI_VERSION
25616#undef JSON_HEDLEY_TI_VERSION_CHECK
25617#undef JSON_HEDLEY_UNAVAILABLE
25618#undef JSON_HEDLEY_UNLIKELY
25619#undef JSON_HEDLEY_UNPREDICTABLE
25620#undef JSON_HEDLEY_UNREACHABLE
25621#undef JSON_HEDLEY_UNREACHABLE_RETURN
25622#undef JSON_HEDLEY_VERSION
25623#undef JSON_HEDLEY_VERSION_DECODE_MAJOR
25624#undef JSON_HEDLEY_VERSION_DECODE_MINOR
25625#undef JSON_HEDLEY_VERSION_DECODE_REVISION
25626#undef JSON_HEDLEY_VERSION_ENCODE
25627#undef JSON_HEDLEY_WARNING
25628#undef JSON_HEDLEY_WARN_UNUSED_RESULT
25629#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
25630#undef JSON_HEDLEY_FALL_THROUGH
namespace for Niels Lohmann
Definition json.hpp:20208
constexpr bool is_string() const noexcept
return whether value is a string
Definition json.hpp:21507
size_type erase(const typename object_t::key_type &key)
remove element from a JSON object given a key
Definition json.hpp:22742
reference operator[](KeyType &&key)
access specified object element
Definition json.hpp:22308
size_type size() const noexcept
returns the number of elements
Definition json.hpp:23083
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_cbor(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
create a JSON value from an input in CBOR format
Definition json.hpp:24547
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)
Definition json.hpp:21880
const_iterator end() const noexcept
returns an iterator to one past the last element
Definition json.hpp:22940
reference back()
access the last element
Definition json.hpp:22546
basic_json(CompatibleType &&val) noexcept(noexcept(//NOLINT(bugprone-forwarding-reference-overload, bugprone-exception-escape) JSONSerializer< U >::to_json(std::declval< basic_json_t & >(), std::forward< CompatibleType >(val))))
create a JSON value from compatible types
Definition json.hpp:20947
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
Definition json.hpp:22956
basic_json patch(const basic_json &json_patch) const
applies a JSON patch to a copy of the current object
Definition json.hpp:25139
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string
Definition json.hpp:24306
const_reference front() const
access the first element
Definition json.hpp:22539
constexpr bool is_array() const noexcept
return whether value is an array
Definition json.hpp:21500
void swap(reference other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&//NOLINT(cppcoreguidelines-noexcept-swap, performance-noexcept-swap) std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition json.hpp:23601
ReturnType value(const json_pointer &ptr, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:22489
size_type count(KeyType &&key) const
returns the number of occurrences of a key in a JSON object
Definition json.hpp:22859
iter_impl< const basic_json > const_iterator
a const iterator for a basic_json container
Definition json.hpp:20342
std::initializer_list< detail::json_ref< basic_json > > initializer_list_t
helper type for initializer lists of basic_json values
Definition json.hpp:20286
constexpr bool is_number_integer() const noexcept
return whether value is an integer number
Definition json.hpp:21472
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
a const reverse iterator for a basic_json container
Definition json.hpp:20346
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
Definition json.hpp:24742
reference operator[](const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.hpp:24787
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
the type of an element const pointer
Definition json.hpp:20337
std::size_t size_type
a type to represent container sizes
Definition json.hpp:20329
constexpr bool is_structured() const noexcept
return whether type is structured
Definition json.hpp:21444
const_reference operator[](KeyType &&key) const
access specified object element
Definition json.hpp:22332
void swap(binary_t &other)
exchanges the values
Definition json.hpp:23678
ReferenceType get_ref()
get a reference value (implicit)
Definition json.hpp:21970
size_type max_size() const noexcept
returns the maximum possible number of elements
Definition json.hpp:23122
void update(const_reference j, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
Definition json.hpp:23547
ReferenceType get_ref() const
get a reference value (implicit)
Definition json.hpp:21981
constexpr bool is_discarded() const noexcept
return whether value is discarded
Definition json.hpp:21521
reference operator+=(initializer_list_t init)
add an object to an object
Definition json.hpp:23338
void push_back(basic_json &&val)
add an object to an array
Definition json.hpp:23226
const_reference operator[](const typename object_t::key_type &key) const
access specified object element
Definition json.hpp:22277
iteration_proxy< const_iterator > items() const noexcept
helper to access iterator member functions in range-based for
Definition json.hpp:23028
const_reference back() const
access the last element
Definition json.hpp:22555
IteratorType erase(IteratorType first, IteratorType last)
remove elements given an iterator range
Definition json.hpp:22637
reference operator+=(const basic_json &val)
add an object to an array
Definition json.hpp:23283
friend void swap(reference left, reference right) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&//NOLINT(cppcoreguidelines-noexcept-swap, performance-noexcept-swap) std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition json.hpp:23618
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
Definition json.hpp:24643
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(const typename binary_t::container_type &init, typename binary_t::subtype_type subtype)
explicitly create a binary array (with subtype)
Definition json.hpp:21089
iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
inserts copies of element into array
Definition json.hpp:23450
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
Definition json.hpp:24727
static allocator_type get_allocator()
returns the allocator associated with the container
Definition json.hpp:20352
nlohmann::byte_container_with_subtype< BinaryType > binary_t
a type for a packed binary type
Definition json.hpp:20477
reference at(KeyType &&key)
access specified object element with bounds checking
Definition json.hpp:22140
iterator end() noexcept
returns an iterator to one past the last element
Definition json.hpp:22931
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
Definition json.hpp:21479
void update(const_iterator first, const_iterator last, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
Definition json.hpp:23554
static std::vector< std::uint8_t > to_bson(const basic_json &j)
create a BSON serialization of a given JSON value
Definition json.hpp:24506
const_reverse_iterator rbegin() const noexcept
returns an iterator to the reverse-beginning
Definition json.hpp:22963
void push_back(initializer_list_t init)
add an object to an object
Definition json.hpp:23322
detail::parser_callback_t< basic_json > parser_callback_t
per-element parser callback type
Definition json.hpp:20914
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
Definition json.hpp:21130
static void to_msgpack(const basic_json &j, detail::output_adapter< char > o)
create a MessagePack serialization of a given JSON value
Definition json.hpp:24442
iterator begin() noexcept
returns an iterator to the first element
Definition json.hpp:22906
ReturnType value(const typename object_t::key_type &key, ValueType &&default_value) const
access specified object element with default value
Definition json.hpp:22387
const_iterator cend() const noexcept
returns an iterator to one past the last element
Definition json.hpp:22947
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
Definition json.hpp:24697
const_reference at(const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.hpp:24829
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init)
explicitly create a binary array
Definition json.hpp:21100
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
Definition json.hpp:20935
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_cbor(InputType &&i, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
create a JSON value from an input in CBOR format
Definition json.hpp:24531
basic_json flatten() const
return flattened JSON value
Definition json.hpp:24843
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
Definition json.hpp:24658
size_type erase(KeyType &&key)
remove element from a JSON object given a key
Definition json.hpp:22753
const binary_t & get_binary() const
get a binary value
Definition json.hpp:22052
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
inserts range of elements into array
Definition json.hpp:23470
void patch_inplace(const basic_json &json_patch)
applies a JSON patch in-place without copying the object
Definition json.hpp:24868
ReturnType value(KeyType &&key, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:22440
const_reference operator[](const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.hpp:24801
ArrayType< basic_json, AllocatorType< basic_json > > array_t
a type for an array
Definition json.hpp:20453
bool contains(KeyType &&key) const
check the existence of an element in a JSON object
Definition json.hpp:22876
static void to_cbor(const basic_json &j, detail::output_adapter< std::uint8_t > o)
create a CBOR serialization of a given JSON value
Definition json.hpp:24412
static void to_bson(const basic_json &j, detail::output_adapter< char > o)
create a BSON serialization of a given JSON value
Definition json.hpp:24522
iterator find(const typename object_t::key_type &key)
find an element in a JSON object
Definition json.hpp:22789
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(const typename binary_t::container_type &init)
explicitly create a binary array (without subtype)
Definition json.hpp:21078
static std::vector< std::uint8_t > to_bjdata(const basic_json &j, const bool use_size=false, const bool use_type=false, const bjdata_version_t version=bjdata_version_t::draft2)
create a BJData serialization of a given JSON value
Definition json.hpp:24476
const_reference at(KeyType &&key) const
access specified object element with bounds checking
Definition json.hpp:22178
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json meta()
returns version information on the library
Definition json.hpp:20360
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
Definition json.hpp:21137
const_iterator find(const typename object_t::key_type &key) const
find an element in a JSON object
Definition json.hpp:22803
static std::vector< std::uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
Definition json.hpp:24403
IteratorType erase(IteratorType pos)
remove element given an iterator
Definition json.hpp:22567
iterator insert(const_iterator pos, const basic_json &val)
inserts element into array
Definition json.hpp:23423
NumberFloatType number_float_t
a type for a number (floating-point)
Definition json.hpp:20473
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition json.hpp:22362
AllocatorType< basic_json > allocator_type
the allocator type
Definition json.hpp:20332
typename std::allocator_traits< allocator_type >::pointer pointer
the type of an element pointer
Definition json.hpp:20335
string_t dump(const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
serialization
Definition json.hpp:21408
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
Definition json.hpp:25291
ValueType & get_to(ValueType &v) const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), v)))
get a value (explicit)
Definition json.hpp:21934
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, const bjdata_version_t version=bjdata_version_t::draft2)
create a BJData serialization of a given JSON value
Definition json.hpp:24488
reference at(size_type idx)
access specified array element with bounds checking
Definition json.hpp:22074
iterator find(KeyType &&key)
find an element in a JSON object
Definition json.hpp:22819
constexpr bool is_number_float() const noexcept
return whether value is a floating-point number
Definition json.hpp:21486
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
Definition json.hpp:22970
static std::vector< std::uint8_t > to_ubjson(const basic_json &j, const bool use_size=false, const bool use_type=false)
create a UBJSON serialization of a given JSON value
Definition json.hpp:24449
reference at(const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.hpp:24815
BooleanType boolean_t
a type for a boolean
Definition json.hpp:20461
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json diff(const basic_json &source, const basic_json &target, const string_t &path="")
creates a diff as a JSON patch
Definition json.hpp:25149
std::less< StringType > default_object_comparator_t
default object key comparator type The actual object key comparator type (object_comparator_t) may be...
Definition json.hpp:20440
reference operator+=(const typename object_t::value_type &val)
add an object to an object
Definition json.hpp:23314
const_iterator cbegin() const noexcept
returns a const iterator to the first element
Definition json.hpp:22922
reference operator[](typename object_t::key_type key)
access specified object element
Definition json.hpp:22255
constexpr auto get_ptr() const noexcept -> decltype(std::declval< const basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition json.hpp:21692
~basic_json() noexcept
destructor
Definition json.hpp:21390
const_reverse_iterator crend() const noexcept
returns a const reverse iterator to one before the first
Definition json.hpp:22991
basic_json(initializer_list_t init, bool type_deduction=true, value_t manual_type=value_t::array)
create a container (array or object) from an initializer list
Definition json.hpp:21019
void swap(typename binary_t::container_type &other)
exchanges the values
Definition json.hpp:23694
binary_t & get_binary()
get a binary value
Definition json.hpp:22040
const_iterator begin() const noexcept
returns an iterator to the first element
Definition json.hpp:22915
constexpr bool is_number() const noexcept
return whether value is a number
Definition json.hpp:21465
void insert(const_iterator first, const_iterator last)
inserts range of elements into object
Definition json.hpp:23521
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
Definition json.hpp:24589
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
Definition json.hpp:21921
reference operator[](size_type idx)
access specified array element
Definition json.hpp:22196
basic_json & operator=(basic_json other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value &&std::is_nothrow_move_assignable< json_base_class_t >::value)
copy assignment
Definition json.hpp:21361
static void to_ubjson(const basic_json &j, detail::output_adapter< char > o, const bool use_size=false, const bool use_type=false)
create a UBJSON serialization of a given JSON value
Definition json.hpp:24468
NumberIntegerType number_integer_t
a type for a number (integer)
Definition json.hpp:20465
auto get_ptr() noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition json.hpp:21681
const_reference at(const typename object_t::key_type &key) const
access specified object element with bounds checking
Definition json.hpp:22158
constexpr bool is_binary() const noexcept
return whether value is a binary array
Definition json.hpp:21514
void swap(object_t &other)
exchanges the values
Definition json.hpp:23646
basic_json unflatten() const
unflatten a previously flattened JSON value
Definition json.hpp:24852
iterator insert(const_iterator pos, initializer_list_t ilist)
inserts elements from initializer list into array
Definition json.hpp:23501
static void to_bjdata(const basic_json &j, detail::output_adapter< char > o, const bool use_size=false, const bool use_type=false, const bjdata_version_t version=bjdata_version_t::draft2)
create a BJData serialization of a given JSON value
Definition json.hpp:24497
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init, typename binary_t::subtype_type subtype)
explicitly create a binary array (with subtype)
Definition json.hpp:21111
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
Definition json.hpp:23021
bool empty() const noexcept
checks whether the container is empty.
Definition json.hpp:23044
void swap(array_t &other)
exchanges the values
Definition json.hpp:23630
void erase(const size_type idx)
remove element from a JSON array given an index
Definition json.hpp:22760
reference operator+=(basic_json &&val)
add an object to an array
Definition json.hpp:23251
bool contains(const json_pointer &ptr) const
check the existence of an element in a JSON object given a JSON pointer
Definition json.hpp:22883
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition json.hpp:21430
reference emplace_back(Args &&... args)
add an object to an array
Definition json.hpp:23347
ValueType value(const json_pointer &ptr, const ValueType &default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:22463
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
Definition json.hpp:21122
StringType string_t
a type for a string
Definition json.hpp:20457
ObjectType< StringType, basic_json, default_object_comparator_t, AllocatorType< std::pair< const StringType, basic_json > > > object_t
a type for an object
Definition json.hpp:20449
void push_back(const basic_json &val)
add an object to an array
Definition json.hpp:23259
ValueType value(KeyType &&key, const ValueType &default_value) const
access specified object element with default value
Definition json.hpp:22413
reference at(const typename object_t::key_type &key)
access specified object element with bounds checking
Definition json.hpp:22120
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
Definition json.hpp:24712
json_value m_value
the value of the current element
Definition json.hpp:24344
const_reverse_iterator crbegin() const noexcept
returns a const reverse iterator to the last element
Definition json.hpp:22984
json_sax< basic_json > json_sax_t
SAX interface type, see nlohmann::json_sax
Definition json.hpp:20290
constexpr bool is_boolean() const noexcept
return whether value is a boolean
Definition json.hpp:21458
size_type count(const typename object_t::key_type &key) const
returns the number of occurrences of a key in a JSON object
Definition json.hpp:22849
reference front()
access the first element
Definition json.hpp:22532
constexpr bool is_primitive() const noexcept
return whether type is primitive
Definition json.hpp:21437
constexpr bool is_null() const noexcept
return whether value is null
Definition json.hpp:21451
void clear() noexcept
clears the contents
Definition json.hpp:23165
static void to_ubjson(const basic_json &j, detail::output_adapter< std::uint8_t > o, const bool use_size=false, const bool use_type=false)
create a UBJSON serialization of a given JSON value
Definition json.hpp:24460
basic_json(basic_json &&other) noexcept
move constructor
Definition json.hpp:21335
iter_impl< basic_json > iterator
an iterator for a basic_json container
Definition json.hpp:20340
basic_json(const value_t v)
create an empty value with a given type
Definition json.hpp:20927
const_reference operator[](size_type idx) const
access specified array element
Definition json.hpp:22242
std::ptrdiff_t difference_type
a type to represent differences between iterators
Definition json.hpp:20327
iterator insert(const_iterator pos, basic_json &&val)
inserts element into array
Definition json.hpp:23443
const_reverse_iterator rend() const noexcept
returns an iterator to the reverse-end
Definition json.hpp:22977
NumberUnsignedType number_unsigned_t
a type for a number (unsigned)
Definition json.hpp:20469
friend std::istream & operator>>(std::istream &i, basic_json &j)
deserialize from stream
Definition json.hpp:24291
static std::vector< std::uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
Definition json.hpp:24426
void swap(string_t &other)
exchanges the values
Definition json.hpp:23662
basic_json(const BasicJsonType &val)
create a JSON value from an existing one
Definition json.hpp:20961
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
a reverse iterator for a basic_json container
Definition json.hpp:20344
const_reference at(size_type idx) const
access specified array element with bounds checking
Definition json.hpp:22097
detail::actual_object_comparator_t< basic_json > object_comparator_t
object key comparator type
Definition json.hpp:20481
basic_json(const basic_json &other)
copy constructor
Definition json.hpp:21262
void push_back(const typename object_t::value_type &val)
add an object to an object
Definition json.hpp:23291
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
Definition json.hpp:23372
static void to_cbor(const basic_json &j, detail::output_adapter< char > o)
create a CBOR serialization of a given JSON value
Definition json.hpp:24419
constexpr bool is_object() const noexcept
return whether value is an object
Definition json.hpp:21493
static void to_msgpack(const basic_json &j, detail::output_adapter< std::uint8_t > o)
create a MessagePack serialization of a given JSON value
Definition json.hpp:24435
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
Definition json.hpp:24604
iterator insert_iterator(const_iterator pos, Args &&... args)
Definition json.hpp:23404
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
Definition json.hpp:21149
bool contains(const typename object_t::key_type &key) const
check the existence of an element in a JSON object
Definition json.hpp:22867
static void to_bson(const basic_json &j, detail::output_adapter< std::uint8_t > o)
create a BSON serialization of a given JSON value
Definition json.hpp:24515
const_iterator find(KeyType &&key) const
find an element in a JSON object
Definition json.hpp:22835
::nlohmann::json_pointer< StringType > json_pointer
JSON Pointer, see nlohmann::json_pointer
Definition json.hpp:20276
an internal type for a backed binary type
Definition json.hpp:6244
byte_container_with_subtype() noexcept(noexcept(container_type()))
Definition json.hpp:6250
byte_container_with_subtype(container_type &&b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))
Definition json.hpp:6272
byte_container_with_subtype(container_type &&b) noexcept(noexcept(container_type(std::move(b))))
Definition json.hpp:6260
constexpr subtype_type subtype() const noexcept
return the binary subtype
Definition json.hpp:6299
byte_container_with_subtype(const container_type &b, subtype_type subtype_) noexcept(noexcept(container_type(b)))
Definition json.hpp:6265
constexpr bool has_subtype() const noexcept
return whether the value has a subtype
Definition json.hpp:6306
byte_container_with_subtype(const container_type &b) noexcept(noexcept(container_type(b)))
Definition json.hpp:6255
void set_subtype(subtype_type subtype_) noexcept
sets the binary subtype
Definition json.hpp:6291
void clear_subtype() noexcept
clears the binary subtype
Definition json.hpp:6313
deserialization of CBOR, MessagePack, and UBJSON values
Definition json.hpp:9897
binary_reader(InputAdapterType &&adapter, const input_format_t format=input_format_t::json) noexcept
create a binary reader
Definition json.hpp:9913
bool sax_parse(const input_format_t format, json_sax_t *sax_, const bool strict=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
Definition json.hpp:9934
general exception of the basic_json class
Definition json.hpp:4545
const int id
the id of the exception
Definition json.hpp:4554
const char * what() const noexcept override
returns the explanatory string
Definition json.hpp:4548
exception indicating errors with iterators
Definition json.hpp:4714
a template for a bidirectional iterator for the basic_json class This class implements a both iterato...
Definition json.hpp:13687
iter_impl operator+(difference_type i) const
add to iterator
Definition json.hpp:14270
iter_impl & operator=(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting assignment
Definition json.hpp:13824
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
Definition json.hpp:14215
iter_impl(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting constructor
Definition json.hpp:13814
bool operator<(const iter_impl &other) const
comparison: smaller
Definition json.hpp:14157
bool operator<=(const iter_impl &other) const
comparison: less than or equal
Definition json.hpp:14197
iter_impl & operator-=(difference_type i)
subtract from iterator
Definition json.hpp:14261
iter_impl & operator--()
pre-decrement (–it)
Definition json.hpp:14067
const object_t::key_type & key() const
return the key of an object iterator
Definition json.hpp:14370
bool operator==(const IterImpl &other) const
comparison: equal
Definition json.hpp:14108
iter_impl operator++(int) &
post-increment (it++)
Definition json.hpp:14005
iter_impl & operator+=(difference_type i)
add to iterator
Definition json.hpp:14224
reference operator[](difference_type n) const
access to successor
Definition json.hpp:14332
typename BasicJsonType::difference_type difference_type
a type to represent differences between iterators
Definition json.hpp:13717
pointer operator->() const
dereference the iterator
Definition json.hpp:13963
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition json.hpp:14395
difference_type operator-(const iter_impl &other) const
return difference
Definition json.hpp:14303
std::bidirectional_iterator_tag iterator_category
Definition json.hpp:13712
friend iter_impl operator+(difference_type i, const iter_impl &it)
addition of distance and iterator
Definition json.hpp:14281
reference value() const
return the value of an iterator
Definition json.hpp:14386
bool operator>(const iter_impl &other) const
comparison: greater than
Definition json.hpp:14206
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)
Definition json.hpp:13721
iter_impl & operator++()
pre-increment (++it)
Definition json.hpp:14016
typename BasicJsonType::value_type value_type
the type of the values when the iterator is dereferenced
Definition json.hpp:13715
reference operator*() const
return a reference to the value pointed to by the iterator
Definition json.hpp:13919
iter_impl operator-(difference_type i) const
subtract from iterator
Definition json.hpp:14292
iter_impl & operator=(const iter_impl< const BasicJsonType > &other) noexcept
converting assignment
Definition json.hpp:13799
bool operator!=(const IterImpl &other) const
comparison: not equal
Definition json.hpp:14148
iter_impl operator--(int) &
post-decrement (it–)
Definition json.hpp:14056
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)
Definition json.hpp:13726
iter_impl(const iter_impl< const BasicJsonType > &other) noexcept
const copy constructor
Definition json.hpp:13789
void set_end() noexcept
set the iterator past the last value
Definition json.hpp:13880
bool operator==(const iteration_proxy_value &o) const
equality operator (needed for InputIterator)
Definition json.hpp:5571
bool operator!=(const iteration_proxy_value &o) const
inequality operator (needed for range-based for)
Definition json.hpp:5577
iteration_proxy_value & operator++()
increment operator (needed for range-based for)
Definition json.hpp:5554
const iteration_proxy_value & operator*() const
dereference operator (needed for range-based for)
Definition json.hpp:5548
IteratorType::reference value() const
return value of the iterator
Definition json.hpp:5619
const string_type & key() const
return key of the iterator
Definition json.hpp:5583
proxy class for the items() function
Definition json.hpp:5627
iteration_proxy_value< IteratorType > end() const noexcept
return iterator end (needed for range-based for)
Definition json.hpp:5652
iteration_proxy_value< IteratorType > begin() const noexcept
return iterator begin (needed for range-based for)
Definition json.hpp:5646
iteration_proxy(typename IteratorType::reference cont) noexcept
construct iteration proxy from a container
Definition json.hpp:5636
Definition json.hpp:15600
a template for a reverse iterator class
Definition json.hpp:14449
json_reverse_iterator operator++(int) &
post-increment (it++)
Definition json.hpp:14465
json_reverse_iterator operator--(int) &
post-decrement (it–)
Definition json.hpp:14477
json_reverse_iterator & operator++()
pre-increment (++it)
Definition json.hpp:14471
json_reverse_iterator & operator+=(difference_type i)
add to iterator
Definition json.hpp:14489
reference operator[](difference_type n) const
access to successor
Definition json.hpp:14513
auto key() const -> decltype(std::declval< Base >().key())
return the key of an object iterator
Definition json.hpp:14519
difference_type operator-(const json_reverse_iterator &other) const
return difference
Definition json.hpp:14507
typename Base::reference reference
the reference type for the pointed-to element
Definition json.hpp:14455
reference value() const
return the value of an iterator
Definition json.hpp:14526
json_reverse_iterator(const base_iterator &it) noexcept
create reverse iterator from base class
Definition json.hpp:14462
json_reverse_iterator & operator--()
pre-decrement (–it)
Definition json.hpp:14483
std::reverse_iterator< Base > base_iterator
shortcut to the reverse iterator adapter
Definition json.hpp:14453
json_reverse_iterator operator-(difference_type i) const
subtract from iterator
Definition json.hpp:14501
json_reverse_iterator(const typename base_iterator::iterator_type &it) noexcept
create reverse iterator from iterator
Definition json.hpp:14458
json_reverse_iterator operator+(difference_type i) const
add to iterator
Definition json.hpp:14495
SAX implementation to create a JSON value from SAX events
Definition json.hpp:8869
json_sax_dom_parser(BasicJsonType &r, const bool allow_exceptions_=true, lexer_t *lexer_=nullptr)
Definition json.hpp:8883
exception indicating other library errors
Definition json.hpp:4766
exception indicating access out of the defined range
Definition json.hpp:4749
exception indicating a parse error
Definition json.hpp:4661
static parse_error create(int id_, const position_t &pos, const std::string &what_arg, BasicJsonContext context)
create a parse error exception
Definition json.hpp:4673
const std::size_t byte
byte index of the parse error
Definition json.hpp:4698
Definition json.hpp:18867
serializer(output_adapter_t< char > s, const char ichar, error_handler_t error_handler_=error_handler_t::strict)
Definition json.hpp:18882
const error_handler_t error_handler
error_handler how to react on decoding errors
Definition json.hpp:19799
string_t indent_string
the indentation string
Definition json.hpp:19796
const char indent_char
the indentation character
Definition json.hpp:19794
void dump(const BasicJsonType &val, const bool pretty_print, const bool ensure_ascii, const unsigned int indent_step, const unsigned int current_indent=0)
internal implementation of the serialization function
Definition json.hpp:18922
exception indicating executing a member function with a wrong type
Definition json.hpp:4732
JSON Pointer defines a string syntax for identifying a specific value within a JSON document
Definition json.hpp:14621
friend json_pointer operator/(const json_pointer &lhs, string_t token)
create a new JSON pointer by appending the unescaped token at the end of the JSON pointer
Definition json.hpp:14716
friend json_pointer operator/(const json_pointer &lhs, std::size_t array_idx)
create a new JSON pointer by appending the array-index-token at the end of the JSON pointer
Definition json.hpp:14723
json_pointer(const string_t &s="")
create JSON pointer
Definition json.hpp:14647
bool empty() const noexcept
return whether pointer points to the root document
Definition json.hpp:14782
void pop_back()
remove last reference token
Definition json.hpp:14744
string_t to_string() const
return a string representation of the JSON pointer
Definition json.hpp:14653
json_pointer & operator/=(std::size_t array_idx)
append an array index at the end of this JSON pointer
Definition json.hpp:14701
void push_back(string_t &&token)
append an unescaped token at the end of the reference pointer
Definition json.hpp:14775
json_pointer & operator/=(const json_pointer &ptr)
append another JSON pointer at the end of this JSON pointer
Definition json.hpp:14683
friend json_pointer operator/(const json_pointer &lhs, const json_pointer &rhs)
create a new JSON pointer by appending the right JSON pointer at the end of the left JSON pointer
Definition json.hpp:14708
json_pointer parent_pointer() const
returns the parent of this JSON pointer
Definition json.hpp:14730
json_pointer & operator/=(string_t token)
append an unescaped reference token at the end of this JSON pointer
Definition json.hpp:14693
const string_t & back() const
return last reference token
Definition json.hpp:14756
friend std::ostream & operator<<(std::ostream &o, const json_pointer &ptr)
write string representation of the JSON pointer to stream
Definition json.hpp:14674
void push_back(const string_t &token)
append an unescaped token at the end of the reference pointer
Definition json.hpp:14768
nlohmann::json json
nlohmann::json 타입을 json으로 별칭 정의
Definition config_manager.cpp:17
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, cppcoreguidelines-noexcept-swap, performance-noexcept-swap) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition json.hpp:25404
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.hpp:15516
bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.hpp:15541
basic_json< nlohmann::ordered_map > ordered_json
specialization that maintains the insertion order of object keys
Definition json.hpp:3568
basic_json<> json
default specialization
Definition json.hpp:3559
detail namespace with internal helper functions
Definition json.hpp:265
void replace_substring(StringType &s, const StringType &f, const StringType &t)
replace all occurrences of a substring by another string
Definition json.hpp:3106
bool little_endianness(int num=1) noexcept
determine system byte order
Definition json.hpp:9883
cbor_tag_handler_t
how to treat CBOR tags
Definition json.hpp:9870
@ store
store tags as binary type
@ error
throw a parse_error exception in case of a tag
value_t
the JSON type enumeration
Definition json.hpp:3008
@ 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)
void unescape(StringType &s)
string unescaping as described in RFC 6901 (Sect. 4)
Definition json.hpp:3140
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
Definition json.hpp:3037
error_handler_t
how to treat decoding errors
Definition json.hpp:18859
@ strict
throw a type_error exception in case of invalid UTF-8
@ replace
replace invalid UTF-8 sequences with U+FFFD
StringType escape(StringType s)
string escaping as described in RFC 6901 (Sect. 4)
Definition json.hpp:3125
namespace for Niels Lohmann
Definition json.hpp:6186
static auto to_json(BasicJsonType &j, TargetType &&val) noexcept(noexcept(::nlohmann::to_json(j, std::forward< TargetType >(val)))) -> decltype(::nlohmann::to_json(j, std::forward< TargetType >(val)), void())
convert any value type to a JSON value
Definition json.hpp:6210
static auto from_json(BasicJsonType &&j) noexcept(noexcept(::nlohmann::from_json(std::forward< BasicJsonType >(j), detail::identity_tag< TargetType > {}))) -> decltype(::nlohmann::from_json(std::forward< BasicJsonType >(j), detail::identity_tag< TargetType > {}))
convert a JSON value to any value type
Definition json.hpp:6200
static auto from_json(BasicJsonType &&j, TargetType &val) noexcept(noexcept(::nlohmann::from_json(std::forward< BasicJsonType >(j), val))) -> decltype(::nlohmann::from_json(std::forward< BasicJsonType >(j), val), void())
convert a JSON value to any value type
Definition json.hpp:6190
an iterator value
Definition json.hpp:13620
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition json.hpp:13624
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition json.hpp:13626
Default base class of the basic_json class.
Definition json.hpp:14568
struct to capture the start position of the current token
Definition json.hpp:3171
std::size_t chars_read_current_line
the number of characters read in the current line
Definition json.hpp:3175
std::size_t lines_read
the number of lines read
Definition json.hpp:3177
std::size_t chars_read_total
the total number of characters read
Definition json.hpp:3173
SAX interface
Definition json.hpp:8734
virtual bool binary(binary_t &val)=0
a binary value was read
virtual bool number_float(number_float_t val, const string_t &s)=0
a floating-point number was read
virtual bool number_unsigned(number_unsigned_t val)=0
an unsigned integer number was read
virtual bool key(string_t &val)=0
an object key was read
virtual bool string(string_t &val)=0
a string value was read
virtual bool number_integer(number_integer_t val)=0
an integer number was read
virtual bool start_object(std::size_t elements)=0
the beginning of an object was read
virtual bool end_array()=0
the end of an array was read
virtual bool boolean(bool val)=0
a boolean value was read
virtual bool end_object()=0
the end of an object was read
virtual bool null()=0
a null value was read
virtual bool parse_error(std::size_t position, const std::string &last_token, const detail::exception &ex)=0
a parse error occurred
virtual bool start_array(std::size_t elements)=0
the beginning of an array was read
a minimal map-like container that preserves insertion order
Definition json.hpp:19841
bool operator()(::nlohmann::detail::value_t lhs, ::nlohmann::detail::value_t rhs) const noexcept
compare two value_t enum values
Definition json.hpp:25387