18#ifndef INCLUDE_NLOHMANN_JSON_HPP_
19#define INCLUDE_NLOHMANN_JSON_HPP_
24#include <initializer_list>
60#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
61 #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH)
62 #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 12 || NLOHMANN_JSON_VERSION_PATCH != 0
63 #warning "Already included a different version of the library!"
68#define NLOHMANN_JSON_VERSION_MAJOR 3
69#define NLOHMANN_JSON_VERSION_MINOR 12
70#define NLOHMANN_JSON_VERSION_PATCH 0
72#ifndef JSON_DIAGNOSTICS
73 #define JSON_DIAGNOSTICS 0
76#ifndef JSON_DIAGNOSTIC_POSITIONS
77 #define JSON_DIAGNOSTIC_POSITIONS 0
80#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
81 #define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0
85 #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag
87 #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS
90#if JSON_DIAGNOSTIC_POSITIONS
91 #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS _dp
93 #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS
96#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
97 #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp
99 #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON
102#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION
103 #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0
107#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b, c) json_abi ## a ## b ## c
108#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b, c) \
109 NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b, c)
111#define NLOHMANN_JSON_ABI_TAGS \
112 NLOHMANN_JSON_ABI_TAGS_CONCAT( \
113 NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \
114 NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON, \
115 NLOHMANN_JSON_ABI_TAG_DIAGNOSTIC_POSITIONS)
118#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \
119 _v ## major ## _ ## minor ## _ ## patch
120#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \
121 NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch)
123#if NLOHMANN_JSON_NAMESPACE_NO_VERSION
124#define NLOHMANN_JSON_NAMESPACE_VERSION
126#define NLOHMANN_JSON_NAMESPACE_VERSION \
127 NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \
128 NLOHMANN_JSON_VERSION_MINOR, \
129 NLOHMANN_JSON_VERSION_PATCH)
133#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b
134#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \
135 NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b)
137#ifndef NLOHMANN_JSON_NAMESPACE
138#define NLOHMANN_JSON_NAMESPACE \
139 nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \
140 NLOHMANN_JSON_ABI_TAGS, \
141 NLOHMANN_JSON_NAMESPACE_VERSION)
144#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
145#define NLOHMANN_JSON_NAMESPACE_BEGIN \
148 inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \
149 NLOHMANN_JSON_ABI_TAGS, \
150 NLOHMANN_JSON_NAMESPACE_VERSION) \
154#ifndef NLOHMANN_JSON_NAMESPACE_END
155#define NLOHMANN_JSON_NAMESPACE_END \
173#include <forward_list>
178#include <type_traits>
179#include <unordered_map>
242#include <type_traits>
258NLOHMANN_JSON_NAMESPACE_BEGIN
266template<
typename ...Ts>
using void_t =
typename make_void<Ts...>::type;
269NLOHMANN_JSON_NAMESPACE_END
272NLOHMANN_JSON_NAMESPACE_BEGIN
280 ~nonesuch() =
delete;
281 nonesuch(nonesuch
const&) =
delete;
282 nonesuch(nonesuch
const&&) =
delete;
283 void operator=(nonesuch
const&) =
delete;
284 void operator=(nonesuch&&) =
delete;
287template<
class Default,
289 template<
class...>
class Op,
293 using value_t = std::false_type;
294 using type = Default;
297template<
class Default,
template<
class...>
class Op,
class... Args>
298struct detector<Default, void_t<Op<Args...>>, Op, Args...>
300 using value_t = std::true_type;
301 using type = Op<Args...>;
304template<
template<
class...>
class Op,
class... Args>
307template<
template<
class...>
class Op,
class... Args>
310template<
template<
class...>
class Op,
class... Args>
313template<
class Default,
template<
class...>
class Op,
class... Args>
314using detected_or =
detector<Default, void, Op, Args...>;
316template<
class Default,
template<
class...>
class Op,
class... Args>
317using detected_or_t =
typename detected_or<Default, Op, Args...>::type;
319template<
class Expected,
template<
class...>
class Op,
class... Args>
320using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
322template<
class To,
template<
class...>
class Op,
class... Args>
323using is_detected_convertible =
324 std::is_convertible<detected_t<Op, Args...>, To>;
327NLOHMANN_JSON_NAMESPACE_END
346#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15)
347#if defined(JSON_HEDLEY_VERSION)
348 #undef JSON_HEDLEY_VERSION
350#define JSON_HEDLEY_VERSION 15
352#if defined(JSON_HEDLEY_STRINGIFY_EX)
353 #undef JSON_HEDLEY_STRINGIFY_EX
355#define JSON_HEDLEY_STRINGIFY_EX(x) #x
357#if defined(JSON_HEDLEY_STRINGIFY)
358 #undef JSON_HEDLEY_STRINGIFY
360#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
362#if defined(JSON_HEDLEY_CONCAT_EX)
363 #undef JSON_HEDLEY_CONCAT_EX
365#define JSON_HEDLEY_CONCAT_EX(a,b) a##b
367#if defined(JSON_HEDLEY_CONCAT)
368 #undef JSON_HEDLEY_CONCAT
370#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
372#if defined(JSON_HEDLEY_CONCAT3_EX)
373 #undef JSON_HEDLEY_CONCAT3_EX
375#define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c
377#if defined(JSON_HEDLEY_CONCAT3)
378 #undef JSON_HEDLEY_CONCAT3
380#define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c)
382#if defined(JSON_HEDLEY_VERSION_ENCODE)
383 #undef JSON_HEDLEY_VERSION_ENCODE
385#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
387#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
388 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
390#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
392#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
393 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
395#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
397#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
398 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
400#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
402#if defined(JSON_HEDLEY_GNUC_VERSION)
403 #undef JSON_HEDLEY_GNUC_VERSION
405#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
406 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
407#elif defined(__GNUC__)
408 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
411#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
412 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
414#if defined(JSON_HEDLEY_GNUC_VERSION)
415 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
417 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
420#if defined(JSON_HEDLEY_MSVC_VERSION)
421 #undef JSON_HEDLEY_MSVC_VERSION
423#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL)
424 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
425#elif defined(_MSC_FULL_VER) && !defined(__ICL)
426 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
427#elif defined(_MSC_VER) && !defined(__ICL)
428 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
431#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
432 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
434#if !defined(JSON_HEDLEY_MSVC_VERSION)
435 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
436#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
437 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
438#elif defined(_MSC_VER) && (_MSC_VER >= 1200)
439 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
441 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))
444#if defined(JSON_HEDLEY_INTEL_VERSION)
445 #undef JSON_HEDLEY_INTEL_VERSION
447#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL)
448 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
449#elif defined(__INTEL_COMPILER) && !defined(__ICL)
450 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
453#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
454 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
456#if defined(JSON_HEDLEY_INTEL_VERSION)
457 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
459 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
462#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
463 #undef JSON_HEDLEY_INTEL_CL_VERSION
465#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL)
466 #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0)
469#if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK)
470 #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
472#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
473 #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
475 #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0)
478#if defined(JSON_HEDLEY_PGI_VERSION)
479 #undef JSON_HEDLEY_PGI_VERSION
481#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
482 #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
485#if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
486 #undef JSON_HEDLEY_PGI_VERSION_CHECK
488#if defined(JSON_HEDLEY_PGI_VERSION)
489 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
491 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
494#if defined(JSON_HEDLEY_SUNPRO_VERSION)
495 #undef JSON_HEDLEY_SUNPRO_VERSION
497#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
498 #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)
499#elif defined(__SUNPRO_C)
500 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
501#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
502 #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)
503#elif defined(__SUNPRO_CC)
504 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
507#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
508 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
510#if defined(JSON_HEDLEY_SUNPRO_VERSION)
511 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
513 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
516#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
517 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
519#if defined(__EMSCRIPTEN__)
520 #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
523#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
524 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
526#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
527 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
529 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
532#if defined(JSON_HEDLEY_ARM_VERSION)
533 #undef JSON_HEDLEY_ARM_VERSION
535#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
536 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)
537#elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
538 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
541#if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
542 #undef JSON_HEDLEY_ARM_VERSION_CHECK
544#if defined(JSON_HEDLEY_ARM_VERSION)
545 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
547 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
550#if defined(JSON_HEDLEY_IBM_VERSION)
551 #undef JSON_HEDLEY_IBM_VERSION
553#if defined(__ibmxl__)
554 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
555#elif defined(__xlC__) && defined(__xlC_ver__)
556 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
557#elif defined(__xlC__)
558 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
561#if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
562 #undef JSON_HEDLEY_IBM_VERSION_CHECK
564#if defined(JSON_HEDLEY_IBM_VERSION)
565 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
567 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
570#if defined(JSON_HEDLEY_TI_VERSION)
571 #undef JSON_HEDLEY_TI_VERSION
574 defined(__TI_COMPILER_VERSION__) && \
576 defined(__TMS470__) || defined(__TI_ARM__) || \
577 defined(__MSP430__) || \
578 defined(__TMS320C2000__) \
580#if (__TI_COMPILER_VERSION__ >= 16000000)
581 #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
585#if defined(JSON_HEDLEY_TI_VERSION_CHECK)
586 #undef JSON_HEDLEY_TI_VERSION_CHECK
588#if defined(JSON_HEDLEY_TI_VERSION)
589 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
591 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
594#if defined(JSON_HEDLEY_TI_CL2000_VERSION)
595 #undef JSON_HEDLEY_TI_CL2000_VERSION
597#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
598 #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
601#if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK)
602 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
604#if defined(JSON_HEDLEY_TI_CL2000_VERSION)
605 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
607 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0)
610#if defined(JSON_HEDLEY_TI_CL430_VERSION)
611 #undef JSON_HEDLEY_TI_CL430_VERSION
613#if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__)
614 #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
617#if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK)
618 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
620#if defined(JSON_HEDLEY_TI_CL430_VERSION)
621 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
623 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0)
626#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
627 #undef JSON_HEDLEY_TI_ARMCL_VERSION
629#if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__))
630 #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
633#if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK)
634 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
636#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
637 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
639 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0)
642#if defined(JSON_HEDLEY_TI_CL6X_VERSION)
643 #undef JSON_HEDLEY_TI_CL6X_VERSION
645#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__)
646 #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
649#if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK)
650 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
652#if defined(JSON_HEDLEY_TI_CL6X_VERSION)
653 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
655 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0)
658#if defined(JSON_HEDLEY_TI_CL7X_VERSION)
659 #undef JSON_HEDLEY_TI_CL7X_VERSION
661#if defined(__TI_COMPILER_VERSION__) && defined(__C7000__)
662 #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
665#if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK)
666 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
668#if defined(JSON_HEDLEY_TI_CL7X_VERSION)
669 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
671 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0)
674#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
675 #undef JSON_HEDLEY_TI_CLPRU_VERSION
677#if defined(__TI_COMPILER_VERSION__) && defined(__PRU__)
678 #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
681#if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK)
682 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
684#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
685 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
687 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0)
690#if defined(JSON_HEDLEY_CRAY_VERSION)
691 #undef JSON_HEDLEY_CRAY_VERSION
694 #if defined(_RELEASE_PATCHLEVEL)
695 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
697 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
701#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
702 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
704#if defined(JSON_HEDLEY_CRAY_VERSION)
705 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
707 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
710#if defined(JSON_HEDLEY_IAR_VERSION)
711 #undef JSON_HEDLEY_IAR_VERSION
713#if defined(__IAR_SYSTEMS_ICC__)
715 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
717 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0)
721#if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
722 #undef JSON_HEDLEY_IAR_VERSION_CHECK
724#if defined(JSON_HEDLEY_IAR_VERSION)
725 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
727 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
730#if defined(JSON_HEDLEY_TINYC_VERSION)
731 #undef JSON_HEDLEY_TINYC_VERSION
733#if defined(__TINYC__)
734 #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
737#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
738 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
740#if defined(JSON_HEDLEY_TINYC_VERSION)
741 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
743 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
746#if defined(JSON_HEDLEY_DMC_VERSION)
747 #undef JSON_HEDLEY_DMC_VERSION
750 #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
753#if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
754 #undef JSON_HEDLEY_DMC_VERSION_CHECK
756#if defined(JSON_HEDLEY_DMC_VERSION)
757 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
759 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
762#if defined(JSON_HEDLEY_COMPCERT_VERSION)
763 #undef JSON_HEDLEY_COMPCERT_VERSION
765#if defined(__COMPCERT_VERSION__)
766 #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)
769#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
770 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
772#if defined(JSON_HEDLEY_COMPCERT_VERSION)
773 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
775 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
778#if defined(JSON_HEDLEY_PELLES_VERSION)
779 #undef JSON_HEDLEY_PELLES_VERSION
782 #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
785#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
786 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
788#if defined(JSON_HEDLEY_PELLES_VERSION)
789 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
791 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
794#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
795 #undef JSON_HEDLEY_MCST_LCC_VERSION
797#if defined(__LCC__) && defined(__LCC_MINOR__)
798 #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__)
801#if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK)
802 #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
804#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
805 #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
807 #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0)
810#if defined(JSON_HEDLEY_GCC_VERSION)
811 #undef JSON_HEDLEY_GCC_VERSION
814 defined(JSON_HEDLEY_GNUC_VERSION) && \
815 !defined(__clang__) && \
816 !defined(JSON_HEDLEY_INTEL_VERSION) && \
817 !defined(JSON_HEDLEY_PGI_VERSION) && \
818 !defined(JSON_HEDLEY_ARM_VERSION) && \
819 !defined(JSON_HEDLEY_CRAY_VERSION) && \
820 !defined(JSON_HEDLEY_TI_VERSION) && \
821 !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \
822 !defined(JSON_HEDLEY_TI_CL430_VERSION) && \
823 !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \
824 !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \
825 !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \
826 !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \
827 !defined(__COMPCERT__) && \
828 !defined(JSON_HEDLEY_MCST_LCC_VERSION)
829 #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
832#if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
833 #undef JSON_HEDLEY_GCC_VERSION_CHECK
835#if defined(JSON_HEDLEY_GCC_VERSION)
836 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
838 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
841#if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
842 #undef JSON_HEDLEY_HAS_ATTRIBUTE
845 defined(__has_attribute) && \
847 (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \
849# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
851# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
854#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
855 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
857#if defined(__has_attribute)
858 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
860 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
863#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
864 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
866#if defined(__has_attribute)
867 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
869 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
872#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
873 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
876 defined(__has_cpp_attribute) && \
877 defined(__cplusplus) && \
878 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0))
879 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
881 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
884#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
885 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
887#if !defined(__cplusplus) || !defined(__has_cpp_attribute)
888 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
890 !defined(JSON_HEDLEY_PGI_VERSION) && \
891 !defined(JSON_HEDLEY_IAR_VERSION) && \
892 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \
893 (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0))
894 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)
896 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
899#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
900 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
902#if defined(__has_cpp_attribute) && defined(__cplusplus)
903 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
905 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
908#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
909 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
911#if defined(__has_cpp_attribute) && defined(__cplusplus)
912 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
914 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
917#if defined(JSON_HEDLEY_HAS_BUILTIN)
918 #undef JSON_HEDLEY_HAS_BUILTIN
920#if defined(__has_builtin)
921 #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
923 #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
926#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
927 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
929#if defined(__has_builtin)
930 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
932 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
935#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
936 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
938#if defined(__has_builtin)
939 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
941 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
944#if defined(JSON_HEDLEY_HAS_FEATURE)
945 #undef JSON_HEDLEY_HAS_FEATURE
947#if defined(__has_feature)
948 #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
950 #define JSON_HEDLEY_HAS_FEATURE(feature) (0)
953#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
954 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
956#if defined(__has_feature)
957 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
959 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
962#if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
963 #undef JSON_HEDLEY_GCC_HAS_FEATURE
965#if defined(__has_feature)
966 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
968 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
971#if defined(JSON_HEDLEY_HAS_EXTENSION)
972 #undef JSON_HEDLEY_HAS_EXTENSION
974#if defined(__has_extension)
975 #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
977 #define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
980#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
981 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
983#if defined(__has_extension)
984 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
986 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
989#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
990 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
992#if defined(__has_extension)
993 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
995 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
998#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
999 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
1001#if defined(__has_declspec_attribute)
1002 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
1004 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
1007#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
1008 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
1010#if defined(__has_declspec_attribute)
1011 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
1013 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
1016#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
1017 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
1019#if defined(__has_declspec_attribute)
1020 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
1022 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
1025#if defined(JSON_HEDLEY_HAS_WARNING)
1026 #undef JSON_HEDLEY_HAS_WARNING
1028#if defined(__has_warning)
1029 #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
1031 #define JSON_HEDLEY_HAS_WARNING(warning) (0)
1034#if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
1035 #undef JSON_HEDLEY_GNUC_HAS_WARNING
1037#if defined(__has_warning)
1038 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
1040 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
1043#if defined(JSON_HEDLEY_GCC_HAS_WARNING)
1044 #undef JSON_HEDLEY_GCC_HAS_WARNING
1046#if defined(__has_warning)
1047 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
1049 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
1053 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1054 defined(__clang__) || \
1055 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1056 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1057 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1058 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
1059 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1060 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1061 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1062 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1063 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1064 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \
1065 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1066 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1067 JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
1068 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
1069 JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
1070 (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
1071 #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
1072#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1073 #define JSON_HEDLEY_PRAGMA(value) __pragma(value)
1075 #define JSON_HEDLEY_PRAGMA(value)
1078#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
1079 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
1081#if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
1082 #undef JSON_HEDLEY_DIAGNOSTIC_POP
1084#if defined(__clang__)
1085 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
1086 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
1087#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1088 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
1089 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
1090#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1091 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
1092 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
1094 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
1095 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1096 #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
1097 #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
1098#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
1099 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
1100 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
1102 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1103 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1104 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \
1105 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1106 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1107 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1108 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
1109 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
1110#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
1111 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
1112 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
1114 #define JSON_HEDLEY_DIAGNOSTIC_PUSH
1115 #define JSON_HEDLEY_DIAGNOSTIC_POP
1120#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
1121 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
1123#if defined(__cplusplus)
1124# if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
1125# if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions")
1126# if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions")
1127# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1128 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1129 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1130 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
1131 _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \
1133 JSON_HEDLEY_DIAGNOSTIC_POP
1135# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1136 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1137 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1138 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
1140 JSON_HEDLEY_DIAGNOSTIC_POP
1143# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1144 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1145 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1147 JSON_HEDLEY_DIAGNOSTIC_POP
1151#if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
1152 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
1155#if defined(JSON_HEDLEY_CONST_CAST)
1156 #undef JSON_HEDLEY_CONST_CAST
1158#if defined(__cplusplus)
1159# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
1161 JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
1162 JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \
1163 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1164# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \
1165 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1166 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
1168 JSON_HEDLEY_DIAGNOSTIC_POP \
1171# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
1174#if defined(JSON_HEDLEY_REINTERPRET_CAST)
1175 #undef JSON_HEDLEY_REINTERPRET_CAST
1177#if defined(__cplusplus)
1178 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
1180 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr))
1183#if defined(JSON_HEDLEY_STATIC_CAST)
1184 #undef JSON_HEDLEY_STATIC_CAST
1186#if defined(__cplusplus)
1187 #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
1189 #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
1192#if defined(JSON_HEDLEY_CPP_CAST)
1193 #undef JSON_HEDLEY_CPP_CAST
1195#if defined(__cplusplus)
1196# if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
1197# define JSON_HEDLEY_CPP_CAST(T, expr) \
1198 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1199 _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \
1201 JSON_HEDLEY_DIAGNOSTIC_POP
1202# elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0)
1203# define JSON_HEDLEY_CPP_CAST(T, expr) \
1204 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1205 _Pragma("diag_suppress=Pe137") \
1206 JSON_HEDLEY_DIAGNOSTIC_POP
1208# define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr))
1211# define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
1214#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
1215 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1217#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
1218 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
1219#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1220 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
1221#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1222 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786))
1223#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1224 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445")
1225#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1226 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1227#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1228 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1229#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1230 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
1231#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1232 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1234 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1235 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1236 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1237 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1238 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1239 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1240 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1241 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1242 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1243 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1244 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1245 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
1246#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
1247 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
1248#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
1249 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
1250#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1251 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
1252#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
1253 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
1255 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1258#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
1259 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1261#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1262 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
1263#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1264 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
1265#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1266 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161))
1267#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1268 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
1269#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1270 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
1271#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1272 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))
1274 JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \
1275 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1276 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1277 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)
1278 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1279#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0)
1280 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1281#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1282 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
1283#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1284 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161")
1286 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1289#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
1290 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1292#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
1293 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"")
1294#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1295 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1296#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
1297 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
1298#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1299 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292))
1300#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
1301 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))
1302#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1303 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098")
1304#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1305 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1306#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
1307 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
1309 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1310 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1311 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0)
1312 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
1313#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1314 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097")
1315#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1316 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1318 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1321#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
1322 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1324#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
1325 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
1326#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1327 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
1328#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
1329 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
1331 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1334#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION)
1335 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1337#if JSON_HEDLEY_HAS_WARNING("-Wunused-function")
1338 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"")
1339#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0)
1340 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"")
1341#elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0)
1342 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505))
1343#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1344 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142")
1346 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1349#if defined(JSON_HEDLEY_DEPRECATED)
1350 #undef JSON_HEDLEY_DEPRECATED
1352#if defined(JSON_HEDLEY_DEPRECATED_FOR)
1353 #undef JSON_HEDLEY_DEPRECATED_FOR
1356 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1357 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1358 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
1359 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
1361 (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1362 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1363 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1364 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1365 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \
1366 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1367 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1368 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \
1369 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1370 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1371 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \
1372 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1373 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
1374 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
1375#elif defined(__cplusplus) && (__cplusplus >= 201402L)
1376 #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
1377 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
1379 JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
1380 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1381 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1382 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1383 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1384 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1385 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1386 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1387 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1388 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1389 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1390 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1391 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1392 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1393 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1394 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1395 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
1396 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
1398 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1399 JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \
1400 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1401 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
1402 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
1403#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1404 #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
1405 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
1407 #define JSON_HEDLEY_DEPRECATED(since)
1408 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
1411#if defined(JSON_HEDLEY_UNAVAILABLE)
1412 #undef JSON_HEDLEY_UNAVAILABLE
1415 JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
1416 JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
1417 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1418 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1419 #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
1421 #define JSON_HEDLEY_UNAVAILABLE(available_since)
1424#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT)
1425 #undef JSON_HEDLEY_WARN_UNUSED_RESULT
1427#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG)
1428 #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
1431 JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
1432 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1433 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1434 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1435 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1436 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1437 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1438 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1439 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1440 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1441 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1442 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1443 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1444 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1445 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1446 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1447 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1448 #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
1449 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__))
1450#elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)
1451 #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1452 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
1453#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
1454 #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1455 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1456#elif defined(_Check_return_)
1457 #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_
1458 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_
1460 #define JSON_HEDLEY_WARN_UNUSED_RESULT
1461 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg)
1464#if defined(JSON_HEDLEY_SENTINEL)
1465 #undef JSON_HEDLEY_SENTINEL
1468 JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
1469 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1470 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1471 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1472 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1473 #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
1475 #define JSON_HEDLEY_SENTINEL(position)
1478#if defined(JSON_HEDLEY_NO_RETURN)
1479 #undef JSON_HEDLEY_NO_RETURN
1481#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1482 #define JSON_HEDLEY_NO_RETURN __noreturn
1484 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1485 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1486 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1487#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
1488 #define JSON_HEDLEY_NO_RETURN _Noreturn
1489#elif defined(__cplusplus) && (__cplusplus >= 201103L)
1490 #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
1492 JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
1493 JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \
1494 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1495 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1496 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1497 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1498 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1499 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1500 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1501 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1502 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1503 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1504 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1505 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1506 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1507 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1508 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1509 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1510#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1511 #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
1513 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1514 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1515 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1516#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1517 #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
1518#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1519 #define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
1520#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1521 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1523 #define JSON_HEDLEY_NO_RETURN
1526#if defined(JSON_HEDLEY_NO_ESCAPE)
1527 #undef JSON_HEDLEY_NO_ESCAPE
1529#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
1530 #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
1532 #define JSON_HEDLEY_NO_ESCAPE
1535#if defined(JSON_HEDLEY_UNREACHABLE)
1536 #undef JSON_HEDLEY_UNREACHABLE
1538#if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
1539 #undef JSON_HEDLEY_UNREACHABLE_RETURN
1541#if defined(JSON_HEDLEY_ASSUME)
1542 #undef JSON_HEDLEY_ASSUME
1545 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1546 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1547 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1548 #define JSON_HEDLEY_ASSUME(expr) __assume(expr)
1549#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
1550 #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
1552 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1553 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1554 #if defined(__cplusplus)
1555 #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
1557 #define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
1561 (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
1562 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1563 JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \
1564 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1565 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \
1566 JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \
1567 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1568 #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
1569#elif defined(JSON_HEDLEY_ASSUME)
1570 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1572#if !defined(JSON_HEDLEY_ASSUME)
1573 #if defined(JSON_HEDLEY_UNREACHABLE)
1574 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1)))
1576 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr)
1579#if defined(JSON_HEDLEY_UNREACHABLE)
1581 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1582 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1583 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))
1585 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
1588 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value)
1590#if !defined(JSON_HEDLEY_UNREACHABLE)
1591 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1594JSON_HEDLEY_DIAGNOSTIC_PUSH
1595#if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
1596 #pragma clang diagnostic ignored "-Wpedantic"
1598#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
1599 #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
1601#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0)
1602 #if defined(__clang__)
1603 #pragma clang diagnostic ignored "-Wvariadic-macros"
1604 #elif defined(JSON_HEDLEY_GCC_VERSION)
1605 #pragma GCC diagnostic ignored "-Wvariadic-macros"
1608#if defined(JSON_HEDLEY_NON_NULL)
1609 #undef JSON_HEDLEY_NON_NULL
1612 JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
1613 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1614 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1615 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1616 #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
1618 #define JSON_HEDLEY_NON_NULL(...)
1620JSON_HEDLEY_DIAGNOSTIC_POP
1622#if defined(JSON_HEDLEY_PRINTF_FORMAT)
1623 #undef JSON_HEDLEY_PRINTF_FORMAT
1625#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO)
1626 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))
1627#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO)
1628 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
1630 JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
1631 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1632 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1633 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1634 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1635 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1636 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1637 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1638 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1639 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1640 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1641 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1642 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1643 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1644 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1645 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1646 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1647 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
1648#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
1649 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
1651 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
1654#if defined(JSON_HEDLEY_CONSTEXPR)
1655 #undef JSON_HEDLEY_CONSTEXPR
1657#if defined(__cplusplus)
1658 #if __cplusplus >= 201103L
1659 #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)
1662#if !defined(JSON_HEDLEY_CONSTEXPR)
1663 #define JSON_HEDLEY_CONSTEXPR
1666#if defined(JSON_HEDLEY_PREDICT)
1667 #undef JSON_HEDLEY_PREDICT
1669#if defined(JSON_HEDLEY_LIKELY)
1670 #undef JSON_HEDLEY_LIKELY
1672#if defined(JSON_HEDLEY_UNLIKELY)
1673 #undef JSON_HEDLEY_UNLIKELY
1675#if defined(JSON_HEDLEY_UNPREDICTABLE)
1676 #undef JSON_HEDLEY_UNPREDICTABLE
1678#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
1679 #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
1682 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
1683 JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \
1684 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1685# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability))
1686# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability))
1687# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability))
1688# define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 )
1689# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 )
1691 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
1692 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1693 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1694 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1695 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1696 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1697 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1698 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1699 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1700 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1701 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1702 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1703 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1704 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \
1705 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1706 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1707# define JSON_HEDLEY_PREDICT(expr, expected, probability) \
1708 (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))
1709# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
1711 double hedley_probability_ = (probability); \
1712 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
1714# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
1716 double hedley_probability_ = (probability); \
1717 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
1719# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1720# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1722# define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))
1723# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
1724# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
1725# define JSON_HEDLEY_LIKELY(expr) (!!(expr))
1726# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
1728#if !defined(JSON_HEDLEY_UNPREDICTABLE)
1729 #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
1732#if defined(JSON_HEDLEY_MALLOC)
1733 #undef JSON_HEDLEY_MALLOC
1736 JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
1737 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1738 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1739 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1740 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1741 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1742 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1743 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1744 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1745 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1746 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1747 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1748 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1749 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1750 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1751 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1752 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1753 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1754 #define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
1755#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1756 #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
1758 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1759 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1760 #define JSON_HEDLEY_MALLOC __declspec(restrict)
1762 #define JSON_HEDLEY_MALLOC
1765#if defined(JSON_HEDLEY_PURE)
1766 #undef JSON_HEDLEY_PURE
1769 JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
1770 JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \
1771 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1772 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1773 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1774 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1775 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1776 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1777 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1778 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1779 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1780 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1781 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1782 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1783 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1784 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1785 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1786 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1787 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1788# define JSON_HEDLEY_PURE __attribute__((__pure__))
1789#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1790# define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
1791#elif defined(__cplusplus) && \
1793 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1794 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \
1795 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \
1797# define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
1799# define JSON_HEDLEY_PURE
1802#if defined(JSON_HEDLEY_CONST)
1803 #undef JSON_HEDLEY_CONST
1806 JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
1807 JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \
1808 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1809 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1810 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1811 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1812 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1813 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1814 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1815 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1816 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1817 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1818 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1819 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1820 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1821 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1822 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1823 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1824 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1825 #define JSON_HEDLEY_CONST __attribute__((__const__))
1827 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1828 #define JSON_HEDLEY_CONST _Pragma("no_side_effect")
1830 #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
1833#if defined(JSON_HEDLEY_RESTRICT)
1834 #undef JSON_HEDLEY_RESTRICT
1836#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
1837 #define JSON_HEDLEY_RESTRICT restrict
1839 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1840 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1841 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1842 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1843 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1844 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1845 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1846 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1847 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \
1848 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1849 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1850 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
1851 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1852 defined(__clang__) || \
1853 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1854 #define JSON_HEDLEY_RESTRICT __restrict
1855#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
1856 #define JSON_HEDLEY_RESTRICT _Restrict
1858 #define JSON_HEDLEY_RESTRICT
1861#if defined(JSON_HEDLEY_INLINE)
1862 #undef JSON_HEDLEY_INLINE
1865 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1866 (defined(__cplusplus) && (__cplusplus >= 199711L))
1867 #define JSON_HEDLEY_INLINE inline
1869 defined(JSON_HEDLEY_GCC_VERSION) || \
1870 JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
1871 #define JSON_HEDLEY_INLINE __inline__
1873 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1874 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1875 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1876 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \
1877 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1878 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1879 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1880 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1881 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1882 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1883 #define JSON_HEDLEY_INLINE __inline
1885 #define JSON_HEDLEY_INLINE
1888#if defined(JSON_HEDLEY_ALWAYS_INLINE)
1889 #undef JSON_HEDLEY_ALWAYS_INLINE
1892 JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
1893 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1894 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1895 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1896 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1897 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1898 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1899 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1900 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1901 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1902 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1903 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1904 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1905 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1906 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1907 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1908 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1909 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1910 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1911# define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
1913 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1914 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1915# define JSON_HEDLEY_ALWAYS_INLINE __forceinline
1916#elif defined(__cplusplus) && \
1918 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1919 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1920 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1921 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1922 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1923 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \
1925# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
1926#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1927# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
1929# define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
1932#if defined(JSON_HEDLEY_NEVER_INLINE)
1933 #undef JSON_HEDLEY_NEVER_INLINE
1936 JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
1937 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1938 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1939 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1940 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1941 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1942 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1943 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1944 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1945 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1946 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1947 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1948 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1949 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1950 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1951 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1952 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1953 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1954 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1955 #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
1957 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1958 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1959 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1960#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
1961 #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
1962#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1963 #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
1964#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1965 #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
1966#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1967 #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
1968#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1969 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1971 #define JSON_HEDLEY_NEVER_INLINE
1974#if defined(JSON_HEDLEY_PRIVATE)
1975 #undef JSON_HEDLEY_PRIVATE
1977#if defined(JSON_HEDLEY_PUBLIC)
1978 #undef JSON_HEDLEY_PUBLIC
1980#if defined(JSON_HEDLEY_IMPORT)
1981 #undef JSON_HEDLEY_IMPORT
1983#if defined(_WIN32) || defined(__CYGWIN__)
1984# define JSON_HEDLEY_PRIVATE
1985# define JSON_HEDLEY_PUBLIC __declspec(dllexport)
1986# define JSON_HEDLEY_IMPORT __declspec(dllimport)
1989 JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
1990 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1991 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1992 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1993 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1994 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1996 defined(__TI_EABI__) && \
1998 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1999 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \
2002 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2003# define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
2004# define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
2006# define JSON_HEDLEY_PRIVATE
2007# define JSON_HEDLEY_PUBLIC
2009# define JSON_HEDLEY_IMPORT extern
2012#if defined(JSON_HEDLEY_NO_THROW)
2013 #undef JSON_HEDLEY_NO_THROW
2016 JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
2017 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
2018 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2019 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2020 #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
2022 JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
2023 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
2024 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
2025 #define JSON_HEDLEY_NO_THROW __declspec(nothrow)
2027 #define JSON_HEDLEY_NO_THROW
2030#if defined(JSON_HEDLEY_FALL_THROUGH)
2031 #undef JSON_HEDLEY_FALL_THROUGH
2034 JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
2035 JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \
2036 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2037 #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
2038#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
2039 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
2040#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
2041 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])
2042#elif defined(__fallthrough)
2043 #define JSON_HEDLEY_FALL_THROUGH __fallthrough
2045 #define JSON_HEDLEY_FALL_THROUGH
2048#if defined(JSON_HEDLEY_RETURNS_NON_NULL)
2049 #undef JSON_HEDLEY_RETURNS_NON_NULL
2052 JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
2053 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
2054 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2055 #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__))
2056#elif defined(_Ret_notnull_)
2057 #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_
2059 #define JSON_HEDLEY_RETURNS_NON_NULL
2062#if defined(JSON_HEDLEY_ARRAY_PARAM)
2063 #undef JSON_HEDLEY_ARRAY_PARAM
2066 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
2067 !defined(__STDC_NO_VLA__) && \
2068 !defined(__cplusplus) && \
2069 !defined(JSON_HEDLEY_PGI_VERSION) && \
2070 !defined(JSON_HEDLEY_TINYC_VERSION)
2071 #define JSON_HEDLEY_ARRAY_PARAM(name) (name)
2073 #define JSON_HEDLEY_ARRAY_PARAM(name)
2076#if defined(JSON_HEDLEY_IS_CONSTANT)
2077 #undef JSON_HEDLEY_IS_CONSTANT
2079#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
2080 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
2084#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
2085 #undef JSON_HEDLEY_IS_CONSTEXPR_
2088 JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
2089 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
2090 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2091 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
2092 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
2093 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
2094 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
2095 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
2096 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
2097 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2098 #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
2100#if !defined(__cplusplus)
2102 JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
2103 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
2104 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2105 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
2106 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
2107 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
2108 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
2109#if defined(__INTPTR_TYPE__)
2110 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
2113 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
2117 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
2118 !defined(JSON_HEDLEY_SUNPRO_VERSION) && \
2119 !defined(JSON_HEDLEY_PGI_VERSION) && \
2120 !defined(JSON_HEDLEY_IAR_VERSION)) || \
2121 (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
2122 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
2123 JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
2124 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
2125 JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
2126#if defined(__INTPTR_TYPE__)
2127 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
2130 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)
2133 defined(JSON_HEDLEY_GCC_VERSION) || \
2134 defined(JSON_HEDLEY_INTEL_VERSION) || \
2135 defined(JSON_HEDLEY_TINYC_VERSION) || \
2136 defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
2137 JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \
2138 defined(JSON_HEDLEY_TI_CL2000_VERSION) || \
2139 defined(JSON_HEDLEY_TI_CL6X_VERSION) || \
2140 defined(JSON_HEDLEY_TI_CL7X_VERSION) || \
2141 defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \
2143# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
2147 ((void*) ((expr) * 0L) ) : \
2148((struct { char v[sizeof(void) * 2]; } *) 1) \
2154#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
2155 #if !defined(JSON_HEDLEY_IS_CONSTANT)
2156 #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
2158 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))
2160 #if !defined(JSON_HEDLEY_IS_CONSTANT)
2161 #define JSON_HEDLEY_IS_CONSTANT(expr) (0)
2163 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
2166#if defined(JSON_HEDLEY_BEGIN_C_DECLS)
2167 #undef JSON_HEDLEY_BEGIN_C_DECLS
2169#if defined(JSON_HEDLEY_END_C_DECLS)
2170 #undef JSON_HEDLEY_END_C_DECLS
2172#if defined(JSON_HEDLEY_C_DECL)
2173 #undef JSON_HEDLEY_C_DECL
2175#if defined(__cplusplus)
2176 #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
2177 #define JSON_HEDLEY_END_C_DECLS }
2178 #define JSON_HEDLEY_C_DECL extern "C"
2180 #define JSON_HEDLEY_BEGIN_C_DECLS
2181 #define JSON_HEDLEY_END_C_DECLS
2182 #define JSON_HEDLEY_C_DECL
2185#if defined(JSON_HEDLEY_STATIC_ASSERT)
2186 #undef JSON_HEDLEY_STATIC_ASSERT
2189 !defined(__cplusplus) && ( \
2190 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
2191 (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
2192 JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
2193 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2194 defined(_Static_assert) \
2196# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
2198 (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
2199 JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \
2200 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2201# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
2203# define JSON_HEDLEY_STATIC_ASSERT(expr, message)
2206#if defined(JSON_HEDLEY_NULL)
2207 #undef JSON_HEDLEY_NULL
2209#if defined(__cplusplus)
2210 #if __cplusplus >= 201103L
2211 #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)
2213 #define JSON_HEDLEY_NULL NULL
2215 #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
2218 #define JSON_HEDLEY_NULL NULL
2220 #define JSON_HEDLEY_NULL ((void*) 0)
2223#if defined(JSON_HEDLEY_MESSAGE)
2224 #undef JSON_HEDLEY_MESSAGE
2226#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2227# define JSON_HEDLEY_MESSAGE(msg) \
2228 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2229 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2230 JSON_HEDLEY_PRAGMA(message msg) \
2231 JSON_HEDLEY_DIAGNOSTIC_POP
2233 JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
2234 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2235# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
2236#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
2237# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
2238#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
2239# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2240#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
2241# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2243# define JSON_HEDLEY_MESSAGE(msg)
2246#if defined(JSON_HEDLEY_WARNING)
2247 #undef JSON_HEDLEY_WARNING
2249#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2250# define JSON_HEDLEY_WARNING(msg) \
2251 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2252 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2253 JSON_HEDLEY_PRAGMA(clang warning msg) \
2254 JSON_HEDLEY_DIAGNOSTIC_POP
2256 JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
2257 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
2258 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2259# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
2261 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
2262 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2263# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
2265# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
2268#if defined(JSON_HEDLEY_REQUIRE)
2269 #undef JSON_HEDLEY_REQUIRE
2271#if defined(JSON_HEDLEY_REQUIRE_MSG)
2272 #undef JSON_HEDLEY_REQUIRE_MSG
2274#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
2275# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
2276# define JSON_HEDLEY_REQUIRE(expr) \
2277 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2278 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2279 __attribute__((diagnose_if(!(expr), #expr, "error"))) \
2280 JSON_HEDLEY_DIAGNOSTIC_POP
2281# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \
2282 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2283 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2284 __attribute__((diagnose_if(!(expr), msg, "error"))) \
2285 JSON_HEDLEY_DIAGNOSTIC_POP
2287# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error")))
2288# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error")))
2291# define JSON_HEDLEY_REQUIRE(expr)
2292# define JSON_HEDLEY_REQUIRE_MSG(expr,msg)
2295#if defined(JSON_HEDLEY_FLAGS)
2296 #undef JSON_HEDLEY_FLAGS
2298#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion"))
2299 #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
2301 #define JSON_HEDLEY_FLAGS
2304#if defined(JSON_HEDLEY_FLAGS_CAST)
2305 #undef JSON_HEDLEY_FLAGS_CAST
2307#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)
2308# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \
2309 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2310 _Pragma("warning(disable:188)") \
2312 JSON_HEDLEY_DIAGNOSTIC_POP \
2315# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
2318#if defined(JSON_HEDLEY_EMPTY_BASES)
2319 #undef JSON_HEDLEY_EMPTY_BASES
2322 (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \
2323 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2324 #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
2326 #define JSON_HEDLEY_EMPTY_BASES
2331#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
2332 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
2334#if defined(__clang__)
2335 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
2337 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
2340#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
2341 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
2343#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
2345#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
2346 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
2348#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
2350#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
2351 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
2353#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
2355#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
2356 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
2358#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
2360#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
2361 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
2363#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
2365#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
2366 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
2368#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
2370#if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
2371 #undef JSON_HEDLEY_CLANG_HAS_WARNING
2373#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
2385#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
2386 #if defined(__clang__)
2387 #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
2388 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
2390 #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
2391 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
2392 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
2399#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)
2400 #if (defined(__cplusplus) && __cplusplus > 202302L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202302L)
2401 #define JSON_HAS_CPP_26
2402 #define JSON_HAS_CPP_23
2403 #define JSON_HAS_CPP_20
2404 #define JSON_HAS_CPP_17
2405 #define JSON_HAS_CPP_14
2406 #elif (defined(__cplusplus) && __cplusplus > 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202002L)
2407 #define JSON_HAS_CPP_23
2408 #define JSON_HAS_CPP_20
2409 #define JSON_HAS_CPP_17
2410 #define JSON_HAS_CPP_14
2411 #elif (defined(__cplusplus) && __cplusplus > 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG > 201703L)
2412 #define JSON_HAS_CPP_20
2413 #define JSON_HAS_CPP_17
2414 #define JSON_HAS_CPP_14
2415 #elif (defined(__cplusplus) && __cplusplus > 201402L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1)
2416 #define JSON_HAS_CPP_17
2417 #define JSON_HAS_CPP_14
2418 #elif (defined(__cplusplus) && __cplusplus > 201103L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
2419 #define JSON_HAS_CPP_14
2422 #define JSON_HAS_CPP_11
2426 #if __has_include(<version>)
2431#if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM)
2432 #ifdef JSON_HAS_CPP_17
2433 #if defined(__cpp_lib_filesystem)
2434 #define JSON_HAS_FILESYSTEM 1
2435 #elif defined(__cpp_lib_experimental_filesystem)
2436 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2437 #elif !defined(__has_include)
2438 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2439 #elif __has_include(<filesystem>)
2440 #define JSON_HAS_FILESYSTEM 1
2441 #elif __has_include(<experimental/filesystem>)
2442 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2446 #if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8
2447 #undef JSON_HAS_FILESYSTEM
2448 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2452 #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 8
2453 #undef JSON_HAS_FILESYSTEM
2454 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2458 #if defined(__clang_major__) && __clang_major__ < 7
2459 #undef JSON_HAS_FILESYSTEM
2460 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2464 #if defined(_MSC_VER) && _MSC_VER < 1914
2465 #undef JSON_HAS_FILESYSTEM
2466 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2470 #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000
2471 #undef JSON_HAS_FILESYSTEM
2472 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2476 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
2477 #undef JSON_HAS_FILESYSTEM
2478 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2483#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2484 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0
2487#ifndef JSON_HAS_FILESYSTEM
2488 #define JSON_HAS_FILESYSTEM 0
2491#ifndef JSON_HAS_THREE_WAY_COMPARISON
2492 #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L \
2493 && defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L
2494 #define JSON_HAS_THREE_WAY_COMPARISON 1
2496 #define JSON_HAS_THREE_WAY_COMPARISON 0
2500#ifndef JSON_HAS_RANGES
2502 #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427
2503 #define JSON_HAS_RANGES 0
2504 #elif defined(__cpp_lib_ranges)
2505 #define JSON_HAS_RANGES 1
2507 #define JSON_HAS_RANGES 0
2511#ifndef JSON_HAS_STATIC_RTTI
2512 #if !defined(_HAS_STATIC_RTTI) || _HAS_STATIC_RTTI != 0
2513 #define JSON_HAS_STATIC_RTTI 1
2515 #define JSON_HAS_STATIC_RTTI 0
2519#ifdef JSON_HAS_CPP_17
2520 #define JSON_INLINE_VARIABLE inline
2522 #define JSON_INLINE_VARIABLE
2525#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address)
2526 #define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]]
2528 #define JSON_NO_UNIQUE_ADDRESS
2532#if defined(__clang__)
2533 #pragma clang diagnostic push
2534 #pragma clang diagnostic ignored "-Wdocumentation"
2535 #pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
2539#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
2540 #define JSON_THROW(exception) throw exception
2541 #define JSON_TRY try
2542 #define JSON_CATCH(exception) catch(exception)
2543 #define JSON_INTERNAL_CATCH(exception) catch(exception)
2546 #define JSON_THROW(exception) std::abort()
2547 #define JSON_TRY if(true)
2548 #define JSON_CATCH(exception) if(false)
2549 #define JSON_INTERNAL_CATCH(exception) if(false)
2553#if defined(JSON_THROW_USER)
2555 #define JSON_THROW JSON_THROW_USER
2557#if defined(JSON_TRY_USER)
2559 #define JSON_TRY JSON_TRY_USER
2561#if defined(JSON_CATCH_USER)
2563 #define JSON_CATCH JSON_CATCH_USER
2564 #undef JSON_INTERNAL_CATCH
2565 #define JSON_INTERNAL_CATCH JSON_CATCH_USER
2567#if defined(JSON_INTERNAL_CATCH_USER)
2568 #undef JSON_INTERNAL_CATCH
2569 #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2573#if !defined(JSON_ASSERT)
2575 #define JSON_ASSERT(x) assert(x)
2579#if defined(JSON_TESTS_PRIVATE)
2580 #define JSON_PRIVATE_UNLESS_TESTED public
2582 #define JSON_PRIVATE_UNLESS_TESTED private
2590#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2591 template<typename BasicJsonType> \
2592 inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
2595 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2597 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2598 auto it = std::find_if(std::begin(m), std::end(m), \
2599 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2601 return ej_pair.first == e; \
2603 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2605 template<typename BasicJsonType> \
2606 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
2609 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2611 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2612 auto it = std::find_if(std::begin(m), std::end(m), \
2613 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2615 return ej_pair.second == j; \
2617 e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2623#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2624 template<template<typename, typename, typename...> class ObjectType, \
2625 template<typename, typename...> class ArrayType, \
2626 class StringType, class BooleanType, class NumberIntegerType, \
2627 class NumberUnsignedType, class NumberFloatType, \
2628 template<typename> class AllocatorType, \
2629 template<typename, typename = void> class JSONSerializer, \
2631 class CustomBaseClass>
2633#define NLOHMANN_BASIC_JSON_TPL \
2634 basic_json<ObjectType, ArrayType, StringType, BooleanType, \
2635 NumberIntegerType, NumberUnsignedType, NumberFloatType, \
2636 AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>
2640#define NLOHMANN_JSON_EXPAND( x ) x
2641#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
2642#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
2643 NLOHMANN_JSON_PASTE64, \
2644 NLOHMANN_JSON_PASTE63, \
2645 NLOHMANN_JSON_PASTE62, \
2646 NLOHMANN_JSON_PASTE61, \
2647 NLOHMANN_JSON_PASTE60, \
2648 NLOHMANN_JSON_PASTE59, \
2649 NLOHMANN_JSON_PASTE58, \
2650 NLOHMANN_JSON_PASTE57, \
2651 NLOHMANN_JSON_PASTE56, \
2652 NLOHMANN_JSON_PASTE55, \
2653 NLOHMANN_JSON_PASTE54, \
2654 NLOHMANN_JSON_PASTE53, \
2655 NLOHMANN_JSON_PASTE52, \
2656 NLOHMANN_JSON_PASTE51, \
2657 NLOHMANN_JSON_PASTE50, \
2658 NLOHMANN_JSON_PASTE49, \
2659 NLOHMANN_JSON_PASTE48, \
2660 NLOHMANN_JSON_PASTE47, \
2661 NLOHMANN_JSON_PASTE46, \
2662 NLOHMANN_JSON_PASTE45, \
2663 NLOHMANN_JSON_PASTE44, \
2664 NLOHMANN_JSON_PASTE43, \
2665 NLOHMANN_JSON_PASTE42, \
2666 NLOHMANN_JSON_PASTE41, \
2667 NLOHMANN_JSON_PASTE40, \
2668 NLOHMANN_JSON_PASTE39, \
2669 NLOHMANN_JSON_PASTE38, \
2670 NLOHMANN_JSON_PASTE37, \
2671 NLOHMANN_JSON_PASTE36, \
2672 NLOHMANN_JSON_PASTE35, \
2673 NLOHMANN_JSON_PASTE34, \
2674 NLOHMANN_JSON_PASTE33, \
2675 NLOHMANN_JSON_PASTE32, \
2676 NLOHMANN_JSON_PASTE31, \
2677 NLOHMANN_JSON_PASTE30, \
2678 NLOHMANN_JSON_PASTE29, \
2679 NLOHMANN_JSON_PASTE28, \
2680 NLOHMANN_JSON_PASTE27, \
2681 NLOHMANN_JSON_PASTE26, \
2682 NLOHMANN_JSON_PASTE25, \
2683 NLOHMANN_JSON_PASTE24, \
2684 NLOHMANN_JSON_PASTE23, \
2685 NLOHMANN_JSON_PASTE22, \
2686 NLOHMANN_JSON_PASTE21, \
2687 NLOHMANN_JSON_PASTE20, \
2688 NLOHMANN_JSON_PASTE19, \
2689 NLOHMANN_JSON_PASTE18, \
2690 NLOHMANN_JSON_PASTE17, \
2691 NLOHMANN_JSON_PASTE16, \
2692 NLOHMANN_JSON_PASTE15, \
2693 NLOHMANN_JSON_PASTE14, \
2694 NLOHMANN_JSON_PASTE13, \
2695 NLOHMANN_JSON_PASTE12, \
2696 NLOHMANN_JSON_PASTE11, \
2697 NLOHMANN_JSON_PASTE10, \
2698 NLOHMANN_JSON_PASTE9, \
2699 NLOHMANN_JSON_PASTE8, \
2700 NLOHMANN_JSON_PASTE7, \
2701 NLOHMANN_JSON_PASTE6, \
2702 NLOHMANN_JSON_PASTE5, \
2703 NLOHMANN_JSON_PASTE4, \
2704 NLOHMANN_JSON_PASTE3, \
2705 NLOHMANN_JSON_PASTE2, \
2706 NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
2707#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
2708#define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
2709#define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
2710#define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
2711#define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
2712#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)
2713#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)
2714#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)
2715#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)
2716#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)
2717#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)
2718#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)
2719#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)
2720#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)
2721#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)
2722#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)
2723#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)
2724#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)
2725#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)
2726#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)
2727#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)
2728#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)
2729#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)
2730#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)
2731#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)
2732#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)
2733#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)
2734#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)
2735#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)
2736#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)
2737#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)
2738#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)
2739#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)
2740#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)
2741#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)
2742#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)
2743#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)
2744#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)
2745#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)
2746#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)
2747#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)
2748#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)
2749#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)
2750#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)
2751#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)
2752#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)
2753#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)
2754#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)
2755#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)
2756#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)
2757#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)
2758#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)
2759#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)
2760#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)
2761#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)
2762#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)
2763#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)
2764#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)
2765#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)
2766#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)
2767#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)
2768#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)
2769#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)
2771#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2772#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2773#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;
2781#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
2782 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2783 friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2784 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2785 friend void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2793#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \
2794 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2795 friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2796 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2797 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__)) }
2805#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \
2806 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2807 friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) }
2815#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
2816 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2817 void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2818 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2819 void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2827#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \
2828 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2829 void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2830 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2831 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__)) }
2839#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \
2840 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2841 void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) }
2849#define NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE(Type, BaseType, ...) \
2850 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2851 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__)) } \
2852 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2853 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__)) }
2861#define NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT(Type, BaseType, ...) \
2862 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2863 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__)) } \
2864 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2865 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__)) }
2873#define NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, BaseType, ...) \
2874 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2875 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__)) }
2883#define NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE(Type, BaseType, ...) \
2884 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2885 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__)) } \
2886 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2887 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__)) }
2895#define NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, BaseType, ...) \
2896 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2897 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__)) } \
2898 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2899 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__)) }
2907#define NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, BaseType, ...) \
2908 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2909 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__)) }
2917#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \
2918 namespace detail { \
2919 using std::std_name; \
2921 template<typename... T> \
2922 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2925 namespace detail2 { \
2926 struct std_name##_tag \
2930 template<typename... T> \
2931 std_name##_tag std_name(T&&...); \
2933 template<typename... T> \
2934 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2936 template<typename... T> \
2937 struct would_call_std_##std_name \
2939 static constexpr auto const value = ::nlohmann::detail:: \
2940 is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \
2944 template<typename... T> \
2945 struct would_call_std_##std_name : detail2::would_call_std_##std_name<T...> \
2949#ifndef JSON_USE_IMPLICIT_CONVERSIONS
2950 #define JSON_USE_IMPLICIT_CONVERSIONS 1
2953#if JSON_USE_IMPLICIT_CONVERSIONS
2954 #define JSON_EXPLICIT
2956 #define JSON_EXPLICIT explicit
2959#ifndef JSON_DISABLE_ENUM_SERIALIZATION
2960 #define JSON_DISABLE_ENUM_SERIALIZATION 0
2963#ifndef JSON_USE_GLOBAL_UDLS
2964 #define JSON_USE_GLOBAL_UDLS 1
2967#if JSON_HAS_THREE_WAY_COMPARISON
2971NLOHMANN_JSON_NAMESPACE_BEGIN
3030#if JSON_HAS_THREE_WAY_COMPARISON
3031 inline std::partial_ordering operator<=>(
const value_t lhs,
const value_t rhs)
noexcept
3036 static constexpr std::array<std::uint8_t, 9> order = {{
3043 const auto l_index =
static_cast<std::size_t
>(lhs);
3044 const auto r_index =
static_cast<std::size_t
>(rhs);
3045#if JSON_HAS_THREE_WAY_COMPARISON
3046 if (l_index < order.size() && r_index < order.size())
3048 return order[l_index] <=> order[r_index];
3050 return std::partial_ordering::unordered;
3052 return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
3060#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__)
3063 return std::is_lt(lhs <=> rhs);
3068NLOHMANN_JSON_NAMESPACE_END
3084NLOHMANN_JSON_NAMESPACE_BEGIN
3101template<
typename StringType>
3103 const StringType& t)
3105 JSON_ASSERT(!f.empty());
3106 for (
auto pos = s.find(f);
3107 pos != StringType::npos;
3108 s.replace(pos, f.size(), t),
3109 pos = s.find(f, pos + t.size()))
3120template<
typename StringType>
3135template<
typename StringType>
3143NLOHMANN_JSON_NAMESPACE_END
3161NLOHMANN_JSON_NAMESPACE_BEGIN
3176 constexpr operator size_t()
const
3183NLOHMANN_JSON_NAMESPACE_END
3201#include <type_traits>
3207NLOHMANN_JSON_NAMESPACE_BEGIN
3212using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
3214#ifdef JSON_HAS_CPP_14
3217using std::enable_if_t;
3218using std::index_sequence;
3219using std::make_index_sequence;
3220using std::index_sequence_for;
3225template<
bool B,
typename T =
void>
3226using enable_if_t =
typename std::enable_if<B, T>::type;
3252template <
typename T, T... Ints>
3255 using value_type = T;
3256 static constexpr std::size_t size()
noexcept
3258 return sizeof...(Ints);
3267template <
size_t... Ints>
3270namespace utility_internal
3273template <
typename Seq,
size_t SeqSize,
size_t Rem>
3277template <
typename T, T... Ints,
size_t SeqSize>
3283template <
typename T, T... Ints,
size_t SeqSize>
3286 using type =
integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >;
3291template <
typename T,
size_t N>
3295 typename Extend <
typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
3298template <
typename T>
3313template <
typename T, T N>
3314using make_integer_sequence =
typename utility_internal::Gen<T, N>::type;
3322using make_index_sequence = make_integer_sequence<size_t, N>;
3329template <
typename... Ts>
3330using index_sequence_for = make_index_sequence<
sizeof...(Ts)>;
3344 static JSON_INLINE_VARIABLE
constexpr T value{};
3347#ifndef JSON_HAS_CPP_17
3348 template<
typename T>
3349 constexpr T static_const<T>::value;
3352template<
typename T,
typename... Args>
3353constexpr std::array<T,
sizeof...(Args)> make_array(Args&& ... args)
3355 return std::array<T,
sizeof...(Args)> {{
static_cast<T
>(std::forward<Args>(args))...}};
3359NLOHMANN_JSON_NAMESPACE_END
3375#include <type_traits>
3377#if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L
3400NLOHMANN_JSON_NAMESPACE_BEGIN
3404template<
typename It,
typename =
void>
3407template<
typename It>
3410 void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
3411 typename It::reference, typename It::iterator_category >>
3413 using difference_type =
typename It::difference_type;
3414 using value_type =
typename It::value_type;
3415 using pointer =
typename It::pointer;
3416 using reference =
typename It::reference;
3417 using iterator_category =
typename It::iterator_category;
3422template<
typename T,
typename =
void>
3436 using iterator_category = std::random_access_iterator_tag;
3437 using value_type = T;
3438 using difference_type = ptrdiff_t;
3440 using reference = T&;
3444NLOHMANN_JSON_NAMESPACE_END
3462NLOHMANN_JSON_NAMESPACE_BEGIN
3464NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin);
3466NLOHMANN_JSON_NAMESPACE_END
3482NLOHMANN_JSON_NAMESPACE_BEGIN
3484NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end);
3486NLOHMANN_JSON_NAMESPACE_END
3501#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
3502 #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
3518 NLOHMANN_JSON_NAMESPACE_BEGIN
3527 template<
typename T =
void,
typename SFINAE =
void>
3532 template<
template<
typename U,
typename V,
typename... Args>
class ObjectType =
3534 template<
typename U,
typename... Args>
class ArrayType = std::vector,
3535 class StringType = std::string,
class BooleanType = bool,
3536 class NumberIntegerType = std::int64_t,
3537 class NumberUnsignedType = std::uint64_t,
3538 class NumberFloatType = double,
3539 template<
typename U>
class AllocatorType = std::allocator,
3540 template<
typename T,
typename SFINAE =
void>
class JSONSerializer =
3542 class BinaryType = std::vector<std::uint8_t>,
3543 class CustomBaseClass =
void>
3548 template<
typename RefStringType>
3559 template<
class Key,
class T,
class IgnoredLess,
class Allocator>
3566 NLOHMANN_JSON_NAMESPACE_END
3571NLOHMANN_JSON_NAMESPACE_BEGIN
3598NLOHMANN_BASIC_JSON_TPL_DECLARATION
3604template<
typename BasicJsonContext>
3606 std::integral_constant < bool,
3607 is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value
3608 || std::is_same<BasicJsonContext, std::nullptr_t>::value >
3629using mapped_type_t =
typename T::mapped_type;
3632using key_type_t =
typename T::key_type;
3635using value_type_t =
typename T::value_type;
3638using difference_type_t =
typename T::difference_type;
3641using pointer_t =
typename T::pointer;
3644using reference_t =
typename T::reference;
3647using iterator_category_t =
typename T::iterator_category;
3649template<
typename T,
typename... Args>
3650using to_json_function =
decltype(T::to_json(std::declval<Args>()...));
3652template<
typename T,
typename... Args>
3653using from_json_function =
decltype(T::from_json(std::declval<Args>()...));
3655template<
typename T,
typename U>
3656using get_template_function =
decltype(std::declval<T>().template get<U>());
3659template<
typename BasicJsonType,
typename T,
typename =
void>
3666template <
typename BasicJsonType,
typename T>
3669 static constexpr bool value = is_detected<get_template_function, const BasicJsonType&, T>::value;
3672template<
typename BasicJsonType,
typename T>
3675 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3677 static constexpr bool value =
3678 is_detected_exact<void, from_json_function, serializer,
3679 const BasicJsonType&, T&>::value;
3684template<
typename BasicJsonType,
typename T,
typename =
void>
3687template<
typename BasicJsonType,
typename T>
3690 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3692 static constexpr bool value =
3693 is_detected_exact<T, from_json_function, serializer,
3694 const BasicJsonType&>::value;
3699template<
typename BasicJsonType,
typename T,
typename =
void>
3702template<
typename BasicJsonType,
typename T>
3705 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3707 static constexpr bool value =
3708 is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
3713using detect_key_compare =
typename T::key_compare;
3716struct has_key_compare : std::integral_constant<bool, is_detected<detect_key_compare, T>::value> {};
3719template<
typename BasicJsonType>
3722 using object_t =
typename BasicJsonType::object_t;
3723 using object_comparator_t =
typename BasicJsonType::default_object_comparator_t;
3724 using type =
typename std::conditional < has_key_compare<object_t>::value,
3725 typename object_t::key_compare, object_comparator_t>::type;
3728template<
typename BasicJsonType>
3729using actual_object_comparator_t =
typename actual_object_comparator<BasicJsonType>::type;
3744 using char_type =
unsigned char;
3745 using int_type = uint64_t;
3748 static int_type to_int_type(char_type c)
noexcept
3750 return static_cast<int_type
>(c);
3753 static char_type to_char_type(int_type i)
noexcept
3755 return static_cast<char_type
>(i);
3758 static constexpr int_type eof()
noexcept
3760 return static_cast<int_type
>(std::char_traits<char>::eof());
3768 using char_type =
signed char;
3769 using int_type = uint64_t;
3772 static int_type to_int_type(char_type c)
noexcept
3774 return static_cast<int_type
>(c);
3777 static char_type to_char_type(int_type i)
noexcept
3779 return static_cast<char_type
>(i);
3782 static constexpr int_type eof()
noexcept
3784 return static_cast<int_type
>(std::char_traits<char>::eof());
3788#if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L
3790struct char_traits<std::byte> : std::char_traits<char>
3792 using char_type = std::byte;
3793 using int_type = uint64_t;
3795 static int_type to_int_type(char_type c)
noexcept
3797 return static_cast<int_type
>(std::to_integer<unsigned char>(c));
3800 static char_type to_char_type(int_type i)
noexcept
3802 return std::byte(
static_cast<unsigned char>(i));
3805 static constexpr int_type eof() noexcept
3807 return static_cast<int_type
>(std::char_traits<char>::eof());
3819template<
class B,
class... Bn>
3821: std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {};
3824template<
class B>
struct negation : std::integral_constant < bool, !B::value > { };
3829template <
typename T>
3832template <
typename T1,
typename T2>
3834 :
conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3836template <
typename T1,
typename T2>
3838 :
conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3840template <
typename... Ts>
3842 :
conjunction<is_default_constructible<Ts>...> {};
3844template <
typename... Ts>
3846 :
conjunction<is_default_constructible<Ts>...> {};
3848template <
typename T,
typename... Args>
3851template <
typename T1,
typename T2>
3854template <
typename T1,
typename T2>
3857template <
typename... Ts>
3860template <
typename... Ts>
3863template<
typename T,
typename =
void>
3873 static constexpr auto value =
3874 is_detected<value_type_t, traits>::value &&
3875 is_detected<difference_type_t, traits>::value &&
3876 is_detected<pointer_t, traits>::value &&
3877 is_detected<iterator_category_t, traits>::value &&
3878 is_detected<reference_t, traits>::value;
3885 using t_ref =
typename std::add_lvalue_reference<T>::type;
3887 using iterator = detected_t<result_of_begin, t_ref>;
3888 using sentinel = detected_t<result_of_end, t_ref>;
3893 static constexpr auto is_iterator_begin =
3897 static constexpr bool value = !std::is_same<iterator, nonesuch>::value && !std::is_same<sentinel, nonesuch>::value && is_iterator_begin;
3901using iterator_t = enable_if_t<is_range<R>::value, result_of_begin<decltype(std::declval<R&>())>>;
3904using range_value_t = value_type_t<iterator_traits<iterator_t<T>>>;
3910template<
typename T,
typename =
void>
3916template<
typename BasicJsonType,
typename CompatibleObjectType,
3920template<
typename BasicJsonType,
typename CompatibleObjectType>
3922 BasicJsonType, CompatibleObjectType,
3923 enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
3924 is_detected<key_type_t, CompatibleObjectType>::value >>
3926 using object_t =
typename BasicJsonType::object_t;
3929 static constexpr bool value =
3931 typename CompatibleObjectType::key_type>::value &&
3933 typename CompatibleObjectType::mapped_type>::value;
3936template<
typename BasicJsonType,
typename CompatibleObjectType>
3940template<
typename BasicJsonType,
typename ConstructibleObjectType,
3944template<
typename BasicJsonType,
typename ConstructibleObjectType>
3946 BasicJsonType, ConstructibleObjectType,
3947 enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&&
3948 is_detected<key_type_t, ConstructibleObjectType>::value >>
3950 using object_t =
typename BasicJsonType::object_t;
3952 static constexpr bool value =
3954 (std::is_move_assignable<ConstructibleObjectType>::value ||
3955 std::is_copy_assignable<ConstructibleObjectType>::value) &&
3957 typename object_t::key_type>::value &&
3959 typename object_t::mapped_type,
3960 typename ConstructibleObjectType::mapped_type >::value)) ||
3962 typename ConstructibleObjectType::mapped_type>::value ||
3965 typename ConstructibleObjectType::mapped_type >::value);
3968template<
typename BasicJsonType,
typename ConstructibleObjectType>
3971 ConstructibleObjectType> {};
3973template<
typename BasicJsonType,
typename CompatibleStringType>
3976 static constexpr auto value =
3980template<
typename BasicJsonType,
typename ConstructibleStringType>
3984#ifdef __INTEL_COMPILER
3985 using laundered_type =
decltype(std::declval<ConstructibleStringType>());
3987 using laundered_type = ConstructibleStringType;
3990 static constexpr auto value =
3993 is_detected_exact<
typename BasicJsonType::string_t::value_type,
3994 value_type_t, laundered_type >>::value;
3997template<
typename BasicJsonType,
typename CompatibleArrayType,
typename =
void>
4000template<
typename BasicJsonType,
typename CompatibleArrayType>
4002 BasicJsonType, CompatibleArrayType,
4004 is_detected<iterator_t, CompatibleArrayType>::value&&
4005 is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value&&
4008 !std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value >>
4010 static constexpr bool value =
4012 range_value_t<CompatibleArrayType>>::value;
4015template<
typename BasicJsonType,
typename CompatibleArrayType>
4019template<
typename BasicJsonType,
typename ConstructibleArrayType,
typename =
void>
4022template<
typename BasicJsonType,
typename ConstructibleArrayType>
4024 BasicJsonType, ConstructibleArrayType,
4025 enable_if_t<std::is_same<ConstructibleArrayType,
4026 typename BasicJsonType::value_type>::value >>
4027 : std::true_type {};
4029template<
typename BasicJsonType,
typename ConstructibleArrayType>
4031 BasicJsonType, ConstructibleArrayType,
4032 enable_if_t < !std::is_same<ConstructibleArrayType,
4033 typename BasicJsonType::value_type>::value&&
4036(std::is_move_assignable<ConstructibleArrayType>::value ||
4037 std::is_copy_assignable<ConstructibleArrayType>::value)&&
4038is_detected<iterator_t, ConstructibleArrayType>::value&&
4039is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value&&
4040is_detected<range_value_t, ConstructibleArrayType>::value&&
4043!std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>::value&&
4045detected_t<range_value_t, ConstructibleArrayType >>::value >>
4047 using value_type = range_value_t<ConstructibleArrayType>;
4049 static constexpr bool value =
4050 std::is_same<value_type,
4051 typename BasicJsonType::array_t::value_type>::value ||
4053 value_type>::value ||
4056 value_type >::value;
4059template<
typename BasicJsonType,
typename ConstructibleArrayType>
4063template<
typename RealIntegerType,
typename CompatibleNumberIntegerType,
4067template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
4069 RealIntegerType, CompatibleNumberIntegerType,
4070 enable_if_t < std::is_integral<RealIntegerType>::value&&
4071 std::is_integral<CompatibleNumberIntegerType>::value&&
4072 !std::is_same<bool, CompatibleNumberIntegerType>::value >>
4075 using RealLimits = std::numeric_limits<RealIntegerType>;
4076 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
4078 static constexpr auto value =
4080 CompatibleNumberIntegerType>::value &&
4081 CompatibleLimits::is_integer &&
4082 RealLimits::is_signed == CompatibleLimits::is_signed;
4085template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
4088 CompatibleNumberIntegerType> {};
4090template<
typename BasicJsonType,
typename CompatibleType,
typename =
void>
4093template<
typename BasicJsonType,
typename CompatibleType>
4095 BasicJsonType, CompatibleType,
4098 static constexpr bool value =
4102template<
typename BasicJsonType,
typename CompatibleType>
4106template<
typename T1,
typename T2>
4109template<
typename T1,
typename... Args>
4112template<
typename BasicJsonType,
typename T>
4115template<
typename BasicJsonType>
4118template<
typename BasicJsonType>
4123template<
template <
typename...>
class Primary,
typename T>
4126template<
template <
typename...>
class Primary,
typename... Args>
4133template <
typename A,
typename B>
4136template <
typename A>
4139template <
typename A>
4143template<
typename Compare,
typename A,
typename B,
typename =
void>
4151template<
typename Compare,
typename A,
typename B>
4153&& std::is_constructible <decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>()))>::value
4154&& std::is_constructible <decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))>::value
4155>> : std::true_type {};
4158using detect_is_transparent =
typename T::is_transparent;
4162template<
typename Comparator,
typename ObjectKeyType,
typename KeyTypeCVRef,
bool RequireTransparentComparator =
true,
4163 bool ExcludeObjectKeyType = RequireTransparentComparator,
typename KeyType = uncvref_t<KeyTypeCVRef>>
4164using is_usable_as_key_type =
typename std::conditional <
4166 && !(ExcludeObjectKeyType && std::is_same<KeyType,
4167 ObjectKeyType>::value)
4168 && (!RequireTransparentComparator
4169 || is_detected <detect_is_transparent, Comparator>::value)
4170 && !is_json_pointer<KeyType>::value,
4172 std::false_type >::type;
4180template<
typename BasicJsonType,
typename KeyTypeCVRef,
bool RequireTransparentComparator =
true,
4181 bool ExcludeObjectKeyType = RequireTransparentComparator,
typename KeyType = uncvref_t<KeyTypeCVRef>>
4182using is_usable_as_basic_json_key_type =
typename std::conditional <
4183 is_usable_as_key_type<
typename BasicJsonType::object_comparator_t,
4184 typename BasicJsonType::object_t::key_type, KeyTypeCVRef,
4185 RequireTransparentComparator, ExcludeObjectKeyType>::value
4188 std::false_type >::type;
4190template<
typename ObjectType,
typename KeyType>
4191using detect_erase_with_key_type =
decltype(std::declval<ObjectType&>().erase(std::declval<KeyType>()));
4194template<
typename BasicJsonType,
typename KeyType>
4195using has_erase_with_key_type =
typename std::conditional <
4197 detect_erase_with_key_type,
4198 typename BasicJsonType::object_t, KeyType >::value,
4200 std::false_type >::type;
4204template <
typename T>
4214 template <
typename C>
static one test(
decltype(&C::capacity) ) ;
4215 template <
typename C>
static two test(...);
4217 enum { value =
sizeof(test<T>(
nullptr)) ==
sizeof(
char) };
4221template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value,
int > = 0 >
4222T conditional_static_cast(U value)
4224 return static_cast<T
>(value);
4227template<typename T, typename U, enable_if_t<std::is_same<T, U>::value,
int> = 0>
4228T conditional_static_cast(U value)
4233template<
typename... Types>
4236template<
typename... Types>
4239template<
typename... Types>
4243template<
typename... Types>
4244using same_sign = std::integral_constant < bool,
4245 all_signed<Types...>::value || all_unsigned<Types...>::value >;
4247template<
typename OfType,
typename T>
4248using never_out_of_range = std::integral_constant < bool,
4249 (std::is_signed<OfType>::value && (
sizeof(T) <
sizeof(OfType)))
4250 || (same_sign<OfType, T>::value &&
sizeof(OfType) ==
sizeof(T)) >;
4252template<
typename OfType,
typename T,
4253 bool OfTypeSigned = std::is_signed<OfType>::value,
4254 bool TSigned = std::is_signed<T>::value>
4257template<
typename OfType,
typename T>
4260 static constexpr bool test(T val)
4262 using CommonType =
typename std::common_type<OfType, T>::type;
4263 return static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4267template<
typename OfType,
typename T>
4270 static constexpr bool test(T val)
4272 using CommonType =
typename std::common_type<OfType, T>::type;
4273 return static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4277template<
typename OfType,
typename T>
4280 static constexpr bool test(T val)
4282 using CommonType =
typename std::common_type<OfType, T>::type;
4283 return val >= 0 &&
static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4287template<
typename OfType,
typename T>
4290 static constexpr bool test(T val)
4292 using CommonType =
typename std::common_type<OfType, T>::type;
4293 return static_cast<CommonType
>(val) >=
static_cast<CommonType
>((std::numeric_limits<OfType>::min)())
4294 &&
static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4298template<
typename OfType,
typename T,
4299 bool NeverOutOfRange = never_out_of_range<OfType, T>::value,
4300 typename = detail::enable_if_t<all_integral<OfType, T>::value>>
4303template<
typename OfType,
typename T>
4306 static constexpr bool test(T val)
4312template<
typename OfType,
typename T>
4315 static constexpr bool test(T )
4321template<
typename OfType,
typename T>
4322constexpr bool value_in_range_of(T val)
4328using bool_constant = std::integral_constant<bool, Value>;
4338constexpr bool is_c_string()
4340 using TUnExt =
typename std::remove_extent<T>::type;
4341 using TUnCVExt =
typename std::remove_cv<TUnExt>::type;
4342 using TUnPtr =
typename std::remove_pointer<T>::type;
4343 using TUnCVPtr =
typename std::remove_cv<TUnPtr>::type;
4345 (std::is_array<T>::value && std::is_same<TUnCVExt, char>::value)
4346 || (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value);
4368 return is_detected<detect_is_transparent, T>::value;
4380NLOHMANN_JSON_NAMESPACE_END
4402NLOHMANN_JSON_NAMESPACE_BEGIN
4406inline std::size_t concat_length()
4411template<
typename... Args>
4412inline std::size_t concat_length(
const char* cstr,
const Args& ... rest);
4414template<
typename StringType,
typename... Args>
4415inline std::size_t concat_length(
const StringType& str,
const Args& ... rest);
4417template<
typename... Args>
4418inline std::size_t concat_length(
const char ,
const Args& ... rest)
4420 return 1 + concat_length(rest...);
4423template<
typename... Args>
4424inline std::size_t concat_length(
const char* cstr,
const Args& ... rest)
4427 return ::strlen(cstr) + concat_length(rest...);
4430template<
typename StringType,
typename... Args>
4431inline std::size_t concat_length(
const StringType& str,
const Args& ... rest)
4433 return str.size() + concat_length(rest...);
4436template<
typename OutStringType>
4437inline void concat_into(OutStringType& )
4440template<
typename StringType,
typename Arg>
4441using string_can_append =
decltype(std::declval<StringType&>().append(std::declval < Arg && > ()));
4443template<
typename StringType,
typename Arg>
4444using detect_string_can_append = is_detected<string_can_append, StringType, Arg>;
4446template<
typename StringType,
typename Arg>
4447using string_can_append_op =
decltype(std::declval<StringType&>() += std::declval < Arg && > ());
4449template<
typename StringType,
typename Arg>
4450using detect_string_can_append_op = is_detected<string_can_append_op, StringType, Arg>;
4452template<
typename StringType,
typename Arg>
4453using string_can_append_iter =
decltype(std::declval<StringType&>().append(std::declval<const Arg&>().begin(), std::declval<const Arg&>().end()));
4455template<
typename StringType,
typename Arg>
4456using detect_string_can_append_iter = is_detected<string_can_append_iter, StringType, Arg>;
4458template<
typename StringType,
typename Arg>
4459using string_can_append_data =
decltype(std::declval<StringType&>().append(std::declval<const Arg&>().data(), std::declval<const Arg&>().size()));
4461template<
typename StringType,
typename Arg>
4462using detect_string_can_append_data = is_detected<string_can_append_data, StringType, Arg>;
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,
int > = 0 >
4467inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest);
4469template <
typename OutStringType,
typename Arg,
typename... Args,
4470 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4471 && !detect_string_can_append_op<OutStringType, Arg>::value
4472 && detect_string_can_append_iter<OutStringType, Arg>::value,
int > = 0 >
4473inline void concat_into(OutStringType& out,
const Arg& arg, Args && ... rest);
4475template <
typename OutStringType,
typename Arg,
typename... Args,
4476 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4477 && !detect_string_can_append_op<OutStringType, Arg>::value
4478 && !detect_string_can_append_iter<OutStringType, Arg>::value
4479 && detect_string_can_append_data<OutStringType, Arg>::value,
int > = 0 >
4480inline void concat_into(OutStringType& out,
const Arg& arg, Args && ... rest);
4482template<
typename OutStringType,
typename Arg,
typename... Args,
4483 enable_if_t<detect_string_can_append<OutStringType, Arg>::value,
int> = 0>
4484inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest)
4486 out.append(std::forward<Arg>(arg));
4487 concat_into(out, std::forward<Args>(rest)...);
4490template <
typename OutStringType,
typename Arg,
typename... Args,
4491 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4492 && detect_string_can_append_op<OutStringType, Arg>::value,
int > >
4493inline void concat_into(OutStringType& out, Arg&& arg, Args&& ... rest)
4495 out += std::forward<Arg>(arg);
4496 concat_into(out, std::forward<Args>(rest)...);
4499template <
typename OutStringType,
typename Arg,
typename... Args,
4500 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4501 && !detect_string_can_append_op<OutStringType, Arg>::value
4502 && detect_string_can_append_iter<OutStringType, Arg>::value,
int > >
4503inline void concat_into(OutStringType& out,
const Arg& arg, Args&& ... rest)
4505 out.append(arg.begin(), arg.end());
4506 concat_into(out, std::forward<Args>(rest)...);
4509template <
typename OutStringType,
typename Arg,
typename... Args,
4510 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4511 && !detect_string_can_append_op<OutStringType, Arg>::value
4512 && !detect_string_can_append_iter<OutStringType, Arg>::value
4513 && detect_string_can_append_data<OutStringType, Arg>::value,
int > >
4514inline void concat_into(OutStringType& out,
const Arg& arg, Args&& ... rest)
4516 out.append(arg.data(), arg.size());
4517 concat_into(out, std::forward<Args>(rest)...);
4520template<
typename OutStringType = std::string,
typename... Args>
4521inline OutStringType concat(Args && ... args)
4524 str.reserve(concat_length(args...));
4525 concat_into(str, std::forward<Args>(args)...);
4530NLOHMANN_JSON_NAMESPACE_END
4540#if defined(__clang__)
4541 #pragma clang diagnostic push
4542 #pragma clang diagnostic ignored "-Wweak-vtables"
4545NLOHMANN_JSON_NAMESPACE_BEGIN
4555class exception :
public std::exception
4559 const char*
what() const noexcept
override
4568 JSON_HEDLEY_NON_NULL(3)
4569 exception(
int id_, const
char* what_arg) :
id(id_), m(what_arg) {}
4571 static std::string name(
const std::string& ename,
int id_)
4573 return concat(
"[json.exception.", ename,
'.', std::to_string(id_),
"] ");
4576 static std::string diagnostics(std::nullptr_t )
4581 template<
typename BasicJsonType>
4582 static std::string diagnostics(
const BasicJsonType* leaf_element)
4585 std::vector<std::string> tokens;
4586 for (
const auto* current = leaf_element; current !=
nullptr && current->m_parent !=
nullptr; current = current->m_parent)
4588 switch (current->m_parent->type())
4592 for (std::size_t i = 0; i < current->m_parent->m_data.m_value.array->size(); ++i)
4594 if (¤t->m_parent->m_data.m_value.array->operator[](i) == current)
4596 tokens.emplace_back(std::to_string(i));
4605 for (
const auto& element : *current->m_parent->m_data.m_value.object)
4607 if (&element.second == current)
4609 tokens.emplace_back(element.first.c_str());
4634 auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
4635 [](
const std::string & a,
const std::string & b)
4637 return concat(a,
'/', detail::escape(b));
4640 return concat(
'(', str,
") ", get_byte_positions(leaf_element));
4642 return get_byte_positions(leaf_element);
4648 std::runtime_error m;
4649#if JSON_DIAGNOSTIC_POSITIONS
4650 template<
typename BasicJsonType>
4651 static std::string get_byte_positions(
const BasicJsonType* leaf_element)
4653 if ((leaf_element->start_pos() != std::string::npos) && (leaf_element->end_pos() != std::string::npos))
4655 return concat(
"(bytes ", std::to_string(leaf_element->start_pos()),
"-", std::to_string(leaf_element->end_pos()),
") ");
4660 template<
typename BasicJsonType>
4661 static std::string get_byte_positions(
const BasicJsonType* leaf_element)
4663 static_cast<void>(leaf_element);
4671class parse_error :
public exception
4683 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4684 static parse_error
create(
int id_,
const position_t& pos,
const std::string& what_arg, BasicJsonContext context)
4686 const std::string w = concat(exception::name(
"parse_error", id_),
"parse error",
4687 position_string(pos),
": ", exception::diagnostics(context), what_arg);
4691 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4692 static parse_error create(
int id_, std::size_t byte_,
const std::string& what_arg, BasicJsonContext context)
4694 const std::string w = concat(exception::name(
"parse_error", id_),
"parse error",
4695 (byte_ != 0 ? (concat(
" at byte ", std::to_string(byte_))) :
""),
4696 ": ", exception::diagnostics(context), what_arg);
4697 return {id_, byte_, w.c_str()};
4712 parse_error(
int id_, std::size_t byte_,
const char* what_arg)
4713 : exception(id_, what_arg),
byte(byte_) {}
4715 static std::string position_string(
const position_t& pos)
4717 return concat(
" at line ", std::to_string(pos.
lines_read + 1),
4724class invalid_iterator :
public exception
4727 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4728 static invalid_iterator create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4730 const std::string w = concat(exception::name(
"invalid_iterator", id_), exception::diagnostics(context), what_arg);
4731 return {id_, w.c_str()};
4735 JSON_HEDLEY_NON_NULL(3)
4736 invalid_iterator(
int id_,
const char* what_arg)
4737 : exception(id_, what_arg) {}
4742class type_error :
public exception
4745 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4746 static type_error create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4748 const std::string w = concat(exception::name(
"type_error", id_), exception::diagnostics(context), what_arg);
4749 return {id_, w.c_str()};
4753 JSON_HEDLEY_NON_NULL(3)
4754 type_error(
int id_,
const char* what_arg) : exception(id_, what_arg) {}
4759class out_of_range :
public exception
4762 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4763 static out_of_range create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4765 const std::string w = concat(exception::name(
"out_of_range", id_), exception::diagnostics(context), what_arg);
4766 return {id_, w.c_str()};
4770 JSON_HEDLEY_NON_NULL(3)
4771 out_of_range(
int id_,
const char* what_arg) : exception(id_, what_arg) {}
4776class other_error :
public exception
4779 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4780 static other_error create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4782 const std::string w = concat(exception::name(
"other_error", id_), exception::diagnostics(context), what_arg);
4783 return {id_, w.c_str()};
4787 JSON_HEDLEY_NON_NULL(3)
4788 other_error(
int id_,
const char* what_arg) : exception(id_, what_arg) {}
4792NLOHMANN_JSON_NAMESPACE_END
4794#if defined(__clang__)
4795 #pragma clang diagnostic pop
4816NLOHMANN_JSON_NAMESPACE_BEGIN
4824NLOHMANN_JSON_NAMESPACE_END
4840#if JSON_HAS_EXPERIMENTAL_FILESYSTEM
4841#include <experimental/filesystem>
4842NLOHMANN_JSON_NAMESPACE_BEGIN
4845namespace std_fs = std::experimental::filesystem;
4847NLOHMANN_JSON_NAMESPACE_END
4848#elif JSON_HAS_FILESYSTEM
4849#include <filesystem>
4850NLOHMANN_JSON_NAMESPACE_BEGIN
4853namespace std_fs = std::filesystem;
4855NLOHMANN_JSON_NAMESPACE_END
4866#ifdef JSON_HAS_CPP_17
4870#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
4871 #include <string_view>
4874NLOHMANN_JSON_NAMESPACE_BEGIN
4878template<
typename BasicJsonType>
4879inline void from_json(
const BasicJsonType& j,
typename std::nullptr_t& n)
4881 if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
4883 JSON_THROW(type_error::create(302, concat(
"type must be null, but is ", j.type_name()), &j));
4888#ifdef JSON_HAS_CPP_17
4889template<
typename BasicJsonType,
typename T>
4890void from_json(
const BasicJsonType& j, std::optional<T>& opt)
4898 opt.emplace(j.template get<T>());
4904template <
typename BasicJsonType,
typename ArithmeticType,
4905 enable_if_t < std::is_arithmetic<ArithmeticType>::value&&
4906 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4908void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val)
4910 switch (
static_cast<value_t>(j))
4914 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4919 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4924 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4936 JSON_THROW(type_error::create(302, concat(
"type must be number, but is ", j.type_name()), &j));
4940template<
typename BasicJsonType>
4941inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::boolean_t& b)
4943 if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
4945 JSON_THROW(type_error::create(302, concat(
"type must be boolean, but is ", j.type_name()), &j));
4947 b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
4950template<
typename BasicJsonType>
4951inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::string_t& s)
4953 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
4955 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
4957 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4961 typename BasicJsonType,
typename StringType,
4963 std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value
4964 && is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value
4965 && !std::is_same<typename BasicJsonType::string_t, StringType>::value
4967inline void from_json(
const BasicJsonType& j, StringType& s)
4969 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
4971 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
4974 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4977template<
typename BasicJsonType>
4978inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_float_t& val)
4980 get_arithmetic_value(j, val);
4983template<
typename BasicJsonType>
4984inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_unsigned_t& val)
4986 get_arithmetic_value(j, val);
4989template<
typename BasicJsonType>
4990inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_integer_t& val)
4992 get_arithmetic_value(j, val);
4995#if !JSON_DISABLE_ENUM_SERIALIZATION
4996template<
typename BasicJsonType,
typename EnumType,
4997 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
4998inline void from_json(
const BasicJsonType& j, EnumType& e)
5000 typename std::underlying_type<EnumType>::type val;
5001 get_arithmetic_value(j, val);
5002 e =
static_cast<EnumType
>(val);
5007template<
typename BasicJsonType,
typename T,
typename Allocator,
5008 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
5009inline void from_json(
const BasicJsonType& j, std::forward_list<T, Allocator>& l)
5011 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5013 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5016 std::transform(j.rbegin(), j.rend(),
5017 std::front_inserter(l), [](
const BasicJsonType & i)
5019 return i.template get<T>();
5024template<
typename BasicJsonType,
typename T,
5025 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
5026inline void from_json(
const BasicJsonType& j, std::valarray<T>& l)
5028 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5030 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5033 std::transform(j.begin(), j.end(), std::begin(l),
5034 [](
const BasicJsonType & elem)
5036 return elem.template get<T>();
5040template<
typename BasicJsonType,
typename T, std::
size_t N>
5041auto from_json(
const BasicJsonType& j, T (&arr)[N])
5042->
decltype(j.template get<T>(), void())
5044 for (std::size_t i = 0; i < N; ++i)
5046 arr[i] = j.at(i).template get<T>();
5050template<
typename BasicJsonType,
typename T, std::
size_t N1, std::
size_t N2>
5051auto from_json(
const BasicJsonType& j, T (&arr)[N1][N2])
5052->
decltype(j.template get<T>(), void())
5054 for (std::size_t i1 = 0; i1 < N1; ++i1)
5056 for (std::size_t i2 = 0; i2 < N2; ++i2)
5058 arr[i1][i2] = j.at(i1).at(i2).template get<T>();
5063template<
typename BasicJsonType,
typename T, std::
size_t N1, std::
size_t N2, std::
size_t N3>
5064auto from_json(
const BasicJsonType& j, T (&arr)[N1][N2][N3])
5065->
decltype(j.template get<T>(), void())
5067 for (std::size_t i1 = 0; i1 < N1; ++i1)
5069 for (std::size_t i2 = 0; i2 < N2; ++i2)
5071 for (std::size_t i3 = 0; i3 < N3; ++i3)
5073 arr[i1][i2][i3] = j.at(i1).at(i2).at(i3).template get<T>();
5079template<
typename BasicJsonType,
typename T, std::
size_t N1, std::
size_t N2, std::
size_t N3, std::
size_t N4>
5080auto from_json(
const BasicJsonType& j, T (&arr)[N1][N2][N3][N4])
5081->
decltype(j.template get<T>(), void())
5083 for (std::size_t i1 = 0; i1 < N1; ++i1)
5085 for (std::size_t i2 = 0; i2 < N2; ++i2)
5087 for (std::size_t i3 = 0; i3 < N3; ++i3)
5089 for (std::size_t i4 = 0; i4 < N4; ++i4)
5091 arr[i1][i2][i3][i4] = j.at(i1).at(i2).at(i3).at(i4).template get<T>();
5098template<
typename BasicJsonType>
5099inline void from_json_array_impl(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr,
priority_tag<3> )
5101 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
5104template<
typename BasicJsonType,
typename T, std::
size_t N>
5105auto from_json_array_impl(
const BasicJsonType& j, std::array<T, N>& arr,
5107->
decltype(j.template get<T>(), void())
5109 for (std::size_t i = 0; i < N; ++i)
5111 arr[i] = j.at(i).template get<T>();
5115template<
typename BasicJsonType,
typename ConstructibleArrayType,
5117 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
5119auto from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
priority_tag<1> )
5121 arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
5122 j.template get<typename ConstructibleArrayType::value_type>(),
5127 ConstructibleArrayType ret;
5128 ret.reserve(j.size());
5129 std::transform(j.begin(), j.end(),
5130 std::inserter(ret, end(ret)), [](
const BasicJsonType & i)
5134 return i.template get<typename ConstructibleArrayType::value_type>();
5136 arr = std::move(ret);
5139template<
typename BasicJsonType,
typename ConstructibleArrayType,
5141 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
5143inline void from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
5148 ConstructibleArrayType ret;
5150 j.begin(), j.end(), std::inserter(ret, end(ret)),
5151 [](
const BasicJsonType & i)
5155 return i.template get<typename ConstructibleArrayType::value_type>();
5157 arr = std::move(ret);
5160template <
typename BasicJsonType,
typename ConstructibleArrayType,
5164 !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
5165 !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&&
5168auto from_json(
const BasicJsonType& j, ConstructibleArrayType& arr)
5170j.template get<typename ConstructibleArrayType::value_type>(),
5173 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5175 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5181template <
typename BasicJsonType,
typename T, std::size_t... Idx >
5182std::array<T,
sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j,
5183 identity_tag<std::array<T,
sizeof...(Idx)>> , index_sequence<Idx...> )
5185 return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
5188template <
typename BasicJsonType,
typename T, std::
size_t N >
5189auto from_json(BasicJsonType&& j,
identity_tag<std::array<T, N>> tag)
5190->
decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}))
5192 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5194 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5197 return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {});
5200template<
typename BasicJsonType>
5201inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::binary_t& bin)
5203 if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
5205 JSON_THROW(type_error::create(302, concat(
"type must be binary, but is ", j.type_name()), &j));
5208 bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
5211template<
typename BasicJsonType,
typename ConstructibleObjectType,
5212 enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value,
int> = 0>
5213inline void from_json(
const BasicJsonType& j, ConstructibleObjectType& obj)
5215 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
5217 JSON_THROW(type_error::create(302, concat(
"type must be object, but is ", j.type_name()), &j));
5220 ConstructibleObjectType ret;
5221 const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
5222 using value_type =
typename ConstructibleObjectType::value_type;
5224 inner_object->begin(), inner_object->end(),
5225 std::inserter(ret, ret.begin()),
5226 [](
typename BasicJsonType::object_t::value_type
const & p)
5228 return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
5230 obj = std::move(ret);
5237template <
typename BasicJsonType,
typename ArithmeticType,
5239 std::is_arithmetic<ArithmeticType>::value&&
5240 !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&&
5241 !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&&
5242 !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&&
5243 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
5245inline void from_json(
const BasicJsonType& j, ArithmeticType& val)
5247 switch (
static_cast<value_t>(j))
5251 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
5256 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
5261 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
5266 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
5277 JSON_THROW(type_error::create(302, concat(
"type must be number, but is ", j.type_name()), &j));
5281template<
typename BasicJsonType,
typename... Args, std::size_t... Idx>
5282std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<Idx...> )
5284 return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).
template get<Args>()...);
5287template<
typename BasicJsonType>
5288std::tuple<> from_json_tuple_impl_base(BasicJsonType& , index_sequence<> )
5293template <
typename BasicJsonType,
class A1,
class A2 >
5296 return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
5297 std::forward<BasicJsonType>(j).at(1).template get<A2>()};
5300template<
typename BasicJsonType,
typename A1,
typename A2>
5301inline void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p,
priority_tag<1> )
5306template<
typename BasicJsonType,
typename... Args>
5309 return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
5312template<
typename BasicJsonType,
typename... Args>
5313inline void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t,
priority_tag<3> )
5315 t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
5318template<
typename BasicJsonType,
typename TupleRelated>
5319auto from_json(BasicJsonType&& j, TupleRelated&& t)
5320->
decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t),
priority_tag<3> {}))
5322 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5324 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5327 return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t),
priority_tag<3> {});
5330template <
typename BasicJsonType,
typename Key,
typename Value,
typename Compare,
typename Allocator,
5331 typename = enable_if_t < !std::is_constructible <
5332 typename BasicJsonType::string_t, Key >::value >>
5333inline void from_json(
const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
5335 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5337 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5340 for (
const auto& p : j)
5342 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
5344 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", p.type_name()), &j));
5346 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
5350template <
typename BasicJsonType,
typename Key,
typename Value,
typename Hash,
typename KeyEqual,
typename Allocator,
5351 typename = enable_if_t < !std::is_constructible <
5352 typename BasicJsonType::string_t, Key >::value >>
5353inline void from_json(
const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
5355 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5357 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5360 for (
const auto& p : j)
5362 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
5364 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", p.type_name()), &j));
5366 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
5370#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
5371template<
typename BasicJsonType>
5372inline void from_json(
const BasicJsonType& j, std_fs::path& p)
5374 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
5376 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
5378 const auto& s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
5382#if defined(__cpp_lib_char8_t) && (__cpp_lib_char8_t >= 201907L)
5383 p = std_fs::path(std::u8string_view(
reinterpret_cast<const char8_t*
>(s.data()), s.size()));
5385 p = std_fs::u8path(s);
5392 template<
typename BasicJsonType,
typename T>
5393 auto operator()(
const BasicJsonType& j, T&& val)
const
5394 noexcept(
noexcept(from_json(j, std::forward<T>(val))))
5395 ->
decltype(from_json(j, std::forward<T>(val)))
5397 return from_json(j, std::forward<T>(val));
5403#ifndef JSON_HAS_CPP_17
5410JSON_INLINE_VARIABLE
constexpr const auto& from_json =
5411 detail::static_const<detail::from_json_fn>::value;
5412#ifndef JSON_HAS_CPP_17
5416NLOHMANN_JSON_NAMESPACE_END
5431#ifdef JSON_HAS_CPP_17
5440#include <type_traits>
5486NLOHMANN_JSON_NAMESPACE_BEGIN
5490template<
typename StringType>
5491void int_to_string(StringType& target, std::size_t value)
5494 using std::to_string;
5495 target = to_string(value);
5498template<
typename StringType>
5499StringType to_string(std::size_t value)
5502 int_to_string(result, value);
5507NLOHMANN_JSON_NAMESPACE_END
5512NLOHMANN_JSON_NAMESPACE_BEGIN
5516template<
typename IteratorType>
class iteration_proxy_value
5519 using difference_type = std::ptrdiff_t;
5520 using value_type = iteration_proxy_value;
5521 using pointer = value_type *;
5522 using reference = value_type &;
5523 using iterator_category = std::forward_iterator_tag;
5524 using string_type =
typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
5528 IteratorType anchor{};
5530 std::size_t array_index = 0;
5532 mutable std::size_t array_index_last = 0;
5534 mutable string_type array_index_str =
"0";
5536 string_type empty_str{};
5539 explicit iteration_proxy_value() =
default;
5540 explicit iteration_proxy_value(IteratorType it, std::size_t array_index_ = 0)
5541 noexcept(std::is_nothrow_move_constructible<IteratorType>::value
5542 && std::is_nothrow_default_constructible<string_type>::value)
5543 : anchor(std::move(it))
5544 , array_index(array_index_)
5547 iteration_proxy_value(iteration_proxy_value
const&) =
default;
5548 iteration_proxy_value& operator=(iteration_proxy_value
const&) =
default;
5550 iteration_proxy_value(iteration_proxy_value&&)
5551 noexcept(std::is_nothrow_move_constructible<IteratorType>::value
5552 && std::is_nothrow_move_constructible<string_type>::value) =
default;
5553 iteration_proxy_value& operator=(iteration_proxy_value&&)
5554 noexcept(std::is_nothrow_move_assignable<IteratorType>::value
5555 && std::is_nothrow_move_assignable<string_type>::value) =
default;
5556 ~iteration_proxy_value() =
default;
5584 return anchor == o.anchor;
5590 return anchor != o.anchor;
5594 const string_type&
key()
const
5596 JSON_ASSERT(anchor.m_object !=
nullptr);
5598 switch (anchor.m_object->type())
5603 if (array_index != array_index_last)
5605 int_to_string( array_index_str, array_index );
5606 array_index_last = array_index;
5608 return array_index_str;
5613 return anchor.key();
5630 typename IteratorType::reference
value()
const
5632 return anchor.value();
5637template<
typename IteratorType>
class iteration_proxy
5641 typename IteratorType::pointer container =
nullptr;
5644 explicit iteration_proxy() =
default;
5648 : container(&cont) {}
5672template<std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
5673auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.key())
5680template<std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
5681auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.value())
5687NLOHMANN_JSON_NAMESPACE_END
5696#if defined(__clang__)
5698 #pragma clang diagnostic push
5699 #pragma clang diagnostic ignored "-Wmismatched-tags"
5701template<
typename IteratorType>
5702class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
5703 :
public std::integral_constant<std::size_t, 2> {};
5705template<std::
size_t N,
typename IteratorType>
5706class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
5709 using type =
decltype(
5710 get<N>(std::declval <
5711 ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));
5713#if defined(__clang__)
5714 #pragma clang diagnostic pop
5720 template <
typename IteratorType>
5721 inline constexpr bool ::std::ranges::enable_borrowed_range<::nlohmann::detail::iteration_proxy<IteratorType>> =
true;
5733NLOHMANN_JSON_NAMESPACE_BEGIN
5753 template<
typename BasicJsonType>
5754 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t b)
noexcept
5756 j.m_data.m_value.destroy(j.m_data.m_type);
5758 j.m_data.m_value = b;
5759 j.assert_invariant();
5766 template<
typename BasicJsonType>
5767 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t& s)
5769 j.m_data.m_value.destroy(j.m_data.m_type);
5771 j.m_data.m_value = s;
5772 j.assert_invariant();
5775 template<
typename BasicJsonType>
5776 static void construct(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
5778 j.m_data.m_value.destroy(j.m_data.m_type);
5780 j.m_data.m_value = std::move(s);
5781 j.assert_invariant();
5784 template <
typename BasicJsonType,
typename CompatibleStringType,
5785 enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
5787 static void construct(BasicJsonType& j,
const CompatibleStringType& str)
5789 j.m_data.m_value.destroy(j.m_data.m_type);
5791 j.m_data.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
5792 j.assert_invariant();
5799 template<
typename BasicJsonType>
5800 static void construct(BasicJsonType& j,
const typename BasicJsonType::binary_t& b)
5802 j.m_data.m_value.destroy(j.m_data.m_type);
5804 j.m_data.m_value =
typename BasicJsonType::binary_t(b);
5805 j.assert_invariant();
5808 template<
typename BasicJsonType>
5809 static void construct(BasicJsonType& j,
typename BasicJsonType::binary_t&& b)
5811 j.m_data.m_value.destroy(j.m_data.m_type);
5813 j.m_data.m_value =
typename BasicJsonType::binary_t(std::move(b));
5814 j.assert_invariant();
5821 template<
typename BasicJsonType>
5822 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val)
noexcept
5824 j.m_data.m_value.destroy(j.m_data.m_type);
5826 j.m_data.m_value = val;
5827 j.assert_invariant();
5834 template<
typename BasicJsonType>
5835 static void construct(BasicJsonType& j,
typename BasicJsonType::number_unsigned_t val)
noexcept
5837 j.m_data.m_value.destroy(j.m_data.m_type);
5839 j.m_data.m_value = val;
5840 j.assert_invariant();
5847 template<
typename BasicJsonType>
5848 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val)
noexcept
5850 j.m_data.m_value.destroy(j.m_data.m_type);
5852 j.m_data.m_value = val;
5853 j.assert_invariant();
5860 template<
typename BasicJsonType>
5861 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
5863 j.m_data.m_value.destroy(j.m_data.m_type);
5865 j.m_data.m_value = arr;
5867 j.assert_invariant();
5870 template<
typename BasicJsonType>
5871 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
5873 j.m_data.m_value.destroy(j.m_data.m_type);
5875 j.m_data.m_value = std::move(arr);
5877 j.assert_invariant();
5880 template <
typename BasicJsonType,
typename CompatibleArrayType,
5881 enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
5883 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
5888 j.m_data.m_value.destroy(j.m_data.m_type);
5890 j.m_data.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
5892 j.assert_invariant();
5895 template<
typename BasicJsonType>
5896 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
5898 j.m_data.m_value.destroy(j.m_data.m_type);
5901 j.m_data.m_value.array->reserve(arr.size());
5902 for (
const bool x : arr)
5904 j.m_data.m_value.array->push_back(x);
5905 j.set_parent(j.m_data.m_value.array->back());
5907 j.assert_invariant();
5910 template<
typename BasicJsonType,
typename T,
5911 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
5912 static void construct(BasicJsonType& j,
const std::valarray<T>& arr)
5914 j.m_data.m_value.destroy(j.m_data.m_type);
5917 j.m_data.m_value.array->resize(arr.size());
5920 std::copy(std::begin(arr), std::end(arr), j.m_data.m_value.array->begin());
5923 j.assert_invariant();
5930 template<
typename BasicJsonType>
5931 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
5933 j.m_data.m_value.destroy(j.m_data.m_type);
5935 j.m_data.m_value = obj;
5937 j.assert_invariant();
5940 template<
typename BasicJsonType>
5941 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
5943 j.m_data.m_value.destroy(j.m_data.m_type);
5945 j.m_data.m_value = std::move(obj);
5947 j.assert_invariant();
5950 template <
typename BasicJsonType,
typename CompatibleObjectType,
5951 enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
int > = 0 >
5952 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
5957 j.m_data.m_value.destroy(j.m_data.m_type);
5959 j.m_data.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
5961 j.assert_invariant();
5969#ifdef JSON_HAS_CPP_17
5970template<
typename BasicJsonType,
typename T,
5971 enable_if_t<std::is_constructible<BasicJsonType, T>::value,
int> = 0>
5972void to_json(BasicJsonType& j,
const std::optional<T>& opt)
noexcept
5974 if (opt.has_value())
5985template<
typename BasicJsonType,
typename T,
5986 enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value,
int> = 0>
5987inline void to_json(BasicJsonType& j, T b)
noexcept
5992template <
typename BasicJsonType,
typename BoolRef,
5994 ((std::is_same<std::vector<bool>::reference, BoolRef>::value
5995 && !std::is_same <std::vector<bool>::reference,
typename BasicJsonType::boolean_t&>::value)
5996 || (std::is_same<std::vector<bool>::const_reference, BoolRef>::value
5997 && !std::is_same <detail::uncvref_t<std::vector<bool>::const_reference>,
5998 typename BasicJsonType::boolean_t >::value))
5999 && std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value,
int > = 0 >
6000inline void to_json(BasicJsonType& j,
const BoolRef& b)
noexcept
6005template<
typename BasicJsonType,
typename CompatibleString,
6006 enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value,
int> = 0>
6007inline void to_json(BasicJsonType& j,
const CompatibleString& s)
6012template<
typename BasicJsonType>
6013inline void to_json(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
6018template<
typename BasicJsonType,
typename FloatType,
6019 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
6020inline void to_json(BasicJsonType& j, FloatType val)
noexcept
6025template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
6026 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value,
int> = 0>
6027inline void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val)
noexcept
6032template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
6033 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value,
int> = 0>
6034inline void to_json(BasicJsonType& j, CompatibleNumberIntegerType val)
noexcept
6039#if !JSON_DISABLE_ENUM_SERIALIZATION
6040template<
typename BasicJsonType,
typename EnumType,
6041 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
6042inline void to_json(BasicJsonType& j, EnumType e)
noexcept
6044 using underlying_type =
typename std::underlying_type<EnumType>::type;
6050template<
typename BasicJsonType>
6051inline void to_json(BasicJsonType& j,
const std::vector<bool>& e)
6056template <
typename BasicJsonType,
typename CompatibleArrayType,
6058 CompatibleArrayType>::value&&
6060 !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&&
6061 !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
6064inline void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
6069template<
typename BasicJsonType>
6070inline void to_json(BasicJsonType& j,
const typename BasicJsonType::binary_t& bin)
6075template<
typename BasicJsonType,
typename T,
6076 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
6077inline void to_json(BasicJsonType& j,
const std::valarray<T>& arr)
6082template<
typename BasicJsonType>
6083inline void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
6088template <
typename BasicJsonType,
typename CompatibleObjectType,
6090inline void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
6095template<
typename BasicJsonType>
6096inline void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
6102 typename BasicJsonType,
typename T, std::size_t N,
6103 enable_if_t < !std::is_constructible<
typename BasicJsonType::string_t,
6104 const T(&)[N]>::value,
6106inline void to_json(BasicJsonType& j,
const T(&arr)[N])
6111template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value,
int > = 0 >
6112inline void to_json(BasicJsonType& j,
const std::pair<T1, T2>& p)
6114 j = { p.first, p.second };
6118template<
typename BasicJsonType,
typename T,
6119 enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value,
int> = 0>
6120inline void to_json(BasicJsonType& j,
const T& b)
6122 j = { {b.key(), b.value()} };
6125template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
6126inline void to_json_tuple_impl(BasicJsonType& j,
const Tuple& t, index_sequence<Idx...> )
6128 j = { std::get<Idx>(t)... };
6131template<
typename BasicJsonType,
typename Tuple>
6132inline void to_json_tuple_impl(BasicJsonType& j,
const Tuple& , index_sequence<> )
6134 using array_t =
typename BasicJsonType::array_t;
6138template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value,
int > = 0>
6139inline void to_json(BasicJsonType& j,
const T& t)
6141 to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
6144#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
6145#if defined(__cpp_lib_char8_t)
6146template<
typename BasicJsonType,
typename Tr,
typename Allocator>
6147inline void to_json(BasicJsonType& j,
const std::basic_string<char8_t, Tr, Allocator>& s)
6149 using OtherAllocator =
typename std::allocator_traits<Allocator>::template rebind_alloc<char>;
6150 j = std::basic_string<char, std::char_traits<char>, OtherAllocator>(s.begin(), s.end(), s.get_allocator());
6154template<
typename BasicJsonType>
6155inline void to_json(BasicJsonType& j,
const std_fs::path& p)
6165 template<
typename BasicJsonType,
typename T>
6166 auto operator()(BasicJsonType& j, T&& val)
const noexcept(
noexcept(to_json(j, std::forward<T>(val))))
6167 ->
decltype(to_json(j, std::forward<T>(val)),
void())
6169 return to_json(j, std::forward<T>(val));
6174#ifndef JSON_HAS_CPP_17
6181JSON_INLINE_VARIABLE
constexpr const auto& to_json =
6182 detail::static_const<detail::to_json_fn>::value;
6183#ifndef JSON_HAS_CPP_17
6187NLOHMANN_JSON_NAMESPACE_END
6192NLOHMANN_JSON_NAMESPACE_BEGIN
6195template<
typename ValueType,
typename>
6200 template<
typename BasicJsonType,
typename TargetType = ValueType>
6201 static auto from_json(BasicJsonType && j, TargetType& val)
noexcept(
6202 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
6203 ->
decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val),
void())
6205 ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
6210 template<
typename BasicJsonType,
typename TargetType = ValueType>
6215 return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
6220 template<
typename BasicJsonType,
typename TargetType = ValueType>
6221 static auto to_json(BasicJsonType& j, TargetType && val)
noexcept(
6222 noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
6223 ->
decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)),
void())
6225 ::nlohmann::to_json(j, std::forward<TargetType>(val));
6229NLOHMANN_JSON_NAMESPACE_END
6249NLOHMANN_JSON_NAMESPACE_BEGIN
6253template<
typename BinaryType>
6257 using container_type = BinaryType;
6258 using subtype_type = std::uint64_t;
6272 : container_type(std::move(b))
6278 , m_subtype(subtype_)
6279 , m_has_subtype(true)
6284 : container_type(std::move(b))
6285 , m_subtype(subtype_)
6286 , m_has_subtype(true)
6291 return std::tie(
static_cast<const BinaryType&
>(*
this), m_subtype, m_has_subtype) ==
6292 std::tie(
static_cast<const BinaryType&
>(rhs), rhs.m_subtype, rhs.m_has_subtype);
6297 return !(rhs == *
this);
6304 m_subtype = subtype_;
6305 m_has_subtype =
true;
6312 return m_has_subtype ? m_subtype :
static_cast<subtype_type
>(-1);
6319 return m_has_subtype;
6327 m_has_subtype =
false;
6331 subtype_type m_subtype = 0;
6332 bool m_has_subtype =
false;
6335NLOHMANN_JSON_NAMESPACE_END
6356#include <functional>
6363NLOHMANN_JSON_NAMESPACE_BEGIN
6368inline std::size_t combine(std::size_t seed, std::size_t h)
noexcept
6370 seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
6385template<
typename BasicJsonType>
6386std::size_t
hash(
const BasicJsonType& j)
6388 using string_t =
typename BasicJsonType::string_t;
6389 using number_integer_t =
typename BasicJsonType::number_integer_t;
6390 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6391 using number_float_t =
typename BasicJsonType::number_float_t;
6393 const auto type =
static_cast<std::size_t
>(j.type());
6396 case BasicJsonType::value_t::null:
6397 case BasicJsonType::value_t::discarded:
6399 return combine(type, 0);
6402 case BasicJsonType::value_t::object:
6404 auto seed = combine(type, j.size());
6405 for (
const auto& element : j.items())
6407 const auto h = std::hash<string_t> {}(element.key());
6408 seed = combine(seed, h);
6409 seed = combine(seed,
hash(element.value()));
6414 case BasicJsonType::value_t::array:
6416 auto seed = combine(type, j.size());
6417 for (
const auto& element : j)
6419 seed = combine(seed,
hash(element));
6424 case BasicJsonType::value_t::string:
6426 const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
6427 return combine(type, h);
6430 case BasicJsonType::value_t::boolean:
6432 const auto h = std::hash<bool> {}(j.template get<bool>());
6433 return combine(type, h);
6436 case BasicJsonType::value_t::number_integer:
6438 const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
6439 return combine(type, h);
6442 case BasicJsonType::value_t::number_unsigned:
6444 const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
6445 return combine(type, h);
6448 case BasicJsonType::value_t::number_float:
6450 const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
6451 return combine(type, h);
6454 case BasicJsonType::value_t::binary:
6456 auto seed = combine(type, j.get_binary().size());
6457 const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
6458 seed = combine(seed, h);
6459 seed = combine(seed,
static_cast<std::size_t
>(j.get_binary().subtype()));
6460 for (
const auto byte : j.get_binary())
6462 seed = combine(seed, std::hash<std::uint8_t> {}(byte));
6474NLOHMANN_JSON_NAMESPACE_END
6499#ifdef __cpp_lib_byteswap
6524#include <type_traits>
6541NLOHMANN_JSON_NAMESPACE_BEGIN
6557class file_input_adapter
6560 using char_type = char;
6562 JSON_HEDLEY_NON_NULL(2)
6563 explicit file_input_adapter(std::FILE* f) noexcept
6566 JSON_ASSERT(m_file !=
nullptr);
6570 file_input_adapter(
const file_input_adapter&) =
delete;
6571 file_input_adapter(file_input_adapter&&)
noexcept =
default;
6572 file_input_adapter& operator=(
const file_input_adapter&) =
delete;
6573 file_input_adapter& operator=(file_input_adapter&&) =
delete;
6574 ~file_input_adapter() =
default;
6576 std::char_traits<char>::int_type get_character()
noexcept
6578 return std::fgetc(m_file);
6583 std::size_t get_elements(T* dest, std::size_t count = 1)
6585 return fread(dest, 1,
sizeof(T) * count, m_file);
6602class input_stream_adapter
6605 using char_type = char;
6607 ~input_stream_adapter()
6613 is->clear(is->rdstate() & std::ios::eofbit);
6617 explicit input_stream_adapter(std::istream& i)
6618 : is(&i), sb(i.rdbuf())
6622 input_stream_adapter(
const input_stream_adapter&) =
delete;
6623 input_stream_adapter& operator=(input_stream_adapter&) =
delete;
6624 input_stream_adapter& operator=(input_stream_adapter&&) =
delete;
6626 input_stream_adapter(input_stream_adapter&& rhs) noexcept
6627 : is(rhs.is), sb(rhs.sb)
6636 std::char_traits<char>::int_type get_character()
6638 auto res = sb->sbumpc();
6640 if (JSON_HEDLEY_UNLIKELY(res == std::char_traits<char>::eof()))
6642 is->clear(is->rdstate() | std::ios::eofbit);
6648 std::size_t get_elements(T* dest, std::size_t count = 1)
6650 auto res =
static_cast<std::size_t
>(sb->sgetn(
reinterpret_cast<char*
>(dest),
static_cast<std::streamsize
>(count *
sizeof(T))));
6651 if (JSON_HEDLEY_UNLIKELY(res < count *
sizeof(T)))
6653 is->clear(is->rdstate() | std::ios::eofbit);
6660 std::istream* is =
nullptr;
6661 std::streambuf* sb =
nullptr;
6667template<
typename IteratorType>
6668class iterator_input_adapter
6671 using char_type =
typename std::iterator_traits<IteratorType>::value_type;
6673 iterator_input_adapter(IteratorType first, IteratorType last)
6674 : current(std::move(first)), end(std::move(last))
6679 if (JSON_HEDLEY_LIKELY(current != end))
6682 std::advance(current, 1);
6691 std::size_t get_elements(T* dest, std::size_t count = 1)
6693 auto* ptr =
reinterpret_cast<char*
>(dest);
6694 for (std::size_t read_index = 0; read_index < count *
sizeof(T); ++read_index)
6696 if (JSON_HEDLEY_LIKELY(current != end))
6698 ptr[read_index] =
static_cast<char>(*current);
6699 std::advance(current, 1);
6706 return count *
sizeof(T);
6710 IteratorType current;
6713 template<
typename BaseInputAdapter,
size_t T>
6714 friend struct wide_string_input_helper;
6718 return current == end;
6722template<
typename BaseInputAdapter,
size_t T>
6725template<
typename BaseInputAdapter>
6729 static void fill_buffer(BaseInputAdapter& input,
6730 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
6731 size_t& utf8_bytes_index,
6732 size_t& utf8_bytes_filled)
6734 utf8_bytes_index = 0;
6736 if (JSON_HEDLEY_UNLIKELY(input.empty()))
6738 utf8_bytes[0] = std::char_traits<char>::eof();
6739 utf8_bytes_filled = 1;
6744 const auto wc = input.get_character();
6749 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6750 utf8_bytes_filled = 1;
6752 else if (wc <= 0x7FF)
6754 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
6755 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6756 utf8_bytes_filled = 2;
6758 else if (wc <= 0xFFFF)
6760 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
6761 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6762 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6763 utf8_bytes_filled = 3;
6765 else if (wc <= 0x10FFFF)
6767 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | ((
static_cast<unsigned int>(wc) >> 18u) & 0x07u));
6768 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
6769 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6770 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6771 utf8_bytes_filled = 4;
6776 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6777 utf8_bytes_filled = 1;
6783template<
typename BaseInputAdapter>
6787 static void fill_buffer(BaseInputAdapter& input,
6788 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
6789 size_t& utf8_bytes_index,
6790 size_t& utf8_bytes_filled)
6792 utf8_bytes_index = 0;
6794 if (JSON_HEDLEY_UNLIKELY(input.empty()))
6796 utf8_bytes[0] = std::char_traits<char>::eof();
6797 utf8_bytes_filled = 1;
6802 const auto wc = input.get_character();
6807 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6808 utf8_bytes_filled = 1;
6810 else if (wc <= 0x7FF)
6812 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u)));
6813 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6814 utf8_bytes_filled = 2;
6816 else if (0xD800 > wc || wc >= 0xE000)
6818 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u)));
6819 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6820 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6821 utf8_bytes_filled = 3;
6825 if (JSON_HEDLEY_UNLIKELY(!input.empty()))
6827 const auto wc2 =
static_cast<unsigned int>(input.get_character());
6828 const auto charcode = 0x10000u + (((
static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
6829 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | (charcode >> 18u));
6830 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 12u) & 0x3Fu));
6831 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 6u) & 0x3Fu));
6832 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (charcode & 0x3Fu));
6833 utf8_bytes_filled = 4;
6837 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6838 utf8_bytes_filled = 1;
6846template<
typename BaseInputAdapter,
typename W
ideCharType>
6847class wide_string_input_adapter
6850 using char_type = char;
6852 wide_string_input_adapter(BaseInputAdapter base)
6853 : base_adapter(base) {}
6855 typename std::char_traits<char>::int_type get_character()
noexcept
6858 if (utf8_bytes_index == utf8_bytes_filled)
6860 fill_buffer<sizeof(WideCharType)>();
6862 JSON_ASSERT(utf8_bytes_filled > 0);
6863 JSON_ASSERT(utf8_bytes_index == 0);
6867 JSON_ASSERT(utf8_bytes_filled > 0);
6868 JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);
6869 return utf8_bytes[utf8_bytes_index++];
6874 std::size_t get_elements(T* , std::size_t = 1)
6876 JSON_THROW(
parse_error::create(112, 1,
"wide string type cannot be interpreted as binary data",
nullptr));
6880 BaseInputAdapter base_adapter;
6889 std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
6892 std::size_t utf8_bytes_index = 0;
6894 std::size_t utf8_bytes_filled = 0;
6897template<
typename IteratorType,
typename Enable =
void>
6900 using iterator_type = IteratorType;
6901 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
6904 static adapter_type create(IteratorType first, IteratorType last)
6906 return adapter_type(std::move(first), std::move(last));
6913 using value_type =
typename std::iterator_traits<T>::value_type;
6916 value =
sizeof(value_type) > 1
6920template<
typename IteratorType>
6923 using iterator_type = IteratorType;
6924 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
6928 static adapter_type create(IteratorType first, IteratorType last)
6930 return adapter_type(base_adapter_type(std::move(first), std::move(last)));
6935template<
typename IteratorType>
6936typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapter(IteratorType first, IteratorType last)
6939 return factory_type::create(first, last);
6946namespace container_input_adapter_factory_impl
6952template<
typename ContainerType,
typename Enable =
void>
6955template<
typename ContainerType>
6957 void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
6959 using adapter_type =
decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
6961 static adapter_type create(
const ContainerType& container)
6963 return input_adapter(begin(container), end(container));
6969template<
typename ContainerType>
6976using string_input_adapter_type =
decltype(input_adapter(std::declval<std::string>()));
6980inline file_input_adapter input_adapter(std::FILE* file)
6982 if (file ==
nullptr)
6984 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));
7000using contiguous_bytes_input_adapter =
decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
7003template <
typename CharT,
7004 typename std::enable_if <
7005 std::is_pointer<CharT>::value&&
7006 !std::is_array<CharT>::value&&
7007 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
7008 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
7010contiguous_bytes_input_adapter input_adapter(CharT b)
7014 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));
7016 auto length = std::strlen(
reinterpret_cast<const char*
>(b));
7017 const auto* ptr =
reinterpret_cast<const char*
>(b);
7018 return input_adapter(ptr, ptr + length);
7021template<
typename T, std::
size_t N>
7022auto input_adapter(T (&
array)[N]) ->
decltype(input_adapter(
array,
array + N))
7030class span_input_adapter
7033 template <
typename CharT,
7034 typename std::enable_if <
7035 std::is_pointer<CharT>::value&&
7036 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
7037 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
7039 span_input_adapter(CharT b, std::size_t l)
7040 : ia(
reinterpret_cast<const char*
>(b),
reinterpret_cast<const char*
>(b) + l) {}
7042 template<
class IteratorType,
7043 typename std::enable_if<
7044 std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
7046 span_input_adapter(IteratorType first, IteratorType last)
7047 : ia(input_adapter(first, last)) {}
7049 contiguous_bytes_input_adapter&& get()
7051 return std::move(ia);
7055 contiguous_bytes_input_adapter ia;
7059NLOHMANN_JSON_NAMESPACE_END
7074#include <type_traits>
7096#include <initializer_list>
7110NLOHMANN_JSON_NAMESPACE_BEGIN
7118template<
typename BasicJsonType>
7145 JSON_HEDLEY_RETURNS_NON_NULL
7152 return "<uninitialized>";
7154 return "true literal";
7156 return "false literal";
7158 return "null literal";
7160 return "string literal";
7164 return "number literal";
7178 return "<parse error>";
7180 return "end of input";
7182 return "'[', '{', or a literal";
7185 return "unknown token";
7195template<
typename BasicJsonType,
typename InputAdapterType>
7198 using number_integer_t =
typename BasicJsonType::number_integer_t;
7199 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7200 using number_float_t =
typename BasicJsonType::number_float_t;
7201 using string_t =
typename BasicJsonType::string_t;
7202 using char_type =
typename InputAdapterType::char_type;
7208 explicit lexer(InputAdapterType&& adapter,
bool ignore_comments_ =
false) noexcept
7209 : ia(std::move(adapter))
7210 , ignore_comments(ignore_comments_)
7211 , decimal_point_char(
static_cast<char_int_type
>(get_decimal_point()))
7215 lexer(
const lexer&) =
delete;
7216 lexer(lexer&&) =
default;
7217 lexer& operator=(lexer&) =
delete;
7218 lexer& operator=(lexer&&) =
default;
7228 static char get_decimal_point()
noexcept
7230 const auto* loc = localeconv();
7231 JSON_ASSERT(loc !=
nullptr);
7232 return (loc->decimal_point ==
nullptr) ?
'.' : *(loc->decimal_point);
7257 JSON_ASSERT(current ==
'u');
7260 const auto factors = { 12u, 8u, 4u, 0u };
7261 for (
const auto factor : factors)
7265 if (current >=
'0' && current <=
'9')
7267 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x30u) << factor);
7269 else if (current >=
'A' && current <=
'F')
7271 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x37u) << factor);
7273 else if (current >=
'a' && current <=
'f')
7275 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x57u) << factor);
7283 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
7302 bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
7304 JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
7307 for (
auto range = ranges.begin(); range != ranges.end(); ++range)
7310 if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range)))
7316 error_message =
"invalid string: ill-formed UTF-8 byte";
7339 token_type scan_string()
7345 JSON_ASSERT(current ==
'\"');
7355 error_message =
"invalid string: missing closing quote";
7356 return token_type::parse_error;
7362 return token_type::value_string;
7406 const int codepoint1 = get_codepoint();
7407 int codepoint = codepoint1;
7409 if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
7411 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7412 return token_type::parse_error;
7416 if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
7419 if (JSON_HEDLEY_LIKELY(get() ==
'\\' && get() ==
'u'))
7421 const int codepoint2 = get_codepoint();
7423 if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
7425 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7426 return token_type::parse_error;
7430 if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))
7433 codepoint =
static_cast<int>(
7435 (
static_cast<unsigned int>(codepoint1) << 10u)
7437 +
static_cast<unsigned int>(codepoint2)
7445 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
7446 return token_type::parse_error;
7451 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
7452 return token_type::parse_error;
7457 if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))
7459 error_message =
"invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
7460 return token_type::parse_error;
7465 JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
7468 if (codepoint < 0x80)
7471 add(
static_cast<char_int_type
>(codepoint));
7473 else if (codepoint <= 0x7FF)
7476 add(
static_cast<char_int_type
>(0xC0u | (
static_cast<unsigned int>(codepoint) >> 6u)));
7477 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7479 else if (codepoint <= 0xFFFF)
7482 add(
static_cast<char_int_type
>(0xE0u | (
static_cast<unsigned int>(codepoint) >> 12u)));
7483 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7484 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7489 add(
static_cast<char_int_type
>(0xF0u | (
static_cast<unsigned int>(codepoint) >> 18u)));
7490 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
7491 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7492 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7500 error_message =
"invalid string: forbidden character after backslash";
7501 return token_type::parse_error;
7510 error_message =
"invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
7511 return token_type::parse_error;
7516 error_message =
"invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
7517 return token_type::parse_error;
7522 error_message =
"invalid string: control character U+0002 (STX) must be escaped to \\u0002";
7523 return token_type::parse_error;
7528 error_message =
"invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
7529 return token_type::parse_error;
7534 error_message =
"invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
7535 return token_type::parse_error;
7540 error_message =
"invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
7541 return token_type::parse_error;
7546 error_message =
"invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
7547 return token_type::parse_error;
7552 error_message =
"invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
7553 return token_type::parse_error;
7558 error_message =
"invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
7559 return token_type::parse_error;
7564 error_message =
"invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
7565 return token_type::parse_error;
7570 error_message =
"invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
7571 return token_type::parse_error;
7576 error_message =
"invalid string: control character U+000B (VT) must be escaped to \\u000B";
7577 return token_type::parse_error;
7582 error_message =
"invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
7583 return token_type::parse_error;
7588 error_message =
"invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
7589 return token_type::parse_error;
7594 error_message =
"invalid string: control character U+000E (SO) must be escaped to \\u000E";
7595 return token_type::parse_error;
7600 error_message =
"invalid string: control character U+000F (SI) must be escaped to \\u000F";
7601 return token_type::parse_error;
7606 error_message =
"invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
7607 return token_type::parse_error;
7612 error_message =
"invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
7613 return token_type::parse_error;
7618 error_message =
"invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
7619 return token_type::parse_error;
7624 error_message =
"invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
7625 return token_type::parse_error;
7630 error_message =
"invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
7631 return token_type::parse_error;
7636 error_message =
"invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
7637 return token_type::parse_error;
7642 error_message =
"invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
7643 return token_type::parse_error;
7648 error_message =
"invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
7649 return token_type::parse_error;
7654 error_message =
"invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
7655 return token_type::parse_error;
7660 error_message =
"invalid string: control character U+0019 (EM) must be escaped to \\u0019";
7661 return token_type::parse_error;
7666 error_message =
"invalid string: control character U+001A (SUB) must be escaped to \\u001A";
7667 return token_type::parse_error;
7672 error_message =
"invalid string: control character U+001B (ESC) must be escaped to \\u001B";
7673 return token_type::parse_error;
7678 error_message =
"invalid string: control character U+001C (FS) must be escaped to \\u001C";
7679 return token_type::parse_error;
7684 error_message =
"invalid string: control character U+001D (GS) must be escaped to \\u001D";
7685 return token_type::parse_error;
7690 error_message =
"invalid string: control character U+001E (RS) must be escaped to \\u001E";
7691 return token_type::parse_error;
7696 error_message =
"invalid string: control character U+001F (US) must be escaped to \\u001F";
7697 return token_type::parse_error;
7832 if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
7834 return token_type::parse_error;
7842 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
7844 return token_type::parse_error;
7866 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
7868 return token_type::parse_error;
7876 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
7878 return token_type::parse_error;
7886 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7888 return token_type::parse_error;
7898 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7900 return token_type::parse_error;
7908 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
7910 return token_type::parse_error;
7918 error_message =
"invalid string: ill-formed UTF-8 byte";
7919 return token_type::parse_error;
7962 error_message =
"invalid comment; missing closing '*/'";
7990 error_message =
"invalid comment; expecting '/' or '*' after '/'";
7996 JSON_HEDLEY_NON_NULL(2)
7997 static void strtof(
float& f,
const char* str,
char** endptr)
noexcept
7999 f = std::strtof(str, endptr);
8002 JSON_HEDLEY_NON_NULL(2)
8003 static void strtof(
double& f,
const char* str,
char** endptr)
noexcept
8005 f = std::strtod(str, endptr);
8008 JSON_HEDLEY_NON_NULL(2)
8009 static void strtof(
long double& f,
const char* str,
char** endptr)
noexcept
8011 f = std::strtold(str, endptr);
8054 token_type scan_number()
8061 token_type number_type = token_type::value_unsigned;
8069 goto scan_number_minus;
8075 goto scan_number_zero;
8089 goto scan_number_any1;
8099 number_type = token_type::value_integer;
8105 goto scan_number_zero;
8119 goto scan_number_any1;
8124 error_message =
"invalid number; expected digit after '-'";
8125 return token_type::parse_error;
8135 add(decimal_point_char);
8136 decimal_point_position = token_buffer.size() - 1;
8137 goto scan_number_decimal1;
8144 goto scan_number_exponent;
8148 goto scan_number_done;
8167 goto scan_number_any1;
8172 add(decimal_point_char);
8173 decimal_point_position = token_buffer.size() - 1;
8174 goto scan_number_decimal1;
8181 goto scan_number_exponent;
8185 goto scan_number_done;
8188scan_number_decimal1:
8190 number_type = token_type::value_float;
8205 goto scan_number_decimal2;
8210 error_message =
"invalid number; expected digit after '.'";
8211 return token_type::parse_error;
8215scan_number_decimal2:
8231 goto scan_number_decimal2;
8238 goto scan_number_exponent;
8242 goto scan_number_done;
8245scan_number_exponent:
8247 number_type = token_type::value_float;
8254 goto scan_number_sign;
8269 goto scan_number_any2;
8275 "invalid number; expected '+', '-', or digit after exponent";
8276 return token_type::parse_error;
8296 goto scan_number_any2;
8301 error_message =
"invalid number; expected digit after exponent sign";
8302 return token_type::parse_error;
8322 goto scan_number_any2;
8326 goto scan_number_done;
8334 char* endptr =
nullptr;
8338 if (number_type == token_type::value_unsigned)
8340 const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
8343 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8345 if (errno != ERANGE)
8347 value_unsigned =
static_cast<number_unsigned_t
>(x);
8348 if (value_unsigned == x)
8350 return token_type::value_unsigned;
8354 else if (number_type == token_type::value_integer)
8356 const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
8359 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8361 if (errno != ERANGE)
8363 value_integer =
static_cast<number_integer_t
>(x);
8364 if (value_integer == x)
8366 return token_type::value_integer;
8373 strtof(value_float, token_buffer.data(), &endptr);
8376 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8378 return token_type::value_float;
8386 JSON_HEDLEY_NON_NULL(2)
8387 token_type scan_literal(
const char_type* literal_text,
const std::size_t length,
8388 token_type return_type)
8391 for (std::size_t i = 1; i < length; ++i)
8395 error_message =
"invalid literal";
8396 return token_type::parse_error;
8407 void reset()
noexcept
8409 token_buffer.clear();
8410 token_string.clear();
8411 decimal_point_position = std::string::npos;
8427 ++position.chars_read_total;
8428 ++position.chars_read_current_line;
8437 current = ia.get_character();
8445 if (current ==
'\n')
8447 ++position.lines_read;
8448 position.chars_read_current_line = 0;
8466 --position.chars_read_total;
8469 if (position.chars_read_current_line == 0)
8471 if (position.lines_read > 0)
8473 --position.lines_read;
8478 --position.chars_read_current_line;
8483 JSON_ASSERT(!token_string.empty());
8484 token_string.pop_back();
8489 void add(char_int_type c)
8491 token_buffer.push_back(
static_cast<typename string_t::value_type
>(c));
8502 return value_integer;
8508 return value_unsigned;
8521 if (decimal_point_char !=
'.' && decimal_point_position != std::string::npos)
8523 token_buffer[decimal_point_position] =
'.';
8525 return token_buffer;
8545 for (
const auto c : token_string)
8547 if (
static_cast<unsigned char>(c) <=
'\x1F')
8550 std::array<char, 9> cs{{}};
8551 static_cast<void>((std::snprintf)(cs.data(), cs.size(),
"<U+%.4X>",
static_cast<unsigned char>(c)));
8552 result += cs.data();
8557 result.push_back(
static_cast<std::string::value_type
>(c));
8565 JSON_HEDLEY_RETURNS_NON_NULL
8568 return error_message;
8584 return get() == 0xBB && get() == 0xBF;
8593 void skip_whitespace()
8599 while (current ==
' ' || current ==
'\t' || current ==
'\n' || current ==
'\r');
8605 if (position.chars_read_total == 0 && !
skip_bom())
8607 error_message =
"invalid BOM; must be 0xEF 0xBB 0xBF if given";
8608 return token_type::parse_error;
8615 while (ignore_comments && current ==
'/')
8617 if (!scan_comment())
8619 return token_type::parse_error;
8630 return token_type::begin_array;
8632 return token_type::end_array;
8634 return token_type::begin_object;
8636 return token_type::end_object;
8638 return token_type::name_separator;
8640 return token_type::value_separator;
8645 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')}};
8646 return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
8650 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')}};
8651 return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
8655 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')}};
8656 return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
8661 return scan_string();
8675 return scan_number();
8680 case char_traits<char_type>::eof():
8685 error_message =
"invalid literal";
8686 return token_type::parse_error;
8692 InputAdapterType ia;
8695 const bool ignore_comments =
false;
8698 char_int_type current = char_traits<char_type>::eof();
8701 bool next_unget =
false;
8704 position_t position {};
8707 std::vector<char_type> token_string {};
8710 string_t token_buffer {};
8713 const char* error_message =
"";
8716 number_integer_t value_integer = 0;
8717 number_unsigned_t value_unsigned = 0;
8718 number_float_t value_float = 0;
8721 const char_int_type decimal_point_char =
'.';
8723 std::size_t decimal_point_position = std::string::npos;
8727NLOHMANN_JSON_NAMESPACE_END
8733NLOHMANN_JSON_NAMESPACE_BEGIN
8743template<
typename BasicJsonType>
8746 using number_integer_t =
typename BasicJsonType::number_integer_t;
8747 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8748 using number_float_t =
typename BasicJsonType::number_float_t;
8749 using string_t =
typename BasicJsonType::string_t;
8750 using binary_t =
typename BasicJsonType::binary_t;
8817 virtual bool key(string_t& val) = 0;
8847 const std::string& last_token,
8850 json_sax() =
default;
8851 json_sax(
const json_sax&) =
default;
8852 json_sax(json_sax&&) noexcept = default;
8853 json_sax& operator=(const json_sax&) = default;
8854 json_sax& operator=(json_sax&&) noexcept = default;
8855 virtual ~json_sax() = default;
8860constexpr std::size_t unknown_size()
8862 return (std::numeric_limits<std::size_t>::max)();
8878template<
typename BasicJsonType,
typename InputAdapterType>
8882 using number_integer_t =
typename BasicJsonType::number_integer_t;
8883 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8884 using number_float_t =
typename BasicJsonType::number_float_t;
8885 using string_t =
typename BasicJsonType::string_t;
8886 using binary_t =
typename BasicJsonType::binary_t;
8894 explicit json_sax_dom_parser(BasicJsonType& r,
const bool allow_exceptions_ =
true, lexer_t* lexer_ =
nullptr)
8895 : root(r), allow_exceptions(allow_exceptions_), m_lexer_ref(lexer_)
8907 handle_value(
nullptr);
8911 bool boolean(
bool val)
8929 bool number_float(number_float_t val,
const string_t& )
8935 bool string(string_t& val)
8941 bool binary(binary_t& val)
8943 handle_value(std::move(val));
8947 bool start_object(std::size_t len)
8949 ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
8951#if JSON_DIAGNOSTIC_POSITIONS
8958 ref_stack.back()->start_position = m_lexer_ref->get_position() - 1;
8962 if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
8964 JSON_THROW(out_of_range::create(408, concat(
"excessive object size: ", std::to_string(len)), ref_stack.back()));
8970 bool key(string_t& val)
8972 JSON_ASSERT(!ref_stack.empty());
8973 JSON_ASSERT(ref_stack.back()->is_object());
8976 object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val));
8982 JSON_ASSERT(!ref_stack.empty());
8983 JSON_ASSERT(ref_stack.back()->is_object());
8985#if JSON_DIAGNOSTIC_POSITIONS
8989 ref_stack.back()->end_position = m_lexer_ref->get_position();
8993 ref_stack.back()->set_parents();
8994 ref_stack.pop_back();
8998 bool start_array(std::size_t len)
9000 ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
9002#if JSON_DIAGNOSTIC_POSITIONS
9007 ref_stack.back()->start_position = m_lexer_ref->get_position() - 1;
9011 if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
9013 JSON_THROW(out_of_range::create(408, concat(
"excessive array size: ", std::to_string(len)), ref_stack.back()));
9021 JSON_ASSERT(!ref_stack.empty());
9022 JSON_ASSERT(ref_stack.back()->is_array());
9024#if JSON_DIAGNOSTIC_POSITIONS
9028 ref_stack.back()->end_position = m_lexer_ref->get_position();
9032 ref_stack.back()->set_parents();
9033 ref_stack.pop_back();
9037 template<
class Exception>
9038 bool parse_error(std::size_t ,
const std::string& ,
9039 const Exception& ex)
9042 static_cast<void>(ex);
9043 if (allow_exceptions)
9050 constexpr bool is_errored()
const
9057#if JSON_DIAGNOSTIC_POSITIONS
9058 void handle_diagnostic_positions_for_json_value(BasicJsonType& v)
9065 v.end_position = m_lexer_ref->get_position();
9069 case value_t::boolean:
9072 v.start_position = v.end_position - (v.m_data.m_value.boolean ? 4 : 5);
9079 v.start_position = v.end_position - 4;
9083 case value_t::string:
9086 v.start_position = v.end_position - v.m_data.m_value.string->size() - 2;
9095 case value_t::discarded:
9097 v.end_position = std::string::npos;
9098 v.start_position = v.end_position;
9102 case value_t::binary:
9103 case value_t::number_integer:
9104 case value_t::number_unsigned:
9105 case value_t::number_float:
9107 v.start_position = v.end_position - m_lexer_ref->get_string().size();
9110 case value_t::object:
9111 case value_t::array:
9131 template<
typename Value>
9132 JSON_HEDLEY_RETURNS_NON_NULL
9133 BasicJsonType* handle_value(Value&& v)
9135 if (ref_stack.empty())
9137 root = BasicJsonType(std::forward<Value>(v));
9139#if JSON_DIAGNOSTIC_POSITIONS
9140 handle_diagnostic_positions_for_json_value(root);
9146 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
9148 if (ref_stack.back()->is_array())
9150 ref_stack.back()->m_data.m_value.array->emplace_back(std::forward<Value>(v));
9152#if JSON_DIAGNOSTIC_POSITIONS
9153 handle_diagnostic_positions_for_json_value(ref_stack.back()->m_data.m_value.array->back());
9156 return &(ref_stack.back()->m_data.m_value.array->back());
9159 JSON_ASSERT(ref_stack.back()->is_object());
9160 JSON_ASSERT(object_element);
9161 *object_element = BasicJsonType(std::forward<Value>(v));
9163#if JSON_DIAGNOSTIC_POSITIONS
9164 handle_diagnostic_positions_for_json_value(*object_element);
9167 return object_element;
9171 BasicJsonType& root;
9173 std::vector<BasicJsonType*> ref_stack {};
9175 BasicJsonType* object_element =
nullptr;
9177 bool errored =
false;
9179 const bool allow_exceptions =
true;
9181 lexer_t* m_lexer_ref =
nullptr;
9184template<
typename BasicJsonType,
typename InputAdapterType>
9185class json_sax_dom_callback_parser
9188 using number_integer_t =
typename BasicJsonType::number_integer_t;
9189 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9190 using number_float_t =
typename BasicJsonType::number_float_t;
9191 using string_t =
typename BasicJsonType::string_t;
9192 using binary_t =
typename BasicJsonType::binary_t;
9193 using parser_callback_t =
typename BasicJsonType::parser_callback_t;
9194 using parse_event_t =
typename BasicJsonType::parse_event_t;
9197 json_sax_dom_callback_parser(BasicJsonType& r,
9198 parser_callback_t cb,
9199 const bool allow_exceptions_ =
true,
9200 lexer_t* lexer_ =
nullptr)
9201 : root(r), callback(std::move(cb)), allow_exceptions(allow_exceptions_), m_lexer_ref(lexer_)
9203 keep_stack.push_back(
true);
9207 json_sax_dom_callback_parser(
const json_sax_dom_callback_parser&) =
delete;
9208 json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) =
default;
9209 json_sax_dom_callback_parser& operator=(
const json_sax_dom_callback_parser&) =
delete;
9210 json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) =
default;
9211 ~json_sax_dom_callback_parser() =
default;
9215 handle_value(
nullptr);
9219 bool boolean(
bool val)
9225 bool number_integer(number_integer_t val)
9231 bool number_unsigned(number_unsigned_t val)
9237 bool number_float(number_float_t val,
const string_t& )
9243 bool string(string_t& val)
9249 bool binary(binary_t& val)
9251 handle_value(std::move(val));
9255 bool start_object(std::size_t len)
9259 keep_stack.push_back(keep);
9261 auto val = handle_value(BasicJsonType::value_t::object,
true);
9262 ref_stack.push_back(val.second);
9264 if (ref_stack.back())
9267#if JSON_DIAGNOSTIC_POSITIONS
9274 ref_stack.back()->start_position = m_lexer_ref->get_position() - 1;
9279 if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
9281 JSON_THROW(out_of_range::create(408, concat(
"excessive object size: ", std::to_string(len)), ref_stack.back()));
9287 bool key(string_t& val)
9289 BasicJsonType k = BasicJsonType(val);
9292 const bool keep = callback(
static_cast<int>(ref_stack.size()),
parse_event_t::key, k);
9293 key_keep_stack.push_back(keep);
9296 if (keep && ref_stack.back())
9298 object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val) = discarded);
9306 if (ref_stack.back())
9311 *ref_stack.back() = discarded;
9313#if JSON_DIAGNOSTIC_POSITIONS
9315 handle_diagnostic_positions_for_json_value(*ref_stack.back());
9321#if JSON_DIAGNOSTIC_POSITIONS
9325 ref_stack.back()->end_position = m_lexer_ref->get_position();
9329 ref_stack.back()->set_parents();
9333 JSON_ASSERT(!ref_stack.empty());
9334 JSON_ASSERT(!keep_stack.empty());
9335 ref_stack.pop_back();
9336 keep_stack.pop_back();
9338 if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
9341 for (
auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
9343 if (it->is_discarded())
9345 ref_stack.back()->erase(it);
9354 bool start_array(std::size_t len)
9357 keep_stack.push_back(keep);
9359 auto val = handle_value(BasicJsonType::value_t::array,
true);
9360 ref_stack.push_back(val.second);
9362 if (ref_stack.back())
9365#if JSON_DIAGNOSTIC_POSITIONS
9372 ref_stack.back()->start_position = m_lexer_ref->get_position() - 1;
9377 if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
9379 JSON_THROW(out_of_range::create(408, concat(
"excessive array size: ", std::to_string(len)), ref_stack.back()));
9390 if (ref_stack.back())
9396#if JSON_DIAGNOSTIC_POSITIONS
9400 ref_stack.back()->end_position = m_lexer_ref->get_position();
9404 ref_stack.back()->set_parents();
9409 *ref_stack.back() = discarded;
9411#if JSON_DIAGNOSTIC_POSITIONS
9413 handle_diagnostic_positions_for_json_value(*ref_stack.back());
9418 JSON_ASSERT(!ref_stack.empty());
9419 JSON_ASSERT(!keep_stack.empty());
9420 ref_stack.pop_back();
9421 keep_stack.pop_back();
9424 if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
9426 ref_stack.back()->m_data.m_value.array->pop_back();
9432 template<
class Exception>
9433 bool parse_error(std::size_t ,
const std::string& ,
9434 const Exception& ex)
9437 static_cast<void>(ex);
9438 if (allow_exceptions)
9445 constexpr bool is_errored()
const
9452#if JSON_DIAGNOSTIC_POSITIONS
9453 void handle_diagnostic_positions_for_json_value(BasicJsonType& v)
9460 v.end_position = m_lexer_ref->get_position();
9467 v.start_position = v.end_position - (v.m_data.m_value.boolean ? 4 : 5);
9474 v.start_position = v.end_position - 4;
9481 v.start_position = v.end_position - v.m_data.m_value.string->size() - 2;
9487 v.end_position = std::string::npos;
9488 v.start_position = v.end_position;
9497 v.start_position = v.end_position - m_lexer_ref->get_string().size();
9531 template<
typename Value>
9532 std::pair<bool, BasicJsonType*> handle_value(Value&& v,
const bool skip_callback =
false)
9534 JSON_ASSERT(!keep_stack.empty());
9538 if (!keep_stack.back())
9540 return {
false,
nullptr};
9544 auto value = BasicJsonType(std::forward<Value>(v));
9546#if JSON_DIAGNOSTIC_POSITIONS
9547 handle_diagnostic_positions_for_json_value(value);
9551 const bool keep = skip_callback || callback(
static_cast<int>(ref_stack.size()),
parse_event_t::value, value);
9556 return {
false,
nullptr};
9559 if (ref_stack.empty())
9561 root = std::move(value);
9562 return {
true, & root};
9567 if (!ref_stack.back())
9569 return {
false,
nullptr};
9573 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
9576 if (ref_stack.back()->is_array())
9578 ref_stack.back()->m_data.m_value.array->emplace_back(std::move(value));
9579 return {
true, & (ref_stack.back()->m_data.m_value.array->back())};
9583 JSON_ASSERT(ref_stack.back()->is_object());
9585 JSON_ASSERT(!key_keep_stack.empty());
9586 const bool store_element = key_keep_stack.back();
9587 key_keep_stack.pop_back();
9591 return {
false,
nullptr};
9594 JSON_ASSERT(object_element);
9595 *object_element = std::move(value);
9596 return {
true, object_element};
9600 BasicJsonType& root;
9602 std::vector<BasicJsonType*> ref_stack {};
9604 std::vector<bool> keep_stack {};
9606 std::vector<bool> key_keep_stack {};
9608 BasicJsonType* object_element =
nullptr;
9610 bool errored =
false;
9612 const parser_callback_t callback =
nullptr;
9614 const bool allow_exceptions =
true;
9616 BasicJsonType discarded = BasicJsonType::value_t::discarded;
9618 lexer_t* m_lexer_ref =
nullptr;
9621template<
typename BasicJsonType>
9625 using number_integer_t =
typename BasicJsonType::number_integer_t;
9626 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9627 using number_float_t =
typename BasicJsonType::number_float_t;
9628 using string_t =
typename BasicJsonType::string_t;
9629 using binary_t =
typename BasicJsonType::binary_t;
9641 bool number_integer(number_integer_t )
9646 bool number_unsigned(number_unsigned_t )
9651 bool number_float(number_float_t ,
const string_t& )
9656 bool string(string_t& )
9661 bool binary(binary_t& )
9666 bool start_object(std::size_t = detail::unknown_size())
9671 bool key(string_t& )
9681 bool start_array(std::size_t = detail::unknown_size())
9698NLOHMANN_JSON_NAMESPACE_END
9726NLOHMANN_JSON_NAMESPACE_BEGIN
9731using null_function_t =
decltype(std::declval<T&>().null());
9734using boolean_function_t =
9735 decltype(std::declval<T&>().boolean(std::declval<bool>()));
9737template<
typename T,
typename Integer>
9738using number_integer_function_t =
9739 decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
9741template<
typename T,
typename Un
signed>
9742using number_unsigned_function_t =
9743 decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
9745template<
typename T,
typename Float,
typename String>
9746using number_float_function_t =
decltype(std::declval<T&>().number_float(
9747 std::declval<Float>(), std::declval<const String&>()));
9749template<
typename T,
typename String>
9750using string_function_t =
9751 decltype(std::declval<T&>().string(std::declval<String&>()));
9753template<
typename T,
typename Binary>
9754using binary_function_t =
9755 decltype(std::declval<T&>().binary(std::declval<Binary&>()));
9758using start_object_function_t =
9759 decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
9761template<
typename T,
typename String>
9762using key_function_t =
9763 decltype(std::declval<T&>().key(std::declval<String&>()));
9766using end_object_function_t =
decltype(std::declval<T&>().end_object());
9769using start_array_function_t =
9770 decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
9773using end_array_function_t =
decltype(std::declval<T&>().end_array());
9775template<
typename T,
typename Exception>
9776using parse_error_function_t =
decltype(std::declval<T&>().parse_error(
9777 std::declval<std::size_t>(), std::declval<const std::string&>(),
9778 std::declval<const Exception&>()));
9780template<
typename SAX,
typename BasicJsonType>
9785 "BasicJsonType must be of type basic_json<...>");
9787 using number_integer_t =
typename BasicJsonType::number_integer_t;
9788 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9789 using number_float_t =
typename BasicJsonType::number_float_t;
9790 using string_t =
typename BasicJsonType::string_t;
9791 using binary_t =
typename BasicJsonType::binary_t;
9792 using exception_t =
typename BasicJsonType::exception;
9795 static constexpr bool value =
9796 is_detected_exact<bool, null_function_t, SAX>::value &&
9797 is_detected_exact<bool, boolean_function_t, SAX>::value &&
9798 is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
9799 is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
9800 is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
9801 is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
9802 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
9803 is_detected_exact<bool, start_object_function_t, SAX>::value &&
9804 is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
9805 is_detected_exact<bool, end_object_function_t, SAX>::value &&
9806 is_detected_exact<bool, start_array_function_t, SAX>::value &&
9807 is_detected_exact<bool, end_array_function_t, SAX>::value &&
9808 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
9811template<
typename SAX,
typename BasicJsonType>
9816 "BasicJsonType must be of type basic_json<...>");
9818 using number_integer_t =
typename BasicJsonType::number_integer_t;
9819 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9820 using number_float_t =
typename BasicJsonType::number_float_t;
9821 using string_t =
typename BasicJsonType::string_t;
9822 using binary_t =
typename BasicJsonType::binary_t;
9823 using exception_t =
typename BasicJsonType::exception;
9826 static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
9827 "Missing/invalid function: bool null()");
9828 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
9829 "Missing/invalid function: bool boolean(bool)");
9830 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
9831 "Missing/invalid function: bool boolean(bool)");
9833 is_detected_exact<bool, number_integer_function_t, SAX,
9834 number_integer_t>::value,
9835 "Missing/invalid function: bool number_integer(number_integer_t)");
9837 is_detected_exact<bool, number_unsigned_function_t, SAX,
9838 number_unsigned_t>::value,
9839 "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
9840 static_assert(is_detected_exact<bool, number_float_function_t, SAX,
9841 number_float_t, string_t>::value,
9842 "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
9844 is_detected_exact<bool, string_function_t, SAX, string_t>::value,
9845 "Missing/invalid function: bool string(string_t&)");
9847 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
9848 "Missing/invalid function: bool binary(binary_t&)");
9849 static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
9850 "Missing/invalid function: bool start_object(std::size_t)");
9851 static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
9852 "Missing/invalid function: bool key(string_t&)");
9853 static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
9854 "Missing/invalid function: bool end_object()");
9855 static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
9856 "Missing/invalid function: bool start_array(std::size_t)");
9857 static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
9858 "Missing/invalid function: bool end_array()");
9860 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
9861 "Missing/invalid function: bool parse_error(std::size_t, const "
9862 "std::string&, const exception&)");
9866NLOHMANN_JSON_NAMESPACE_END
9875NLOHMANN_JSON_NAMESPACE_BEGIN
9896 return *
reinterpret_cast<char*
>(&num) == 1;
9906template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX = json_sax_dom_parser<BasicJsonType, InputAdapterType>>
9909 using number_integer_t =
typename BasicJsonType::number_integer_t;
9910 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9911 using number_float_t =
typename BasicJsonType::number_float_t;
9912 using string_t =
typename BasicJsonType::string_t;
9913 using binary_t =
typename BasicJsonType::binary_t;
9914 using json_sax_t = SAX;
9915 using char_type =
typename InputAdapterType::char_type;
9924 explicit binary_reader(InputAdapterType&& adapter,
const input_format_t format = input_format_t::json) noexcept : ia(std::move(adapter)), input_format(format)
9944 JSON_HEDLEY_NON_NULL(3)
9947 const
bool strict = true,
9951 bool result =
false;
9955 case input_format_t::bson:
9956 result = parse_bson_internal();
9959 case input_format_t::cbor:
9960 result = parse_cbor_internal(
true, tag_handler);
9963 case input_format_t::msgpack:
9964 result = parse_msgpack_internal();
9967 case input_format_t::ubjson:
9968 case input_format_t::bjdata:
9969 result = parse_ubjson_internal();
9972 case input_format_t::json:
9980 if (input_format == input_format_t::ubjson || input_format == input_format_t::bjdata)
9991 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(110, chars_read,
9992 exception_message(input_format, concat(
"expected end of input; last byte: 0x", get_token_string()),
"value"),
nullptr));
10008 bool parse_bson_internal()
10010 std::int32_t document_size{};
10011 get_number<std::int32_t, true>(input_format_t::bson, document_size);
10013 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
10018 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
false)))
10023 return sax->end_object();
10033 bool get_bson_cstr(string_t& result)
10035 auto out = std::back_inserter(result);
10039 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"cstring")))
10043 if (current == 0x00)
10047 *out++ =
static_cast<typename string_t::value_type
>(current);
10062 template<
typename NumberType>
10063 bool get_bson_string(
const NumberType len, string_t& result)
10065 if (JSON_HEDLEY_UNLIKELY(len < 1))
10067 auto last_token = get_token_string();
10068 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
10069 exception_message(input_format_t::bson, concat(
"string length must be at least 1, is ", std::to_string(len)),
"string"),
nullptr));
10072 return get_string(input_format_t::bson, len -
static_cast<NumberType
>(1), result) && get() != char_traits<char_type>::eof();
10084 template<
typename NumberType>
10085 bool get_bson_binary(
const NumberType len, binary_t& result)
10087 if (JSON_HEDLEY_UNLIKELY(len < 0))
10089 auto last_token = get_token_string();
10090 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
10091 exception_message(input_format_t::bson, concat(
"byte array length cannot be negative, is ", std::to_string(len)),
"binary"),
nullptr));
10095 std::uint8_t subtype{};
10096 get_number<std::uint8_t>(input_format_t::bson, subtype);
10097 result.set_subtype(subtype);
10099 return get_binary(input_format_t::bson, len, result);
10112 bool parse_bson_element_internal(
const char_int_type element_type,
10113 const std::size_t element_type_parse_position)
10115 switch (element_type)
10120 return get_number<double, true>(input_format_t::bson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10125 std::int32_t len{};
10127 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
10132 return parse_bson_internal();
10137 return parse_bson_array();
10142 std::int32_t len{};
10144 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
10149 return sax->boolean(get() != 0);
10154 return sax->null();
10159 std::int32_t value{};
10160 return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
10165 std::int64_t value{};
10166 return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
10171 std::uint64_t value{};
10172 return get_number<std::uint64_t, true>(input_format_t::bson, value) && sax->number_unsigned(value);
10177 std::array<char, 3> cr{{}};
10178 static_cast<void>((std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(element_type)));
10179 const std::string cr_str{cr.data()};
10180 return sax->parse_error(element_type_parse_position, cr_str,
10181 parse_error::create(114, element_type_parse_position, concat(
"Unsupported BSON record type 0x", cr_str),
nullptr));
10198 bool parse_bson_element_list(
const bool is_array)
10202 while (
auto element_type = get())
10204 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"element list")))
10209 const std::size_t element_type_parse_position = chars_read;
10210 if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key)))
10215 if (!is_array && !sax->key(key))
10220 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
10236 bool parse_bson_array()
10238 std::int32_t document_size{};
10239 get_number<std::int32_t, true>(input_format_t::bson, document_size);
10241 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
10246 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
true)))
10251 return sax->end_array();
10266 bool parse_cbor_internal(
const bool get_char,
10267 const cbor_tag_handler_t tag_handler)
10269 switch (get_char ? get() : current)
10272 case char_traits<char_type>::eof():
10300 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
10304 std::uint8_t number{};
10305 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
10310 std::uint16_t number{};
10311 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
10316 std::uint32_t number{};
10317 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
10322 std::uint64_t number{};
10323 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
10351 return sax->number_integer(
static_cast<std::int8_t
>(0x20 - 1 - current));
10355 std::uint8_t number{};
10356 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
10361 std::uint16_t number{};
10362 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
10367 std::uint32_t number{};
10368 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
10373 std::uint64_t number{};
10374 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1)
10375 -
static_cast<number_integer_t
>(number));
10410 return get_cbor_binary(b) && sax->binary(b);
10445 return get_cbor_string(s) && sax->string(s);
10473 return get_cbor_array(
10474 conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
10478 std::uint8_t len{};
10479 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
10484 std::uint16_t len{};
10485 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
10490 std::uint32_t len{};
10491 return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
10496 std::uint64_t len{};
10497 return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
10501 return get_cbor_array(detail::unknown_size(), tag_handler);
10528 return get_cbor_object(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
10532 std::uint8_t len{};
10533 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
10538 std::uint16_t len{};
10539 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
10544 std::uint32_t len{};
10545 return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
10550 std::uint64_t len{};
10551 return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
10555 return get_cbor_object(detail::unknown_size(), tag_handler);
10577 switch (tag_handler)
10579 case cbor_tag_handler_t::error:
10581 auto last_token = get_token_string();
10582 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
10583 exception_message(input_format_t::cbor, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
10586 case cbor_tag_handler_t::ignore:
10593 std::uint8_t subtype_to_ignore{};
10594 get_number(input_format_t::cbor, subtype_to_ignore);
10599 std::uint16_t subtype_to_ignore{};
10600 get_number(input_format_t::cbor, subtype_to_ignore);
10605 std::uint32_t subtype_to_ignore{};
10606 get_number(input_format_t::cbor, subtype_to_ignore);
10611 std::uint64_t subtype_to_ignore{};
10612 get_number(input_format_t::cbor, subtype_to_ignore);
10618 return parse_cbor_internal(
true, tag_handler);
10621 case cbor_tag_handler_t::store:
10629 std::uint8_t subtype{};
10630 get_number(input_format_t::cbor, subtype);
10631 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
10636 std::uint16_t subtype{};
10637 get_number(input_format_t::cbor, subtype);
10638 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
10643 std::uint32_t subtype{};
10644 get_number(input_format_t::cbor, subtype);
10645 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
10650 std::uint64_t subtype{};
10651 get_number(input_format_t::cbor, subtype);
10652 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
10656 return parse_cbor_internal(
true, tag_handler);
10659 return get_cbor_binary(b) && sax->binary(b);
10663 JSON_ASSERT(
false);
10669 return sax->boolean(
false);
10672 return sax->boolean(
true);
10675 return sax->null();
10679 const auto byte1_raw = get();
10680 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
10684 const auto byte2_raw = get();
10685 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
10690 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
10691 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
10701 const auto half =
static_cast<unsigned int>((byte1 << 8u) + byte2);
10702 const double val = [&half]
10704 const int exp = (half >> 10u) & 0x1Fu;
10705 const unsigned int mant = half & 0x3FFu;
10706 JSON_ASSERT(0 <= exp&& exp <= 32);
10707 JSON_ASSERT(mant <= 1024);
10711 return std::ldexp(mant, -24);
10714 ? std::numeric_limits<double>::infinity()
10715 : std::numeric_limits<double>::quiet_NaN();
10717 return std::ldexp(mant + 1024, exp - 25);
10720 return sax->number_float((half & 0x8000u) != 0
10721 ?
static_cast<number_float_t
>(-val)
10722 :
static_cast<number_float_t
>(val),
"");
10728 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10734 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10739 auto last_token = get_token_string();
10740 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
10741 exception_message(input_format_t::cbor, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
10757 bool get_cbor_string(string_t& result)
10759 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"string")))
10792 return get_string(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
10797 std::uint8_t len{};
10798 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10803 std::uint16_t len{};
10804 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10809 std::uint32_t len{};
10810 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10815 std::uint64_t len{};
10816 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10821 while (get() != 0xFF)
10824 if (!get_cbor_string(chunk))
10828 result.append(chunk);
10835 auto last_token = get_token_string();
10836 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
10837 exception_message(input_format_t::cbor, concat(
"expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token),
"string"),
nullptr));
10853 bool get_cbor_binary(binary_t& result)
10855 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"binary")))
10888 return get_binary(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
10893 std::uint8_t len{};
10894 return get_number(input_format_t::cbor, len) &&
10895 get_binary(input_format_t::cbor, len, result);
10900 std::uint16_t len{};
10901 return get_number(input_format_t::cbor, len) &&
10902 get_binary(input_format_t::cbor, len, result);
10907 std::uint32_t len{};
10908 return get_number(input_format_t::cbor, len) &&
10909 get_binary(input_format_t::cbor, len, result);
10914 std::uint64_t len{};
10915 return get_number(input_format_t::cbor, len) &&
10916 get_binary(input_format_t::cbor, len, result);
10921 while (get() != 0xFF)
10924 if (!get_cbor_binary(chunk))
10928 result.insert(result.end(), chunk.begin(), chunk.end());
10935 auto last_token = get_token_string();
10936 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
10937 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));
10948 bool get_cbor_array(
const std::size_t len,
10949 const cbor_tag_handler_t tag_handler)
10951 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
10956 if (len != detail::unknown_size())
10958 for (std::size_t i = 0; i < len; ++i)
10960 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
10968 while (get() != 0xFF)
10970 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
false, tag_handler)))
10977 return sax->end_array();
10986 bool get_cbor_object(
const std::size_t len,
10987 const cbor_tag_handler_t tag_handler)
10989 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
10997 if (len != detail::unknown_size())
10999 for (std::size_t i = 0; i < len; ++i)
11002 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
11007 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
11016 while (get() != 0xFF)
11018 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
11023 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
11032 return sax->end_object();
11042 bool parse_msgpack_internal()
11047 case char_traits<char_type>::eof():
11179 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
11198 return get_msgpack_object(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x0Fu));
11217 return get_msgpack_array(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x0Fu));
11257 return get_msgpack_string(s) && sax->string(s);
11261 return sax->null();
11264 return sax->boolean(
false);
11267 return sax->boolean(
true);
11282 return get_msgpack_binary(b) && sax->binary(b);
11288 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
11294 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
11299 std::uint8_t number{};
11300 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
11305 std::uint16_t number{};
11306 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
11311 std::uint32_t number{};
11312 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
11317 std::uint64_t number{};
11318 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
11323 std::int8_t number{};
11324 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
11329 std::int16_t number{};
11330 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
11335 std::int32_t number{};
11336 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
11341 std::int64_t number{};
11342 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
11347 std::uint16_t len{};
11348 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
11353 std::uint32_t len{};
11354 return get_number(input_format_t::msgpack, len) && get_msgpack_array(conditional_static_cast<std::size_t>(len));
11359 std::uint16_t len{};
11360 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
11365 std::uint32_t len{};
11366 return get_number(input_format_t::msgpack, len) && get_msgpack_object(conditional_static_cast<std::size_t>(len));
11402 return sax->number_integer(
static_cast<std::int8_t
>(current));
11406 auto last_token = get_token_string();
11407 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
11408 exception_message(input_format_t::msgpack, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
11423 bool get_msgpack_string(string_t& result)
11425 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack,
"string")))
11466 return get_string(input_format_t::msgpack,
static_cast<unsigned int>(current) & 0x1Fu, result);
11471 std::uint8_t len{};
11472 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
11477 std::uint16_t len{};
11478 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
11483 std::uint32_t len{};
11484 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
11489 auto last_token = get_token_string();
11490 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
11491 exception_message(input_format_t::msgpack, concat(
"expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token),
"string"),
nullptr));
11506 bool get_msgpack_binary(binary_t& result)
11509 auto assign_and_return_true = [&result](std::int8_t subtype)
11511 result.set_subtype(
static_cast<std::uint8_t
>(subtype));
11519 std::uint8_t len{};
11520 return get_number(input_format_t::msgpack, len) &&
11521 get_binary(input_format_t::msgpack, len, result);
11526 std::uint16_t len{};
11527 return get_number(input_format_t::msgpack, len) &&
11528 get_binary(input_format_t::msgpack, len, result);
11533 std::uint32_t len{};
11534 return get_number(input_format_t::msgpack, len) &&
11535 get_binary(input_format_t::msgpack, len, result);
11540 std::uint8_t len{};
11541 std::int8_t subtype{};
11542 return get_number(input_format_t::msgpack, len) &&
11543 get_number(input_format_t::msgpack, subtype) &&
11544 get_binary(input_format_t::msgpack, len, result) &&
11545 assign_and_return_true(subtype);
11550 std::uint16_t len{};
11551 std::int8_t subtype{};
11552 return get_number(input_format_t::msgpack, len) &&
11553 get_number(input_format_t::msgpack, subtype) &&
11554 get_binary(input_format_t::msgpack, len, result) &&
11555 assign_and_return_true(subtype);
11560 std::uint32_t len{};
11561 std::int8_t subtype{};
11562 return get_number(input_format_t::msgpack, len) &&
11563 get_number(input_format_t::msgpack, subtype) &&
11564 get_binary(input_format_t::msgpack, len, result) &&
11565 assign_and_return_true(subtype);
11570 std::int8_t subtype{};
11571 return get_number(input_format_t::msgpack, subtype) &&
11572 get_binary(input_format_t::msgpack, 1, result) &&
11573 assign_and_return_true(subtype);
11578 std::int8_t subtype{};
11579 return get_number(input_format_t::msgpack, subtype) &&
11580 get_binary(input_format_t::msgpack, 2, result) &&
11581 assign_and_return_true(subtype);
11586 std::int8_t subtype{};
11587 return get_number(input_format_t::msgpack, subtype) &&
11588 get_binary(input_format_t::msgpack, 4, result) &&
11589 assign_and_return_true(subtype);
11594 std::int8_t subtype{};
11595 return get_number(input_format_t::msgpack, subtype) &&
11596 get_binary(input_format_t::msgpack, 8, result) &&
11597 assign_and_return_true(subtype);
11602 std::int8_t subtype{};
11603 return get_number(input_format_t::msgpack, subtype) &&
11604 get_binary(input_format_t::msgpack, 16, result) &&
11605 assign_and_return_true(subtype);
11617 bool get_msgpack_array(
const std::size_t len)
11619 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
11624 for (std::size_t i = 0; i < len; ++i)
11626 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
11632 return sax->end_array();
11639 bool get_msgpack_object(
const std::size_t len)
11641 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
11647 for (std::size_t i = 0; i < len; ++i)
11650 if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key)))
11655 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
11662 return sax->end_object();
11676 bool parse_ubjson_internal(
const bool get_char =
true)
11678 return get_ubjson_value(get_char ? get_ignore_noop() : current);
11695 bool get_ubjson_string(string_t& result,
const bool get_char =
true)
11702 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"value")))
11711 std::uint8_t len{};
11712 return get_number(input_format, len) && get_string(input_format, len, result);
11718 return get_number(input_format, len) && get_string(input_format, len, result);
11723 std::int16_t len{};
11724 return get_number(input_format, len) && get_string(input_format, len, result);
11729 std::int32_t len{};
11730 return get_number(input_format, len) && get_string(input_format, len, result);
11735 std::int64_t len{};
11736 return get_number(input_format, len) && get_string(input_format, len, result);
11741 if (input_format != input_format_t::bjdata)
11745 std::uint16_t len{};
11746 return get_number(input_format, len) && get_string(input_format, len, result);
11751 if (input_format != input_format_t::bjdata)
11755 std::uint32_t len{};
11756 return get_number(input_format, len) && get_string(input_format, len, result);
11761 if (input_format != input_format_t::bjdata)
11765 std::uint64_t len{};
11766 return get_number(input_format, len) && get_string(input_format, len, result);
11772 auto last_token = get_token_string();
11773 std::string message;
11775 if (input_format != input_format_t::bjdata)
11777 message =
"expected length type specification (U, i, I, l, L); last byte: 0x" + last_token;
11781 message =
"expected length type specification (U, i, u, I, m, l, M, L); last byte: 0x" + last_token;
11783 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message,
"string"),
nullptr));
11790 bool get_ubjson_ndarray_size(std::vector<size_t>& dim)
11792 std::pair<std::size_t, char_int_type> size_and_type;
11794 bool no_ndarray =
true;
11796 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type, no_ndarray)))
11801 if (size_and_type.first != npos)
11803 if (size_and_type.second != 0)
11805 if (size_and_type.second !=
'N')
11807 for (std::size_t i = 0; i < size_and_type.first; ++i)
11809 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, size_and_type.second)))
11813 dim.push_back(dimlen);
11819 for (std::size_t i = 0; i < size_and_type.first; ++i)
11821 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray)))
11825 dim.push_back(dimlen);
11831 while (current !=
']')
11833 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, current)))
11837 dim.push_back(dimlen);
11855 bool get_ubjson_size_value(std::size_t& result,
bool& is_ndarray, char_int_type prefix = 0)
11859 prefix = get_ignore_noop();
11866 std::uint8_t number{};
11867 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11871 result =
static_cast<std::size_t
>(number);
11877 std::int8_t number{};
11878 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11884 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11885 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11887 result =
static_cast<std::size_t
>(number);
11893 std::int16_t number{};
11894 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11900 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11901 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11903 result =
static_cast<std::size_t
>(number);
11909 std::int32_t number{};
11910 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11916 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11917 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11919 result =
static_cast<std::size_t
>(number);
11925 std::int64_t number{};
11926 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11932 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11933 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11935 if (!value_in_range_of<std::size_t>(number))
11937 return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,
11938 exception_message(input_format,
"integer value overflow",
"size"),
nullptr));
11940 result =
static_cast<std::size_t
>(number);
11946 if (input_format != input_format_t::bjdata)
11950 std::uint16_t number{};
11951 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11955 result =
static_cast<std::size_t
>(number);
11961 if (input_format != input_format_t::bjdata)
11965 std::uint32_t number{};
11966 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11970 result = conditional_static_cast<std::size_t>(number);
11976 if (input_format != input_format_t::bjdata)
11980 std::uint64_t number{};
11981 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11985 if (!value_in_range_of<std::size_t>(number))
11987 return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,
11988 exception_message(input_format,
"integer value overflow",
"size"),
nullptr));
11990 result = detail::conditional_static_cast<std::size_t>(number);
11996 if (input_format != input_format_t::bjdata)
12002 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));
12004 std::vector<size_t> dim;
12005 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_ndarray_size(dim)))
12009 if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1))
12011 result = dim.at(dim.size() - 1);
12025 string_t
key =
"_ArraySize_";
12026 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(3) || !sax->key(key) || !sax->start_array(dim.size())))
12036 if (JSON_HEDLEY_UNLIKELY(i > 0 && result > (std::numeric_limits<std::size_t>::max)() / i))
12038 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));
12042 if (result == 0 || result == npos)
12044 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));
12046 if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(
static_cast<number_unsigned_t
>(i))))
12052 return sax->end_array();
12061 auto last_token = get_token_string();
12062 std::string message;
12064 if (input_format != input_format_t::bjdata)
12066 message =
"expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token;
12070 message =
"expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x" + last_token;
12072 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message,
"size"),
nullptr));
12086 bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result,
bool inside_ndarray =
false)
12088 result.first = npos;
12090 bool is_ndarray =
false;
12094 if (current ==
'$')
12096 result.second = get();
12097 if (input_format == input_format_t::bjdata
12098 && JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second)))
12100 auto last_token = get_token_string();
12101 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
12102 exception_message(input_format, concat(
"marker 0x", last_token,
" is not a permitted optimized array type"),
"type"),
nullptr));
12105 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"type")))
12111 if (JSON_HEDLEY_UNLIKELY(current !=
'#'))
12113 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"value")))
12117 auto last_token = get_token_string();
12118 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
12119 exception_message(input_format, concat(
"expected '#' after type information; last byte: 0x", last_token),
"size"),
nullptr));
12122 const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
12123 if (input_format == input_format_t::bjdata && is_ndarray)
12125 if (inside_ndarray)
12127 return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
12128 exception_message(input_format,
"ndarray can not be recursive",
"size"),
nullptr));
12130 result.second |= (1 << 8);
12135 if (current ==
'#')
12137 const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
12138 if (input_format == input_format_t::bjdata && is_ndarray)
12140 return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
12141 exception_message(input_format,
"ndarray requires both type and size",
"size"),
nullptr));
12153 bool get_ubjson_value(
const char_int_type prefix)
12157 case char_traits<char_type>::eof():
12158 return unexpect_eof(input_format,
"value");
12161 return sax->boolean(
true);
12163 return sax->boolean(
false);
12166 return sax->null();
12170 if (input_format != input_format_t::bjdata)
12174 std::uint8_t number{};
12175 return get_number(input_format, number) && sax->number_unsigned(number);
12180 std::uint8_t number{};
12181 return get_number(input_format, number) && sax->number_unsigned(number);
12186 std::int8_t number{};
12187 return get_number(input_format, number) && sax->number_integer(number);
12192 std::int16_t number{};
12193 return get_number(input_format, number) && sax->number_integer(number);
12198 std::int32_t number{};
12199 return get_number(input_format, number) && sax->number_integer(number);
12204 std::int64_t number{};
12205 return get_number(input_format, number) && sax->number_integer(number);
12210 if (input_format != input_format_t::bjdata)
12214 std::uint16_t number{};
12215 return get_number(input_format, number) && sax->number_unsigned(number);
12220 if (input_format != input_format_t::bjdata)
12224 std::uint32_t number{};
12225 return get_number(input_format, number) && sax->number_unsigned(number);
12230 if (input_format != input_format_t::bjdata)
12234 std::uint64_t number{};
12235 return get_number(input_format, number) && sax->number_unsigned(number);
12240 if (input_format != input_format_t::bjdata)
12244 const auto byte1_raw = get();
12245 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
12249 const auto byte2_raw = get();
12250 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
12255 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
12256 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
12266 const auto half =
static_cast<unsigned int>((byte2 << 8u) + byte1);
12267 const double val = [&half]
12269 const int exp = (half >> 10u) & 0x1Fu;
12270 const unsigned int mant = half & 0x3FFu;
12271 JSON_ASSERT(0 <= exp&& exp <= 32);
12272 JSON_ASSERT(mant <= 1024);
12276 return std::ldexp(mant, -24);
12279 ? std::numeric_limits<double>::infinity()
12280 : std::numeric_limits<double>::quiet_NaN();
12282 return std::ldexp(mant + 1024, exp - 25);
12285 return sax->number_float((half & 0x8000u) != 0
12286 ?
static_cast<number_float_t
>(-val)
12287 :
static_cast<number_float_t
>(val),
"");
12293 return get_number(input_format, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
12299 return get_number(input_format, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
12304 return get_ubjson_high_precision_number();
12310 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"char")))
12314 if (JSON_HEDLEY_UNLIKELY(current > 127))
12316 auto last_token = get_token_string();
12317 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
12318 exception_message(input_format, concat(
"byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token),
"char"),
nullptr));
12320 string_t s(1,
static_cast<typename string_t::value_type
>(current));
12321 return sax->string(s);
12327 return get_ubjson_string(s) && sax->string(s);
12331 return get_ubjson_array();
12334 return get_ubjson_object();
12339 auto last_token = get_token_string();
12340 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));
12346 bool get_ubjson_array()
12348 std::pair<std::size_t, char_int_type> size_and_type;
12349 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
12357 if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
12359 size_and_type.second &= ~(
static_cast<char_int_type
>(1) << 8);
12360 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)
12362 return p.first < t;
12364 string_t
key =
"_ArrayType_";
12365 if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second))
12367 auto last_token = get_token_string();
12368 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
12369 exception_message(input_format,
"invalid byte: 0x" + last_token,
"type"),
nullptr));
12372 string_t type = it->second;
12373 if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type)))
12378 if (size_and_type.second ==
'C' || size_and_type.second ==
'B')
12380 size_and_type.second =
'U';
12383 key =
"_ArrayData_";
12384 if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->start_array(size_and_type.first) ))
12389 for (std::size_t i = 0; i < size_and_type.first; ++i)
12391 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
12397 return (sax->end_array() && sax->end_object());
12401 if (input_format == input_format_t::bjdata && size_and_type.first != npos && size_and_type.second ==
'B')
12404 return get_binary(input_format, size_and_type.first, result) && sax->binary(result);
12407 if (size_and_type.first != npos)
12409 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
12414 if (size_and_type.second != 0)
12416 if (size_and_type.second !=
'N')
12418 for (std::size_t i = 0; i < size_and_type.first; ++i)
12420 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
12429 for (std::size_t i = 0; i < size_and_type.first; ++i)
12431 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
12440 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
12445 while (current !=
']')
12447 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(
false)))
12455 return sax->end_array();
12461 bool get_ubjson_object()
12463 std::pair<std::size_t, char_int_type> size_and_type;
12464 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
12470 if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
12472 auto last_token = get_token_string();
12473 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
12474 exception_message(input_format,
"BJData object does not support ND-array size in optimized format",
"object"),
nullptr));
12478 if (size_and_type.first != npos)
12480 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))
12485 if (size_and_type.second != 0)
12487 for (std::size_t i = 0; i < size_and_type.first; ++i)
12489 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
12493 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
12502 for (std::size_t i = 0; i < size_and_type.first; ++i)
12504 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
12508 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
12518 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
12523 while (current !=
'}')
12525 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key,
false) || !sax->key(key)))
12529 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
12538 return sax->end_object();
12544 bool get_ubjson_high_precision_number()
12547 std::size_t size{};
12548 bool no_ndarray =
true;
12549 auto res = get_ubjson_size_value(size, no_ndarray);
12550 if (JSON_HEDLEY_UNLIKELY(!res))
12556 std::vector<char> number_vector;
12557 for (std::size_t i = 0; i < size; ++i)
12560 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
12564 number_vector.push_back(
static_cast<char>(current));
12568 using ia_type =
decltype(detail::input_adapter(number_vector));
12569 auto number_lexer = detail::lexer<BasicJsonType, ia_type>(detail::input_adapter(number_vector),
false);
12570 const auto result_number = number_lexer.scan();
12571 const auto number_string = number_lexer.get_token_string();
12572 const auto result_remainder = number_lexer.scan();
12576 if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
12578 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
12579 exception_message(input_format, concat(
"invalid number text: ", number_lexer.get_token_string()),
"high-precision number"),
nullptr));
12582 switch (result_number)
12584 case token_type::value_integer:
12585 return sax->number_integer(number_lexer.get_number_integer());
12586 case token_type::value_unsigned:
12587 return sax->number_unsigned(number_lexer.get_number_unsigned());
12588 case token_type::value_float:
12589 return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
12590 case token_type::uninitialized:
12591 case token_type::literal_true:
12592 case token_type::literal_false:
12593 case token_type::literal_null:
12594 case token_type::value_string:
12595 case token_type::begin_array:
12596 case token_type::begin_object:
12597 case token_type::end_array:
12598 case token_type::end_object:
12599 case token_type::name_separator:
12600 case token_type::value_separator:
12601 case token_type::parse_error:
12602 case token_type::end_of_input:
12603 case token_type::literal_or_value:
12605 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
12606 exception_message(input_format, concat(
"invalid number text: ", number_lexer.get_token_string()),
"high-precision number"),
nullptr));
12623 char_int_type get()
12626 return current = ia.get_character();
12638 bool get_to(T& dest,
const input_format_t format,
const char* context)
12640 auto new_chars_read = ia.get_elements(&dest);
12641 chars_read += new_chars_read;
12642 if (JSON_HEDLEY_UNLIKELY(new_chars_read <
sizeof(T)))
12646 sax->parse_error(chars_read,
"<end of file>", parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context),
nullptr));
12655 char_int_type get_ignore_noop()
12661 while (current ==
'N');
12666 template<
class NumberType>
12667 static void byte_swap(NumberType& number)
12669 constexpr std::size_t sz =
sizeof(number);
12670#ifdef __cpp_lib_byteswap
12671 if constexpr (sz == 1)
12675 else if constexpr(std::is_integral_v<NumberType>)
12677 number = std::byteswap(number);
12683 auto* ptr =
reinterpret_cast<std::uint8_t*
>(&number);
12684 for (std::size_t i = 0; i < sz / 2; ++i)
12686 std::swap(ptr[i], ptr[sz - i - 1]);
12688#ifdef __cpp_lib_byteswap
12708 template<
typename NumberType,
bool InputIsLittleEndian = false>
12709 bool get_number(
const input_format_t format, NumberType& result)
12713 if (JSON_HEDLEY_UNLIKELY(!get_to(result, format,
"number")))
12717 if (is_little_endian != (InputIsLittleEndian || format == input_format_t::bjdata))
12738 template<
typename NumberType>
12739 bool get_string(
const input_format_t format,
12740 const NumberType len,
12743 bool success =
true;
12744 for (NumberType i = 0; i < len; i++)
12747 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"string")))
12752 result.push_back(
static_cast<typename string_t::value_type
>(current));
12771 template<
typename NumberType>
12772 bool get_binary(
const input_format_t format,
12773 const NumberType len,
12776 bool success =
true;
12777 for (NumberType i = 0; i < len; i++)
12780 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"binary")))
12785 result.push_back(
static_cast<typename binary_t::value_type
>(current));
12795 JSON_HEDLEY_NON_NULL(3)
12796 bool unexpect_eof(const input_format_t format, const
char* context)
const
12798 if (JSON_HEDLEY_UNLIKELY(current == char_traits<char_type>::eof()))
12800 return sax->parse_error(chars_read,
"<end of file>",
12801 parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context),
nullptr));
12809 std::string get_token_string()
const
12811 std::array<char, 3> cr{{}};
12812 static_cast<void>((std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(current)));
12813 return std::string{cr.data()};
12822 std::string exception_message(
const input_format_t format,
12823 const std::string& detail,
12824 const std::string& context)
const
12826 std::string error_msg =
"syntax error while parsing ";
12830 case input_format_t::cbor:
12831 error_msg +=
"CBOR";
12834 case input_format_t::msgpack:
12835 error_msg +=
"MessagePack";
12838 case input_format_t::ubjson:
12839 error_msg +=
"UBJSON";
12842 case input_format_t::bson:
12843 error_msg +=
"BSON";
12846 case input_format_t::bjdata:
12847 error_msg +=
"BJData";
12850 case input_format_t::json:
12852 JSON_ASSERT(
false);
12855 return concat(error_msg,
' ', context,
": ", detail);
12859 static JSON_INLINE_VARIABLE
constexpr std::size_t npos = detail::unknown_size();
12862 InputAdapterType ia;
12865 char_int_type current = char_traits<char_type>::eof();
12868 std::size_t chars_read = 0;
12877 json_sax_t* sax =
nullptr;
12880#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ \
12881 make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
12883#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
12884 make_array<bjd_type>( \
12885 bjd_type{'B', "byte"}, \
12886 bjd_type{'C', "char"}, \
12887 bjd_type{'D', "double"}, \
12888 bjd_type{'I', "int16"}, \
12889 bjd_type{'L', "int64"}, \
12890 bjd_type{'M', "uint64"}, \
12891 bjd_type{'U', "uint8"}, \
12892 bjd_type{'d', "single"}, \
12893 bjd_type{'i', "int8"}, \
12894 bjd_type{'l', "int32"}, \
12895 bjd_type{'m', "uint32"}, \
12896 bjd_type{'u', "uint16"})
12898 JSON_PRIVATE_UNLESS_TESTED:
12901 const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers =
12902 JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_;
12904 using bjd_type = std::pair<char_int_type, string_t>;
12906 const decltype(JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_) bjd_types_map =
12907 JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_;
12909#undef JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_
12910#undef JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_
12913#ifndef JSON_HAS_CPP_17
12914 template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX>
12915 constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos;
12919NLOHMANN_JSON_NAMESPACE_END
12938#include <functional>
12960NLOHMANN_JSON_NAMESPACE_BEGIN
12983template<
typename BasicJsonType>
12984using parser_callback_t =
12985 std::function<bool(
int , parse_event_t , BasicJsonType& )>;
12992template<
typename BasicJsonType,
typename InputAdapterType>
12995 using number_integer_t =
typename BasicJsonType::number_integer_t;
12996 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
12997 using number_float_t =
typename BasicJsonType::number_float_t;
12998 using string_t =
typename BasicJsonType::string_t;
13000 using token_type =
typename lexer_t::token_type;
13005 parser_callback_t<BasicJsonType> cb =
nullptr,
13006 const bool allow_exceptions_ =
true,
13007 const bool ignore_comments =
false,
13008 const bool ignore_trailing_commas_ =
false)
13009 : callback(std::move(cb))
13010 , m_lexer(std::move(adapter), ignore_comments)
13011 , allow_exceptions(allow_exceptions_)
13012 , ignore_trailing_commas(ignore_trailing_commas_)
13033 sax_parse_internal(&sdp);
13036 if (
strict && (get_token() != token_type::end_of_input))
13038 sdp.parse_error(m_lexer.get_position(),
13039 m_lexer.get_token_string(),
13041 exception_message(token_type::end_of_input,
"value"),
nullptr));
13045 if (sdp.is_errored())
13053 if (result.is_discarded())
13061 sax_parse_internal(&sdp);
13064 if (
strict && (get_token() != token_type::end_of_input))
13066 sdp.parse_error(m_lexer.get_position(),
13067 m_lexer.get_token_string(),
13068 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"),
nullptr));
13072 if (sdp.is_errored())
13079 result.assert_invariant();
13091 return sax_parse(&sax_acceptor,
strict);
13094 template<
typename SAX>
13095 JSON_HEDLEY_NON_NULL(2)
13096 bool sax_parse(SAX* sax, const
bool strict = true)
13099 const bool result = sax_parse_internal(sax);
13102 if (result && strict && (get_token() != token_type::end_of_input))
13104 return sax->parse_error(m_lexer.get_position(),
13105 m_lexer.get_token_string(),
13106 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"),
nullptr));
13113 template<
typename SAX>
13114 JSON_HEDLEY_NON_NULL(2)
13115 bool sax_parse_internal(SAX* sax)
13119 std::vector<bool> states;
13121 bool skip_to_state_evaluation =
false;
13125 if (!skip_to_state_evaluation)
13128 switch (last_token)
13130 case token_type::begin_object:
13132 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
13138 if (get_token() == token_type::end_object)
13140 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
13148 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
13150 return sax->parse_error(m_lexer.get_position(),
13151 m_lexer.get_token_string(),
13152 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"),
nullptr));
13154 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
13160 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
13162 return sax->parse_error(m_lexer.get_position(),
13163 m_lexer.get_token_string(),
13164 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"),
nullptr));
13168 states.push_back(
false);
13175 case token_type::begin_array:
13177 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
13183 if (get_token() == token_type::end_array)
13185 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
13193 states.push_back(
true);
13199 case token_type::value_float:
13201 const auto res = m_lexer.get_number_float();
13203 if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))
13205 return sax->parse_error(m_lexer.get_position(),
13206 m_lexer.get_token_string(),
13207 out_of_range::create(406, concat(
"number overflow parsing '", m_lexer.get_token_string(),
'\''),
nullptr));
13210 if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
13218 case token_type::literal_false:
13220 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
false)))
13227 case token_type::literal_null:
13229 if (JSON_HEDLEY_UNLIKELY(!sax->null()))
13236 case token_type::literal_true:
13238 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
true)))
13245 case token_type::value_integer:
13247 if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer())))
13254 case token_type::value_string:
13256 if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))
13263 case token_type::value_unsigned:
13265 if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned())))
13272 case token_type::parse_error:
13275 return sax->parse_error(m_lexer.get_position(),
13276 m_lexer.get_token_string(),
13277 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized,
"value"),
nullptr));
13279 case token_type::end_of_input:
13281 if (JSON_HEDLEY_UNLIKELY(m_lexer.get_position().chars_read_total == 1))
13283 return sax->parse_error(m_lexer.get_position(),
13284 m_lexer.get_token_string(),
13285 parse_error::create(101, m_lexer.get_position(),
13286 "attempting to parse an empty input; check that your input string or stream contains the expected JSON",
nullptr));
13289 return sax->parse_error(m_lexer.get_position(),
13290 m_lexer.get_token_string(),
13291 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value,
"value"),
nullptr));
13293 case token_type::uninitialized:
13294 case token_type::end_array:
13295 case token_type::end_object:
13296 case token_type::name_separator:
13297 case token_type::value_separator:
13298 case token_type::literal_or_value:
13301 return sax->parse_error(m_lexer.get_position(),
13302 m_lexer.get_token_string(),
13303 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value,
"value"),
nullptr));
13309 skip_to_state_evaluation =
false;
13313 if (states.empty())
13323 if (get_token() == token_type::value_separator)
13329 if (!(ignore_trailing_commas && last_token == token_type::end_array))
13336 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
13338 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
13347 JSON_ASSERT(!states.empty());
13349 skip_to_state_evaluation =
true;
13353 return sax->parse_error(m_lexer.get_position(),
13354 m_lexer.get_token_string(),
13355 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array,
"array"),
nullptr));
13362 if (get_token() == token_type::value_separator)
13367 if (!(ignore_trailing_commas && last_token == token_type::end_object))
13370 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
13372 return sax->parse_error(m_lexer.get_position(),
13373 m_lexer.get_token_string(),
13374 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"),
nullptr));
13377 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
13383 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
13385 return sax->parse_error(m_lexer.get_position(),
13386 m_lexer.get_token_string(),
13387 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"),
nullptr));
13397 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
13399 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
13408 JSON_ASSERT(!states.empty());
13410 skip_to_state_evaluation =
true;
13414 return sax->parse_error(m_lexer.get_position(),
13415 m_lexer.get_token_string(),
13416 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object,
"object"),
nullptr));
13421 token_type get_token()
13423 return last_token = m_lexer.scan();
13426 std::string exception_message(
const token_type expected,
const std::string& context)
13428 std::string error_msg =
"syntax error ";
13430 if (!context.empty())
13432 error_msg += concat(
"while parsing ", context,
' ');
13437 if (last_token == token_type::parse_error)
13439 error_msg += concat(m_lexer.get_error_message(),
"; last read: '",
13440 m_lexer.get_token_string(),
'\'');
13444 error_msg += concat(
"unexpected ", lexer_t::token_type_name(last_token));
13447 if (expected != token_type::uninitialized)
13449 error_msg += concat(
"; expected ", lexer_t::token_type_name(expected));
13457 const parser_callback_t<BasicJsonType> callback =
nullptr;
13459 token_type last_token = token_type::uninitialized;
13463 const bool allow_exceptions =
true;
13465 const bool ignore_trailing_commas =
false;
13469NLOHMANN_JSON_NAMESPACE_END
13501NLOHMANN_JSON_NAMESPACE_BEGIN
13517 using difference_type = std::ptrdiff_t;
13518 static constexpr difference_type begin_value = 0;
13519 static constexpr difference_type end_value = begin_value + 1;
13521 JSON_PRIVATE_UNLESS_TESTED:
13523 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
13526 constexpr difference_type get_value()
const noexcept
13534 m_it = begin_value;
13546 return m_it == begin_value;
13552 return m_it == end_value;
13557 return lhs.m_it == rhs.m_it;
13560 friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
13562 return lhs.m_it < rhs.m_it;
13565 primitive_iterator_t operator+(difference_type n)
noexcept
13567 auto result = *
this;
13572 friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
13574 return lhs.m_it - rhs.m_it;
13577 primitive_iterator_t& operator++() noexcept
13583 primitive_iterator_t operator++(
int)&
noexcept
13585 auto result = *
this;
13590 primitive_iterator_t& operator--() noexcept
13596 primitive_iterator_t operator--(
int)&
noexcept
13598 auto result = *
this;
13603 primitive_iterator_t& operator+=(difference_type n)
noexcept
13609 primitive_iterator_t& operator-=(difference_type n)
noexcept
13617NLOHMANN_JSON_NAMESPACE_END
13620NLOHMANN_JSON_NAMESPACE_BEGIN
13641NLOHMANN_JSON_NAMESPACE_END
13655#include <type_traits>
13672NLOHMANN_JSON_NAMESPACE_BEGIN
13677template<
typename IteratorType>
class iteration_proxy;
13678template<
typename IteratorType>
class iteration_proxy_value;
13696template<
typename BasicJsonType>
13700 using other_iter_impl = iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value,
typename std::remove_const<BasicJsonType>::type,
const BasicJsonType>::type>;
13702 friend other_iter_impl;
13703 friend BasicJsonType;
13707 using object_t =
typename BasicJsonType::object_t;
13708 using array_t =
typename BasicJsonType::array_t;
13711 "iter_impl only accepts (const) basic_json");
13713 static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value
13714 && std::is_base_of<std::bidirectional_iterator_tag, typename std::iterator_traits<typename array_t::iterator>::iterator_category>
::value,
13715 "basic_json iterator assumes array and object type iterators satisfy the LegacyBidirectionalIterator named requirement.");
13730 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
13731 typename BasicJsonType::const_pointer,
13732 typename BasicJsonType::pointer>::type;
13735 typename std::conditional<std::is_const<BasicJsonType>::value,
13736 typename BasicJsonType::const_reference,
13737 typename BasicJsonType::reference>::type;
13739 iter_impl() =
default;
13740 ~iter_impl() =
default;
13741 iter_impl(iter_impl&&) noexcept = default;
13742 iter_impl& operator=(iter_impl&&) noexcept = default;
13750 explicit iter_impl(
pointer object) noexcept : m_object(
object)
13752 JSON_ASSERT(m_object !=
nullptr);
13754 switch (m_object->m_data.m_type)
13758 m_it.object_iterator =
typename object_t::iterator();
13764 m_it.array_iterator =
typename array_t::iterator();
13801 : m_object(other.m_object),
m_it(other.m_it)
13810 iter_impl&
operator=(
const iter_impl<const BasicJsonType>& other)
noexcept
13812 if (&other !=
this)
13814 m_object = other.m_object;
13825 iter_impl(
const iter_impl<
typename std::remove_const<BasicJsonType>::type>& other) noexcept
13826 : m_object(other.m_object),
m_it(other.m_it)
13835 iter_impl&
operator=(
const iter_impl<
typename std::remove_const<BasicJsonType>::type>& other)
noexcept
13837 m_object = other.m_object;
13842 JSON_PRIVATE_UNLESS_TESTED:
13847 void set_begin() noexcept
13849 JSON_ASSERT(m_object !=
nullptr);
13851 switch (m_object->m_data.m_type)
13855 m_it.object_iterator = m_object->m_data.m_value.object->begin();
13859 case value_t::array:
13861 m_it.array_iterator = m_object->m_data.m_value.array->begin();
13865 case value_t::null:
13868 m_it.primitive_iterator.set_end();
13872 case value_t::string:
13873 case value_t::boolean:
13874 case value_t::number_integer:
13875 case value_t::number_unsigned:
13876 case value_t::number_float:
13877 case value_t::binary:
13878 case value_t::discarded:
13881 m_it.primitive_iterator.set_begin();
13893 JSON_ASSERT(m_object !=
nullptr);
13895 switch (m_object->m_data.m_type)
13899 m_it.object_iterator = m_object->m_data.m_value.object->end();
13905 m_it.array_iterator = m_object->m_data.m_value.array->end();
13919 m_it.primitive_iterator.set_end();
13932 JSON_ASSERT(m_object !=
nullptr);
13934 switch (m_object->m_data.m_type)
13938 JSON_ASSERT(
m_it.object_iterator != m_object->m_data.m_value.object->end());
13939 return m_it.object_iterator->second;
13944 JSON_ASSERT(
m_it.array_iterator != m_object->m_data.m_value.array->end());
13945 return *
m_it.array_iterator;
13949 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13960 if (JSON_HEDLEY_LIKELY(
m_it.primitive_iterator.is_begin()))
13965 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13976 JSON_ASSERT(m_object !=
nullptr);
13978 switch (m_object->m_data.m_type)
13982 JSON_ASSERT(
m_it.object_iterator != m_object->m_data.m_value.object->end());
13983 return &(
m_it.object_iterator->second);
13988 JSON_ASSERT(
m_it.array_iterator != m_object->m_data.m_value.array->end());
13989 return &*
m_it.array_iterator;
14002 if (JSON_HEDLEY_LIKELY(
m_it.primitive_iterator.is_begin()))
14007 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
14018 auto result = *
this;
14029 JSON_ASSERT(m_object !=
nullptr);
14031 switch (m_object->m_data.m_type)
14035 std::advance(
m_it.object_iterator, 1);
14041 std::advance(
m_it.array_iterator, 1);
14055 ++
m_it.primitive_iterator;
14069 auto result = *
this;
14080 JSON_ASSERT(m_object !=
nullptr);
14082 switch (m_object->m_data.m_type)
14086 std::advance(
m_it.object_iterator, -1);
14092 std::advance(
m_it.array_iterator, -1);
14106 --
m_it.primitive_iterator;
14118 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 >
14122 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
14124 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", m_object));
14128 if (m_object ==
nullptr)
14133 switch (m_object->m_data.m_type)
14136 return (
m_it.object_iterator == other.m_it.object_iterator);
14139 return (
m_it.array_iterator == other.m_it.array_iterator);
14150 return (
m_it.primitive_iterator == other.m_it.primitive_iterator);
14158 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 >
14171 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
14173 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", m_object));
14177 if (m_object ==
nullptr)
14183 switch (m_object->m_data.m_type)
14186 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators", m_object));
14189 return (
m_it.array_iterator < other.
m_it.array_iterator);
14200 return (
m_it.primitive_iterator < other.
m_it.primitive_iterator);
14210 return !other.operator < (*this);
14237 JSON_ASSERT(m_object !=
nullptr);
14239 switch (m_object->m_data.m_type)
14242 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", m_object));
14246 std::advance(
m_it.array_iterator, i);
14260 m_it.primitive_iterator += i;
14283 auto result = *
this;
14305 auto result = *
this;
14316 JSON_ASSERT(m_object !=
nullptr);
14318 switch (m_object->m_data.m_type)
14321 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", m_object));
14324 return m_it.array_iterator - other.
m_it.array_iterator;
14335 return m_it.primitive_iterator - other.
m_it.primitive_iterator;
14345 JSON_ASSERT(m_object !=
nullptr);
14347 switch (m_object->m_data.m_type)
14350 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators", m_object));
14353 return *std::next(
m_it.array_iterator, n);
14356 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
14367 if (JSON_HEDLEY_LIKELY(
m_it.primitive_iterator.get_value() == -n))
14372 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
14381 const typename object_t::key_type&
key()
const
14383 JSON_ASSERT(m_object !=
nullptr);
14385 if (JSON_HEDLEY_LIKELY(m_object->is_object()))
14387 return m_it.object_iterator->first;
14390 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators", m_object));
14402 JSON_PRIVATE_UNLESS_TESTED:
14404 pointer m_object =
nullptr;
14410NLOHMANN_JSON_NAMESPACE_END
14432NLOHMANN_JSON_NAMESPACE_BEGIN
14458template<
typename Base>
14462 using difference_type = std::ptrdiff_t;
14530 auto key() const -> decltype(std::declval<Base>().
key())
14532 auto it = --this->base();
14539 auto it = --this->base();
14540 return it.operator * ();
14545NLOHMANN_JSON_NAMESPACE_END
14560#include <type_traits>
14565NLOHMANN_JSON_NAMESPACE_BEGIN
14582using json_base_class =
typename std::conditional <
14583 std::is_same<T, void>::value,
14589NLOHMANN_JSON_NAMESPACE_END
14602#include <algorithm>
14626NLOHMANN_JSON_NAMESPACE_BEGIN
14630template<
typename RefStringType>
14634 NLOHMANN_BASIC_JSON_TPL_DECLARATION
14635 friend class basic_json;
14638 friend class json_pointer;
14640 template<
typename T>
14641 struct string_t_helper
14646 NLOHMANN_BASIC_JSON_TPL_DECLARATION
14647 struct string_t_helper<NLOHMANN_BASIC_JSON_TPL>
14649 using type = StringType;
14654 using string_t =
typename string_t_helper<RefStringType>::type;
14659 : reference_tokens(split(s))
14666 return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
14668 [](
const string_t& a,
const string_t& b)
14670 return detail::concat(a,
'/', detail::escape(b));
14676 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, to_string())
14677 operator string_t()
const
14685 friend std::ostream&
operator<<(std::ostream& o,
const json_pointer& ptr)
14696 reference_tokens.insert(reference_tokens.end(),
14697 ptr.reference_tokens.begin(),
14698 ptr.reference_tokens.end());
14714 return *
this /= std::to_string(array_idx);
14720 const json_pointer& rhs)
14722 return json_pointer(lhs) /= rhs;
14727 friend json_pointer
operator/(
const json_pointer& lhs, string_t token)
14729 return json_pointer(lhs) /= std::move(token);
14734 friend json_pointer
operator/(
const json_pointer& lhs, std::size_t array_idx)
14736 return json_pointer(lhs) /= array_idx;
14748 json_pointer res = *
this;
14757 if (JSON_HEDLEY_UNLIKELY(
empty()))
14759 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
14762 reference_tokens.pop_back();
14769 if (JSON_HEDLEY_UNLIKELY(
empty()))
14771 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
14774 return reference_tokens.back();
14781 reference_tokens.push_back(token);
14788 reference_tokens.push_back(std::move(token));
14795 return reference_tokens.empty();
14809 template<
typename BasicJsonType>
14810 static typename BasicJsonType::size_type array_index(
const string_t& s)
14812 using size_type =
typename BasicJsonType::size_type;
14815 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] ==
'0'))
14821 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >=
'1' && s[0] <=
'9')))
14826 const char* p = s.c_str();
14827 char* p_end =
nullptr;
14829 const unsigned long long res = std::strtoull(p, &p_end, 10);
14832 || JSON_HEDLEY_UNLIKELY(
static_cast<std::size_t
>(p_end - p) != s.size()))
14834 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", s,
"'"),
nullptr));
14839 if (res >=
static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))
14841 JSON_THROW(detail::out_of_range::create(410, detail::concat(
"array index ", s,
" exceeds size_type"),
nullptr));
14844 return static_cast<size_type
>(res);
14847 JSON_PRIVATE_UNLESS_TESTED:
14848 json_pointer top()
const
14850 if (JSON_HEDLEY_UNLIKELY(empty()))
14852 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
14855 json_pointer result = *
this;
14856 result.reference_tokens = {reference_tokens[0]};
14869 template<
typename BasicJsonType>
14870 BasicJsonType& get_and_create(BasicJsonType& j)
const
14876 for (
const auto& reference_token : reference_tokens)
14878 switch (result->type())
14882 if (reference_token ==
"0")
14885 result = &result->operator[](0);
14890 result = &result->operator[](reference_token);
14898 result = &result->operator[](reference_token);
14905 result = &result->operator[](array_index<BasicJsonType>(reference_token));
14923 JSON_THROW(detail::type_error::create(313,
"invalid value to unflatten", &j));
14949 template<
typename BasicJsonType>
14950 BasicJsonType& get_unchecked(BasicJsonType* ptr)
const
14952 for (
const auto& reference_token : reference_tokens)
14955 if (ptr->is_null())
14959 std::all_of(reference_token.begin(), reference_token.end(),
14960 [](
const unsigned char x)
14962 return std::isdigit(x);
14966 *ptr = (nums || reference_token ==
"-")
14971 switch (ptr->type())
14976 ptr = &ptr->operator[](reference_token);
14982 if (reference_token ==
"-")
14985 ptr = &ptr->operator[](ptr->m_data.m_value.array->size());
14990 ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));
15004 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
15017 template<
typename BasicJsonType>
15018 BasicJsonType& get_checked(BasicJsonType* ptr)
const
15020 for (
const auto& reference_token : reference_tokens)
15022 switch (ptr->type())
15027 ptr = &ptr->at(reference_token);
15033 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
15036 JSON_THROW(detail::out_of_range::create(402, detail::concat(
15037 "array index '-' (", std::to_string(ptr->m_data.m_value.array->size()),
15038 ") is out of range"), ptr));
15042 ptr = &ptr->at(array_index<BasicJsonType>(reference_token));
15055 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
15075 template<
typename BasicJsonType>
15076 const BasicJsonType& get_unchecked(
const BasicJsonType* ptr)
const
15078 for (
const auto& reference_token : reference_tokens)
15080 switch (ptr->type())
15085 ptr = &ptr->operator[](reference_token);
15091 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
15094 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));
15098 ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));
15111 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
15124 template<
typename BasicJsonType>
15125 const BasicJsonType& get_checked(
const BasicJsonType* ptr)
const
15127 for (
const auto& reference_token : reference_tokens)
15129 switch (ptr->type())
15134 ptr = &ptr->at(reference_token);
15140 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
15143 JSON_THROW(detail::out_of_range::create(402, detail::concat(
15144 "array index '-' (", std::to_string(ptr->m_data.m_value.array->size()),
15145 ") is out of range"), ptr));
15149 ptr = &ptr->at(array_index<BasicJsonType>(reference_token));
15162 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
15173 template<
typename BasicJsonType>
15174 bool contains(
const BasicJsonType* ptr)
const
15176 for (
const auto& reference_token : reference_tokens)
15178 switch (ptr->type())
15182 if (!ptr->contains(reference_token))
15188 ptr = &ptr->operator[](reference_token);
15194 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
15199 if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !(
"0" <= reference_token && reference_token <=
"9")))
15204 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
15206 if (JSON_HEDLEY_UNLIKELY(!(
'1' <= reference_token[0] && reference_token[0] <=
'9')))
15211 for (std::size_t i = 1; i < reference_token.size(); i++)
15213 if (JSON_HEDLEY_UNLIKELY(!(
'0' <= reference_token[i] && reference_token[i] <=
'9')))
15221 const auto idx = array_index<BasicJsonType>(reference_token);
15222 if (idx >= ptr->size())
15228 ptr = &ptr->operator[](idx);
15262 static std::vector<string_t> split(
const string_t& reference_string)
15264 std::vector<string_t> result;
15267 if (reference_string.empty())
15273 if (JSON_HEDLEY_UNLIKELY(reference_string[0] !=
'/'))
15275 JSON_THROW(
detail::parse_error::create(107, 1, detail::concat(
"JSON pointer must be empty or begin with '/' - was: '", reference_string,
"'"),
nullptr));
15283 std::size_t slash = reference_string.find_first_of(
'/', 1),
15290 start = (slash == string_t::npos) ? 0 : slash + 1,
15292 slash = reference_string.find_first_of(
'/', start))
15296 auto reference_token = reference_string.substr(start, slash - start);
15299 for (std::size_t pos = reference_token.find_first_of(
'~');
15300 pos != string_t::npos;
15301 pos = reference_token.find_first_of(
'~', pos + 1))
15303 JSON_ASSERT(reference_token[pos] ==
'~');
15306 if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
15307 (reference_token[pos + 1] !=
'0' &&
15308 reference_token[pos + 1] !=
'1')))
15316 result.push_back(reference_token);
15330 template<
typename BasicJsonType>
15331 static void flatten(
const string_t& reference_string,
15332 const BasicJsonType& value,
15333 BasicJsonType& result)
15335 switch (value.type())
15339 if (value.m_data.m_value.array->empty())
15342 result[reference_string] =
nullptr;
15347 for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i)
15349 flatten(detail::concat<string_t>(reference_string,
'/', std::to_string(i)),
15350 value.m_data.m_value.array->operator[](i), result);
15358 if (value.m_data.m_value.object->empty())
15361 result[reference_string] =
nullptr;
15366 for (
const auto& element : *value.m_data.m_value.object)
15368 flatten(detail::concat<string_t>(reference_string,
'/',
detail::escape(element.first)), element.second, result);
15385 result[reference_string] = value;
15401 template<
typename BasicJsonType>
15402 static BasicJsonType
15403 unflatten(
const BasicJsonType& value)
15405 if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
15407 JSON_THROW(detail::type_error::create(314,
"only objects can be unflattened", &value));
15410 BasicJsonType result;
15413 for (
const auto& element : *value.m_data.m_value.object)
15415 if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
15417 JSON_THROW(detail::type_error::create(315,
"values in object must be primitive", &element.second));
15424 json_pointer(element.first).get_and_create(result) = element.second;
15431 json_pointer<string_t> convert() const&
15433 json_pointer<string_t> result;
15434 result.reference_tokens = reference_tokens;
15438 json_pointer<string_t> convert()&&
15440 json_pointer<string_t> result;
15441 result.reference_tokens = std::move(reference_tokens);
15446#if JSON_HAS_THREE_WAY_COMPARISON
15449 template<
typename RefStringTypeRhs>
15450 bool operator==(
const json_pointer<RefStringTypeRhs>& rhs)
const noexcept
15452 return reference_tokens == rhs.reference_tokens;
15457 JSON_HEDLEY_DEPRECATED_FOR(3.11.2,
operator==(json_pointer))
15458 bool operator==(
const string_t& rhs)
const
15460 return *
this == json_pointer(rhs);
15464 template<
typename RefStringTypeRhs>
15465 std::strong_ordering operator<=>(
const json_pointer<RefStringTypeRhs>& rhs)
const noexcept
15467 return reference_tokens <=> rhs.reference_tokens;
15472 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15474 friend bool operator==(
const json_pointer<RefStringTypeLhs>& lhs,
15475 const json_pointer<RefStringTypeRhs>& rhs)
noexcept;
15479 template<
typename RefStringTypeLhs,
typename StringType>
15481 friend bool operator==(
const json_pointer<RefStringTypeLhs>& lhs,
15482 const StringType& rhs);
15486 template<
typename RefStringTypeRhs,
typename StringType>
15488 friend bool operator==(
const StringType& lhs,
15489 const json_pointer<RefStringTypeRhs>& rhs);
15493 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15495 friend bool operator!=(
const json_pointer<RefStringTypeLhs>& lhs,
15496 const json_pointer<RefStringTypeRhs>& rhs)
noexcept;
15500 template<
typename RefStringTypeLhs,
typename StringType>
15502 friend bool operator!=(
const json_pointer<RefStringTypeLhs>& lhs,
15503 const StringType& rhs);
15507 template<
typename RefStringTypeRhs,
typename StringType>
15509 friend bool operator!=(
const StringType& lhs,
15510 const json_pointer<RefStringTypeRhs>& rhs);
15513 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15515 friend bool operator<(
const json_pointer<RefStringTypeLhs>& lhs,
15516 const json_pointer<RefStringTypeRhs>& rhs)
noexcept;
15521 std::vector<string_t> reference_tokens;
15524#if !JSON_HAS_THREE_WAY_COMPARISON
15526template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15528 const json_pointer<RefStringTypeRhs>& rhs)
noexcept
15530 return lhs.reference_tokens == rhs.reference_tokens;
15533template<
typename RefStringTypeLhs,
15534 typename StringType =
typename json_pointer<RefStringTypeLhs>::string_t>
15536inline
bool operator==(const json_pointer<RefStringTypeLhs>& lhs,
15537 const StringType& rhs)
15539 return lhs == json_pointer<RefStringTypeLhs>(rhs);
15542template<
typename RefStringTypeRhs,
15543 typename StringType =
typename json_pointer<RefStringTypeRhs>::string_t>
15545inline
bool operator==(const StringType& lhs,
15546 const json_pointer<RefStringTypeRhs>& rhs)
15548 return json_pointer<RefStringTypeRhs>(lhs) == rhs;
15551template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15553 const json_pointer<RefStringTypeRhs>& rhs)
noexcept
15555 return !(lhs == rhs);
15558template<
typename RefStringTypeLhs,
15559 typename StringType =
typename json_pointer<RefStringTypeLhs>::string_t>
15561inline
bool operator!=(const json_pointer<RefStringTypeLhs>& lhs,
15562 const StringType& rhs)
15564 return !(lhs == rhs);
15567template<
typename RefStringTypeRhs,
15568 typename StringType =
typename json_pointer<RefStringTypeRhs>::string_t>
15570inline
bool operator!=(const StringType& lhs,
15571 const json_pointer<RefStringTypeRhs>& rhs)
15573 return !(lhs == rhs);
15576template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15578 const json_pointer<RefStringTypeRhs>& rhs)
noexcept
15580 return lhs.reference_tokens < rhs.reference_tokens;
15584NLOHMANN_JSON_NAMESPACE_END
15597#include <initializer_list>
15605NLOHMANN_JSON_NAMESPACE_BEGIN
15609template<
typename BasicJsonType>
15613 using value_type = BasicJsonType;
15615 json_ref(value_type&& value)
15616 : owned_value(std::move(value))
15619 json_ref(
const value_type& value)
15620 : value_ref(&value)
15623 json_ref(std::initializer_list<json_ref> init)
15624 : owned_value(init)
15629 enable_if_t<std::is_constructible<value_type, Args...>::value,
int> = 0 >
15630 json_ref(Args && ... args)
15631 : owned_value(std::forward<Args>(args)...)
15635 json_ref(json_ref&&)
noexcept =
default;
15636 json_ref(
const json_ref&) =
delete;
15637 json_ref& operator=(
const json_ref&) =
delete;
15638 json_ref& operator=(json_ref&&) =
delete;
15639 ~json_ref() =
default;
15641 value_type moved_or_copied()
const
15643 if (value_ref ==
nullptr)
15645 return std::move(owned_value);
15650 value_type
const& operator*()
const
15652 return value_ref ? *value_ref : owned_value;
15655 value_type
const* operator->()
const
15661 mutable value_type owned_value =
nullptr;
15662 value_type
const* value_ref =
nullptr;
15666NLOHMANN_JSON_NAMESPACE_END
15691#include <algorithm>
15717#include <algorithm>
15732NLOHMANN_JSON_NAMESPACE_BEGIN
15737template<
typename CharType>
struct output_adapter_protocol
15739 virtual void write_character(CharType c) = 0;
15740 virtual void write_characters(
const CharType* s, std::size_t length) = 0;
15741 virtual ~output_adapter_protocol() =
default;
15743 output_adapter_protocol() =
default;
15744 output_adapter_protocol(
const output_adapter_protocol&) =
default;
15745 output_adapter_protocol(output_adapter_protocol&&)
noexcept =
default;
15746 output_adapter_protocol& operator=(
const output_adapter_protocol&) =
default;
15747 output_adapter_protocol& operator=(output_adapter_protocol&&)
noexcept =
default;
15751template<
typename CharType>
15755template<
typename CharType,
typename AllocatorType = std::allocator<CharType>>
15756class output_vector_adapter :
public output_adapter_protocol<CharType>
15759 explicit output_vector_adapter(std::vector<CharType, AllocatorType>& vec) noexcept
15763 void write_character(CharType c)
override
15768 JSON_HEDLEY_NON_NULL(2)
15769 void write_characters(
const CharType* s, std::size_t length)
override
15771 v.insert(v.end(), s, s + length);
15775 std::vector<CharType, AllocatorType>& v;
15780template<
typename CharType>
15781class output_stream_adapter :
public output_adapter_protocol<CharType>
15784 explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
15788 void write_character(CharType c)
override
15793 JSON_HEDLEY_NON_NULL(2)
15794 void write_characters(
const CharType* s, std::size_t length)
override
15796 stream.write(s,
static_cast<std::streamsize
>(length));
15800 std::basic_ostream<CharType>& stream;
15805template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
15806class output_string_adapter :
public output_adapter_protocol<CharType>
15809 explicit output_string_adapter(StringType& s) noexcept
15813 void write_character(CharType c)
override
15818 JSON_HEDLEY_NON_NULL(2)
15819 void write_characters(
const CharType* s, std::size_t length)
override
15821 str.append(s, length);
15828template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
15829class output_adapter
15832 template<
typename AllocatorType = std::allocator<CharType>>
15833 output_adapter(std::vector<CharType, AllocatorType>& vec)
15837 output_adapter(std::basic_ostream<CharType>& s)
15841 output_adapter(StringType& s)
15854NLOHMANN_JSON_NAMESPACE_END
15859NLOHMANN_JSON_NAMESPACE_BEGIN
15877template<
typename BasicJsonType,
typename CharType>
15880 using string_t =
typename BasicJsonType::string_t;
15881 using binary_t =
typename BasicJsonType::binary_t;
15882 using number_float_t =
typename BasicJsonType::number_float_t;
15905 write_bson_object(*j.m_data.m_value.object);
15920 JSON_THROW(type_error::create(317, concat(
"to serialize to BSON, top-level type must be object, but is ", j.type_name()), &j));
15934 oa->write_character(to_char_type(0xF6));
15940 oa->write_character(j.m_data.m_value.boolean
15941 ? to_char_type(0xF5)
15942 : to_char_type(0xF4));
15948 if (j.m_data.m_value.number_integer >= 0)
15953 if (j.m_data.m_value.number_integer <= 0x17)
15955 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15957 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
15959 oa->write_character(to_char_type(0x18));
15960 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15962 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
15964 oa->write_character(to_char_type(0x19));
15965 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
15967 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
15969 oa->write_character(to_char_type(0x1A));
15970 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
15974 oa->write_character(to_char_type(0x1B));
15975 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
15982 const auto positive_number = -1 - j.m_data.m_value.number_integer;
15983 if (j.m_data.m_value.number_integer >= -24)
15985 write_number(
static_cast<std::uint8_t
>(0x20 + positive_number));
15987 else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
15989 oa->write_character(to_char_type(0x38));
15990 write_number(
static_cast<std::uint8_t
>(positive_number));
15992 else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
15994 oa->write_character(to_char_type(0x39));
15995 write_number(
static_cast<std::uint16_t
>(positive_number));
15997 else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
15999 oa->write_character(to_char_type(0x3A));
16000 write_number(
static_cast<std::uint32_t
>(positive_number));
16004 oa->write_character(to_char_type(0x3B));
16005 write_number(
static_cast<std::uint64_t
>(positive_number));
16013 if (j.m_data.m_value.number_unsigned <= 0x17)
16015 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_unsigned));
16017 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
16019 oa->write_character(to_char_type(0x18));
16020 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_unsigned));
16022 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
16024 oa->write_character(to_char_type(0x19));
16025 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_unsigned));
16027 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
16029 oa->write_character(to_char_type(0x1A));
16030 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_unsigned));
16034 oa->write_character(to_char_type(0x1B));
16035 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_unsigned));
16042 if (std::isnan(j.m_data.m_value.number_float))
16045 oa->write_character(to_char_type(0xF9));
16046 oa->write_character(to_char_type(0x7E));
16047 oa->write_character(to_char_type(0x00));
16049 else if (std::isinf(j.m_data.m_value.number_float))
16052 oa->write_character(to_char_type(0xf9));
16053 oa->write_character(j.m_data.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
16054 oa->write_character(to_char_type(0x00));
16058 write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::cbor);
16066 const auto N = j.m_data.m_value.string->size();
16069 write_number(
static_cast<std::uint8_t
>(0x60 + N));
16071 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
16073 oa->write_character(to_char_type(0x78));
16074 write_number(
static_cast<std::uint8_t
>(N));
16076 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16078 oa->write_character(to_char_type(0x79));
16079 write_number(
static_cast<std::uint16_t
>(N));
16081 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16083 oa->write_character(to_char_type(0x7A));
16084 write_number(
static_cast<std::uint32_t
>(N));
16087 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
16089 oa->write_character(to_char_type(0x7B));
16090 write_number(
static_cast<std::uint64_t
>(N));
16095 oa->write_characters(
16096 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
16097 j.m_data.m_value.string->size());
16104 const auto N = j.m_data.m_value.array->size();
16107 write_number(
static_cast<std::uint8_t
>(0x80 + N));
16109 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
16111 oa->write_character(to_char_type(0x98));
16112 write_number(
static_cast<std::uint8_t
>(N));
16114 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16116 oa->write_character(to_char_type(0x99));
16117 write_number(
static_cast<std::uint16_t
>(N));
16119 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16121 oa->write_character(to_char_type(0x9A));
16122 write_number(
static_cast<std::uint32_t
>(N));
16125 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
16127 oa->write_character(to_char_type(0x9B));
16128 write_number(
static_cast<std::uint64_t
>(N));
16133 for (
const auto& el : *j.m_data.m_value.array)
16142 if (j.m_data.m_value.binary->has_subtype())
16144 if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)())
16146 write_number(
static_cast<std::uint8_t
>(0xd8));
16147 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.binary->subtype()));
16149 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint16_t>::max)())
16151 write_number(
static_cast<std::uint8_t
>(0xd9));
16152 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.binary->subtype()));
16154 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint32_t>::max)())
16156 write_number(
static_cast<std::uint8_t
>(0xda));
16157 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.binary->subtype()));
16159 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint64_t>::max)())
16161 write_number(
static_cast<std::uint8_t
>(0xdb));
16162 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.binary->subtype()));
16167 const auto N = j.m_data.m_value.binary->size();
16170 write_number(
static_cast<std::uint8_t
>(0x40 + N));
16172 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
16174 oa->write_character(to_char_type(0x58));
16175 write_number(
static_cast<std::uint8_t
>(N));
16177 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16179 oa->write_character(to_char_type(0x59));
16180 write_number(
static_cast<std::uint16_t
>(N));
16182 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16184 oa->write_character(to_char_type(0x5A));
16185 write_number(
static_cast<std::uint32_t
>(N));
16188 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
16190 oa->write_character(to_char_type(0x5B));
16191 write_number(
static_cast<std::uint64_t
>(N));
16196 oa->write_characters(
16197 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
16206 const auto N = j.m_data.m_value.object->size();
16209 write_number(
static_cast<std::uint8_t
>(0xA0 + N));
16211 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
16213 oa->write_character(to_char_type(0xB8));
16214 write_number(
static_cast<std::uint8_t
>(N));
16216 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16218 oa->write_character(to_char_type(0xB9));
16219 write_number(
static_cast<std::uint16_t
>(N));
16221 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16223 oa->write_character(to_char_type(0xBA));
16224 write_number(
static_cast<std::uint32_t
>(N));
16227 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
16229 oa->write_character(to_char_type(0xBB));
16230 write_number(
static_cast<std::uint64_t
>(N));
16235 for (
const auto& el : *j.m_data.m_value.object)
16258 oa->write_character(to_char_type(0xC0));
16264 oa->write_character(j.m_data.m_value.boolean
16265 ? to_char_type(0xC3)
16266 : to_char_type(0xC2));
16272 if (j.m_data.m_value.number_integer >= 0)
16277 if (j.m_data.m_value.number_unsigned < 128)
16280 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
16282 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
16285 oa->write_character(to_char_type(0xCC));
16286 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
16288 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
16291 oa->write_character(to_char_type(0xCD));
16292 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
16294 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
16297 oa->write_character(to_char_type(0xCE));
16298 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
16300 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
16303 oa->write_character(to_char_type(0xCF));
16304 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
16309 if (j.m_data.m_value.number_integer >= -32)
16312 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.number_integer));
16314 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&
16315 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
16318 oa->write_character(to_char_type(0xD0));
16319 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.number_integer));
16321 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&
16322 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
16325 oa->write_character(to_char_type(0xD1));
16326 write_number(
static_cast<std::int16_t
>(j.m_data.m_value.number_integer));
16328 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&
16329 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
16332 oa->write_character(to_char_type(0xD2));
16333 write_number(
static_cast<std::int32_t
>(j.m_data.m_value.number_integer));
16335 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&
16336 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
16339 oa->write_character(to_char_type(0xD3));
16340 write_number(
static_cast<std::int64_t
>(j.m_data.m_value.number_integer));
16348 if (j.m_data.m_value.number_unsigned < 128)
16351 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
16353 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
16356 oa->write_character(to_char_type(0xCC));
16357 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
16359 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
16362 oa->write_character(to_char_type(0xCD));
16363 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
16365 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
16368 oa->write_character(to_char_type(0xCE));
16369 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
16371 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
16374 oa->write_character(to_char_type(0xCF));
16375 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
16382 write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::msgpack);
16389 const auto N = j.m_data.m_value.string->size();
16393 write_number(
static_cast<std::uint8_t
>(0xA0 | N));
16395 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
16398 oa->write_character(to_char_type(0xD9));
16399 write_number(
static_cast<std::uint8_t
>(N));
16401 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16404 oa->write_character(to_char_type(0xDA));
16405 write_number(
static_cast<std::uint16_t
>(N));
16407 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16410 oa->write_character(to_char_type(0xDB));
16411 write_number(
static_cast<std::uint32_t
>(N));
16415 oa->write_characters(
16416 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
16417 j.m_data.m_value.string->size());
16424 const auto N = j.m_data.m_value.array->size();
16428 write_number(
static_cast<std::uint8_t
>(0x90 | N));
16430 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16433 oa->write_character(to_char_type(0xDC));
16434 write_number(
static_cast<std::uint16_t
>(N));
16436 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16439 oa->write_character(to_char_type(0xDD));
16440 write_number(
static_cast<std::uint32_t
>(N));
16444 for (
const auto& el : *j.m_data.m_value.array)
16455 const bool use_ext = j.m_data.m_value.binary->has_subtype();
16458 const auto N = j.m_data.m_value.binary->size();
16459 if (N <= (std::numeric_limits<std::uint8_t>::max)())
16461 std::uint8_t output_type{};
16468 output_type = 0xD4;
16471 output_type = 0xD5;
16474 output_type = 0xD6;
16477 output_type = 0xD7;
16480 output_type = 0xD8;
16483 output_type = 0xC7;
16491 output_type = 0xC4;
16495 oa->write_character(to_char_type(output_type));
16498 write_number(
static_cast<std::uint8_t
>(N));
16501 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16503 const std::uint8_t output_type = use_ext
16507 oa->write_character(to_char_type(output_type));
16508 write_number(
static_cast<std::uint16_t
>(N));
16510 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16512 const std::uint8_t output_type = use_ext
16516 oa->write_character(to_char_type(output_type));
16517 write_number(
static_cast<std::uint32_t
>(N));
16523 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.binary->subtype()));
16527 oa->write_characters(
16528 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
16537 const auto N = j.m_data.m_value.object->size();
16541 write_number(
static_cast<std::uint8_t
>(0x80 | (N & 0xF)));
16543 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16546 oa->write_character(to_char_type(0xDE));
16547 write_number(
static_cast<std::uint16_t
>(N));
16549 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16552 oa->write_character(to_char_type(0xDF));
16553 write_number(
static_cast<std::uint32_t
>(N));
16557 for (
const auto& el : *j.m_data.m_value.object)
16580 const bool use_type,
const bool add_prefix =
true,
16581 const bool use_bjdata =
false,
const bjdata_version_t bjdata_version = bjdata_version_t::draft2)
16583 const bool bjdata_draft3 = use_bjdata && bjdata_version == bjdata_version_t::draft3;
16591 oa->write_character(to_char_type(
'Z'));
16600 oa->write_character(j.m_data.m_value.boolean
16601 ? to_char_type(
'T')
16602 : to_char_type(
'F'));
16609 write_number_with_ubjson_prefix(j.m_data.m_value.number_integer, add_prefix, use_bjdata);
16615 write_number_with_ubjson_prefix(j.m_data.m_value.number_unsigned, add_prefix, use_bjdata);
16621 write_number_with_ubjson_prefix(j.m_data.m_value.number_float, add_prefix, use_bjdata);
16629 oa->write_character(to_char_type(
'S'));
16631 write_number_with_ubjson_prefix(j.m_data.m_value.string->size(),
true, use_bjdata);
16632 oa->write_characters(
16633 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
16634 j.m_data.m_value.string->size());
16642 oa->write_character(to_char_type(
'['));
16645 bool prefix_required =
true;
16646 if (use_type && !j.m_data.m_value.array->empty())
16648 JSON_ASSERT(use_count);
16649 const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
16650 const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
16651 [
this, first_prefix, use_bjdata](
const BasicJsonType & v)
16653 return ubjson_prefix(v, use_bjdata) == first_prefix;
16656 std::vector<CharType> bjdx = {
'[',
'{',
'S',
'H',
'T',
'F',
'N',
'Z'};
16658 if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
16660 prefix_required =
false;
16661 oa->write_character(to_char_type(
'$'));
16662 oa->write_character(first_prefix);
16668 oa->write_character(to_char_type(
'#'));
16669 write_number_with_ubjson_prefix(j.m_data.m_value.array->size(),
true, use_bjdata);
16672 for (
const auto& el : *j.m_data.m_value.array)
16674 write_ubjson(el, use_count, use_type, prefix_required, use_bjdata, bjdata_version);
16679 oa->write_character(to_char_type(
']'));
16689 oa->write_character(to_char_type(
'['));
16692 if (use_type && (bjdata_draft3 || !j.m_data.m_value.binary->empty()))
16694 JSON_ASSERT(use_count);
16695 oa->write_character(to_char_type(
'$'));
16696 oa->write_character(bjdata_draft3 ?
'B' :
'U');
16701 oa->write_character(to_char_type(
'#'));
16702 write_number_with_ubjson_prefix(j.m_data.m_value.binary->size(),
true, use_bjdata);
16707 oa->write_characters(
16708 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
16709 j.m_data.m_value.binary->size());
16713 for (
size_t i = 0; i < j.m_data.m_value.binary->size(); ++i)
16715 oa->write_character(to_char_type(bjdata_draft3 ?
'B' :
'U'));
16716 oa->write_character(j.m_data.m_value.binary->data()[i]);
16722 oa->write_character(to_char_type(
']'));
16730 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())
16732 if (!write_bjdata_ndarray(*j.m_data.m_value.object, use_count, use_type, bjdata_version))
16740 oa->write_character(to_char_type(
'{'));
16743 bool prefix_required =
true;
16744 if (use_type && !j.m_data.m_value.object->empty())
16746 JSON_ASSERT(use_count);
16747 const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
16748 const bool same_prefix = std::all_of(j.begin(), j.end(),
16749 [
this, first_prefix, use_bjdata](
const BasicJsonType & v)
16751 return ubjson_prefix(v, use_bjdata) == first_prefix;
16754 std::vector<CharType> bjdx = {
'[',
'{',
'S',
'H',
'T',
'F',
'N',
'Z'};
16756 if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
16758 prefix_required =
false;
16759 oa->write_character(to_char_type(
'$'));
16760 oa->write_character(first_prefix);
16766 oa->write_character(to_char_type(
'#'));
16767 write_number_with_ubjson_prefix(j.m_data.m_value.object->size(),
true, use_bjdata);
16770 for (
const auto& el : *j.m_data.m_value.object)
16772 write_number_with_ubjson_prefix(el.first.size(),
true, use_bjdata);
16773 oa->write_characters(
16774 reinterpret_cast<const CharType*
>(el.first.c_str()),
16776 write_ubjson(el.second, use_count, use_type, prefix_required, use_bjdata, bjdata_version);
16781 oa->write_character(to_char_type(
'}'));
16802 static std::size_t calc_bson_entry_header_size(
const string_t& name,
const BasicJsonType& j)
16804 const auto it = name.find(
static_cast<typename string_t::value_type
>(0));
16805 if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
16807 JSON_THROW(out_of_range::create(409, concat(
"BSON key cannot contain code point U+0000 (at byte ", std::to_string(it),
")"), &j));
16810 static_cast<void>(j);
16811 return 1ul + name.size() + 1u;
16817 void write_bson_entry_header(
const string_t& name,
16818 const std::uint8_t element_type)
16820 oa->write_character(to_char_type(element_type));
16821 oa->write_characters(
16822 reinterpret_cast<const CharType*
>(name.c_str()),
16829 void write_bson_boolean(
const string_t& name,
16832 write_bson_entry_header(name, 0x08);
16833 oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
16839 void write_bson_double(
const string_t& name,
16840 const double value)
16842 write_bson_entry_header(name, 0x01);
16843 write_number<double>(value,
true);
16849 static std::size_t calc_bson_string_size(
const string_t& value)
16851 return sizeof(std::int32_t) + value.size() + 1ul;
16857 void write_bson_string(
const string_t& name,
16858 const string_t& value)
16860 write_bson_entry_header(name, 0x02);
16862 write_number<std::int32_t>(
static_cast<std::int32_t
>(value.size() + 1ul),
true);
16863 oa->write_characters(
16864 reinterpret_cast<const CharType*
>(value.c_str()),
16871 void write_bson_null(
const string_t& name)
16873 write_bson_entry_header(name, 0x0A);
16879 static std::size_t calc_bson_integer_size(
const std::int64_t value)
16881 return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()
16882 ?
sizeof(std::int32_t)
16883 :
sizeof(std::int64_t);
16889 void write_bson_integer(
const string_t& name,
16890 const std::int64_t value)
16892 if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
16894 write_bson_entry_header(name, 0x10);
16895 write_number<std::int32_t>(
static_cast<std::int32_t
>(value),
true);
16899 write_bson_entry_header(name, 0x12);
16900 write_number<std::int64_t>(
static_cast<std::int64_t
>(value),
true);
16907 static constexpr std::size_t calc_bson_unsigned_size(
const std::uint64_t value)
noexcept
16909 return (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16910 ?
sizeof(std::int32_t)
16911 : sizeof(std::int64_t);
16917 void write_bson_unsigned(
const string_t& name,
16918 const BasicJsonType& j)
16920 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16922 write_bson_entry_header(name, 0x10 );
16923 write_number<std::int32_t>(
static_cast<std::int32_t
>(j.m_data.m_value.number_unsigned),
true);
16925 else if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
16927 write_bson_entry_header(name, 0x12 );
16928 write_number<std::int64_t>(
static_cast<std::int64_t
>(j.m_data.m_value.number_unsigned),
true);
16932 write_bson_entry_header(name, 0x11 );
16933 write_number<std::uint64_t>(
static_cast<std::uint64_t
>(j.m_data.m_value.number_unsigned),
true);
16940 void write_bson_object_entry(
const string_t& name,
16941 const typename BasicJsonType::object_t& value)
16943 write_bson_entry_header(name, 0x03);
16944 write_bson_object(value);
16950 static std::size_t calc_bson_array_size(
const typename BasicJsonType::array_t& value)
16952 std::size_t array_index = 0ul;
16954 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)
16956 return result + calc_bson_element_size(std::to_string(array_index++), el);
16959 return sizeof(std::int32_t) + embedded_document_size + 1ul;
16965 static std::size_t calc_bson_binary_size(
const typename BasicJsonType::binary_t& value)
16967 return sizeof(std::int32_t) + value.size() + 1ul;
16973 void write_bson_array(
const string_t& name,
16974 const typename BasicJsonType::array_t& value)
16976 write_bson_entry_header(name, 0x04);
16977 write_number<std::int32_t>(
static_cast<std::int32_t
>(calc_bson_array_size(value)),
true);
16979 std::size_t array_index = 0ul;
16981 for (
const auto& el : value)
16983 write_bson_element(std::to_string(array_index++), el);
16986 oa->write_character(to_char_type(0x00));
16992 void write_bson_binary(
const string_t& name,
16993 const binary_t& value)
16995 write_bson_entry_header(name, 0x05);
16997 write_number<std::int32_t>(
static_cast<std::int32_t
>(value.size()),
true);
16998 write_number(value.has_subtype() ?
static_cast<std::uint8_t
>(value.subtype()) :
static_cast<std::uint8_t
>(0x00));
17000 oa->write_characters(
reinterpret_cast<const CharType*
>(value.data()), value.size());
17007 static std::size_t calc_bson_element_size(
const string_t& name,
17008 const BasicJsonType& j)
17010 const auto header_size = calc_bson_entry_header_size(name, j);
17013 case value_t::object:
17014 return header_size + calc_bson_object_size(*j.m_data.m_value.object);
17016 case value_t::array:
17017 return header_size + calc_bson_array_size(*j.m_data.m_value.array);
17019 case value_t::binary:
17020 return header_size + calc_bson_binary_size(*j.m_data.m_value.binary);
17022 case value_t::boolean:
17023 return header_size + 1ul;
17025 case value_t::number_float:
17026 return header_size + 8ul;
17028 case value_t::number_integer:
17029 return header_size + calc_bson_integer_size(j.m_data.m_value.number_integer);
17031 case value_t::number_unsigned:
17032 return header_size + calc_bson_unsigned_size(j.m_data.m_value.number_unsigned);
17034 case value_t::string:
17035 return header_size + calc_bson_string_size(*j.m_data.m_value.string);
17037 case value_t::null:
17038 return header_size + 0ul;
17041 case value_t::discarded:
17043 JSON_ASSERT(
false);
17055 void write_bson_element(
const string_t& name,
17056 const BasicJsonType& j)
17060 case value_t::object:
17061 return write_bson_object_entry(name, *j.m_data.m_value.object);
17063 case value_t::array:
17064 return write_bson_array(name, *j.m_data.m_value.array);
17066 case value_t::binary:
17067 return write_bson_binary(name, *j.m_data.m_value.binary);
17069 case value_t::boolean:
17070 return write_bson_boolean(name, j.m_data.m_value.boolean);
17072 case value_t::number_float:
17073 return write_bson_double(name, j.m_data.m_value.number_float);
17075 case value_t::number_integer:
17076 return write_bson_integer(name, j.m_data.m_value.number_integer);
17078 case value_t::number_unsigned:
17079 return write_bson_unsigned(name, j);
17081 case value_t::string:
17082 return write_bson_string(name, *j.m_data.m_value.string);
17084 case value_t::null:
17085 return write_bson_null(name);
17088 case value_t::discarded:
17090 JSON_ASSERT(
false);
17102 static std::size_t calc_bson_object_size(
const typename BasicJsonType::object_t& value)
17104 const std::size_t document_size = std::accumulate(value.begin(), value.end(),
static_cast<std::size_t
>(0),
17105 [](
size_t result,
const typename BasicJsonType::object_t::value_type & el)
17107 return result += calc_bson_element_size(el.first, el.second);
17110 return sizeof(std::int32_t) + document_size + 1ul;
17117 void write_bson_object(
const typename BasicJsonType::object_t& value)
17119 write_number<std::int32_t>(
static_cast<std::int32_t
>(calc_bson_object_size(value)),
true);
17121 for (
const auto& el : value)
17123 write_bson_element(el.first, el.second);
17126 oa->write_character(to_char_type(0x00));
17133 static constexpr CharType get_cbor_float_prefix(
float )
17135 return to_char_type(0xFA);
17138 static constexpr CharType get_cbor_float_prefix(
double )
17140 return to_char_type(0xFB);
17147 static constexpr CharType get_msgpack_float_prefix(
float )
17149 return to_char_type(0xCA);
17152 static constexpr CharType get_msgpack_float_prefix(
double )
17154 return to_char_type(0xCB);
17162 template<
typename NumberType,
typename std::enable_if<
17163 std::is_floating_point<NumberType>::value,
int>::type = 0>
17164 void write_number_with_ubjson_prefix(
const NumberType n,
17165 const bool add_prefix,
17166 const bool use_bjdata)
17170 oa->write_character(get_ubjson_float_prefix(n));
17172 write_number(n, use_bjdata);
17176 template<
typename NumberType,
typename std::enable_if<
17177 std::is_unsigned<NumberType>::value,
int>::type = 0>
17178 void write_number_with_ubjson_prefix(
const NumberType n,
17179 const bool add_prefix,
17180 const bool use_bjdata)
17182 if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
17186 oa->write_character(to_char_type(
'i'));
17188 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
17190 else if (n <= (std::numeric_limits<std::uint8_t>::max)())
17194 oa->write_character(to_char_type(
'U'));
17196 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
17198 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
17202 oa->write_character(to_char_type(
'I'));
17204 write_number(
static_cast<std::int16_t
>(n), use_bjdata);
17206 else if (use_bjdata && n <=
static_cast<uint64_t
>((std::numeric_limits<uint16_t>::max)()))
17210 oa->write_character(to_char_type(
'u'));
17212 write_number(
static_cast<std::uint16_t
>(n), use_bjdata);
17214 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
17218 oa->write_character(to_char_type(
'l'));
17220 write_number(
static_cast<std::int32_t
>(n), use_bjdata);
17222 else if (use_bjdata && n <=
static_cast<uint64_t
>((std::numeric_limits<uint32_t>::max)()))
17226 oa->write_character(to_char_type(
'm'));
17228 write_number(
static_cast<std::uint32_t
>(n), use_bjdata);
17230 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
17234 oa->write_character(to_char_type(
'L'));
17236 write_number(
static_cast<std::int64_t
>(n), use_bjdata);
17238 else if (use_bjdata && n <= (std::numeric_limits<uint64_t>::max)())
17242 oa->write_character(to_char_type(
'M'));
17244 write_number(
static_cast<std::uint64_t
>(n), use_bjdata);
17250 oa->write_character(to_char_type(
'H'));
17253 const auto number = BasicJsonType(n).dump();
17254 write_number_with_ubjson_prefix(number.size(),
true, use_bjdata);
17255 for (std::size_t i = 0; i < number.size(); ++i)
17257 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
17263 template <
typename NumberType,
typename std::enable_if <
17264 std::is_signed<NumberType>::value&&
17265 !std::is_floating_point<NumberType>::value,
int >::type = 0 >
17266 void write_number_with_ubjson_prefix(
const NumberType n,
17267 const bool add_prefix,
17268 const bool use_bjdata)
17270 if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
17274 oa->write_character(to_char_type(
'i'));
17276 write_number(
static_cast<std::int8_t
>(n), use_bjdata);
17278 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)()))
17282 oa->write_character(to_char_type(
'U'));
17284 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
17286 else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
17290 oa->write_character(to_char_type(
'I'));
17292 write_number(
static_cast<std::int16_t
>(n), use_bjdata);
17294 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)())))
17298 oa->write_character(to_char_type(
'u'));
17300 write_number(
static_cast<uint16_t
>(n), use_bjdata);
17302 else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
17306 oa->write_character(to_char_type(
'l'));
17308 write_number(
static_cast<std::int32_t
>(n), use_bjdata);
17310 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)())))
17314 oa->write_character(to_char_type(
'm'));
17316 write_number(
static_cast<uint32_t
>(n), use_bjdata);
17318 else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
17322 oa->write_character(to_char_type(
'L'));
17324 write_number(
static_cast<std::int64_t
>(n), use_bjdata);
17331 oa->write_character(to_char_type(
'H'));
17334 const auto number = BasicJsonType(n).dump();
17335 write_number_with_ubjson_prefix(number.size(),
true, use_bjdata);
17336 for (std::size_t i = 0; i < number.size(); ++i)
17338 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
17347 CharType ubjson_prefix(
const BasicJsonType& j,
const bool use_bjdata)
const noexcept
17351 case value_t::null:
17354 case value_t::boolean:
17355 return j.m_data.m_value.boolean ?
'T' :
'F';
17357 case value_t::number_integer:
17359 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)())
17363 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)())
17367 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)())
17371 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)()))
17375 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)())
17379 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)()))
17383 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)())
17391 case value_t::number_unsigned:
17393 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
17397 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint8_t>::max)()))
17401 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
17405 if (use_bjdata && j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint16_t>::max)()))
17409 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
17413 if (use_bjdata && j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint32_t>::max)()))
17417 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
17421 if (use_bjdata && j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
17429 case value_t::number_float:
17430 return get_ubjson_float_prefix(j.m_data.m_value.number_float);
17432 case value_t::string:
17435 case value_t::array:
17436 case value_t::binary:
17439 case value_t::object:
17442 case value_t::discarded:
17448 static constexpr CharType get_ubjson_float_prefix(
float )
17453 static constexpr CharType get_ubjson_float_prefix(
double )
17461 bool write_bjdata_ndarray(
const typename BasicJsonType::object_t& value,
const bool use_count,
const bool use_type,
const bjdata_version_t bjdata_version)
17463 std::map<string_t, CharType> bjdtype = {{
"uint8",
'U'}, {
"int8",
'i'}, {
"uint16",
'u'}, {
"int16",
'I'},
17464 {
"uint32",
'm'}, {
"int32",
'l'}, {
"uint64",
'M'}, {
"int64",
'L'}, {
"single",
'd'}, {
"double",
'D'},
17465 {
"char",
'C'}, {
"byte",
'B'}
17468 string_t
key =
"_ArrayType_";
17469 auto it = bjdtype.find(
static_cast<string_t
>(value.at(key)));
17470 if (it == bjdtype.end())
17474 CharType dtype = it->second;
17476 key =
"_ArraySize_";
17477 std::size_t len = (value.at(key).empty() ? 0 : 1);
17478 for (
const auto& el : value.at(key))
17480 len *=
static_cast<std::size_t
>(el.m_data.m_value.number_unsigned);
17483 key =
"_ArrayData_";
17484 if (value.at(key).size() != len)
17489 oa->write_character(
'[');
17490 oa->write_character(
'$');
17491 oa->write_character(dtype);
17492 oa->write_character(
'#');
17494 key =
"_ArraySize_";
17495 write_ubjson(value.at(key), use_count, use_type,
true,
true, bjdata_version);
17497 key =
"_ArrayData_";
17498 if (dtype ==
'U' || dtype ==
'C' || dtype ==
'B')
17500 for (
const auto& el : value.at(key))
17502 write_number(
static_cast<std::uint8_t
>(el.m_data.m_value.number_unsigned),
true);
17505 else if (dtype ==
'i')
17507 for (
const auto& el : value.at(key))
17509 write_number(
static_cast<std::int8_t
>(el.m_data.m_value.number_integer),
true);
17512 else if (dtype ==
'u')
17514 for (
const auto& el : value.at(key))
17516 write_number(
static_cast<std::uint16_t
>(el.m_data.m_value.number_unsigned),
true);
17519 else if (dtype ==
'I')
17521 for (
const auto& el : value.at(key))
17523 write_number(
static_cast<std::int16_t
>(el.m_data.m_value.number_integer),
true);
17526 else if (dtype ==
'm')
17528 for (
const auto& el : value.at(key))
17530 write_number(
static_cast<std::uint32_t
>(el.m_data.m_value.number_unsigned),
true);
17533 else if (dtype ==
'l')
17535 for (
const auto& el : value.at(key))
17537 write_number(
static_cast<std::int32_t
>(el.m_data.m_value.number_integer),
true);
17540 else if (dtype ==
'M')
17542 for (
const auto& el : value.at(key))
17544 write_number(
static_cast<std::uint64_t
>(el.m_data.m_value.number_unsigned),
true);
17547 else if (dtype ==
'L')
17549 for (
const auto& el : value.at(key))
17551 write_number(
static_cast<std::int64_t
>(el.m_data.m_value.number_integer),
true);
17554 else if (dtype ==
'd')
17556 for (
const auto& el : value.at(key))
17558 write_number(
static_cast<float>(el.m_data.m_value.number_float),
true);
17561 else if (dtype ==
'D')
17563 for (
const auto& el : value.at(key))
17565 write_number(
static_cast<double>(el.m_data.m_value.number_float),
true);
17588 template<
typename NumberType>
17589 void write_number(
const NumberType n,
const bool OutputIsLittleEndian =
false)
17592 std::array<CharType,
sizeof(NumberType)> vec{};
17593 std::memcpy(vec.data(), &n,
sizeof(NumberType));
17596 if (is_little_endian != OutputIsLittleEndian)
17599 std::reverse(vec.begin(), vec.end());
17602 oa->write_characters(vec.data(),
sizeof(NumberType));
17608#pragma GCC diagnostic push
17609#pragma GCC diagnostic ignored "-Wfloat-equal"
17611 if (!std::isfinite(n) || ((
static_cast<double>(n) >=
static_cast<double>(std::numeric_limits<float>::lowest()) &&
17612 static_cast<double>(n) <=
static_cast<double>((std::numeric_limits<float>::max)()) &&
17613 static_cast<double>(
static_cast<float>(n)) ==
static_cast<double>(n))))
17615 oa->write_character(format == detail::input_format_t::cbor
17616 ? get_cbor_float_prefix(
static_cast<float>(n))
17617 : get_msgpack_float_prefix(
static_cast<float>(n)));
17618 write_number(
static_cast<float>(n));
17622 oa->write_character(format == detail::input_format_t::cbor
17623 ? get_cbor_float_prefix(n)
17624 : get_msgpack_float_prefix(n));
17628#pragma GCC diagnostic pop
17637 template <
typename C = CharType,
17638 enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * =
nullptr >
17639 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
17641 return *
reinterpret_cast<char*
>(&x);
17644 template <
typename C = CharType,
17645 enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * =
nullptr >
17646 static CharType to_char_type(std::uint8_t x)
noexcept
17655#ifdef JSON_HAS_CPP_26
17656 static_assert(std::is_trivially_copyable<CharType>::value,
"CharType must be trivially copyable");
17657 static_assert(std::is_trivially_default_constructible<CharType>::value,
"CharType must be trivially default constructible");
17659 static_assert(std::is_trivial<CharType>::value,
"CharType must be trivial");
17662 static_assert(
sizeof(std::uint8_t) ==
sizeof(CharType),
"size of CharType must be equal to std::uint8_t");
17664 std::memcpy(&result, &x,
sizeof(x));
17668 template<
typename C = CharType,
17669 enable_if_t<std::is_unsigned<C>::value>* =
nullptr>
17670 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
17675 template <
typename InputCharType,
typename C = CharType,
17677 std::is_signed<C>::value &&
17678 std::is_signed<char>::value &&
17679 std::is_same<char, typename std::remove_cv<InputCharType>::type>::value
17681 static constexpr CharType to_char_type(InputCharType x)
noexcept
17691 output_adapter_t<CharType> oa =
nullptr;
17695NLOHMANN_JSON_NAMESPACE_END
17711#include <algorithm>
17721#include <type_traits>
17741#include <type_traits>
17746NLOHMANN_JSON_NAMESPACE_BEGIN
17772template<
typename Target,
typename Source>
17773Target reinterpret_bits(
const Source source)
17775 static_assert(
sizeof(Target) ==
sizeof(Source),
"size mismatch");
17778 std::memcpy(&target, &source,
sizeof(Source));
17784 static constexpr int kPrecision = 64;
17786 std::uint64_t f = 0;
17789 constexpr diyfp(std::uint64_t f_,
int e_) noexcept : f(f_), e(e_) {}
17795 static diyfp
sub(
const diyfp& x,
const diyfp& y)
noexcept
17797 JSON_ASSERT(x.e == y.e);
17798 JSON_ASSERT(x.f >= y.f);
17800 return {x.f - y.f, x.e};
17807 static diyfp
mul(
const diyfp& x,
const diyfp& y)
noexcept
17809 static_assert(kPrecision == 64,
"internal error");
17834 const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
17835 const std::uint64_t u_hi = x.f >> 32u;
17836 const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
17837 const std::uint64_t v_hi = y.f >> 32u;
17839 const std::uint64_t p0 = u_lo * v_lo;
17840 const std::uint64_t p1 = u_lo * v_hi;
17841 const std::uint64_t p2 = u_hi * v_lo;
17842 const std::uint64_t p3 = u_hi * v_hi;
17844 const std::uint64_t p0_hi = p0 >> 32u;
17845 const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
17846 const std::uint64_t p1_hi = p1 >> 32u;
17847 const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
17848 const std::uint64_t p2_hi = p2 >> 32u;
17850 std::uint64_t Q = p0_hi + p1_lo + p2_lo;
17861 Q += std::uint64_t{1} << (64u - 32u - 1u);
17863 const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
17865 return {h, x.e + y.e + 64};
17874 JSON_ASSERT(x.f != 0);
17876 while ((x.f >> 63u) == 0)
17891 const int delta = x.e - target_exponent;
17893 JSON_ASSERT(delta >= 0);
17894 JSON_ASSERT(((x.f << delta) >> delta) == x.f);
17896 return {x.f << delta, target_exponent};
17913template<
typename FloatType>
17916 JSON_ASSERT(std::isfinite(value));
17917 JSON_ASSERT(value > 0);
17926 static_assert(std::numeric_limits<FloatType>::is_iec559,
17927 "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
17929 constexpr int kPrecision = std::numeric_limits<FloatType>::digits;
17930 constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
17931 constexpr int kMinExp = 1 - kBias;
17932 constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
17934 using bits_type =
typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
17936 const auto bits =
static_cast<std::uint64_t
>(reinterpret_bits<bits_type>(value));
17937 const std::uint64_t E = bits >> (kPrecision - 1);
17938 const std::uint64_t F = bits & (kHiddenBit - 1);
17940 const bool is_denormal = E == 0;
17941 const diyfp v = is_denormal
17942 ?
diyfp(F, kMinExp)
17943 :
diyfp(F + kHiddenBit,
static_cast<int>(E) - kBias);
17966 const bool lower_boundary_is_closer = F == 0 && E > 1;
17967 const diyfp m_plus =
diyfp((2 * v.f) + 1, v.e - 1);
17968 const diyfp m_minus = lower_boundary_is_closer
17969 ?
diyfp((4 * v.f) - 1, v.e - 2)
17970 :
diyfp((2 * v.f) - 1, v.e - 1);
18036constexpr int kAlpha = -60;
18037constexpr int kGamma = -32;
18105 constexpr int kCachedPowersMinDecExp = -300;
18106 constexpr int kCachedPowersDecStep = 8;
18108 static constexpr std::array<cached_power, 79> kCachedPowers =
18111 { 0xAB70FE17C79AC6CA, -1060, -300 },
18112 { 0xFF77B1FCBEBCDC4F, -1034, -292 },
18113 { 0xBE5691EF416BD60C, -1007, -284 },
18114 { 0x8DD01FAD907FFC3C, -980, -276 },
18115 { 0xD3515C2831559A83, -954, -268 },
18116 { 0x9D71AC8FADA6C9B5, -927, -260 },
18117 { 0xEA9C227723EE8BCB, -901, -252 },
18118 { 0xAECC49914078536D, -874, -244 },
18119 { 0x823C12795DB6CE57, -847, -236 },
18120 { 0xC21094364DFB5637, -821, -228 },
18121 { 0x9096EA6F3848984F, -794, -220 },
18122 { 0xD77485CB25823AC7, -768, -212 },
18123 { 0xA086CFCD97BF97F4, -741, -204 },
18124 { 0xEF340A98172AACE5, -715, -196 },
18125 { 0xB23867FB2A35B28E, -688, -188 },
18126 { 0x84C8D4DFD2C63F3B, -661, -180 },
18127 { 0xC5DD44271AD3CDBA, -635, -172 },
18128 { 0x936B9FCEBB25C996, -608, -164 },
18129 { 0xDBAC6C247D62A584, -582, -156 },
18130 { 0xA3AB66580D5FDAF6, -555, -148 },
18131 { 0xF3E2F893DEC3F126, -529, -140 },
18132 { 0xB5B5ADA8AAFF80B8, -502, -132 },
18133 { 0x87625F056C7C4A8B, -475, -124 },
18134 { 0xC9BCFF6034C13053, -449, -116 },
18135 { 0x964E858C91BA2655, -422, -108 },
18136 { 0xDFF9772470297EBD, -396, -100 },
18137 { 0xA6DFBD9FB8E5B88F, -369, -92 },
18138 { 0xF8A95FCF88747D94, -343, -84 },
18139 { 0xB94470938FA89BCF, -316, -76 },
18140 { 0x8A08F0F8BF0F156B, -289, -68 },
18141 { 0xCDB02555653131B6, -263, -60 },
18142 { 0x993FE2C6D07B7FAC, -236, -52 },
18143 { 0xE45C10C42A2B3B06, -210, -44 },
18144 { 0xAA242499697392D3, -183, -36 },
18145 { 0xFD87B5F28300CA0E, -157, -28 },
18146 { 0xBCE5086492111AEB, -130, -20 },
18147 { 0x8CBCCC096F5088CC, -103, -12 },
18148 { 0xD1B71758E219652C, -77, -4 },
18149 { 0x9C40000000000000, -50, 4 },
18150 { 0xE8D4A51000000000, -24, 12 },
18151 { 0xAD78EBC5AC620000, 3, 20 },
18152 { 0x813F3978F8940984, 30, 28 },
18153 { 0xC097CE7BC90715B3, 56, 36 },
18154 { 0x8F7E32CE7BEA5C70, 83, 44 },
18155 { 0xD5D238A4ABE98068, 109, 52 },
18156 { 0x9F4F2726179A2245, 136, 60 },
18157 { 0xED63A231D4C4FB27, 162, 68 },
18158 { 0xB0DE65388CC8ADA8, 189, 76 },
18159 { 0x83C7088E1AAB65DB, 216, 84 },
18160 { 0xC45D1DF942711D9A, 242, 92 },
18161 { 0x924D692CA61BE758, 269, 100 },
18162 { 0xDA01EE641A708DEA, 295, 108 },
18163 { 0xA26DA3999AEF774A, 322, 116 },
18164 { 0xF209787BB47D6B85, 348, 124 },
18165 { 0xB454E4A179DD1877, 375, 132 },
18166 { 0x865B86925B9BC5C2, 402, 140 },
18167 { 0xC83553C5C8965D3D, 428, 148 },
18168 { 0x952AB45CFA97A0B3, 455, 156 },
18169 { 0xDE469FBD99A05FE3, 481, 164 },
18170 { 0xA59BC234DB398C25, 508, 172 },
18171 { 0xF6C69A72A3989F5C, 534, 180 },
18172 { 0xB7DCBF5354E9BECE, 561, 188 },
18173 { 0x88FCF317F22241E2, 588, 196 },
18174 { 0xCC20CE9BD35C78A5, 614, 204 },
18175 { 0x98165AF37B2153DF, 641, 212 },
18176 { 0xE2A0B5DC971F303A, 667, 220 },
18177 { 0xA8D9D1535CE3B396, 694, 228 },
18178 { 0xFB9B7CD9A4A7443C, 720, 236 },
18179 { 0xBB764C4CA7A44410, 747, 244 },
18180 { 0x8BAB8EEFB6409C1A, 774, 252 },
18181 { 0xD01FEF10A657842C, 800, 260 },
18182 { 0x9B10A4E5E9913129, 827, 268 },
18183 { 0xE7109BFBA19C0C9D, 853, 276 },
18184 { 0xAC2820D9623BF429, 880, 284 },
18185 { 0x80444B5E7AA7CF85, 907, 292 },
18186 { 0xBF21E44003ACDD2D, 933, 300 },
18187 { 0x8E679C2F5E44FF8F, 960, 308 },
18188 { 0xD433179D9C8CB841, 986, 316 },
18189 { 0x9E19DB92B4E31BA9, 1013, 324 },
18197 JSON_ASSERT(e >= -1500);
18198 JSON_ASSERT(e <= 1500);
18199 const int f = kAlpha - e - 1;
18200 const int k = ((f * 78913) / (1 << 18)) +
static_cast<int>(f > 0);
18202 const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
18203 JSON_ASSERT(index >= 0);
18204 JSON_ASSERT(
static_cast<std::size_t
>(index) < kCachedPowers.size());
18206 const cached_power cached = kCachedPowers[
static_cast<std::size_t
>(index)];
18207 JSON_ASSERT(kAlpha <= cached.e + e + 64);
18208 JSON_ASSERT(kGamma >= cached.e + e + 64);
18220 if (n >= 1000000000)
18222 pow10 = 1000000000;
18226 if (n >= 100000000)
18271inline void grisu2_round(
char* buf,
int len, std::uint64_t dist, std::uint64_t delta,
18272 std::uint64_t rest, std::uint64_t ten_k)
18274 JSON_ASSERT(len >= 1);
18275 JSON_ASSERT(dist <= delta);
18276 JSON_ASSERT(rest <= delta);
18277 JSON_ASSERT(ten_k > 0);
18299 && delta - rest >= ten_k
18300 && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
18302 JSON_ASSERT(buf[len - 1] !=
'0');
18315 static_assert(kAlpha >= -60,
"internal error");
18316 static_assert(kGamma <= -32,
"internal error");
18330 JSON_ASSERT(M_plus.e >= kAlpha);
18331 JSON_ASSERT(M_plus.e <= kGamma);
18333 std::uint64_t delta =
diyfp::sub(M_plus, M_minus).f;
18334 std::uint64_t dist =
diyfp::sub(M_plus, w ).f;
18343 const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
18345 auto p1 =
static_cast<std::uint32_t
>(M_plus.f >> -one.e);
18346 std::uint64_t p2 = M_plus.f & (one.f - 1);
18352 JSON_ASSERT(p1 > 0);
18354 std::uint32_t pow10{};
18382 const std::uint32_t d = p1 / pow10;
18383 const std::uint32_t r = p1 % pow10;
18388 JSON_ASSERT(d <= 9);
18389 buffer[length++] =
static_cast<char>(
'0' + d);
18408 const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
18413 decimal_exponent += n;
18424 const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
18425 grisu2_round(buffer, length, dist, delta, rest, ten_n);
18475 JSON_ASSERT(p2 > delta);
18486 JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
18488 const std::uint64_t d = p2 >> -one.e;
18489 const std::uint64_t r = p2 & (one.f - 1);
18495 JSON_ASSERT(d <= 9);
18496 buffer[length++] =
static_cast<char>(
'0' + d);
18521 decimal_exponent -= m;
18529 const std::uint64_t ten_m = one.f;
18530 grisu2_round(buffer, length, dist, delta, p2, ten_m);
18552JSON_HEDLEY_NON_NULL(1)
18553inline
void grisu2(
char* buf,
int& len,
int& decimal_exponent,
18556 JSON_ASSERT(m_plus.e == m_minus.e);
18557 JSON_ASSERT(m_plus.e == v.e);
18570 const diyfp c_minus_k(cached.f, cached.e);
18598 const diyfp M_minus(w_minus.f + 1, w_minus.e);
18599 const diyfp M_plus (w_plus.f - 1, w_plus.e );
18601 decimal_exponent = -cached.k;
18611template<
typename FloatType>
18612JSON_HEDLEY_NON_NULL(1)
18613void
grisu2(
char* buf,
int& len,
int& decimal_exponent, FloatType value)
18615 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
18616 "internal error: not enough precision");
18618 JSON_ASSERT(std::isfinite(value));
18619 JSON_ASSERT(value > 0);
18643 grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
18651JSON_HEDLEY_NON_NULL(1)
18652JSON_HEDLEY_RETURNS_NON_NULL
18655 JSON_ASSERT(e > -1000);
18656 JSON_ASSERT(e < 1000);
18668 auto k =
static_cast<std::uint32_t
>(e);
18674 *buf++ =
static_cast<char>(
'0' + k);
18678 *buf++ =
static_cast<char>(
'0' + (k / 10));
18680 *buf++ =
static_cast<char>(
'0' + k);
18684 *buf++ =
static_cast<char>(
'0' + (k / 100));
18686 *buf++ =
static_cast<char>(
'0' + (k / 10));
18688 *buf++ =
static_cast<char>(
'0' + k);
18703JSON_HEDLEY_NON_NULL(1)
18704JSON_HEDLEY_RETURNS_NON_NULL
18706 int min_exp,
int max_exp)
18708 JSON_ASSERT(min_exp < 0);
18709 JSON_ASSERT(max_exp > 0);
18712 const int n = len + decimal_exponent;
18718 if (k <= n && n <= max_exp)
18723 std::memset(buf + k,
'0',
static_cast<size_t>(n) -
static_cast<size_t>(k));
18727 return buf + (
static_cast<size_t>(n) + 2);
18730 if (0 < n && n <= max_exp)
18735 JSON_ASSERT(k > n);
18737 std::memmove(buf + (
static_cast<size_t>(n) + 1), buf + n,
static_cast<size_t>(k) -
static_cast<size_t>(n));
18739 return buf + (
static_cast<size_t>(k) + 1U);
18742 if (min_exp < n && n <= 0)
18747 std::memmove(buf + (2 +
static_cast<size_t>(-n)), buf,
static_cast<size_t>(k));
18750 std::memset(buf + 2,
'0',
static_cast<size_t>(-n));
18751 return buf + (2U +
static_cast<size_t>(-n) +
static_cast<size_t>(k));
18766 std::memmove(buf + 2, buf + 1,
static_cast<size_t>(k) - 1);
18768 buf += 1 +
static_cast<size_t>(k);
18787template<
typename FloatType>
18788JSON_HEDLEY_NON_NULL(1, 2)
18789JSON_HEDLEY_RETURNS_NON_NULL
18790char*
to_chars(
char* first, const
char* last, FloatType value)
18792 static_cast<void>(last);
18793 JSON_ASSERT(std::isfinite(value));
18796 if (std::signbit(value))
18803#pragma GCC diagnostic push
18804#pragma GCC diagnostic ignored "-Wfloat-equal"
18815#pragma GCC diagnostic pop
18818 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
18825 int decimal_exponent = 0;
18828 JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
18831 constexpr int kMinExp = -4;
18833 constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10;
18835 JSON_ASSERT(last - first >= kMaxExp + 2);
18836 JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
18837 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
18843NLOHMANN_JSON_NAMESPACE_END
18860NLOHMANN_JSON_NAMESPACE_BEGIN
18876template<
typename BasicJsonType>
18879 using string_t =
typename BasicJsonType::string_t;
18880 using number_float_t =
typename BasicJsonType::number_float_t;
18881 using number_integer_t =
typename BasicJsonType::number_integer_t;
18882 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
18883 using binary_char_t =
typename BasicJsonType::binary_t::value_type;
18884 static constexpr std::uint8_t UTF8_ACCEPT = 0;
18885 static constexpr std::uint8_t UTF8_REJECT = 1;
18896 ,
loc(std::localeconv())
18934 const bool pretty_print,
18935 const bool ensure_ascii,
18936 const unsigned int indent_step,
18937 const unsigned int current_indent = 0)
18939 switch (val.m_data.m_type)
18943 if (val.m_data.m_value.object->empty())
18945 o->write_characters(
"{}", 2);
18951 o->write_characters(
"{\n", 2);
18954 const auto new_indent = current_indent + indent_step;
18955 if (JSON_HEDLEY_UNLIKELY(
indent_string.size() < new_indent))
18961 auto i = val.m_data.m_value.object->cbegin();
18962 for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)
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);
18969 o->write_characters(
",\n", 2);
18973 JSON_ASSERT(i != val.m_data.m_value.object->cend());
18974 JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
18976 o->write_character(
'\"');
18977 dump_escaped(i->first, ensure_ascii);
18978 o->write_characters(
"\": ", 3);
18979 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
18981 o->write_character(
'\n');
18982 o->write_characters(
indent_string.c_str(), current_indent);
18983 o->write_character(
'}');
18987 o->write_character(
'{');
18990 auto i = val.m_data.m_value.object->cbegin();
18991 for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)
18993 o->write_character(
'\"');
18994 dump_escaped(i->first, ensure_ascii);
18995 o->write_characters(
"\":", 2);
18996 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
18997 o->write_character(
',');
19001 JSON_ASSERT(i != val.m_data.m_value.object->cend());
19002 JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
19003 o->write_character(
'\"');
19004 dump_escaped(i->first, ensure_ascii);
19005 o->write_characters(
"\":", 2);
19006 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
19008 o->write_character(
'}');
19016 if (val.m_data.m_value.array->empty())
19018 o->write_characters(
"[]", 2);
19024 o->write_characters(
"[\n", 2);
19027 const auto new_indent = current_indent + indent_step;
19028 if (JSON_HEDLEY_UNLIKELY(
indent_string.size() < new_indent))
19034 for (
auto i = val.m_data.m_value.array->cbegin();
19035 i != val.m_data.m_value.array->cend() - 1; ++i)
19038 dump(*i,
true, ensure_ascii, indent_step, new_indent);
19039 o->write_characters(
",\n", 2);
19043 JSON_ASSERT(!val.m_data.m_value.array->empty());
19045 dump(val.m_data.m_value.array->back(),
true, ensure_ascii, indent_step, new_indent);
19047 o->write_character(
'\n');
19048 o->write_characters(
indent_string.c_str(), current_indent);
19049 o->write_character(
']');
19053 o->write_character(
'[');
19056 for (
auto i = val.m_data.m_value.array->cbegin();
19057 i != val.m_data.m_value.array->cend() - 1; ++i)
19059 dump(*i,
false, ensure_ascii, indent_step, current_indent);
19060 o->write_character(
',');
19064 JSON_ASSERT(!val.m_data.m_value.array->empty());
19065 dump(val.m_data.m_value.array->back(),
false, ensure_ascii, indent_step, current_indent);
19067 o->write_character(
']');
19075 o->write_character(
'\"');
19076 dump_escaped(*val.m_data.m_value.string, ensure_ascii);
19077 o->write_character(
'\"');
19085 o->write_characters(
"{\n", 2);
19088 const auto new_indent = current_indent + indent_step;
19089 if (JSON_HEDLEY_UNLIKELY(
indent_string.size() < new_indent))
19096 o->write_characters(
"\"bytes\": [", 10);
19098 if (!val.m_data.m_value.binary->empty())
19100 for (
auto i = val.m_data.m_value.binary->cbegin();
19101 i != val.m_data.m_value.binary->cend() - 1; ++i)
19104 o->write_characters(
", ", 2);
19106 dump_integer(val.m_data.m_value.binary->back());
19109 o->write_characters(
"],\n", 3);
19112 o->write_characters(
"\"subtype\": ", 11);
19113 if (val.m_data.m_value.binary->has_subtype())
19115 dump_integer(val.m_data.m_value.binary->subtype());
19119 o->write_characters(
"null", 4);
19121 o->write_character(
'\n');
19122 o->write_characters(
indent_string.c_str(), current_indent);
19123 o->write_character(
'}');
19127 o->write_characters(
"{\"bytes\":[", 10);
19129 if (!val.m_data.m_value.binary->empty())
19131 for (
auto i = val.m_data.m_value.binary->cbegin();
19132 i != val.m_data.m_value.binary->cend() - 1; ++i)
19135 o->write_character(
',');
19137 dump_integer(val.m_data.m_value.binary->back());
19140 o->write_characters(
"],\"subtype\":", 12);
19141 if (val.m_data.m_value.binary->has_subtype())
19143 dump_integer(val.m_data.m_value.binary->subtype());
19144 o->write_character(
'}');
19148 o->write_characters(
"null}", 5);
19156 if (val.m_data.m_value.boolean)
19158 o->write_characters(
"true", 4);
19162 o->write_characters(
"false", 5);
19169 dump_integer(val.m_data.m_value.number_integer);
19175 dump_integer(val.m_data.m_value.number_unsigned);
19181 dump_float(val.m_data.m_value.number_float);
19187 o->write_characters(
"<discarded>", 11);
19193 o->write_characters(
"null", 4);
19198 JSON_ASSERT(
false);
19202 JSON_PRIVATE_UNLESS_TESTED:
19217 void dump_escaped(
const string_t& s,
const bool ensure_ascii)
19219 std::uint32_t codepoint{};
19220 std::uint8_t state = UTF8_ACCEPT;
19221 std::size_t bytes = 0;
19224 std::size_t bytes_after_last_accept = 0;
19225 std::size_t undumped_chars = 0;
19227 for (std::size_t i = 0; i < s.size(); ++i)
19229 const auto byte =
static_cast<std::uint8_t
>(s[i]);
19231 switch (decode(state, codepoint,
byte))
19239 string_buffer[bytes++] =
'\\';
19240 string_buffer[bytes++] =
'b';
19246 string_buffer[bytes++] =
'\\';
19247 string_buffer[bytes++] =
't';
19253 string_buffer[bytes++] =
'\\';
19254 string_buffer[bytes++] =
'n';
19260 string_buffer[bytes++] =
'\\';
19261 string_buffer[bytes++] =
'f';
19267 string_buffer[bytes++] =
'\\';
19268 string_buffer[bytes++] =
'r';
19274 string_buffer[bytes++] =
'\\';
19275 string_buffer[bytes++] =
'\"';
19281 string_buffer[bytes++] =
'\\';
19282 string_buffer[bytes++] =
'\\';
19290 if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
19292 if (codepoint <= 0xFFFF)
19295 static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 7,
"\\u%04x",
19296 static_cast<std::uint16_t
>(codepoint)));
19302 static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 13,
"\\u%04x\\u%04x",
19303 static_cast<std::uint16_t
>(0xD7C0u + (codepoint >> 10u)),
19304 static_cast<std::uint16_t
>(0xDC00u + (codepoint & 0x3FFu))));
19312 string_buffer[bytes++] = s[i];
19321 if (string_buffer.size() - bytes < 13)
19323 o->write_characters(string_buffer.data(), bytes);
19328 bytes_after_last_accept = bytes;
19329 undumped_chars = 0;
19335 switch (error_handler)
19337 case error_handler_t::strict:
19339 JSON_THROW(type_error::create(316, concat(
"invalid UTF-8 byte at index ", std::to_string(i),
": 0x", hex_bytes(
byte | 0)),
nullptr));
19342 case error_handler_t::ignore:
19343 case error_handler_t::replace:
19349 if (undumped_chars > 0)
19356 bytes = bytes_after_last_accept;
19358 if (error_handler == error_handler_t::replace)
19363 string_buffer[bytes++] =
'\\';
19364 string_buffer[bytes++] =
'u';
19365 string_buffer[bytes++] =
'f';
19366 string_buffer[bytes++] =
'f';
19367 string_buffer[bytes++] =
'f';
19368 string_buffer[bytes++] =
'd';
19372 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xEF');
19373 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBF');
19374 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBD');
19380 if (string_buffer.size() - bytes < 13)
19382 o->write_characters(string_buffer.data(), bytes);
19386 bytes_after_last_accept = bytes;
19389 undumped_chars = 0;
19392 state = UTF8_ACCEPT;
19397 JSON_ASSERT(
false);
19407 string_buffer[bytes++] = s[i];
19416 if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
19421 o->write_characters(string_buffer.data(), bytes);
19427 switch (error_handler)
19429 case error_handler_t::strict:
19431 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));
19434 case error_handler_t::ignore:
19437 o->write_characters(string_buffer.data(), bytes_after_last_accept);
19441 case error_handler_t::replace:
19444 o->write_characters(string_buffer.data(), bytes_after_last_accept);
19448 o->write_characters(
"\\ufffd", 6);
19452 o->write_characters(
"\xEF\xBF\xBD", 3);
19458 JSON_ASSERT(
false);
19472 unsigned int count_digits(number_unsigned_t x)
noexcept
19474 unsigned int n_digits = 1;
19483 return n_digits + 1;
19487 return n_digits + 2;
19491 return n_digits + 3;
19503 static std::string hex_bytes(std::uint8_t
byte)
19505 std::string result =
"FF";
19506 constexpr const char* nibble_to_hex =
"0123456789ABCDEF";
19507 result[0] = nibble_to_hex[
byte / 16];
19508 result[1] = nibble_to_hex[
byte % 16];
19513 template <typename NumberType, enable_if_t<std::is_signed<NumberType>::value,
int> = 0>
19514 bool is_negative_number(NumberType x)
19519 template < typename NumberType, enable_if_t <std::is_unsigned<NumberType>::value,
int > = 0 >
19520 bool is_negative_number(NumberType )
19534 template <
typename NumberType, detail::enable_if_t <
19535 std::is_integral<NumberType>::value ||
19536 std::is_same<NumberType, number_unsigned_t>::value ||
19537 std::is_same<NumberType, number_integer_t>::value ||
19538 std::is_same<NumberType, binary_char_t>::value,
19540 void dump_integer(NumberType x)
19542 static constexpr std::array<std::array<char, 2>, 100> digits_to_99
19545 {{
'0',
'0'}}, {{
'0',
'1'}}, {{
'0',
'2'}}, {{
'0',
'3'}}, {{
'0',
'4'}}, {{
'0',
'5'}}, {{
'0',
'6'}}, {{
'0',
'7'}}, {{
'0',
'8'}}, {{
'0',
'9'}},
19546 {{
'1',
'0'}}, {{
'1',
'1'}}, {{
'1',
'2'}}, {{
'1',
'3'}}, {{
'1',
'4'}}, {{
'1',
'5'}}, {{
'1',
'6'}}, {{
'1',
'7'}}, {{
'1',
'8'}}, {{
'1',
'9'}},
19547 {{
'2',
'0'}}, {{
'2',
'1'}}, {{
'2',
'2'}}, {{
'2',
'3'}}, {{
'2',
'4'}}, {{
'2',
'5'}}, {{
'2',
'6'}}, {{
'2',
'7'}}, {{
'2',
'8'}}, {{
'2',
'9'}},
19548 {{
'3',
'0'}}, {{
'3',
'1'}}, {{
'3',
'2'}}, {{
'3',
'3'}}, {{
'3',
'4'}}, {{
'3',
'5'}}, {{
'3',
'6'}}, {{
'3',
'7'}}, {{
'3',
'8'}}, {{
'3',
'9'}},
19549 {{
'4',
'0'}}, {{
'4',
'1'}}, {{
'4',
'2'}}, {{
'4',
'3'}}, {{
'4',
'4'}}, {{
'4',
'5'}}, {{
'4',
'6'}}, {{
'4',
'7'}}, {{
'4',
'8'}}, {{
'4',
'9'}},
19550 {{
'5',
'0'}}, {{
'5',
'1'}}, {{
'5',
'2'}}, {{
'5',
'3'}}, {{
'5',
'4'}}, {{
'5',
'5'}}, {{
'5',
'6'}}, {{
'5',
'7'}}, {{
'5',
'8'}}, {{
'5',
'9'}},
19551 {{
'6',
'0'}}, {{
'6',
'1'}}, {{
'6',
'2'}}, {{
'6',
'3'}}, {{
'6',
'4'}}, {{
'6',
'5'}}, {{
'6',
'6'}}, {{
'6',
'7'}}, {{
'6',
'8'}}, {{
'6',
'9'}},
19552 {{
'7',
'0'}}, {{
'7',
'1'}}, {{
'7',
'2'}}, {{
'7',
'3'}}, {{
'7',
'4'}}, {{
'7',
'5'}}, {{
'7',
'6'}}, {{
'7',
'7'}}, {{
'7',
'8'}}, {{
'7',
'9'}},
19553 {{
'8',
'0'}}, {{
'8',
'1'}}, {{
'8',
'2'}}, {{
'8',
'3'}}, {{
'8',
'4'}}, {{
'8',
'5'}}, {{
'8',
'6'}}, {{
'8',
'7'}}, {{
'8',
'8'}}, {{
'8',
'9'}},
19554 {{
'9',
'0'}}, {{
'9',
'1'}}, {{
'9',
'2'}}, {{
'9',
'3'}}, {{
'9',
'4'}}, {{
'9',
'5'}}, {{
'9',
'6'}}, {{
'9',
'7'}}, {{
'9',
'8'}}, {{
'9',
'9'}},
19561 o->write_character(
'0');
19566 auto buffer_ptr = number_buffer.begin();
19568 number_unsigned_t abs_value;
19570 unsigned int n_chars{};
19572 if (is_negative_number(x))
19575 abs_value = remove_sign(
static_cast<number_integer_t
>(x));
19578 n_chars = 1 + count_digits(abs_value);
19582 abs_value =
static_cast<number_unsigned_t
>(x);
19583 n_chars = count_digits(abs_value);
19587 JSON_ASSERT(n_chars < number_buffer.size() - 1);
19591 buffer_ptr +=
static_cast<typename decltype(number_buffer)::difference_type
>(n_chars);
19595 while (abs_value >= 100)
19597 const auto digits_index =
static_cast<unsigned>((abs_value % 100));
19599 *(--buffer_ptr) = digits_to_99[digits_index][1];
19600 *(--buffer_ptr) = digits_to_99[digits_index][0];
19603 if (abs_value >= 10)
19605 const auto digits_index =
static_cast<unsigned>(abs_value);
19606 *(--buffer_ptr) = digits_to_99[digits_index][1];
19607 *(--buffer_ptr) = digits_to_99[digits_index][0];
19611 *(--buffer_ptr) =
static_cast<char>(
'0' + abs_value);
19614 o->write_characters(number_buffer.data(), n_chars);
19625 void dump_float(number_float_t x)
19628 if (!std::isfinite(x))
19630 o->write_characters(
"null", 4);
19639 static constexpr bool is_ieee_single_or_double
19640 = (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) ||
19641 (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);
19643 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
19646 void dump_float(number_float_t x, std::true_type )
19648 auto* begin = number_buffer.data();
19649 auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
19651 o->write_characters(begin,
static_cast<size_t>(end - begin));
19654 void dump_float(number_float_t x, std::false_type )
19657 static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
19661 std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(),
"%.*g", d, x);
19664 JSON_ASSERT(len > 0);
19666 JSON_ASSERT(
static_cast<std::size_t
>(len) < number_buffer.size());
19669 if (thousands_sep !=
'\0')
19672 const auto end = std::remove(number_buffer.begin(), number_buffer.begin() + len, thousands_sep);
19673 std::fill(end, number_buffer.end(),
'\0');
19674 JSON_ASSERT((end - number_buffer.begin()) <= len);
19675 len = (end - number_buffer.begin());
19679 if (decimal_point !=
'\0' && decimal_point !=
'.')
19682 const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
19683 if (dec_pos != number_buffer.end())
19689 o->write_characters(number_buffer.data(),
static_cast<std::size_t
>(len));
19692 const bool value_is_int_like =
19693 std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
19696 return c ==
'.' || c ==
'e';
19699 if (value_is_int_like)
19701 o->write_characters(
".0", 2);
19726 static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep,
const std::uint8_t
byte)
noexcept
19728 static const std::array<std::uint8_t, 400> utf8d =
19731 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,
19732 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,
19733 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,
19734 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,
19735 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,
19736 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,
19737 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,
19738 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3,
19739 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
19740 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1,
19741 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,
19742 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,
19743 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,
19744 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
19748 JSON_ASSERT(
byte < utf8d.size());
19749 const std::uint8_t type = utf8d[byte];
19751 codep = (state != UTF8_ACCEPT)
19752 ? (
byte & 0x3fu) | (codep << 6u)
19753 : (0xFFu >> type) & (byte);
19755 const std::size_t index = 256u + (
static_cast<size_t>(state) * 16u) +
static_cast<size_t>(type);
19756 JSON_ASSERT(index < utf8d.size());
19757 state = utf8d[index];
19766 number_unsigned_t remove_sign(number_unsigned_t x)
19768 JSON_ASSERT(
false);
19781 number_unsigned_t remove_sign(number_integer_t x)
noexcept
19783 JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)());
19784 return static_cast<number_unsigned_t
>(-(x + 1)) + 1;
19789 output_adapter_t<char> o =
nullptr;
19814NLOHMANN_JSON_NAMESPACE_END
19831#include <functional>
19832#include <initializer_list>
19835#include <stdexcept>
19836#include <type_traits>
19845NLOHMANN_JSON_NAMESPACE_BEGIN
19849template <
class Key,
class T,
class IgnoredLess = std::less<Key>,
19850 class Allocator = std::allocator<std::pair<const Key, T>>>
19851 struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
19853 using key_type = Key;
19854 using mapped_type = T;
19855 using Container = std::vector<std::pair<const Key, T>, Allocator>;
19856 using iterator =
typename Container::iterator;
19857 using const_iterator =
typename Container::const_iterator;
19858 using size_type =
typename Container::size_type;
19859 using value_type =
typename Container::value_type;
19860#ifdef JSON_HAS_CPP_14
19861 using key_compare = std::equal_to<>;
19863 using key_compare = std::equal_to<Key>;
19868 ordered_map()
noexcept(
noexcept(Container())) : Container{} {}
19869 explicit ordered_map(
const Allocator& alloc)
noexcept(
noexcept(Container(alloc))) : Container{alloc} {}
19870 template <
class It>
19871 ordered_map(It first, It last,
const Allocator& alloc = Allocator())
19872 : Container{first, last, alloc} {}
19873 ordered_map(std::initializer_list<value_type> init,
const Allocator& alloc = Allocator() )
19874 : Container{init, alloc} {}
19876 std::pair<iterator, bool> emplace(
const key_type& key, T&& t)
19878 for (
auto it = this->begin(); it != this->end(); ++it)
19880 if (m_compare(it->first, key))
19882 return {it,
false};
19885 Container::emplace_back(key, std::forward<T>(t));
19886 return {std::prev(this->end()),
true};
19889 template<
class KeyType, detail::enable_if_t<
19890 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19891 std::pair<iterator, bool> emplace(KeyType && key, T && t)
19893 for (
auto it = this->begin(); it != this->end(); ++it)
19895 if (m_compare(it->first, key))
19897 return {it,
false};
19900 Container::emplace_back(std::forward<KeyType>(key), std::forward<T>(t));
19901 return {std::prev(this->end()),
true};
19904 T& operator[](
const key_type& key)
19906 return emplace(key, T{}).first->second;
19909 template<
class KeyType, detail::enable_if_t<
19910 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19911 T & operator[](KeyType && key)
19913 return emplace(std::forward<KeyType>(key), T{}).first->second;
19916 const T& operator[](
const key_type& key)
const
19921 template<
class KeyType, detail::enable_if_t<
19922 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19923 const T & operator[](KeyType && key)
const
19925 return at(std::forward<KeyType>(key));
19928 T& at(
const key_type& key)
19930 for (
auto it = this->begin(); it != this->end(); ++it)
19932 if (m_compare(it->first, key))
19938 JSON_THROW(std::out_of_range(
"key not found"));
19941 template<
class KeyType, detail::enable_if_t<
19942 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19943 T & at(KeyType && key)
19945 for (
auto it = this->begin(); it != this->end(); ++it)
19947 if (m_compare(it->first, key))
19953 JSON_THROW(std::out_of_range(
"key not found"));
19956 const T& at(
const key_type& key)
const
19958 for (
auto it = this->begin(); it != this->end(); ++it)
19960 if (m_compare(it->first, key))
19966 JSON_THROW(std::out_of_range(
"key not found"));
19969 template<
class KeyType, detail::enable_if_t<
19970 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19971 const T & at(KeyType && key)
const
19973 for (
auto it = this->begin(); it != this->end(); ++it)
19975 if (m_compare(it->first, key))
19981 JSON_THROW(std::out_of_range(
"key not found"));
19984 size_type erase(
const key_type& key)
19986 for (
auto it = this->begin(); it != this->end(); ++it)
19988 if (m_compare(it->first, key))
19991 for (
auto next = it; ++next != this->end(); ++it)
19994 new (&*it) value_type{std::move(*next)};
19996 Container::pop_back();
20003 template<
class KeyType, detail::enable_if_t<
20004 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
20005 size_type erase(KeyType && key)
20007 for (
auto it = this->begin(); it != this->end(); ++it)
20009 if (m_compare(it->first, key))
20012 for (
auto next = it; ++next != this->end(); ++it)
20015 new (&*it) value_type{std::move(*next)};
20017 Container::pop_back();
20024 iterator erase(iterator pos)
20026 return erase(pos, std::next(pos));
20029 iterator erase(iterator first, iterator last)
20036 const auto elements_affected = std::distance(first, last);
20037 const auto offset = std::distance(Container::begin(), first);
20059 for (
auto it = first; std::next(it, elements_affected) != Container::end(); ++it)
20062 new (&*it) value_type{std::move(*std::next(it, elements_affected))};
20070 Container::resize(this->size() -
static_cast<size_type
>(elements_affected));
20079 return Container::begin() + offset;
20082 size_type count(
const key_type& key)
const
20084 for (
auto it = this->begin(); it != this->end(); ++it)
20086 if (m_compare(it->first, key))
20094 template<
class KeyType, detail::enable_if_t<
20095 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
20096 size_type count(KeyType && key)
const
20098 for (
auto it = this->begin(); it != this->end(); ++it)
20100 if (m_compare(it->first, key))
20108 iterator find(
const key_type& key)
20110 for (
auto it = this->begin(); it != this->end(); ++it)
20112 if (m_compare(it->first, key))
20117 return Container::end();
20120 template<
class KeyType, detail::enable_if_t<
20121 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
20122 iterator find(KeyType && key)
20124 for (
auto it = this->begin(); it != this->end(); ++it)
20126 if (m_compare(it->first, key))
20131 return Container::end();
20134 const_iterator find(
const key_type& key)
const
20136 for (
auto it = this->begin(); it != this->end(); ++it)
20138 if (m_compare(it->first, key))
20143 return Container::end();
20146 std::pair<iterator, bool> insert( value_type&& value )
20148 return emplace(value.first, std::move(value.second));
20151 std::pair<iterator, bool> insert(
const value_type& value )
20153 for (
auto it = this->begin(); it != this->end(); ++it)
20155 if (m_compare(it->first, value.first))
20157 return {it,
false};
20160 Container::push_back(value);
20161 return {--this->end(),
true};
20164 template<
typename InputIt>
20165 using require_input_iter =
typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
20166 std::input_iterator_tag>::value>::type;
20168 template<
typename InputIt,
typename = require_input_iter<InputIt>>
20169 void insert(InputIt first, InputIt last)
20171 for (
auto it = first; it != last; ++it)
20178 JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare();
20181NLOHMANN_JSON_NAMESPACE_END
20184#if defined(JSON_HAS_CPP_17)
20185 #if JSON_HAS_STATIC_RTTI
20188 #include <string_view>
20196NLOHMANN_JSON_NAMESPACE_BEGIN
20216NLOHMANN_BASIC_JSON_TPL_DECLARATION
20218 :
public ::nlohmann::detail::json_base_class<CustomBaseClass>
20224 friend class ::nlohmann::json_pointer;
20228 template<
typename BasicJsonType,
typename InputType>
20229 friend class ::nlohmann::detail::parser;
20230 friend ::nlohmann::detail::serializer<basic_json>;
20231 template<
typename BasicJsonType>
20232 friend class ::nlohmann::detail::iter_impl;
20233 template<
typename BasicJsonType,
typename CharType>
20234 friend class ::nlohmann::detail::binary_writer;
20235 template<
typename BasicJsonType,
typename InputType,
typename SAX>
20236 friend class ::nlohmann::detail::binary_reader;
20237 template<
typename BasicJsonType,
typename InputAdapterType>
20238 friend class ::nlohmann::detail::json_sax_dom_parser;
20239 template<
typename BasicJsonType,
typename InputAdapterType>
20240 friend class ::nlohmann::detail::json_sax_dom_callback_parser;
20241 friend class ::nlohmann::detail::exception;
20244 using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
20245 using json_base_class_t = ::nlohmann::detail::json_base_class<CustomBaseClass>;
20247 JSON_PRIVATE_UNLESS_TESTED:
20249 using lexer = ::nlohmann::detail::lexer_base<basic_json>;
20251 template<
typename InputAdapterType>
20252 static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
20253 InputAdapterType adapter,
20254 detail::parser_callback_t<basic_json>cb =
nullptr,
20255 const bool allow_exceptions =
true,
20256 const bool ignore_comments =
false,
20257 const bool ignore_trailing_commas =
false
20260 return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
20261 std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas);
20265 using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
20266 template<
typename BasicJsonType>
20267 using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
20268 template<
typename BasicJsonType>
20269 using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>;
20270 template<
typename Iterator>
20271 using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>;
20272 template<
typename Base>
using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>;
20274 template<
typename CharType>
20275 using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>;
20277 template<
typename InputType>
20278 using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
20279 template<
typename CharType>
using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
20281 JSON_PRIVATE_UNLESS_TESTED:
20282 using serializer = ::nlohmann::detail::serializer<basic_json>;
20288 template<
typename T,
typename SFINAE>
20289 using json_serializer = JSONSerializer<T, SFINAE>;
20346 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
20348 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
20370 JSON_HEDLEY_WARN_UNUSED_RESULT
20375 result[
"copyright"] =
"(C) 2013-2025 Niels Lohmann";
20376 result[
"name"] =
"JSON for Modern C++";
20377 result[
"url"] =
"https://github.com/nlohmann/json";
20378 result[
"version"][
"string"] =
20379 detail::concat(std::to_string(NLOHMANN_JSON_VERSION_MAJOR),
'.',
20380 std::to_string(NLOHMANN_JSON_VERSION_MINOR),
'.',
20381 std::to_string(NLOHMANN_JSON_VERSION_PATCH));
20382 result[
"version"][
"major"] = NLOHMANN_JSON_VERSION_MAJOR;
20383 result[
"version"][
"minor"] = NLOHMANN_JSON_VERSION_MINOR;
20384 result[
"version"][
"patch"] = NLOHMANN_JSON_VERSION_PATCH;
20387 result[
"platform"] =
"win32";
20388#elif defined __linux__
20389 result[
"platform"] =
"linux";
20390#elif defined __APPLE__
20391 result[
"platform"] =
"apple";
20392#elif defined __unix__
20393 result[
"platform"] =
"unix";
20395 result[
"platform"] =
"unknown";
20398#if defined(__ICC) || defined(__INTEL_COMPILER)
20399 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
20400#elif defined(__clang__)
20401 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
20402#elif defined(__GNUC__) || defined(__GNUG__)
20403 result[
"compiler"] = {{
"family",
"gcc"}, {
"version", detail::concat(
20404 std::to_string(__GNUC__),
'.',
20405 std::to_string(__GNUC_MINOR__),
'.',
20406 std::to_string(__GNUC_PATCHLEVEL__))
20409#elif defined(__HP_cc) || defined(__HP_aCC)
20410 result[
"compiler"] =
"hp"
20411#elif defined(__IBMCPP__)
20412 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
20413#elif defined(_MSC_VER)
20414 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
20415#elif defined(__PGI)
20416 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
20417#elif defined(__SUNPRO_CC)
20418 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
20420 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
20423#if defined(_MSVC_LANG)
20424 result[
"compiler"][
"c++"] = std::to_string(_MSVC_LANG);
20425#elif defined(__cplusplus)
20426 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
20428 result[
"compiler"][
"c++"] =
"unknown";
20446#if defined(JSON_HAS_CPP_14)
20449 using default_object_comparator_t = std::less<>;
20459 AllocatorType<std::pair<
const StringType,
20464 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
20488 using binary_t = nlohmann::byte_container_with_subtype<BinaryType>;
20499 template<
typename T,
typename... Args>
20500 JSON_HEDLEY_RETURNS_NON_NULL
20501 static T* create(Args&& ... args)
20503 AllocatorType<T> alloc;
20504 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
20506 auto deleter = [&](T * obj)
20508 AllocatorTraits::deallocate(alloc, obj, 1);
20510 std::unique_ptr<T,
decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
20511 AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
20512 JSON_ASSERT(obj !=
nullptr);
20513 return obj.release();
20520 JSON_PRIVATE_UNLESS_TESTED:
20559 number_integer_t number_integer;
20561 number_unsigned_t number_unsigned;
20563 number_float_t number_float;
20566 json_value() =
default;
20568 json_value(boolean_t v) noexcept : boolean(v) {}
20574 json_value(number_float_t v) noexcept :
number_float(v) {}
20576 json_value(value_t t)
20580 case value_t::object:
20582 object = create<object_t>();
20586 case value_t::array:
20588 array = create<array_t>();
20592 case value_t::string:
20594 string = create<string_t>(
"");
20598 case value_t::binary:
20600 binary = create<binary_t>();
20604 case value_t::boolean:
20606 boolean =
static_cast<boolean_t
>(
false);
20610 case value_t::number_integer:
20616 case value_t::number_unsigned:
20622 case value_t::number_float:
20628 case value_t::null:
20634 case value_t::discarded:
20638 if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
20640 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.12.0",
nullptr));
20648 json_value(
const string_t& value) :
string(create<string_t>(value)) {}
20651 json_value(string_t&& value) :
string(create<string_t>(std::move(value))) {}
20654 json_value(
const object_t& value) :
object(create<object_t>(value)) {}
20657 json_value(object_t&& value) :
object(create<object_t>(std::move(value))) {}
20660 json_value(
const array_t& value) :
array(create<array_t>(value)) {}
20663 json_value(array_t&& value) :
array(create<array_t>(std::move(value))) {}
20666 json_value(
const typename binary_t::container_type& value) :
binary(create<binary_t>(value)) {}
20669 json_value(
typename binary_t::container_type&& value) :
binary(create<binary_t>(std::move(value))) {}
20672 json_value(
const binary_t& value) :
binary(create<binary_t>(value)) {}
20675 json_value(binary_t&& value) :
binary(create<binary_t>(std::move(value))) {}
20677 void destroy(value_t t)
20680 (t == value_t::object &&
object ==
nullptr) ||
20681 (t == value_t::array && array ==
nullptr) ||
20682 (t == value_t::string &&
string ==
nullptr) ||
20683 (t == value_t::binary && binary ==
nullptr)
20689 if (t == value_t::array || t == value_t::object)
20692 std::vector<basic_json> stack;
20695 if (t == value_t::array)
20697 stack.reserve(
array->size());
20698 std::move(
array->begin(),
array->end(), std::back_inserter(stack));
20702 stack.reserve(
object->size());
20703 for (
auto&& it : *
object)
20705 stack.push_back(std::move(it.second));
20709 while (!stack.empty())
20712 basic_json current_item(std::move(stack.back()));
20717 if (current_item.is_array())
20719 std::move(current_item.m_data.m_value.array->begin(), current_item.m_data.m_value.array->end(), std::back_inserter(stack));
20721 current_item.m_data.m_value.array->clear();
20723 else if (current_item.is_object())
20725 for (
auto&& it : *current_item.m_data.m_value.object)
20727 stack.push_back(std::move(it.second));
20730 current_item.m_data.m_value.object->clear();
20740 case value_t::object:
20742 AllocatorType<object_t> alloc;
20743 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
object);
20744 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
object, 1);
20748 case value_t::array:
20750 AllocatorType<array_t> alloc;
20751 std::allocator_traits<
decltype(alloc)>::destroy(alloc, array);
20752 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, array, 1);
20756 case value_t::string:
20758 AllocatorType<string_t> alloc;
20759 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
string);
20760 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
string, 1);
20764 case value_t::binary:
20766 AllocatorType<binary_t> alloc;
20767 std::allocator_traits<
decltype(alloc)>::destroy(alloc, binary);
20768 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, binary, 1);
20772 case value_t::null:
20773 case value_t::boolean:
20774 case value_t::number_integer:
20775 case value_t::number_unsigned:
20776 case value_t::number_float:
20777 case value_t::discarded:
20805 void assert_invariant(
bool check_parents =
true) const noexcept
20807 JSON_ASSERT(m_data.m_type != value_t::object || m_data.m_value.object !=
nullptr);
20808 JSON_ASSERT(m_data.m_type != value_t::array || m_data.m_value.array !=
nullptr);
20809 JSON_ASSERT(m_data.m_type != value_t::string || m_data.m_value.string !=
nullptr);
20810 JSON_ASSERT(m_data.m_type != value_t::binary || m_data.m_value.binary !=
nullptr);
20812#if JSON_DIAGNOSTICS
20816 JSON_ASSERT(!check_parents || !is_structured() || std::all_of(begin(), end(), [
this](
const basic_json & j)
20818 return j.m_parent ==
this;
20823 static_cast<void>(check_parents);
20828#if JSON_DIAGNOSTICS
20829 switch (m_data.m_type)
20831 case value_t::array:
20833 for (
auto& element : *m_data.m_value.array)
20835 element.m_parent =
this;
20840 case value_t::object:
20842 for (
auto& element : *m_data.m_value.object)
20844 element.second.m_parent =
this;
20849 case value_t::null:
20850 case value_t::string:
20851 case value_t::boolean:
20852 case value_t::number_integer:
20853 case value_t::number_unsigned:
20854 case value_t::number_float:
20855 case value_t::binary:
20856 case value_t::discarded:
20863 iterator set_parents(iterator it,
typename iterator::difference_type count_set_parents)
20865#if JSON_DIAGNOSTICS
20866 for (
typename iterator::difference_type i = 0; i < count_set_parents; ++i)
20868 (it + i)->m_parent =
this;
20871 static_cast<void>(count_set_parents);
20876 reference set_parent(reference j, std::size_t old_capacity = detail::unknown_size())
20878#if JSON_DIAGNOSTICS
20879 if (old_capacity != detail::unknown_size())
20882 JSON_ASSERT(type() == value_t::array);
20883 if (JSON_HEDLEY_UNLIKELY(m_data.m_value.array->capacity() != old_capacity))
20893#ifdef JSON_HEDLEY_MSVC_VERSION
20894#pragma warning(push )
20895#pragma warning(disable : 4127)
20897 if (detail::is_ordered_map<object_t>::value)
20902#ifdef JSON_HEDLEY_MSVC_VERSION
20903#pragma warning( pop )
20908 static_cast<void>(j);
20909 static_cast<void>(old_capacity);
20941 assert_invariant();
20949 assert_invariant();
20954 template <
typename CompatibleType,
20955 typename U = detail::uncvref_t<CompatibleType>,
20956 detail::enable_if_t <
20959 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
20960 std::forward<CompatibleType>(val))))
20962 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
20964 assert_invariant();
20969 template <
typename BasicJsonType,
20970 detail::enable_if_t <
20973#if JSON_DIAGNOSTIC_POSITIONS
20974 : start_position(val.start_pos()),
20975 end_position(val.end_pos())
20978 using other_boolean_t =
typename BasicJsonType::boolean_t;
20979 using other_number_float_t =
typename BasicJsonType::number_float_t;
20980 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
20981 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
20982 using other_string_t =
typename BasicJsonType::string_t;
20983 using other_object_t =
typename BasicJsonType::object_t;
20984 using other_array_t =
typename BasicJsonType::array_t;
20985 using other_binary_t =
typename BasicJsonType::binary_t;
20987 switch (val.type())
20989 case value_t::boolean:
20992 case value_t::number_float:
20995 case value_t::number_integer:
20998 case value_t::number_unsigned:
21001 case value_t::string:
21004 case value_t::object:
21007 case value_t::array:
21010 case value_t::binary:
21013 case value_t::null:
21016 case value_t::discarded:
21017 m_data.m_type = value_t::discarded;
21020 JSON_ASSERT(
false);
21022 JSON_ASSERT(m_data.m_type == val.type());
21025 assert_invariant();
21031 bool type_deduction =
true,
21032 value_t manual_type = value_t::array)
21036 bool is_an_object = std::all_of(init.begin(), init.end(),
21042 return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[static_cast<size_type>(0)].is_string();
21046 if (!type_deduction)
21049 if (manual_type == value_t::array)
21051 is_an_object =
false;
21055 if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))
21057 JSON_THROW(type_error::create(301,
"cannot create object from initializer list",
nullptr));
21064 m_data.m_type = value_t::object;
21065 m_data.m_value = value_t::object;
21067 for (
auto& element_ref : init)
21069 auto element = element_ref.moved_or_copied();
21070 m_data.m_value.object->emplace(
21071 std::move(*((*element.m_data.m_value.array)[0].m_data.m_value.string)),
21072 std::move((*element.m_data.m_value.array)[1]));
21078 m_data.m_type = value_t::array;
21079 m_data.m_value.array = create<array_t>(init.begin(), init.end());
21083 assert_invariant();
21088 JSON_HEDLEY_WARN_UNUSED_RESULT
21092 res.m_data.m_type = value_t::binary;
21093 res.m_data.m_value = init;
21099 JSON_HEDLEY_WARN_UNUSED_RESULT
21100 static basic_json binary(
const typename binary_t::container_type& init,
typename binary_t::subtype_type subtype)
21103 res.m_data.m_type = value_t::binary;
21104 res.m_data.m_value =
binary_t(init, subtype);
21110 JSON_HEDLEY_WARN_UNUSED_RESULT
21114 res.m_data.m_type = value_t::binary;
21115 res.m_data.m_value = std::move(init);
21121 JSON_HEDLEY_WARN_UNUSED_RESULT
21122 static basic_json binary(
typename binary_t::container_type&& init,
typename binary_t::subtype_type subtype)
21125 res.m_data.m_type = value_t::binary;
21126 res.m_data.m_value =
binary_t(std::move(init), subtype);
21132 JSON_HEDLEY_WARN_UNUSED_RESULT
21135 return basic_json(init,
false, value_t::array);
21140 JSON_HEDLEY_WARN_UNUSED_RESULT
21143 return basic_json(init,
false, value_t::object);
21152 assert_invariant();
21157 template <
class InputIT,
typename std::enable_if <
21158 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
21159 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int >::type = 0 >
21162 JSON_ASSERT(first.m_object !=
nullptr);
21163 JSON_ASSERT(last.m_object !=
nullptr);
21166 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
21168 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible",
nullptr));
21172 m_data.m_type = first.m_object->m_data.m_type;
21175 switch (m_data.m_type)
21177 case value_t::boolean:
21178 case value_t::number_float:
21179 case value_t::number_integer:
21180 case value_t::number_unsigned:
21181 case value_t::string:
21183 if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
21184 || !last.m_it.primitive_iterator.is_end()))
21186 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", first.m_object));
21191 case value_t::null:
21192 case value_t::object:
21193 case value_t::array:
21194 case value_t::binary:
21195 case value_t::discarded:
21200 switch (m_data.m_type)
21202 case value_t::number_integer:
21204 m_data.m_value.number_integer = first.m_object->m_data.m_value.number_integer;
21208 case value_t::number_unsigned:
21210 m_data.m_value.number_unsigned = first.m_object->m_data.m_value.number_unsigned;
21214 case value_t::number_float:
21216 m_data.m_value.number_float = first.m_object->m_data.m_value.number_float;
21220 case value_t::boolean:
21222 m_data.m_value.boolean = first.m_object->m_data.m_value.boolean;
21226 case value_t::string:
21228 m_data.m_value = *first.m_object->m_data.m_value.string;
21232 case value_t::object:
21234 m_data.m_value.object = create<object_t>(first.m_it.object_iterator,
21235 last.m_it.object_iterator);
21239 case value_t::array:
21241 m_data.m_value.array = create<array_t>(first.m_it.array_iterator,
21242 last.m_it.array_iterator);
21246 case value_t::binary:
21248 m_data.m_value = *first.m_object->m_data.m_value.binary;
21252 case value_t::null:
21253 case value_t::discarded:
21255 JSON_THROW(invalid_iterator::create(206, detail::concat(
"cannot construct with iterators from ", first.m_object->type_name()), first.m_object));
21259 assert_invariant();
21266 template<
typename JsonRef,
21267 detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
21268 std::is_same<typename JsonRef::value_type, basic_json>>::value,
int> = 0 >
21274 : json_base_class_t(other)
21275#if JSON_DIAGNOSTIC_POSITIONS
21276 , start_position(other.start_position)
21277 , end_position(other.end_position)
21280 m_data.m_type = other.m_data.m_type;
21282 other.assert_invariant();
21284 switch (m_data.m_type)
21286 case value_t::object:
21288 m_data.m_value = *other.m_data.m_value.object;
21292 case value_t::array:
21294 m_data.m_value = *other.m_data.m_value.array;
21298 case value_t::string:
21300 m_data.m_value = *other.m_data.m_value.string;
21304 case value_t::boolean:
21306 m_data.m_value = other.m_data.m_value.boolean;
21310 case value_t::number_integer:
21312 m_data.m_value = other.m_data.m_value.number_integer;
21316 case value_t::number_unsigned:
21318 m_data.m_value = other.m_data.m_value.number_unsigned;
21322 case value_t::number_float:
21324 m_data.m_value = other.m_data.m_value.number_float;
21328 case value_t::binary:
21330 m_data.m_value = *other.m_data.m_value.binary;
21334 case value_t::null:
21335 case value_t::discarded:
21341 assert_invariant();
21347 : json_base_class_t(std::forward<json_base_class_t>(other)),
21348 m_data(std::move(other.m_data))
21349#if JSON_DIAGNOSTIC_POSITIONS
21350 , start_position(other.start_position)
21351 , end_position(other.end_position)
21355 other.assert_invariant(
false);
21358 other.m_data.m_type = value_t::null;
21359 other.m_data.m_value = {};
21361#if JSON_DIAGNOSTIC_POSITIONS
21362 other.start_position = std::string::npos;
21363 other.end_position = std::string::npos;
21367 assert_invariant();
21373 std::is_nothrow_move_constructible<value_t>::value&&
21374 std::is_nothrow_move_assignable<value_t>::value&&
21375 std::is_nothrow_move_constructible<json_value>::value&&
21376 std::is_nothrow_move_assignable<json_value>::value&&
21377 std::is_nothrow_move_assignable<json_base_class_t>::value
21381 other.assert_invariant();
21384 swap(m_data.m_type, other.m_data.m_type);
21385 swap(m_data.m_value, other.m_data.m_value);
21387#if JSON_DIAGNOSTIC_POSITIONS
21388 swap(start_position, other.start_position);
21389 swap(end_position, other.end_position);
21392 json_base_class_t::operator=(std::move(other));
21395 assert_invariant();
21403 assert_invariant(
false);
21420 const char indent_char =
' ',
21421 const bool ensure_ascii =
false,
21429 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
21433 s.dump(*
this,
false, ensure_ascii, 0);
21441 constexpr value_t
type() const noexcept
21443 return m_data.m_type;
21464 return m_data.m_type == value_t::null;
21471 return m_data.m_type == value_t::boolean;
21485 return m_data.m_type == value_t::number_integer || m_data.m_type == value_t::number_unsigned;
21492 return m_data.m_type == value_t::number_unsigned;
21499 return m_data.m_type == value_t::number_float;
21506 return m_data.m_type == value_t::object;
21513 return m_data.m_type == value_t::array;
21520 return m_data.m_type == value_t::string;
21527 return m_data.m_type == value_t::binary;
21534 return m_data.m_type == value_t::discarded;
21539 constexpr operator value_t() const noexcept
21541 return m_data.m_type;
21552 boolean_t get_impl(boolean_t* )
const
21554 if (JSON_HEDLEY_LIKELY(is_boolean()))
21556 return m_data.m_value.boolean;
21559 JSON_THROW(type_error::create(302, detail::concat(
"type must be boolean, but is ", type_name()),
this));
21563 object_t* get_impl_ptr(object_t* )
noexcept
21565 return is_object() ? m_data.m_value.object :
nullptr;
21569 constexpr const object_t* get_impl_ptr(
const object_t* )
const noexcept
21571 return is_object() ? m_data.m_value.object :
nullptr;
21575 array_t* get_impl_ptr(array_t* )
noexcept
21577 return is_array() ? m_data.m_value.array :
nullptr;
21581 constexpr const array_t* get_impl_ptr(
const array_t* )
const noexcept
21583 return is_array() ? m_data.m_value.array :
nullptr;
21587 string_t* get_impl_ptr(string_t* )
noexcept
21589 return is_string() ? m_data.m_value.string :
nullptr;
21593 constexpr const string_t* get_impl_ptr(
const string_t* )
const noexcept
21595 return is_string() ? m_data.m_value.string :
nullptr;
21599 boolean_t* get_impl_ptr(boolean_t* )
noexcept
21601 return is_boolean() ? &m_data.m_value.boolean :
nullptr;
21605 constexpr const boolean_t* get_impl_ptr(
const boolean_t* )
const noexcept
21607 return is_boolean() ? &m_data.m_value.boolean :
nullptr;
21611 number_integer_t* get_impl_ptr(number_integer_t* )
noexcept
21613 return m_data.m_type == value_t::number_integer ? &m_data.m_value.number_integer :
nullptr;
21617 constexpr const number_integer_t* get_impl_ptr(
const number_integer_t* )
const noexcept
21619 return m_data.m_type == value_t::number_integer ? &m_data.m_value.number_integer :
nullptr;
21623 number_unsigned_t* get_impl_ptr(number_unsigned_t* )
noexcept
21625 return is_number_unsigned() ? &m_data.m_value.number_unsigned :
nullptr;
21629 constexpr const number_unsigned_t* get_impl_ptr(
const number_unsigned_t* )
const noexcept
21631 return is_number_unsigned() ? &m_data.m_value.number_unsigned :
nullptr;
21635 number_float_t* get_impl_ptr(number_float_t* )
noexcept
21637 return is_number_float() ? &m_data.m_value.number_float :
nullptr;
21641 constexpr const number_float_t* get_impl_ptr(
const number_float_t* )
const noexcept
21643 return is_number_float() ? &m_data.m_value.number_float :
nullptr;
21647 binary_t* get_impl_ptr(binary_t* )
noexcept
21649 return is_binary() ? m_data.m_value.binary :
nullptr;
21653 constexpr const binary_t* get_impl_ptr(
const binary_t* )
const noexcept
21655 return is_binary() ? m_data.m_value.binary :
nullptr;
21669 template<
typename ReferenceType,
typename ThisType>
21670 static ReferenceType get_ref_impl(ThisType& obj)
21673 auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
21675 if (JSON_HEDLEY_LIKELY(ptr !=
nullptr))
21680 JSON_THROW(type_error::create(303, detail::concat(
"incompatible ReferenceType for get_ref, actual type is ", obj.type_name()), &obj));
21690 template<
typename PointerType,
typename std::enable_if<
21691 std::is_pointer<PointerType>::value,
int>::type = 0>
21692 auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
21695 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
21700 template <
typename PointerType,
typename std::enable_if <
21701 std::is_pointer<PointerType>::value&&
21702 std::is_const<typename std::remove_pointer<PointerType>::type>::value,
int >::type = 0 >
21703 constexpr auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
21706 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
21748 template <
typename ValueType,
21749 detail::enable_if_t <
21754 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
21756 auto ret = ValueType();
21757 JSONSerializer<ValueType>::from_json(*
this, ret);
21791 template <
typename ValueType,
21792 detail::enable_if_t <
21793 detail::has_non_default_from_json<basic_json_t, ValueType>::value,
21795 ValueType get_impl(detail::priority_tag<1> )
const noexcept(
noexcept(
21796 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
21798 return JSONSerializer<ValueType>::from_json(*
this);
21816 template <
typename BasicJsonType,
21817 detail::enable_if_t <
21818 detail::is_basic_json<BasicJsonType>::value,
21820 BasicJsonType get_impl(detail::priority_tag<2> )
const
21839 template<
typename BasicJsonType,
21840 detail::enable_if_t<
21841 std::is_same<BasicJsonType, basic_json_t>::value,
21843 basic_json get_impl(detail::priority_tag<3> )
const
21852 template<
typename PointerType,
21853 detail::enable_if_t<
21854 std::is_pointer<PointerType>::value,
21856 constexpr auto get_impl(detail::priority_tag<4> )
const noexcept
21857 ->
decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>())
21860 return get_ptr<PointerType>();
21887 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>>
21888#if defined(JSON_HAS_CPP_14)
21892 noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(
detail::priority_tag<4> {})))
21898 static_assert(!std::is_reference<ValueTypeCV>::value,
21899 "get() cannot be used with reference types, you might want to use get_ref()");
21900 return get_impl<ValueType>(detail::priority_tag<4> {});
21930 template<
typename PointerType,
typename std::enable_if<
21931 std::is_pointer<PointerType>::value,
int>::type = 0>
21932 auto get() noexcept -> decltype(std::declval<basic_json_t&>().template
get_ptr<PointerType>())
21940 template <
typename ValueType,
21941 detail::enable_if_t <
21945 ValueType &
get_to(ValueType& v)
const noexcept(
noexcept(
21946 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
21948 JSONSerializer<ValueType>::from_json(*
this, v);
21954 template<
typename ValueType,
21955 detail::enable_if_t <
21958 ValueType & get_to(ValueType& v)
const
21965 typename T, std::size_t N,
21966 typename Array = T (&)[N],
21967 detail::enable_if_t <
21968 detail::has_from_json<basic_json_t, Array>::value,
int > = 0 >
21969 Array get_to(T (&v)[N])
const
21970 noexcept(
noexcept(JSONSerializer<Array>::from_json(
21971 std::declval<const basic_json_t&>(), v)))
21973 JSONSerializer<Array>::from_json(*
this, v);
21979 template<
typename ReferenceType,
typename std::enable_if<
21980 std::is_reference<ReferenceType>::value,
int>::type = 0>
21984 return get_ref_impl<ReferenceType>(*
this);
21989 template <
typename ReferenceType,
typename std::enable_if <
21990 std::is_reference<ReferenceType>::value&&
21991 std::is_const<typename std::remove_reference<ReferenceType>::type>::value,
int >::type = 0 >
21995 return get_ref_impl<ReferenceType>(*
this);
22027 template <
typename ValueType,
typename std::enable_if <
22035#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
22038#if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI
22042 >::value,
int >::type = 0 >
22043 JSON_EXPLICIT
operator ValueType()
const
22055 JSON_THROW(type_error::create(302, detail::concat(
"type must be binary, but is ",
type_name()),
this));
22067 JSON_THROW(type_error::create(302, detail::concat(
"type must be binary, but is ",
type_name()),
this));
22088 if (JSON_HEDLEY_LIKELY(
is_array()))
22092 return set_parent(m_data.m_value.array->at(idx));
22094 JSON_CATCH (std::out_of_range&)
22097 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
22102 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
this));
22111 if (JSON_HEDLEY_LIKELY(
is_array()))
22115 return m_data.m_value.array->at(idx);
22117 JSON_CATCH (std::out_of_range&)
22120 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
22125 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
this));
22134 if (JSON_HEDLEY_UNLIKELY(!
is_object()))
22136 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
this));
22140 if (it == m_data.m_value.object->end())
22142 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
key,
"' not found"),
this));
22144 return set_parent(it->second);
22149 template<
class KeyType, detail::enable_if_t<
22150 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22154 if (JSON_HEDLEY_UNLIKELY(!
is_object()))
22156 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
this));
22159 auto it = m_data.
m_value.object->find(std::forward<KeyType>(
key));
22160 if (it == m_data.m_value.object->end())
22162 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
string_t(std::forward<KeyType>(
key)),
"' not found"),
this));
22164 return set_parent(it->second);
22172 if (JSON_HEDLEY_UNLIKELY(!
is_object()))
22174 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
this));
22178 if (it == m_data.m_value.object->end())
22180 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
key,
"' not found"),
this));
22187 template<
class KeyType, detail::enable_if_t<
22188 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22192 if (JSON_HEDLEY_UNLIKELY(!
is_object()))
22194 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ",
type_name()),
this));
22197 auto it = m_data.
m_value.object->find(std::forward<KeyType>(
key));
22198 if (it == m_data.m_value.object->end())
22200 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
string_t(std::forward<KeyType>(
key)),
"' not found"),
this));
22212 m_data.m_type = value_t::array;
22213 m_data.m_value.array = create<array_t>();
22214 assert_invariant();
22218 if (JSON_HEDLEY_LIKELY(
is_array()))
22221 if (idx >= m_data.m_value.array->size())
22223#if JSON_DIAGNOSTICS
22225 const auto old_size = m_data.m_value.array->size();
22226 const auto old_capacity = m_data.m_value.array->capacity();
22228 m_data.m_value.array->resize(idx + 1);
22230#if JSON_DIAGNOSTICS
22231 if (JSON_HEDLEY_UNLIKELY(m_data.m_value.array->capacity() != old_capacity))
22239 set_parents(
begin() +
static_cast<typename iterator::difference_type
>(old_size),
static_cast<typename iterator::difference_type
>(idx + 1 - old_size));
22242 assert_invariant();
22245 return m_data.m_value.array->operator[](idx);
22248 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a numeric argument with ",
type_name()),
this));
22256 if (JSON_HEDLEY_LIKELY(
is_array()))
22258 return m_data.m_value.array->operator[](idx);
22261 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a numeric argument with ",
type_name()),
this));
22271 m_data.m_type = value_t::object;
22272 m_data.m_value.object = create<object_t>();
22273 assert_invariant();
22279 auto result = m_data.m_value.object->emplace(std::move(
key),
nullptr);
22280 return set_parent(result.first->second);
22283 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ",
type_name()),
this));
22293 auto it = m_data.m_value.object->find(
key);
22294 JSON_ASSERT(it != m_data.m_value.object->end());
22298 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ",
type_name()),
this));
22303 template<
typename T>
22304 reference operator[](T*
key)
22306 return operator[](
typename object_t::key_type(
key));
22309 template<
typename T>
22310 const_reference operator[](T*
key)
const
22312 return operator[](
typename object_t::key_type(
key));
22317 template<
class KeyType, detail::enable_if_t<
22318 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int > = 0 >
22324 m_data.m_type = value_t::object;
22325 m_data.m_value.object = create<object_t>();
22326 assert_invariant();
22332 auto result = m_data.m_value.object->emplace(std::forward<KeyType>(
key),
nullptr);
22333 return set_parent(result.first->second);
22336 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ",
type_name()),
this));
22341 template<
class KeyType, detail::enable_if_t<
22342 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int > = 0 >
22348 auto it = m_data.m_value.object->find(std::forward<KeyType>(
key));
22349 JSON_ASSERT(it != m_data.m_value.object->end());
22353 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ",
type_name()),
this));
22357 template<
typename KeyType>
22359 object_comparator_t,
const typename object_t::key_type&, KeyType >;
22361 template<
typename ValueType>
22362 using value_return_type = std::conditional <
22363 detail::is_c_string_uncvref<ValueType>::value,
22364 string_t,
typename std::decay<ValueType>::type >;
22369 template <
class ValueType, detail::enable_if_t <
22371 && detail::is_getable<basic_json_t, ValueType>::value
22372 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22373 ValueType
value(
const typename object_t::key_type&
key,
const ValueType& default_value)
const
22385 return default_value;
22388 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
22393 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
22394 detail::enable_if_t <
22396 && detail::is_getable<basic_json_t, ReturnType>::value
22397 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22398 ReturnType
value(
const typename object_t::key_type&
key, ValueType && default_value)
const
22410 return std::forward<ValueType>(default_value);
22413 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
22418 template <
class ValueType,
class KeyType, detail::enable_if_t <
22420 && !detail::is_json_pointer<KeyType>::value
22421 && is_comparable_with_object_key<KeyType>::value
22422 && detail::is_getable<basic_json_t, ValueType>::value
22423 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22424 ValueType
value(KeyType &&
key,
const ValueType& default_value)
const
22430 const auto it =
find(std::forward<KeyType>(
key));
22436 return default_value;
22439 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
22444 template < class ValueType, class KeyType, class ReturnType = typename value_return_type<ValueType>::type,
22445 detail::enable_if_t <
22447 && !detail::is_json_pointer<KeyType>::value
22448 && is_comparable_with_object_key<KeyType>::value
22449 && detail::is_getable<basic_json_t, ReturnType>::value
22450 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22451 ReturnType
value(KeyType &&
key, ValueType && default_value)
const
22457 const auto it =
find(std::forward<KeyType>(
key));
22463 return std::forward<ValueType>(default_value);
22466 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
22471 template <
class ValueType, detail::enable_if_t <
22472 detail::is_getable<basic_json_t, ValueType>::value
22473 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22485 JSON_INTERNAL_CATCH (out_of_range&)
22487 return default_value;
22491 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
22496 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
22497 detail::enable_if_t <
22498 detail::is_getable<basic_json_t, ReturnType>::value
22499 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22511 JSON_INTERNAL_CATCH (out_of_range&)
22513 return std::forward<ValueType>(default_value);
22517 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ",
type_name()),
this));
22520 template <
class ValueType,
class BasicJsonType, detail::enable_if_t <
22522 && detail::is_getable<basic_json_t, ValueType>::value
22523 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22525 ValueType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr,
const ValueType& default_value)
const
22527 return value(ptr.convert(), default_value);
22530 template < class ValueType, class BasicJsonType, class ReturnType = typename value_return_type<ValueType>::type,
22531 detail::enable_if_t <
22532 detail::is_basic_json<BasicJsonType>::value
22533 && detail::is_getable<basic_json_t, ReturnType>::value
22534 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22536 ReturnType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, ValueType && default_value)
const
22538 return value(ptr.convert(), std::forward<ValueType>(default_value));
22575 template <
class IteratorType, detail::enable_if_t <
22576 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
22577 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
22581 if (JSON_HEDLEY_UNLIKELY(
this != pos.m_object))
22583 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
22586 IteratorType result =
end();
22588 switch (m_data.m_type)
22590 case value_t::boolean:
22591 case value_t::number_float:
22592 case value_t::number_integer:
22593 case value_t::number_unsigned:
22594 case value_t::string:
22595 case value_t::binary:
22597 if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
22599 JSON_THROW(invalid_iterator::create(205,
"iterator out of range",
this));
22604 AllocatorType<string_t> alloc;
22605 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.string);
22606 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.string, 1);
22607 m_data.m_value.string =
nullptr;
22611 AllocatorType<binary_t> alloc;
22612 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.binary);
22613 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.binary, 1);
22614 m_data.m_value.binary =
nullptr;
22617 m_data.m_type = value_t::null;
22618 assert_invariant();
22622 case value_t::object:
22624 result.m_it.object_iterator = m_data.m_value.object->erase(pos.m_it.object_iterator);
22628 case value_t::array:
22630 result.m_it.array_iterator = m_data.m_value.array->erase(pos.m_it.array_iterator);
22634 case value_t::null:
22635 case value_t::discarded:
22637 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ",
type_name()),
this));
22645 template <
class IteratorType, detail::enable_if_t <
22646 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
22647 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
22648 IteratorType
erase(IteratorType first, IteratorType last)
22651 if (JSON_HEDLEY_UNLIKELY(
this != first.m_object ||
this != last.m_object))
22653 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value",
this));
22656 IteratorType result =
end();
22658 switch (m_data.m_type)
22660 case value_t::boolean:
22661 case value_t::number_float:
22662 case value_t::number_integer:
22663 case value_t::number_unsigned:
22664 case value_t::string:
22665 case value_t::binary:
22667 if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
22668 || !last.m_it.primitive_iterator.is_end()))
22670 JSON_THROW(invalid_iterator::create(204,
"iterators out of range",
this));
22675 AllocatorType<string_t> alloc;
22676 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.string);
22677 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.string, 1);
22678 m_data.m_value.string =
nullptr;
22682 AllocatorType<binary_t> alloc;
22683 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.binary);
22684 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.binary, 1);
22685 m_data.m_value.binary =
nullptr;
22688 m_data.m_type = value_t::null;
22689 assert_invariant();
22693 case value_t::object:
22695 result.m_it.object_iterator = m_data.m_value.object->erase(first.m_it.object_iterator,
22696 last.m_it.object_iterator);
22700 case value_t::array:
22702 result.m_it.array_iterator = m_data.m_value.array->erase(first.m_it.array_iterator,
22703 last.m_it.array_iterator);
22707 case value_t::null:
22708 case value_t::discarded:
22710 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ",
type_name()),
this));
22717 template <
typename KeyType, detail::enable_if_t <
22718 detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int > = 0 >
22719 size_type erase_internal(KeyType &&
key)
22722 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22724 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
22727 return m_data.m_value.object->erase(std::forward<KeyType>(
key));
22730 template <
typename KeyType, detail::enable_if_t <
22731 !detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int > = 0 >
22732 size_type erase_internal(KeyType &&
key)
22735 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22737 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
22740 const auto it = m_data.m_value.object->find(std::forward<KeyType>(
key));
22741 if (it != m_data.m_value.object->end())
22743 m_data.m_value.object->erase(it);
22757 return erase_internal(
key);
22762 template<
class KeyType, detail::enable_if_t<
22763 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22766 return erase_internal(std::forward<KeyType>(
key));
22774 if (JSON_HEDLEY_LIKELY(
is_array()))
22776 if (JSON_HEDLEY_UNLIKELY(idx >=
size()))
22778 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
22781 m_data.m_value.array->erase(m_data.m_value.array->begin() +
static_cast<difference_type>(idx));
22785 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ",
type_name()),
this));
22802 auto result =
end();
22806 result.m_it.object_iterator = m_data.m_value.object->find(
key);
22816 auto result =
cend();
22820 result.m_it.object_iterator = m_data.m_value.object->find(
key);
22828 template<
class KeyType, detail::enable_if_t<
22829 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22832 auto result =
end();
22836 result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(
key));
22844 template<
class KeyType, detail::enable_if_t<
22845 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22848 auto result =
cend();
22852 result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(
key));
22863 return is_object() ? m_data.m_value.object->count(
key) : 0;
22868 template<
class KeyType, detail::enable_if_t<
22869 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22873 return is_object() ? m_data.m_value.object->count(std::forward<KeyType>(
key)) : 0;
22880 return is_object() && m_data.m_value.object->find(
key) != m_data.m_value.object->end();
22885 template<
class KeyType, detail::enable_if_t<
22886 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22889 return is_object() && m_data.m_value.object->find(std::forward<KeyType>(
key)) != m_data.m_value.object->end();
22896 return ptr.contains(
this);
22899 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
22901 bool contains(
const typename ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
22903 return ptr.contains(
this);
22920 result.set_begin();
22936 result.set_begin();
23013 JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
23016 return ref.items();
23024 JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
23027 return ref.items();
23034 return iteration_proxy<iterator>(*
this);
23039 iteration_proxy<const_iterator>
items() const noexcept
23041 return iteration_proxy<const_iterator>(*
this);
23057 switch (m_data.m_type)
23059 case value_t::null:
23065 case value_t::array:
23068 return m_data.m_value.array->empty();
23071 case value_t::object:
23074 return m_data.m_value.object->empty();
23077 case value_t::string:
23078 case value_t::boolean:
23079 case value_t::number_integer:
23080 case value_t::number_unsigned:
23081 case value_t::number_float:
23082 case value_t::binary:
23083 case value_t::discarded:
23096 switch (m_data.m_type)
23098 case value_t::null:
23104 case value_t::array:
23107 return m_data.m_value.array->size();
23110 case value_t::object:
23113 return m_data.m_value.object->size();
23116 case value_t::string:
23117 case value_t::boolean:
23118 case value_t::number_integer:
23119 case value_t::number_unsigned:
23120 case value_t::number_float:
23121 case value_t::binary:
23122 case value_t::discarded:
23135 switch (m_data.m_type)
23137 case value_t::array:
23140 return m_data.m_value.array->max_size();
23143 case value_t::object:
23146 return m_data.m_value.object->max_size();
23149 case value_t::null:
23150 case value_t::string:
23151 case value_t::boolean:
23152 case value_t::number_integer:
23153 case value_t::number_unsigned:
23154 case value_t::number_float:
23155 case value_t::binary:
23156 case value_t::discarded:
23178 switch (m_data.m_type)
23180 case value_t::number_integer:
23182 m_data.m_value.number_integer = 0;
23186 case value_t::number_unsigned:
23188 m_data.m_value.number_unsigned = 0;
23192 case value_t::number_float:
23194 m_data.m_value.number_float = 0.0;
23198 case value_t::boolean:
23200 m_data.m_value.boolean =
false;
23204 case value_t::string:
23206 m_data.m_value.string->clear();
23210 case value_t::binary:
23212 m_data.m_value.binary->clear();
23216 case value_t::array:
23218 m_data.m_value.array->clear();
23222 case value_t::object:
23224 m_data.m_value.object->clear();
23228 case value_t::null:
23229 case value_t::discarded:
23242 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ",
type_name()),
this));
23248 m_data.m_type = value_t::array;
23249 m_data.m_value = value_t::array;
23250 assert_invariant();
23254 const auto old_capacity = m_data.m_value.array->capacity();
23255 m_data.m_value.array->push_back(std::move(val));
23256 set_parent(m_data.m_value.array->back(), old_capacity);
23275 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ",
type_name()),
this));
23281 m_data.m_type = value_t::array;
23282 m_data.m_value = value_t::array;
23283 assert_invariant();
23287 const auto old_capacity = m_data.m_value.array->capacity();
23288 m_data.m_value.array->push_back(val);
23289 set_parent(m_data.m_value.array->back(), old_capacity);
23307 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ",
type_name()),
this));
23313 m_data.m_type = value_t::object;
23314 m_data.m_value = value_t::object;
23315 assert_invariant();
23319 auto res = m_data.m_value.object->insert(val);
23320 set_parent(res.first->second);
23335 if (
is_object() && init.size() == 2 && (*init.begin())->is_string())
23338 push_back(
typename object_t::value_type(
23339 std::move(
key.get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
23357 template<
class... Args>
23363 JSON_THROW(type_error::create(311, detail::concat(
"cannot use emplace_back() with ",
type_name()),
this));
23369 m_data.m_type = value_t::array;
23370 m_data.m_value = value_t::array;
23371 assert_invariant();
23375 const auto old_capacity = m_data.
m_value.array->capacity();
23376 m_data.m_value.array->emplace_back(std::forward<Args>(args)...);
23377 return set_parent(m_data.m_value.array->back(), old_capacity);
23382 template<
class... Args>
23388 JSON_THROW(type_error::create(311, detail::concat(
"cannot use emplace() with ",
type_name()),
this));
23394 m_data.m_type = value_t::object;
23395 m_data.m_value = value_t::object;
23396 assert_invariant();
23400 auto res = m_data.m_value.object->emplace(std::forward<Args>(args)...);
23401 set_parent(res.first->second);
23405 it.m_it.object_iterator = res.first;
23408 return {it, res.second};
23414 template<
typename... Args>
23418 JSON_ASSERT(m_data.m_value.array !=
nullptr);
23420 auto insert_pos = std::distance(m_data.m_value.array->begin(), pos.m_it.array_iterator);
23421 m_data.m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
23422 result.m_it.array_iterator = m_data.m_value.array->begin() + insert_pos;
23437 if (JSON_HEDLEY_LIKELY(
is_array()))
23440 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23442 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
23449 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ",
type_name()),
this));
23456 return insert(pos, val);
23464 if (JSON_HEDLEY_LIKELY(
is_array()))
23467 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23469 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
23476 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ",
type_name()),
this));
23484 if (JSON_HEDLEY_UNLIKELY(!
is_array()))
23486 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ",
type_name()),
this));
23490 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23492 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
23496 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23498 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
23501 if (JSON_HEDLEY_UNLIKELY(first.m_object ==
this))
23503 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container",
this));
23507 return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
23515 if (JSON_HEDLEY_UNLIKELY(!
is_array()))
23517 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ",
type_name()),
this));
23521 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23523 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
23535 if (JSON_HEDLEY_UNLIKELY(!
is_object()))
23537 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ",
type_name()),
this));
23541 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23543 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
23547 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
23549 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects",
this));
23552 m_data.m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
23570 m_data.m_type = value_t::object;
23571 m_data.m_value.object = create<object_t>();
23572 assert_invariant();
23575 if (JSON_HEDLEY_UNLIKELY(!
is_object()))
23577 JSON_THROW(type_error::create(312, detail::concat(
"cannot use update() with ",
type_name()),
this));
23581 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23583 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
23587 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
23589 JSON_THROW(type_error::create(312, detail::concat(
"cannot use update() with ", first.m_object->type_name()), first.m_object));
23592 for (
auto it = first; it != last; ++it)
23594 if (merge_objects && it.value().is_object())
23596 auto it2 = m_data.m_value.object->find(it.key());
23597 if (it2 != m_data.m_value.object->end())
23599 it2->second.update(it.value(),
true);
23603 m_data.m_value.object->operator[](it.key()) = it.value();
23604#if JSON_DIAGNOSTICS
23605 m_data.m_value.object->operator[](it.key()).m_parent =
this;
23613 std::is_nothrow_move_constructible<value_t>::value&&
23614 std::is_nothrow_move_assignable<value_t>::value&&
23615 std::is_nothrow_move_constructible<json_value>::value&&
23616 std::is_nothrow_move_assignable<json_value>::value
23619 std::swap(m_data.m_type, other.m_data.m_type);
23620 std::swap(m_data.m_value, other.m_data.m_value);
23623 other.set_parents();
23624 assert_invariant();
23630 std::is_nothrow_move_constructible<value_t>::value&&
23631 std::is_nothrow_move_assignable<value_t>::value&&
23632 std::is_nothrow_move_constructible<json_value>::value&&
23633 std::is_nothrow_move_assignable<json_value>::value
23644 if (JSON_HEDLEY_LIKELY(
is_array()))
23647 swap(*(m_data.m_value.array), other);
23651 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(array_t&) with ",
type_name()),
this));
23663 swap(*(m_data.m_value.object), other);
23667 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(object_t&) with ",
type_name()),
this));
23679 swap(*(m_data.m_value.string), other);
23683 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(string_t&) with ",
type_name()),
this));
23695 swap(*(m_data.m_value.binary), other);
23699 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(binary_t&) with ",
type_name()),
this));
23705 void swap(
typename binary_t::container_type& other)
23711 swap(*(m_data.m_value.binary), other);
23715 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(binary_t::container_type&) with ",
type_name()),
this));
23730#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result) \
23731 const auto lhs_type = lhs.type(); \
23732 const auto rhs_type = rhs.type(); \
23734 if (lhs_type == rhs_type) \
23736 switch (lhs_type) \
23738 case value_t::array: \
23739 return (*lhs.m_data.m_value.array) op (*rhs.m_data.m_value.array); \
23741 case value_t::object: \
23742 return (*lhs.m_data.m_value.object) op (*rhs.m_data.m_value.object); \
23744 case value_t::null: \
23745 return (null_result); \
23747 case value_t::string: \
23748 return (*lhs.m_data.m_value.string) op (*rhs.m_data.m_value.string); \
23750 case value_t::boolean: \
23751 return (lhs.m_data.m_value.boolean) op (rhs.m_data.m_value.boolean); \
23753 case value_t::number_integer: \
23754 return (lhs.m_data.m_value.number_integer) op (rhs.m_data.m_value.number_integer); \
23756 case value_t::number_unsigned: \
23757 return (lhs.m_data.m_value.number_unsigned) op (rhs.m_data.m_value.number_unsigned); \
23759 case value_t::number_float: \
23760 return (lhs.m_data.m_value.number_float) op (rhs.m_data.m_value.number_float); \
23762 case value_t::binary: \
23763 return (*lhs.m_data.m_value.binary) op (*rhs.m_data.m_value.binary); \
23765 case value_t::discarded: \
23767 return (unordered_result); \
23770 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) \
23772 return static_cast<number_float_t>(lhs.m_data.m_value.number_integer) op rhs.m_data.m_value.number_float; \
23774 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) \
23776 return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_integer); \
23778 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) \
23780 return static_cast<number_float_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_float; \
23782 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) \
23784 return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_unsigned); \
23786 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) \
23788 return static_cast<number_integer_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_integer; \
23790 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) \
23792 return lhs.m_data.m_value.number_integer op static_cast<number_integer_t>(rhs.m_data.m_value.number_unsigned); \
23794 else if(compares_unordered(lhs, rhs))\
23796 return (unordered_result);\
23799 return (default_result);
23801 JSON_PRIVATE_UNLESS_TESTED:
23807 static bool compares_unordered(const_reference lhs, const_reference rhs,
bool inverse =
false) noexcept
23809 if ((lhs.is_number_float() && std::isnan(lhs.m_data.m_value.number_float) && rhs.is_number())
23810 || (rhs.is_number_float() && std::isnan(rhs.m_data.m_value.number_float) && lhs.is_number()))
23814#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
23815 return (lhs.is_discarded() || rhs.is_discarded()) && !inverse;
23817 static_cast<void>(inverse);
23818 return lhs.is_discarded() || rhs.is_discarded();
23823 bool compares_unordered(const_reference rhs,
bool inverse =
false) const noexcept
23825 return compares_unordered(*
this, rhs, inverse);
23829#if JSON_HAS_THREE_WAY_COMPARISON
23832 bool operator==(const_reference rhs)
const noexcept
23835#pragma GCC diagnostic push
23836#pragma GCC diagnostic ignored "-Wfloat-equal"
23838 const_reference lhs = *
this;
23839 JSON_IMPLEMENT_OPERATOR( ==,
true,
false,
false)
23841#pragma GCC diagnostic pop
23847 template<
typename ScalarType>
23848 requires std::is_scalar_v<ScalarType>
23849 bool operator==(ScalarType rhs)
const noexcept
23851 return *
this == basic_json(rhs);
23856 bool operator!=(const_reference rhs)
const noexcept
23858 if (compares_unordered(rhs,
true))
23862 return !operator==(rhs);
23867 std::partial_ordering operator<=>(const_reference rhs)
const noexcept
23869 const_reference lhs = *
this;
23872 JSON_IMPLEMENT_OPERATOR(<=>,
23873 std::partial_ordering::equivalent,
23874 std::partial_ordering::unordered,
23875 lhs_type <=> rhs_type)
23880 template<
typename ScalarType>
23881 requires std::is_scalar_v<ScalarType>
23882 std::partial_ordering operator<=>(ScalarType rhs)
const noexcept
23884 return *this <=> basic_json(rhs);
23887#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
23893 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON)
23894 bool operator<=(const_reference rhs)
const noexcept
23896 if (compares_unordered(rhs,
true))
23900 return !(rhs < *
this);
23905 template<
typename ScalarType>
23906 requires std::is_scalar_v<ScalarType>
23907 bool operator<=(ScalarType rhs)
const noexcept
23909 return *
this <= basic_json(rhs);
23914 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON)
23915 bool operator>=(const_reference rhs)
const noexcept
23917 if (compares_unordered(rhs,
true))
23921 return !(*
this < rhs);
23926 template<
typename ScalarType>
23927 requires std::is_scalar_v<ScalarType>
23928 bool operator>=(ScalarType rhs)
const noexcept
23930 return *
this >= basic_json(rhs);
23936 friend bool operator==(const_reference lhs, const_reference rhs)
noexcept
23939#pragma GCC diagnostic push
23940#pragma GCC diagnostic ignored "-Wfloat-equal"
23942 JSON_IMPLEMENT_OPERATOR( ==,
true,
false,
false)
23944#pragma GCC diagnostic pop
23950 template<
typename ScalarType,
typename std::enable_if<
23951 std::is_scalar<ScalarType>::value,
int>::type = 0>
23952 friend bool operator==(const_reference lhs, ScalarType rhs)
noexcept
23954 return lhs == basic_json(rhs);
23959 template<
typename ScalarType,
typename std::enable_if<
23960 std::is_scalar<ScalarType>::value,
int>::type = 0>
23961 friend bool operator==(ScalarType lhs, const_reference rhs)
noexcept
23963 return basic_json(lhs) == rhs;
23968 friend bool operator!=(const_reference lhs, const_reference rhs)
noexcept
23970 if (compares_unordered(lhs, rhs,
true))
23974 return !(lhs == rhs);
23979 template<
typename ScalarType,
typename std::enable_if<
23980 std::is_scalar<ScalarType>::value,
int>::type = 0>
23981 friend bool operator!=(const_reference lhs, ScalarType rhs)
noexcept
23983 return lhs != basic_json(rhs);
23988 template<
typename ScalarType,
typename std::enable_if<
23989 std::is_scalar<ScalarType>::value,
int>::type = 0>
23990 friend bool operator!=(ScalarType lhs, const_reference rhs)
noexcept
23992 return basic_json(lhs) != rhs;
23997 friend bool operator<(const_reference lhs, const_reference rhs)
noexcept
24002 JSON_IMPLEMENT_OPERATOR( <,
false,
false,
operator<(lhs_type, rhs_type))
24007 template<
typename ScalarType,
typename std::enable_if<
24008 std::is_scalar<ScalarType>::value,
int>::type = 0>
24009 friend bool operator<(const_reference lhs, ScalarType rhs)
noexcept
24011 return lhs < basic_json(rhs);
24016 template<
typename ScalarType,
typename std::enable_if<
24017 std::is_scalar<ScalarType>::value,
int>::type = 0>
24018 friend bool operator<(ScalarType lhs, const_reference rhs)
noexcept
24020 return basic_json(lhs) < rhs;
24025 friend bool operator<=(const_reference lhs, const_reference rhs)
noexcept
24027 if (compares_unordered(lhs, rhs,
true))
24031 return !(rhs < lhs);
24036 template<
typename ScalarType,
typename std::enable_if<
24037 std::is_scalar<ScalarType>::value,
int>::type = 0>
24038 friend bool operator<=(const_reference lhs, ScalarType rhs)
noexcept
24040 return lhs <= basic_json(rhs);
24045 template<
typename ScalarType,
typename std::enable_if<
24046 std::is_scalar<ScalarType>::value,
int>::type = 0>
24047 friend bool operator<=(ScalarType lhs, const_reference rhs)
noexcept
24049 return basic_json(lhs) <= rhs;
24054 friend bool operator>(const_reference lhs, const_reference rhs)
noexcept
24057 if (compares_unordered(lhs, rhs))
24061 return !(lhs <= rhs);
24066 template<
typename ScalarType,
typename std::enable_if<
24067 std::is_scalar<ScalarType>::value,
int>::type = 0>
24068 friend bool operator>(const_reference lhs, ScalarType rhs)
noexcept
24070 return lhs > basic_json(rhs);
24075 template<
typename ScalarType,
typename std::enable_if<
24076 std::is_scalar<ScalarType>::value,
int>::type = 0>
24077 friend bool operator>(ScalarType lhs, const_reference rhs)
noexcept
24079 return basic_json(lhs) > rhs;
24084 friend bool operator>=(const_reference lhs, const_reference rhs)
noexcept
24086 if (compares_unordered(lhs, rhs,
true))
24090 return !(lhs < rhs);
24095 template<
typename ScalarType,
typename std::enable_if<
24096 std::is_scalar<ScalarType>::value,
int>::type = 0>
24097 friend bool operator>=(const_reference lhs, ScalarType rhs)
noexcept
24099 return lhs >= basic_json(rhs);
24104 template<
typename ScalarType,
typename std::enable_if<
24105 std::is_scalar<ScalarType>::value,
int>::type = 0>
24106 friend bool operator>=(ScalarType lhs, const_reference rhs)
noexcept
24108 return basic_json(lhs) >= rhs;
24112#undef JSON_IMPLEMENT_OPERATOR
24125 friend std::ostream& operator<<(std::ostream& o,
const basic_json& j)
24128 const bool pretty_print = o.width() > 0;
24129 const auto indentation = pretty_print ? o.width() : 0;
24135 serializer s(detail::output_adapter<char>(o), o.fill());
24136 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
24146 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator<<(std::ostream&,
const basic_json&))
24147 friend std::ostream& operator>>(
const basic_json& j, std::ostream& o)
24163 template<
typename InputType>
24164 JSON_HEDLEY_WARN_UNUSED_RESULT
24165 static basic_json parse(InputType&& i,
24166 parser_callback_t cb =
nullptr,
24167 const bool allow_exceptions =
true,
24168 const bool ignore_comments =
false,
24169 const bool ignore_trailing_commas =
false)
24172 parser(detail::input_adapter(std::forward<InputType>(i)), std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas).parse(
true, result);
24178 template<
typename IteratorType>
24179 JSON_HEDLEY_WARN_UNUSED_RESULT
24180 static basic_json parse(IteratorType first,
24182 parser_callback_t cb =
nullptr,
24183 const bool allow_exceptions =
true,
24184 const bool ignore_comments =
false,
24185 const bool ignore_trailing_commas =
false)
24188 parser(detail::input_adapter(std::move(first), std::move(last)), std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas).parse(
true, result);
24192 JSON_HEDLEY_WARN_UNUSED_RESULT
24193 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len))
24194 static basic_json parse(detail::span_input_adapter&& i,
24195 parser_callback_t cb =
nullptr,
24196 const bool allow_exceptions =
true,
24197 const bool ignore_comments =
false,
24198 const bool ignore_trailing_commas =
false)
24201 parser(i.get(), std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas).parse(
true, result);
24207 template<
typename InputType>
24208 static bool accept(InputType&& i,
24209 const bool ignore_comments =
false,
24210 const bool ignore_trailing_commas =
false)
24212 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false, ignore_comments, ignore_trailing_commas).accept(
true);
24217 template<
typename IteratorType>
24218 static bool accept(IteratorType first, IteratorType last,
24219 const bool ignore_comments =
false,
24220 const bool ignore_trailing_commas =
false)
24222 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false, ignore_comments, ignore_trailing_commas).accept(
true);
24225 JSON_HEDLEY_WARN_UNUSED_RESULT
24226 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len))
24227 static bool accept(detail::span_input_adapter&& i,
24228 const bool ignore_comments =
false,
24229 const bool ignore_trailing_commas =
false)
24231 return parser(i.get(),
nullptr,
false, ignore_comments, ignore_trailing_commas).accept(
true);
24236 template <
typename InputType,
typename SAX>
24237 JSON_HEDLEY_NON_NULL(2)
24238 static
bool sax_parse(InputType&& i, SAX* sax,
24239 input_format_t format = input_format_t::json,
24240 const
bool strict = true,
24241 const
bool ignore_comments = false,
24242 const
bool ignore_trailing_commas = false)
24244#if defined(__clang__)
24245#pragma clang diagnostic push
24246#pragma clang diagnostic ignored "-Wtautological-pointer-compare"
24247#elif defined(__GNUC__)
24248#pragma GCC diagnostic push
24249#pragma GCC diagnostic ignored "-Wnonnull-compare"
24251 if (sax ==
nullptr)
24253 JSON_THROW(other_error::create(502,
"SAX handler must not be null",
nullptr));
24255#if defined(__clang__)
24256#pragma clang diagnostic pop
24257#elif defined(__GNUC__)
24258#pragma GCC diagnostic pop
24260 auto ia = detail::input_adapter(std::forward<InputType>(i));
24261 return format == input_format_t::json
24262 ? parser(std::move(ia),
nullptr,
true, ignore_comments, ignore_trailing_commas).sax_parse(sax, strict)
24263 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia), format).sax_parse(format, sax, strict);
24268 template<
class IteratorType,
class SAX>
24269 JSON_HEDLEY_NON_NULL(3)
24270 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
24271 input_format_t format = input_format_t::json,
24272 const
bool strict = true,
24273 const
bool ignore_comments = false,
24274 const
bool ignore_trailing_commas = false)
24276#if defined(__clang__)
24277#pragma clang diagnostic push
24278#pragma clang diagnostic ignored "-Wtautological-pointer-compare"
24279#elif defined(__GNUC__)
24280#pragma GCC diagnostic push
24281#pragma GCC diagnostic ignored "-Wnonnull-compare"
24283 if (sax ==
nullptr)
24285 JSON_THROW(other_error::create(502,
"SAX handler must not be null",
nullptr));
24287#if defined(__clang__)
24288#pragma clang diagnostic pop
24289#elif defined(__GNUC__)
24290#pragma GCC diagnostic pop
24292 auto ia = detail::input_adapter(std::move(first), std::move(last));
24293 return format == input_format_t::json
24294 ? parser(std::move(ia),
nullptr,
true, ignore_comments, ignore_trailing_commas).sax_parse(sax, strict)
24303 template <
typename SAX>
24304 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, sax_parse(ptr, ptr + len, ...))
24305 JSON_HEDLEY_NON_NULL(2)
24306 static
bool sax_parse(
detail::span_input_adapter&& i, SAX* sax,
24307 input_format_t format = input_format_t::json,
24308 const
bool strict = true,
24309 const
bool ignore_comments = false,
24310 const
bool ignore_trailing_commas = false)
24312#if defined(__clang__)
24313#pragma clang diagnostic push
24314#pragma clang diagnostic ignored "-Wtautological-pointer-compare"
24315#elif defined(__GNUC__)
24316#pragma GCC diagnostic push
24317#pragma GCC diagnostic ignored "-Wnonnull-compare"
24319 if (sax ==
nullptr)
24321 JSON_THROW(other_error::create(502,
"SAX handler must not be null",
nullptr));
24323#if defined(__clang__)
24324#pragma clang diagnostic pop
24325#elif defined(__GNUC__)
24326#pragma GCC diagnostic pop
24329 return format == input_format_t::json
24331 ? parser(std::move(ia),
nullptr,
true, ignore_comments, ignore_trailing_commas).sax_parse(sax, strict)
24342 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator>>(std::istream&,
basic_json&))
24352 parser(detail::input_adapter(i)).parse(
false, j);
24364 JSON_HEDLEY_RETURNS_NON_NULL
24367 switch (m_data.m_type)
24369 case value_t::null:
24371 case value_t::object:
24373 case value_t::array:
24375 case value_t::string:
24377 case value_t::boolean:
24379 case value_t::binary:
24381 case value_t::discarded:
24382 return "discarded";
24383 case value_t::number_integer:
24384 case value_t::number_unsigned:
24385 case value_t::number_float:
24392 JSON_PRIVATE_UNLESS_TESTED:
24400 value_t m_type = value_t::null;
24405 data(
const value_t v)
24406 : m_type(v), m_value(v)
24410 data(size_type cnt,
const basic_json& val)
24413 m_value.array = create<array_t>(cnt, val);
24416 data() noexcept = default;
24417 data(data&&) noexcept = default;
24418 data(const data&) noexcept = delete;
24419 data& operator=(data&&) noexcept = delete;
24420 data& operator=(const data&) noexcept = delete;
24424 m_value.destroy(m_type);
24430#if JSON_DIAGNOSTICS
24432 basic_json* m_parent =
nullptr;
24435#if JSON_DIAGNOSTIC_POSITIONS
24437 std::size_t start_position = std::string::npos;
24439 std::size_t end_position = std::string::npos;
24441 constexpr std::size_t start_pos() const noexcept
24443 return start_position;
24446 constexpr std::size_t end_pos() const noexcept
24448 return end_position;
24464 std::vector<std::uint8_t> result;
24473 binary_writer<std::uint8_t>(o).write_cbor(j);
24480 binary_writer<char>(o).write_cbor(j);
24487 std::vector<std::uint8_t> result;
24496 binary_writer<std::uint8_t>(o).write_msgpack(j);
24503 binary_writer<char>(o).write_msgpack(j);
24509 const bool use_size =
false,
24510 const bool use_type =
false)
24512 std::vector<std::uint8_t> result;
24513 to_ubjson(j, result, use_size, use_type);
24520 const bool use_size =
false,
const bool use_type =
false)
24522 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);
24528 const bool use_size =
false,
const bool use_type =
false)
24530 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
24536 const bool use_size =
false,
24537 const bool use_type =
false,
24540 std::vector<std::uint8_t> result;
24541 to_bjdata(j, result, use_size, use_type, version);
24548 const bool use_size =
false,
const bool use_type =
false,
24551 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type,
true,
true, version);
24557 const bool use_size =
false,
const bool use_type =
false,
24560 binary_writer<char>(o).write_ubjson(j, use_size, use_type,
true,
true, version);
24567 std::vector<std::uint8_t> result;
24576 binary_writer<std::uint8_t>(o).write_bson(j);
24583 binary_writer<char>(o).write_bson(j);
24588 template<
typename InputType>
24589 JSON_HEDLEY_WARN_UNUSED_RESULT
24591 const bool strict =
true,
24592 const bool allow_exceptions =
true,
24596 auto ia = detail::input_adapter(std::forward<InputType>(i));
24598 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24599 return res ? result :
basic_json(value_t::discarded);
24604 template<
typename IteratorType>
24605 JSON_HEDLEY_WARN_UNUSED_RESULT
24607 const bool strict =
true,
24608 const bool allow_exceptions =
true,
24612 auto ia = detail::input_adapter(std::move(first), std::move(last));
24614 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24615 return res ? result :
basic_json(value_t::discarded);
24618 template<
typename T>
24619 JSON_HEDLEY_WARN_UNUSED_RESULT
24620 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
24621 static basic_json from_cbor(
const T* ptr, std::size_t len,
24622 const bool strict =
true,
24623 const bool allow_exceptions =
true,
24624 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24626 return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
24629 JSON_HEDLEY_WARN_UNUSED_RESULT
24630 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
24631 static basic_json from_cbor(detail::span_input_adapter&& i,
24632 const bool strict =
true,
24633 const bool allow_exceptions =
true,
24634 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24638 detail::json_sax_dom_parser<basic_json,
decltype(ia)> sdp(result, allow_exceptions);
24640 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24641 return res ? result : basic_json(value_t::discarded);
24646 template<
typename InputType>
24647 JSON_HEDLEY_WARN_UNUSED_RESULT
24649 const bool strict =
true,
24650 const bool allow_exceptions =
true)
24653 auto ia = detail::input_adapter(std::forward<InputType>(i));
24655 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
24656 return res ? result :
basic_json(value_t::discarded);
24661 template<
typename IteratorType>
24662 JSON_HEDLEY_WARN_UNUSED_RESULT
24664 const bool strict =
true,
24665 const bool allow_exceptions =
true)
24668 auto ia = detail::input_adapter(std::move(first), std::move(last));
24670 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
24671 return res ? result :
basic_json(value_t::discarded);
24674 template<
typename T>
24675 JSON_HEDLEY_WARN_UNUSED_RESULT
24676 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
24677 static basic_json from_msgpack(
const T* ptr, std::size_t len,
24678 const bool strict =
true,
24679 const bool allow_exceptions =
true)
24681 return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
24684 JSON_HEDLEY_WARN_UNUSED_RESULT
24685 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
24686 static basic_json from_msgpack(detail::span_input_adapter&& i,
24687 const bool strict =
true,
24688 const bool allow_exceptions =
true)
24692 detail::json_sax_dom_parser<basic_json,
decltype(ia)> sdp(result, allow_exceptions);
24694 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
24695 return res ? result : basic_json(value_t::discarded);
24700 template<
typename InputType>
24701 JSON_HEDLEY_WARN_UNUSED_RESULT
24703 const bool strict =
true,
24704 const bool allow_exceptions =
true)
24707 auto ia = detail::input_adapter(std::forward<InputType>(i));
24709 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
24710 return res ? result :
basic_json(value_t::discarded);
24715 template<
typename IteratorType>
24716 JSON_HEDLEY_WARN_UNUSED_RESULT
24718 const bool strict =
true,
24719 const bool allow_exceptions =
true)
24722 auto ia = detail::input_adapter(std::move(first), std::move(last));
24724 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
24725 return res ? result :
basic_json(value_t::discarded);
24728 template<
typename T>
24729 JSON_HEDLEY_WARN_UNUSED_RESULT
24730 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
24731 static basic_json from_ubjson(
const T* ptr, std::size_t len,
24732 const bool strict =
true,
24733 const bool allow_exceptions =
true)
24735 return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
24738 JSON_HEDLEY_WARN_UNUSED_RESULT
24739 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
24740 static basic_json from_ubjson(detail::span_input_adapter&& i,
24741 const bool strict =
true,
24742 const bool allow_exceptions =
true)
24746 detail::json_sax_dom_parser<basic_json,
decltype(ia)> sdp(result, allow_exceptions);
24748 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
24749 return res ? result : basic_json(value_t::discarded);
24754 template<
typename InputType>
24755 JSON_HEDLEY_WARN_UNUSED_RESULT
24757 const bool strict =
true,
24758 const bool allow_exceptions =
true)
24761 auto ia = detail::input_adapter(std::forward<InputType>(i));
24763 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
24764 return res ? result :
basic_json(value_t::discarded);
24769 template<
typename IteratorType>
24770 JSON_HEDLEY_WARN_UNUSED_RESULT
24772 const bool strict =
true,
24773 const bool allow_exceptions =
true)
24776 auto ia = detail::input_adapter(std::move(first), std::move(last));
24778 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
24779 return res ? result :
basic_json(value_t::discarded);
24784 template<
typename InputType>
24785 JSON_HEDLEY_WARN_UNUSED_RESULT
24787 const bool strict =
true,
24788 const bool allow_exceptions =
true)
24791 auto ia = detail::input_adapter(std::forward<InputType>(i));
24793 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
24794 return res ? result :
basic_json(value_t::discarded);
24799 template<
typename IteratorType>
24800 JSON_HEDLEY_WARN_UNUSED_RESULT
24802 const bool strict =
true,
24803 const bool allow_exceptions =
true)
24806 auto ia = detail::input_adapter(std::move(first), std::move(last));
24808 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
24809 return res ? result :
basic_json(value_t::discarded);
24812 template<
typename T>
24813 JSON_HEDLEY_WARN_UNUSED_RESULT
24814 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
24815 static basic_json from_bson(
const T* ptr, std::size_t len,
24816 const bool strict =
true,
24817 const bool allow_exceptions =
true)
24819 return from_bson(ptr, ptr + len, strict, allow_exceptions);
24822 JSON_HEDLEY_WARN_UNUSED_RESULT
24823 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
24824 static basic_json from_bson(detail::span_input_adapter&& i,
24825 const bool strict =
true,
24826 const bool allow_exceptions =
true)
24830 detail::json_sax_dom_parser<basic_json,
decltype(ia)> sdp(result, allow_exceptions);
24832 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
24833 return res ? result : basic_json(value_t::discarded);
24848 return ptr.get_unchecked(
this);
24851 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
24853 reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr)
24855 return ptr.get_unchecked(
this);
24862 return ptr.get_unchecked(
this);
24865 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
24867 const_reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
24869 return ptr.get_unchecked(
this);
24876 return ptr.get_checked(
this);
24879 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
24881 reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr)
24883 return ptr.get_checked(
this);
24890 return ptr.get_checked(
this);
24893 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
24895 const_reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
24897 return ptr.get_checked(
this);
24905 json_pointer::flatten(
"", *
this, result);
24913 return json_pointer::unflatten(*
this);
24931 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
24933 const auto get_op = [](
const string_t& op)
24937 return patch_operations::add;
24939 if (op ==
"remove")
24941 return patch_operations::remove;
24943 if (op ==
"replace")
24945 return patch_operations::replace;
24949 return patch_operations::move;
24953 return patch_operations::copy;
24957 return patch_operations::test;
24960 return patch_operations::invalid;
24975 if (top_pointer != ptr)
24977 result.
at(top_pointer);
24981 const auto last_path = ptr.
back();
24986 switch (parent.m_data.m_type)
24988 case value_t::null:
24989 case value_t::object:
24992 parent[last_path] = val;
24996 case value_t::array:
24998 if (last_path ==
"-")
25005 const auto idx = json_pointer::template array_index<basic_json_t>(last_path);
25006 if (JSON_HEDLEY_UNLIKELY(idx > parent.
size()))
25009 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"), &parent));
25019 case value_t::string:
25020 case value_t::boolean:
25021 case value_t::number_integer:
25022 case value_t::number_unsigned:
25023 case value_t::number_float:
25024 case value_t::binary:
25025 case value_t::discarded:
25027 JSON_ASSERT(
false);
25032 const auto operation_remove = [
this, & result](
json_pointer & ptr)
25035 const auto last_path = ptr.
back();
25043 auto it = parent.
find(last_path);
25044 if (JSON_HEDLEY_LIKELY(it != parent.
end()))
25050 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", last_path,
"' not found"),
this));
25056 parent.
erase(json_pointer::template array_index<basic_json_t>(last_path));
25061 if (JSON_HEDLEY_UNLIKELY(!json_patch.
is_array()))
25063 JSON_THROW(
parse_error::create(104, 0,
"JSON patch must be an array of objects", &json_patch));
25067 for (
const auto& val : json_patch)
25070 const auto get_value = [&val](
const string_t& op,
25075 auto it = val.m_data.m_value.object->find(member);
25078 const auto error_msg = (op ==
"op") ?
"operation" : detail::concat(
"operation '", op,
'\'');
25081 if (JSON_HEDLEY_UNLIKELY(it == val.m_data.m_value.object->end()))
25084 JSON_THROW(
parse_error::create(105, 0, detail::concat(error_msg,
" must have member '", member,
"'"), &val));
25088 if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
25091 JSON_THROW(
parse_error::create(105, 0, detail::concat(error_msg,
" must have string member '", member,
"'"), &val));
25099 if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
25105 const auto op = get_value(
"op",
"op",
true).template
get<string_t>();
25106 const auto path = get_value(op,
"path",
true).template
get<string_t>();
25109 switch (get_op(op))
25111 case patch_operations::add:
25113 operation_add(ptr, get_value(
"add",
"value",
false));
25117 case patch_operations::remove:
25119 operation_remove(ptr);
25123 case patch_operations::replace:
25126 result.
at(ptr) = get_value(
"replace",
"value",
false);
25130 case patch_operations::move:
25132 const auto from_path = get_value(
"move",
"from",
true).template
get<string_t>();
25142 operation_remove(from_ptr);
25143 operation_add(ptr, v);
25147 case patch_operations::copy:
25149 const auto from_path = get_value(
"copy",
"from",
true).template
get<string_t>();
25158 operation_add(ptr, v);
25162 case patch_operations::test:
25164 bool success =
false;
25169 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
25171 JSON_INTERNAL_CATCH (out_of_range&)
25177 if (JSON_HEDLEY_UNLIKELY(!success))
25179 JSON_THROW(other_error::create(501, detail::concat(
"unsuccessful: ", val.dump()), &val));
25185 case patch_operations::invalid:
25190 JSON_THROW(
parse_error::create(105, 0, detail::concat(
"operation value '", op,
"' is invalid"), &val));
25207 JSON_HEDLEY_WARN_UNUSED_RESULT
25215 if (source == target)
25220 if (source.
type() != target.
type())
25225 {
"op",
"replace"}, {
"path", path}, {
"value", target}
25230 switch (source.
type())
25232 case value_t::array:
25236 while (i < source.
size() && i < target.
size())
25239 auto temp_diff =
diff(source[i], target[i], detail::concat<string_t>(path,
'/', detail::to_string<string_t>(i)));
25240 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
25249 while (i < source.
size())
25253 result.
insert(result.
begin() + end_index,
object(
25256 {
"path", detail::concat<string_t>(path,
'/', detail::to_string<string_t>(i))}
25262 while (i < target.
size())
25267 {
"path", detail::concat<string_t>(path,
"/-")},
25268 {
"value", target[i]}
25276 case value_t::object:
25279 for (
auto it = source.
cbegin(); it != source.
cend(); ++it)
25282 const auto path_key = detail::concat<string_t>(path,
'/',
detail::escape(it.key()));
25284 if (target.
find(it.key()) != target.
end())
25287 auto temp_diff =
diff(it.value(), target[it.key()], path_key);
25288 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
25295 {
"op",
"remove"}, {
"path", path_key}
25301 for (
auto it = target.
cbegin(); it != target.
cend(); ++it)
25303 if (source.
find(it.key()) == source.
end())
25306 const auto path_key = detail::concat<string_t>(path,
'/',
detail::escape(it.key()));
25309 {
"op",
"add"}, {
"path", path_key},
25310 {
"value", it.value()}
25318 case value_t::null:
25319 case value_t::string:
25320 case value_t::boolean:
25321 case value_t::number_integer:
25322 case value_t::number_unsigned:
25323 case value_t::number_float:
25324 case value_t::binary:
25325 case value_t::discarded:
25331 {
"op",
"replace"}, {
"path", path}, {
"value", target}
25358 for (
auto it = apply_patch.
begin(); it != apply_patch.
end(); ++it)
25360 if (it.value().is_null())
25366 operator[](it.key()).merge_patch(it.value());
25372 *
this = apply_patch;
25381NLOHMANN_BASIC_JSON_TPL_DECLARATION
25382std::string to_string(
const NLOHMANN_BASIC_JSON_TPL& j)
25387inline namespace literals
25389inline namespace json_literals
25394JSON_HEDLEY_NON_NULL(1)
25395#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
25396 inline nlohmann::json
operator""_json(
const char* s, std::size_t n)
25399 inline nlohmann::json
operator"" _json(
const char* s, std::size_t n)
25402 return nlohmann::json::parse(s, s + n);
25405#if defined(__cpp_char8_t)
25406JSON_HEDLEY_NON_NULL(1)
25407inline nlohmann::json operator
""_json(const
char8_t* s, std::
size_t n)
25409 return nlohmann::json::parse(
reinterpret_cast<const char*
>(s),
25410 reinterpret_cast<const char*
>(s) + n);
25416JSON_HEDLEY_NON_NULL(1)
25417#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
25427#if defined(__cpp_char8_t)
25436NLOHMANN_JSON_NAMESPACE_END
25447NLOHMANN_BASIC_JSON_TPL_DECLARATION
25448struct hash<nlohmann::NLOHMANN_BASIC_JSON_TPL>
25450 std::size_t operator()(
const nlohmann::NLOHMANN_BASIC_JSON_TPL& j)
const
25452 return nlohmann::detail::hash(j);
25458struct less< ::nlohmann::detail::value_t>
25465 ::nlohmann::detail::value_t rhs)
const noexcept
25467#if JSON_HAS_THREE_WAY_COMPARISON
25468 return std::is_lt(lhs <=> rhs);
25470 return ::nlohmann::detail::operator<(lhs, rhs);
25476#ifndef JSON_HAS_CPP_20
25480NLOHMANN_BASIC_JSON_TPL_DECLARATION
25481inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC_JSON_TPL& j2)
noexcept(
25482 is_nothrow_move_constructible<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value&&
25483 is_nothrow_move_assignable<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value)
25492#if JSON_USE_GLOBAL_UDLS
25493 #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
25494 using nlohmann::literals::json_literals::operator
""_json;
25495 using nlohmann::literals::json_literals::operator
""_json_pointer;
25498 using nlohmann::literals::json_literals::operator
"" _json;
25499 using nlohmann::literals::json_literals::operator
"" _json_pointer;
25515#if defined(__clang__)
25516 #pragma clang diagnostic pop
25521#undef JSON_INTERNAL_CATCH
25523#undef JSON_PRIVATE_UNLESS_TESTED
25524#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
25525#undef NLOHMANN_BASIC_JSON_TPL
25526#undef JSON_EXPLICIT
25527#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
25528#undef JSON_INLINE_VARIABLE
25529#undef JSON_NO_UNIQUE_ADDRESS
25530#undef JSON_DISABLE_ENUM_SERIALIZATION
25531#undef JSON_USE_GLOBAL_UDLS
25533#ifndef JSON_TEST_KEEP_MACROS
25536 #undef JSON_HAS_CPP_11
25537 #undef JSON_HAS_CPP_14
25538 #undef JSON_HAS_CPP_17
25539 #undef JSON_HAS_CPP_20
25540 #undef JSON_HAS_CPP_23
25541 #undef JSON_HAS_CPP_26
25542 #undef JSON_HAS_FILESYSTEM
25543 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
25544 #undef JSON_HAS_THREE_WAY_COMPARISON
25545 #undef JSON_HAS_RANGES
25546 #undef JSON_HAS_STATIC_RTTI
25547 #undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
25561#undef JSON_HEDLEY_ALWAYS_INLINE
25562#undef JSON_HEDLEY_ARM_VERSION
25563#undef JSON_HEDLEY_ARM_VERSION_CHECK
25564#undef JSON_HEDLEY_ARRAY_PARAM
25565#undef JSON_HEDLEY_ASSUME
25566#undef JSON_HEDLEY_BEGIN_C_DECLS
25567#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
25568#undef JSON_HEDLEY_CLANG_HAS_BUILTIN
25569#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
25570#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
25571#undef JSON_HEDLEY_CLANG_HAS_EXTENSION
25572#undef JSON_HEDLEY_CLANG_HAS_FEATURE
25573#undef JSON_HEDLEY_CLANG_HAS_WARNING
25574#undef JSON_HEDLEY_COMPCERT_VERSION
25575#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
25576#undef JSON_HEDLEY_CONCAT
25577#undef JSON_HEDLEY_CONCAT3
25578#undef JSON_HEDLEY_CONCAT3_EX
25579#undef JSON_HEDLEY_CONCAT_EX
25580#undef JSON_HEDLEY_CONST
25581#undef JSON_HEDLEY_CONSTEXPR
25582#undef JSON_HEDLEY_CONST_CAST
25583#undef JSON_HEDLEY_CPP_CAST
25584#undef JSON_HEDLEY_CRAY_VERSION
25585#undef JSON_HEDLEY_CRAY_VERSION_CHECK
25586#undef JSON_HEDLEY_C_DECL
25587#undef JSON_HEDLEY_DEPRECATED
25588#undef JSON_HEDLEY_DEPRECATED_FOR
25589#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
25590#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
25591#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
25592#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
25593#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
25594#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
25595#undef JSON_HEDLEY_DIAGNOSTIC_POP
25596#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
25597#undef JSON_HEDLEY_DMC_VERSION
25598#undef JSON_HEDLEY_DMC_VERSION_CHECK
25599#undef JSON_HEDLEY_EMPTY_BASES
25600#undef JSON_HEDLEY_EMSCRIPTEN_VERSION
25601#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
25602#undef JSON_HEDLEY_END_C_DECLS
25603#undef JSON_HEDLEY_FLAGS
25604#undef JSON_HEDLEY_FLAGS_CAST
25605#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
25606#undef JSON_HEDLEY_GCC_HAS_BUILTIN
25607#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
25608#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
25609#undef JSON_HEDLEY_GCC_HAS_EXTENSION
25610#undef JSON_HEDLEY_GCC_HAS_FEATURE
25611#undef JSON_HEDLEY_GCC_HAS_WARNING
25612#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
25613#undef JSON_HEDLEY_GCC_VERSION
25614#undef JSON_HEDLEY_GCC_VERSION_CHECK
25615#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
25616#undef JSON_HEDLEY_GNUC_HAS_BUILTIN
25617#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
25618#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
25619#undef JSON_HEDLEY_GNUC_HAS_EXTENSION
25620#undef JSON_HEDLEY_GNUC_HAS_FEATURE
25621#undef JSON_HEDLEY_GNUC_HAS_WARNING
25622#undef JSON_HEDLEY_GNUC_VERSION
25623#undef JSON_HEDLEY_GNUC_VERSION_CHECK
25624#undef JSON_HEDLEY_HAS_ATTRIBUTE
25625#undef JSON_HEDLEY_HAS_BUILTIN
25626#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
25627#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
25628#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
25629#undef JSON_HEDLEY_HAS_EXTENSION
25630#undef JSON_HEDLEY_HAS_FEATURE
25631#undef JSON_HEDLEY_HAS_WARNING
25632#undef JSON_HEDLEY_IAR_VERSION
25633#undef JSON_HEDLEY_IAR_VERSION_CHECK
25634#undef JSON_HEDLEY_IBM_VERSION
25635#undef JSON_HEDLEY_IBM_VERSION_CHECK
25636#undef JSON_HEDLEY_IMPORT
25637#undef JSON_HEDLEY_INLINE
25638#undef JSON_HEDLEY_INTEL_CL_VERSION
25639#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
25640#undef JSON_HEDLEY_INTEL_VERSION
25641#undef JSON_HEDLEY_INTEL_VERSION_CHECK
25642#undef JSON_HEDLEY_IS_CONSTANT
25643#undef JSON_HEDLEY_IS_CONSTEXPR_
25644#undef JSON_HEDLEY_LIKELY
25645#undef JSON_HEDLEY_MALLOC
25646#undef JSON_HEDLEY_MCST_LCC_VERSION
25647#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
25648#undef JSON_HEDLEY_MESSAGE
25649#undef JSON_HEDLEY_MSVC_VERSION
25650#undef JSON_HEDLEY_MSVC_VERSION_CHECK
25651#undef JSON_HEDLEY_NEVER_INLINE
25652#undef JSON_HEDLEY_NON_NULL
25653#undef JSON_HEDLEY_NO_ESCAPE
25654#undef JSON_HEDLEY_NO_RETURN
25655#undef JSON_HEDLEY_NO_THROW
25656#undef JSON_HEDLEY_NULL
25657#undef JSON_HEDLEY_PELLES_VERSION
25658#undef JSON_HEDLEY_PELLES_VERSION_CHECK
25659#undef JSON_HEDLEY_PGI_VERSION
25660#undef JSON_HEDLEY_PGI_VERSION_CHECK
25661#undef JSON_HEDLEY_PREDICT
25662#undef JSON_HEDLEY_PRINTF_FORMAT
25663#undef JSON_HEDLEY_PRIVATE
25664#undef JSON_HEDLEY_PUBLIC
25665#undef JSON_HEDLEY_PURE
25666#undef JSON_HEDLEY_REINTERPRET_CAST
25667#undef JSON_HEDLEY_REQUIRE
25668#undef JSON_HEDLEY_REQUIRE_CONSTEXPR
25669#undef JSON_HEDLEY_REQUIRE_MSG
25670#undef JSON_HEDLEY_RESTRICT
25671#undef JSON_HEDLEY_RETURNS_NON_NULL
25672#undef JSON_HEDLEY_SENTINEL
25673#undef JSON_HEDLEY_STATIC_ASSERT
25674#undef JSON_HEDLEY_STATIC_CAST
25675#undef JSON_HEDLEY_STRINGIFY
25676#undef JSON_HEDLEY_STRINGIFY_EX
25677#undef JSON_HEDLEY_SUNPRO_VERSION
25678#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
25679#undef JSON_HEDLEY_TINYC_VERSION
25680#undef JSON_HEDLEY_TINYC_VERSION_CHECK
25681#undef JSON_HEDLEY_TI_ARMCL_VERSION
25682#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
25683#undef JSON_HEDLEY_TI_CL2000_VERSION
25684#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
25685#undef JSON_HEDLEY_TI_CL430_VERSION
25686#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
25687#undef JSON_HEDLEY_TI_CL6X_VERSION
25688#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
25689#undef JSON_HEDLEY_TI_CL7X_VERSION
25690#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
25691#undef JSON_HEDLEY_TI_CLPRU_VERSION
25692#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
25693#undef JSON_HEDLEY_TI_VERSION
25694#undef JSON_HEDLEY_TI_VERSION_CHECK
25695#undef JSON_HEDLEY_UNAVAILABLE
25696#undef JSON_HEDLEY_UNLIKELY
25697#undef JSON_HEDLEY_UNPREDICTABLE
25698#undef JSON_HEDLEY_UNREACHABLE
25699#undef JSON_HEDLEY_UNREACHABLE_RETURN
25700#undef JSON_HEDLEY_VERSION
25701#undef JSON_HEDLEY_VERSION_DECODE_MAJOR
25702#undef JSON_HEDLEY_VERSION_DECODE_MINOR
25703#undef JSON_HEDLEY_VERSION_DECODE_REVISION
25704#undef JSON_HEDLEY_VERSION_ENCODE
25705#undef JSON_HEDLEY_WARNING
25706#undef JSON_HEDLEY_WARN_UNUSED_RESULT
25707#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
25708#undef JSON_HEDLEY_FALL_THROUGH
a class to store JSON values
Definition json.hpp:20219
constexpr bool is_string() const noexcept
Definition json.hpp:21518
size_type erase(const typename object_t::key_type &key)
remove element from a JSON object given a key
Definition json.hpp:22753
detail::cbor_tag_handler_t cbor_tag_handler_t
Definition json.hpp:20293
reference operator[](KeyType &&key)
access specified object element
Definition json.hpp:22319
size_type size() const noexcept
Definition json.hpp:23094
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:24606
auto get() const noexcept(noexcept(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))) -> decltype(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))
Definition json.hpp:21891
const_iterator end() const noexcept
returns an iterator to one past the last element
Definition json.hpp:22951
reference back()
access the last element
Definition json.hpp:22557
basic_json value_type
Definition json.hpp:20330
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:20958
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
Definition json.hpp:22967
basic_json patch(const basic_json &json_patch) const
applies a JSON patch to a copy of the current object
Definition json.hpp:25198
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
Definition json.hpp:24365
const_reference front() const
access the first element
Definition json.hpp:22550
constexpr bool is_array() const noexcept
Definition json.hpp:21511
void swap(reference other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&//NOLINT(cppcoreguidelines-noexcept-swap, performance-noexcept-swap) std::is_nothrow_move_assignable< json_value >::value)
Definition json.hpp:23612
ReturnType value(const json_pointer &ptr, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:22500
size_type count(KeyType &&key) const
returns the number of occurrences of a key in a JSON object
Definition json.hpp:22870
iter_impl< const basic_json > const_iterator
Definition json.hpp:20353
constexpr bool is_number_integer() const noexcept
Definition json.hpp:21483
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
Definition json.hpp:20357
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:24801
reference operator[](const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.hpp:24846
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
Definition json.hpp:20348
std::size_t size_type
Definition json.hpp:20340
constexpr bool is_structured() const noexcept
return whether type is structured
Definition json.hpp:21455
const_reference operator[](KeyType &&key) const
access specified object element
Definition json.hpp:22343
detail::error_handler_t error_handler_t
Definition json.hpp:20291
const value_type & const_reference
Definition json.hpp:20335
void swap(binary_t &other)
exchanges the values
Definition json.hpp:23689
ReferenceType get_ref()
Definition json.hpp:21981
size_type max_size() const noexcept
returns the maximum possible number of elements
Definition json.hpp:23133
void update(const_reference j, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
Definition json.hpp:23558
ReferenceType get_ref() const
get a reference value (implicit)
Definition json.hpp:21992
constexpr bool is_discarded() const noexcept
return whether value is discarded
Definition json.hpp:21532
reference operator+=(initializer_list_t init)
add an object to an object
Definition json.hpp:23349
void push_back(basic_json &&val)
add an object to an array
Definition json.hpp:23237
const_reference operator[](const typename object_t::key_type &key) const
access specified object element
Definition json.hpp:22288
iteration_proxy< const_iterator > items() const noexcept
helper to access iterator member functions in range-based for
Definition json.hpp:23039
basic_json & operator=(basic_json other) noexcept(//NOLINT(cppcoreguidelines-c-copy-assignment-signature, misc-unconventional-assign-operator)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:21372
const_reference back() const
access the last element
Definition json.hpp:22566
IteratorType erase(IteratorType first, IteratorType last)
remove elements given an iterator range
Definition json.hpp:22648
reference operator+=(const basic_json &val)
add an object to an array
Definition json.hpp:23294
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:23629
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:24702
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:21100
iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
inserts copies of element into array
Definition json.hpp:23461
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:24786
static allocator_type get_allocator()
returns the allocator associated with the container
Definition json.hpp:20363
nlohmann::byte_container_with_subtype< std::vector< std::uint8_t > > binary_t
Definition json.hpp:20488
reference at(KeyType &&key)
access specified object element with bounds checking
Definition json.hpp:22151
iterator end() noexcept
Definition json.hpp:22942
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
Definition json.hpp:21490
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:23565
static std::vector< std::uint8_t > to_bson(const basic_json &j)
create a BSON serialization of a given JSON value
Definition json.hpp:24565
const_reverse_iterator rbegin() const noexcept
returns an iterator to the reverse-beginning
Definition json.hpp:22974
void push_back(initializer_list_t init)
add an object to an object
Definition json.hpp:23333
detail::parser_callback_t< basic_json > parser_callback_t
Definition json.hpp:20925
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
Definition json.hpp:21141
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:24501
iterator begin() noexcept
Definition json.hpp:22917
detail::parse_event_t parse_event_t
Definition json.hpp:20921
ReturnType value(const typename object_t::key_type &key, ValueType &&default_value) const
access specified object element with default value
Definition json.hpp:22398
const_iterator cend() const noexcept
Definition json.hpp:22958
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:24756
const_reference at(const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.hpp:24888
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init)
explicitly create a binary array
Definition json.hpp:21111
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
Definition json.hpp:20946
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:24590
basic_json flatten() const
return flattened JSON value
Definition json.hpp:24902
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:24717
size_type erase(KeyType &&key)
remove element from a JSON object given a key
Definition json.hpp:22764
std::vector< basic_json, std::allocator< basic_json > > array_t
Definition json.hpp:20464
nlohmann::ordered_map< std::string, basic_json, default_object_comparator_t, std::allocator< std::pair< const std::string, basic_json > > > object_t
Definition json.hpp:20456
const binary_t & get_binary() const
get a binary value
Definition json.hpp:22063
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
inserts range of elements into array
Definition json.hpp:23481
void patch_inplace(const basic_json &json_patch)
applies a JSON patch in-place without copying the object
Definition json.hpp:24927
ReturnType value(KeyType &&key, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:22451
const_reference operator[](const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.hpp:24860
value_type & reference
Definition json.hpp:20333
std::initializer_list< detail::json_ref< basic_json > > initializer_list_t
Definition json.hpp:20297
bool contains(KeyType &&key) const
check the existence of an element in a JSON object
Definition json.hpp:22887
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:24471
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:24581
iterator find(const typename object_t::key_type &key)
Definition json.hpp:22800
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:21089
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:24535
const_reference at(KeyType &&key) const
access specified object element with bounds checking
Definition json.hpp:22189
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json meta()
returns version information on the library
Definition json.hpp:20371
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
Definition json.hpp:21148
const_iterator find(const typename object_t::key_type &key) const
find an element in a JSON object
Definition json.hpp:22814
static std::vector< std::uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
Definition json.hpp:24462
IteratorType erase(IteratorType pos)
remove element given an iterator
Definition json.hpp:22578
iterator insert(const_iterator pos, const basic_json &val)
inserts element into array
Definition json.hpp:23434
double number_float_t
Definition json.hpp:20484
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition json.hpp:22373
std::allocator< basic_json > allocator_type
Definition json.hpp:20343
typename std::allocator_traits< allocator_type >::pointer pointer
Definition json.hpp:20346
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:21419
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
Definition json.hpp:25350
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:21945
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:24547
reference at(size_type idx)
access specified array element with bounds checking
Definition json.hpp:22085
iterator find(KeyType &&key)
find an element in a JSON object
Definition json.hpp:22830
constexpr bool is_number_float() const noexcept
Definition json.hpp:21497
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
Definition json.hpp:22981
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:24508
reference at(const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.hpp:24874
bool boolean_t
Definition json.hpp:20472
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:25208
std::less< std::string > default_object_comparator_t
Definition json.hpp:20451
reference operator+=(const typename object_t::value_type &val)
add an object to an object
Definition json.hpp:23325
const_iterator cbegin() const noexcept
Definition json.hpp:22933
reference operator[](typename object_t::key_type key)
access specified object element
Definition json.hpp:22266
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:21703
~basic_json() noexcept
destructor
Definition json.hpp:21401
const_reverse_iterator crend() const noexcept
Definition json.hpp:23002
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:21030
void swap(typename binary_t::container_type &other)
exchanges the values
Definition json.hpp:23705
binary_t & get_binary()
get a binary value
Definition json.hpp:22051
const_iterator begin() const noexcept
returns an iterator to the first element
Definition json.hpp:22926
constexpr bool is_number() const noexcept
Definition json.hpp:21476
void insert(const_iterator first, const_iterator last)
inserts range of elements into object
Definition json.hpp:23532
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:24648
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
Definition json.hpp:21932
reference operator[](size_type idx)
access specified array element
Definition json.hpp:22207
static iteration_proxy< iterator > iterator_wrapper(reference ref) noexcept
Definition json.hpp:23014
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:24527
std::int64_t number_integer_t
Definition json.hpp:20476
auto get_ptr() noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition json.hpp:21692
const_reference at(const typename object_t::key_type &key) const
access specified object element with bounds checking
Definition json.hpp:22169
constexpr bool is_binary() const noexcept
Definition json.hpp:21525
void swap(object_t &other)
exchanges the values
Definition json.hpp:23657
basic_json unflatten() const
unflatten a previously flattened JSON value
Definition json.hpp:24911
iterator insert(const_iterator pos, initializer_list_t ilist)
inserts elements from initializer list into array
Definition json.hpp:23512
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:24556
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:21122
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
Definition json.hpp:23032
bool empty() const noexcept
checks whether the container is empty.
Definition json.hpp:23055
void swap(array_t &other)
exchanges the values
Definition json.hpp:23641
void erase(const size_type idx)
remove element from a JSON array given an index
Definition json.hpp:22771
reference operator+=(basic_json &&val)
add an object to an array
Definition json.hpp:23262
bool contains(const json_pointer &ptr) const
check the existence of an element in a JSON object given a JSON pointer
Definition json.hpp:22894
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition json.hpp:21441
reference emplace_back(Args &&... args)
add an object to an array
Definition json.hpp:23358
ValueType value(const json_pointer &ptr, const ValueType &default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:22474
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
Definition json.hpp:21133
detail::bjdata_version_t bjdata_version_t
Definition json.hpp:20295
std::string string_t
Definition json.hpp:20468
void push_back(const basic_json &val)
add an object to an array
Definition json.hpp:23270
ValueType value(KeyType &&key, const ValueType &default_value) const
access specified object element with default value
Definition json.hpp:22424
reference at(const typename object_t::key_type &key)
access specified object element with bounds checking
Definition json.hpp:22131
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:24771
json_value m_value
the value of the current element
Definition json.hpp:24403
const_reverse_iterator crbegin() const noexcept
Definition json.hpp:22995
json_sax< basic_json > json_sax_t
Definition json.hpp:20301
constexpr bool is_boolean() const noexcept
Definition json.hpp:21469
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:22860
reference front()
access the first element
Definition json.hpp:22543
constexpr bool is_primitive() const noexcept
return whether type is primitive
Definition json.hpp:21448
constexpr bool is_null() const noexcept
Definition json.hpp:21462
void clear() noexcept
clears the contents
Definition json.hpp:23176
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:24519
basic_json(basic_json &&other) noexcept
move constructor
Definition json.hpp:21346
iter_impl< basic_json > iterator
Definition json.hpp:20351
basic_json(const value_t v)
create an empty value with a given type
Definition json.hpp:20938
const_reference operator[](size_type idx) const
access specified array element
Definition json.hpp:22253
std::ptrdiff_t difference_type
Definition json.hpp:20338
iterator insert(const_iterator pos, basic_json &&val)
inserts element into array
Definition json.hpp:23454
const_reverse_iterator rend() const noexcept
returns an iterator to the reverse-end
Definition json.hpp:22988
std::uint64_t number_unsigned_t
Definition json.hpp:20480
friend std::istream & operator>>(std::istream &i, basic_json &j)
Definition json.hpp:24350
static std::vector< std::uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
Definition json.hpp:24485
void swap(string_t &other)
exchanges the values
Definition json.hpp:23673
basic_json(const BasicJsonType &val)
create a JSON value from an existing one
Definition json.hpp:20972
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
Definition json.hpp:20355
const_reference at(size_type idx) const
access specified array element with bounds checking
Definition json.hpp:22108
detail::actual_object_comparator_t< basic_json > object_comparator_t
Definition json.hpp:20492
basic_json(const basic_json &other)
copy constructor
Definition json.hpp:21273
void push_back(const typename object_t::value_type &val)
add an object to an object
Definition json.hpp:23302
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
Definition json.hpp:23383
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:24478
constexpr bool is_object() const noexcept
Definition json.hpp:21504
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:24494
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:24663
iterator insert_iterator(const_iterator pos, Args &&... args)
Helper for insertion of an iterator.
Definition json.hpp:23415
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
Definition json.hpp:21160
bool contains(const typename object_t::key_type &key) const
check the existence of an element in a JSON object
Definition json.hpp:22878
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:24574
const_iterator find(KeyType &&key) const
find an element in a JSON object
Definition json.hpp:22846
::nlohmann::json_pointer< std::string > json_pointer
Definition json.hpp:20287
an internal type for a backed binary type
Definition json.hpp:6255
byte_container_with_subtype() noexcept(noexcept(container_type()))
Definition json.hpp:6261
byte_container_with_subtype(container_type &&b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))
Definition json.hpp:6283
byte_container_with_subtype(container_type &&b) noexcept(noexcept(container_type(std::move(b))))
Definition json.hpp:6271
constexpr subtype_type subtype() const noexcept
return the binary subtype
Definition json.hpp:6310
byte_container_with_subtype(const container_type &b, subtype_type subtype_) noexcept(noexcept(container_type(b)))
Definition json.hpp:6276
constexpr bool has_subtype() const noexcept
return whether the value has a subtype
Definition json.hpp:6317
byte_container_with_subtype(const container_type &b) noexcept(noexcept(container_type(b)))
Definition json.hpp:6266
void set_subtype(subtype_type subtype_) noexcept
sets the binary subtype
Definition json.hpp:6302
void clear_subtype() noexcept
clears the binary subtype
Definition json.hpp:6324
deserialization of CBOR, MessagePack, and UBJSON values
Definition json.hpp:9908
binary_reader(InputAdapterType &&adapter, const input_format_t format=input_format_t::json) noexcept
create a binary reader
Definition json.hpp:9924
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:9945
void write_bson(const BasicJsonType &j)
Definition json.hpp:15899
void write_ubjson(const BasicJsonType &j, const bool use_count, const bool use_type, const bool add_prefix=true, const bool use_bjdata=false, const bjdata_version_t bjdata_version=bjdata_version_t::draft2)
Definition json.hpp:16579
binary_writer(output_adapter_t< CharType > adapter)
create a binary writer
Definition json.hpp:15890
void write_msgpack(const BasicJsonType &j)
Definition json.hpp:16252
void write_cbor(const BasicJsonType &j)
Definition json.hpp:15928
general exception of the basic_json class
Definition json.hpp:4556
const int id
the id of the exception
Definition json.hpp:4565
const char * what() const noexcept override
returns the explanatory string
Definition json.hpp:4559
exception indicating errors with iterators
Definition json.hpp:4725
iter_impl operator+(difference_type i) const
add to iterator
Definition json.hpp:14281
iter_impl & operator=(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting assignment
Definition json.hpp:13835
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
Definition json.hpp:14226
iter_impl(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting constructor
Definition json.hpp:13825
bool operator<(const iter_impl &other) const
comparison: smaller
Definition json.hpp:14168
bool operator<=(const iter_impl &other) const
comparison: less than or equal
Definition json.hpp:14208
iter_impl & operator-=(difference_type i)
subtract from iterator
Definition json.hpp:14272
iter_impl & operator--()
pre-decrement (–it)
Definition json.hpp:14078
const object_t::key_type & key() const
return the key of an object iterator
Definition json.hpp:14381
bool operator==(const IterImpl &other) const
comparison: equal
Definition json.hpp:14119
iter_impl operator++(int) &
post-increment (it++)
Definition json.hpp:14016
iter_impl & operator+=(difference_type i)
add to iterator
Definition json.hpp:14235
reference operator[](difference_type n) const
access to successor
Definition json.hpp:14343
typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_pointer, typename BasicJsonType::pointer >::type pointer
Definition json.hpp:13730
typename BasicJsonType::difference_type difference_type
Definition json.hpp:13728
pointer operator->() const
dereference the iterator
Definition json.hpp:13974
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
Definition json.hpp:14406
difference_type operator-(const iter_impl &other) const
return difference
Definition json.hpp:14314
std::bidirectional_iterator_tag iterator_category
Definition json.hpp:13723
friend iter_impl operator+(difference_type i, const iter_impl &it)
addition of distance and iterator
Definition json.hpp:14292
reference value() const
return the value of an iterator
Definition json.hpp:14397
bool operator>(const iter_impl &other) const
comparison: greater than
Definition json.hpp:14217
iter_impl & operator++()
pre-increment (++it)
Definition json.hpp:14027
typename BasicJsonType::value_type value_type
Definition json.hpp:13726
reference operator*() const
return a reference to the value pointed to by the iterator
Definition json.hpp:13930
iter_impl operator-(difference_type i) const
subtract from iterator
Definition json.hpp:14303
typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_reference, typename BasicJsonType::reference >::type reference
Definition json.hpp:13734
iter_impl & operator=(const iter_impl< const BasicJsonType > &other) noexcept
converting assignment
Definition json.hpp:13810
bool operator!=(const IterImpl &other) const
comparison: not equal
Definition json.hpp:14159
iter_impl operator--(int) &
post-decrement (it–)
Definition json.hpp:14067
iter_impl(const iter_impl< const BasicJsonType > &other) noexcept
const copy constructor
Definition json.hpp:13800
void set_end() noexcept
set the iterator past the last value
Definition json.hpp:13891
bool operator==(const iteration_proxy_value &o) const
equality operator (needed for InputIterator)
Definition json.hpp:5582
bool operator!=(const iteration_proxy_value &o) const
inequality operator (needed for range-based for)
Definition json.hpp:5588
iteration_proxy_value & operator++()
increment operator (needed for range-based for)
Definition json.hpp:5565
const iteration_proxy_value & operator*() const
dereference operator (needed for range-based for)
Definition json.hpp:5559
IteratorType::reference value() const
return value of the iterator
Definition json.hpp:5630
const string_type & key() const
return key of the iterator
Definition json.hpp:5594
proxy class for the items() function
Definition json.hpp:5638
iteration_proxy_value< IteratorType > end() const noexcept
return iterator end (needed for range-based for)
Definition json.hpp:5663
iteration_proxy_value< IteratorType > begin() const noexcept
return iterator begin (needed for range-based for)
Definition json.hpp:5657
iteration_proxy(typename IteratorType::reference cont) noexcept
construct iteration proxy from a container
Definition json.hpp:5647
Definition json.hpp:15611
json_reverse_iterator operator++(int) &
post-increment (it++)
Definition json.hpp:14476
json_reverse_iterator operator--(int) &
post-decrement (it–)
Definition json.hpp:14488
json_reverse_iterator & operator++()
pre-increment (++it)
Definition json.hpp:14482
json_reverse_iterator & operator+=(difference_type i)
add to iterator
Definition json.hpp:14500
reference operator[](difference_type n) const
access to successor
Definition json.hpp:14524
auto key() const -> decltype(std::declval< Base >().key())
return the key of an object iterator
Definition json.hpp:14530
difference_type operator-(const json_reverse_iterator &other) const
return difference
Definition json.hpp:14518
typename Base::reference reference
the reference type for the pointed-to element
Definition json.hpp:14466
reference value() const
return the value of an iterator
Definition json.hpp:14537
json_reverse_iterator(const base_iterator &it) noexcept
create reverse iterator from base class
Definition json.hpp:14473
json_reverse_iterator & operator--()
pre-decrement (–it)
Definition json.hpp:14494
std::reverse_iterator< Base > base_iterator
shortcut to the reverse iterator adapter
Definition json.hpp:14464
json_reverse_iterator operator-(difference_type i) const
subtract from iterator
Definition json.hpp:14512
json_reverse_iterator(const typename base_iterator::iterator_type &it) noexcept
create reverse iterator from iterator
Definition json.hpp:14469
json_reverse_iterator operator+(difference_type i) const
add to iterator
Definition json.hpp:14506
SAX implementation to create a JSON value from SAX events.
Definition json.hpp:8880
json_sax_dom_parser(BasicJsonType &r, const bool allow_exceptions_=true, lexer_t *lexer_=nullptr)
Definition json.hpp:8894
JSON_HEDLEY_RETURNS_NON_NULL static JSON_HEDLEY_CONST const char * token_type_name(const token_type t) noexcept
return name of values of type token_type (only used for errors)
Definition json.hpp:7147
token_type
token types for the parser
Definition json.hpp:7124
@ value_float
an floating point number – use get_number_float() for actual value
Definition json.hpp:7132
@ begin_array
the character for array begin [
Definition json.hpp:7133
@ value_string
a string – use get_string() for actual value
Definition json.hpp:7129
@ end_array
the character for array end ]
Definition json.hpp:7135
@ uninitialized
indicating the scanner is uninitialized
Definition json.hpp:7125
@ parse_error
indicating a parse error
Definition json.hpp:7139
@ value_integer
a signed integer – use get_number_integer() for actual value
Definition json.hpp:7131
@ value_separator
the value separator ,
Definition json.hpp:7138
@ end_object
the character for object end }
Definition json.hpp:7136
@ literal_true
the true literal
Definition json.hpp:7126
@ begin_object
the character for object begin {
Definition json.hpp:7134
@ value_unsigned
an unsigned integer – use get_number_unsigned() for actual value
Definition json.hpp:7130
@ literal_null
the null literal
Definition json.hpp:7128
@ end_of_input
indicating the end of the input buffer
Definition json.hpp:7140
@ name_separator
the name separator :
Definition json.hpp:7137
@ literal_or_value
a literal or the begin of a value (only for diagnostics)
Definition json.hpp:7141
@ literal_false
the false literal
Definition json.hpp:7127
lexical analysis
Definition json.hpp:7197
bool skip_bom()
skip the UTF-8 byte order mark
Definition json.hpp:8579
JSON_HEDLEY_RETURNS_NON_NULL constexpr const char * get_error_message() const noexcept
return syntax error message
Definition json.hpp:8566
std::string get_token_string() const
return the last read token (for errors only).
Definition json.hpp:8541
constexpr number_integer_t get_number_integer() const noexcept
return integer value
Definition json.hpp:8500
constexpr position_t get_position() const noexcept
return position of last read token
Definition json.hpp:8533
constexpr number_unsigned_t get_number_unsigned() const noexcept
return unsigned integer value
Definition json.hpp:8506
string_t & get_string()
return current string value (implicitly resets the token; useful only once)
Definition json.hpp:8518
constexpr number_float_t get_number_float() const noexcept
return floating-point value
Definition json.hpp:8512
exception indicating other library errors
Definition json.hpp:4777
exception indicating access out of the defined range
Definition json.hpp:4760
Definition json.hpp:15830
output adapter for output streams
Definition json.hpp:15782
output adapter for basic_string
Definition json.hpp:15807
output adapter for byte vectors
Definition json.hpp:15757
exception indicating a parse error
Definition json.hpp:4672
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:4684
const std::size_t byte
byte index of the parse error
Definition json.hpp:4709
void parse(const bool strict, BasicJsonType &result)
public parser interface
Definition json.hpp:13028
bool accept(const bool strict=true)
public accept interface
Definition json.hpp:13088
parser(InputAdapterType &&adapter, parser_callback_t< BasicJsonType > cb=nullptr, const bool allow_exceptions_=true, const bool ignore_comments=false, const bool ignore_trailing_commas_=false)
a parser reading from an input adapter
Definition json.hpp:13004
Definition json.hpp:13515
constexpr bool is_begin() const noexcept
return whether the iterator can be dereferenced
Definition json.hpp:13544
void set_end() noexcept
set iterator to a defined past the end
Definition json.hpp:13538
constexpr bool is_end() const noexcept
return whether the iterator is at end
Definition json.hpp:13550
void set_begin() noexcept
set iterator to a defined beginning
Definition json.hpp:13532
Definition json.hpp:18878
std::array< char, 512 > string_buffer
string buffer
Definition json.hpp:19802
serializer(output_adapter_t< char > s, const char ichar, error_handler_t error_handler_=error_handler_t::strict)
Definition json.hpp:18893
const char thousands_sep
the locale's thousand separator character
Definition json.hpp:19797
const char decimal_point
the locale's decimal point character
Definition json.hpp:19799
const error_handler_t error_handler
error_handler how to react on decoding errors
Definition json.hpp:19810
string_t indent_string
the indentation string
Definition json.hpp:19807
const std::lconv * loc
the locale
Definition json.hpp:19795
std::array< char, 64 > number_buffer
a (hopefully) large enough character buffer
Definition json.hpp:19792
const char indent_char
the indentation character
Definition json.hpp:19805
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:18933
exception indicating executing a member function with a wrong type
Definition json.hpp:4743
JSON Pointer defines a string syntax for identifying a specific value within a JSON document.
Definition json.hpp:14632
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:14727
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:14734
friend bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
compares two JSON pointers for equality
Definition json.hpp:15527
json_pointer(const string_t &s="")
create JSON pointer
Definition json.hpp:14658
bool empty() const noexcept
return whether pointer points to the root document
Definition json.hpp:14793
void pop_back()
remove last reference token
Definition json.hpp:14755
string_t to_string() const
return a string representation of the JSON pointer
Definition json.hpp:14664
json_pointer & operator/=(std::size_t array_idx)
append an array index at the end of this JSON pointer
Definition json.hpp:14712
void push_back(string_t &&token)
append an unescaped token at the end of the reference pointer
Definition json.hpp:14786
friend bool operator<(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
compares two JSON pointer for less-than
Definition json.hpp:15577
json_pointer & operator/=(const json_pointer &ptr)
append another JSON pointer at the end of this JSON pointer
Definition json.hpp:14694
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:14719
json_pointer parent_pointer() const
returns the parent of this JSON pointer
Definition json.hpp:14741
json_pointer & operator/=(string_t token)
append an unescaped reference token at the end of this JSON pointer
Definition json.hpp:14704
const string_t & back() const
return last reference token
Definition json.hpp:14767
friend bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
compares two JSON pointers for inequality
Definition json.hpp:15552
friend std::ostream & operator<<(std::ostream &o, const json_pointer &ptr)
write string representation of the JSON pointer to stream
Definition json.hpp:14685
void push_back(const string_t &token)
append an unescaped token at the end of the reference pointer
Definition json.hpp:14779
implements the Grisu2 algorithm for binary to decimal floating-point conversion.
Definition json.hpp:17770
int find_largest_pow10(const std::uint32_t n, std::uint32_t &pow10)
Definition json.hpp:18217
cached_power get_cached_power_for_binary_exponent(int e)
Definition json.hpp:18053
boundaries compute_boundaries(FloatType value)
Definition json.hpp:17914
void grisu2(char *buf, int &len, int &decimal_exponent, diyfp m_minus, diyfp v, diyfp m_plus)
Definition json.hpp:18553
void grisu2_digit_gen(char *buffer, int &length, int &decimal_exponent, diyfp M_minus, diyfp w, diyfp M_plus)
Definition json.hpp:18312
JSON_HEDLEY_RETURNS_NON_NULL char * append_exponent(char *buf, int e)
appends a decimal representation of e to buf
Definition json.hpp:18653
JSON_HEDLEY_RETURNS_NON_NULL char * format_buffer(char *buf, int len, int decimal_exponent, int min_exp, int max_exp)
prettify v = buf * 10^decimal_exponent
Definition json.hpp:18705
Definition json.hpp:17901
Definition json.hpp:18040
detail namespace with internal helper functions
Definition json.hpp:260
input_format_t
the supported input formats
Definition json.hpp:6546
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition json.hpp:13635
JSON_HEDLEY_RETURNS_NON_NULL char * to_chars(char *first, const char *last, FloatType value)
generates a decimal representation of the floating-point number value in [first, last).
Definition json.hpp:18790
parse_event_t
Definition json.hpp:12968
@ value
the parser finished reading a JSON value
Definition json.hpp:12980
@ key
the parser read a key of a value in an object
Definition json.hpp:12978
@ array_end
the parser read ] and finished processing a JSON array
Definition json.hpp:12976
@ array_start
the parser read [ and started to process a JSON array
Definition json.hpp:12974
@ object_start
the parser read { and started to process a JSON object
Definition json.hpp:12970
@ object_end
the parser read } and finished processing a JSON object
Definition json.hpp:12972
std::shared_ptr< output_adapter_protocol< CharType > > output_adapter_t
a type to simplify interfaces
Definition json.hpp:15752
void replace_substring(StringType &s, const StringType &f, const StringType &t)
replace all occurrences of a substring by another string
Definition json.hpp:3102
bool little_endianness(int num=1) noexcept
determine system byte order
Definition json.hpp:9894
cbor_tag_handler_t
how to treat CBOR tags
Definition json.hpp:9881
@ ignore
ignore tags
Definition json.hpp:9883
@ store
store tags as binary type
Definition json.hpp:9884
@ error
throw a parse_error exception in case of a tag
Definition json.hpp:9882
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition json.hpp:13637
value_t
the JSON type enumeration
Definition json.hpp:3004
@ null
null value
Definition json.hpp:3005
@ number_integer
number value (signed integer)
Definition json.hpp:3010
@ boolean
boolean value
Definition json.hpp:3009
@ discarded
discarded by the parser callback function
Definition json.hpp:3014
@ binary
binary array (ordered collection of bytes)
Definition json.hpp:3013
@ object
object (unordered set of name/value pairs)
Definition json.hpp:3006
@ string
string value
Definition json.hpp:3008
@ number_float
number value (floating-point)
Definition json.hpp:3012
@ number_unsigned
number value (unsigned integer)
Definition json.hpp:3011
@ array
array (ordered collection of values)
Definition json.hpp:3007
std::size_t hash(const BasicJsonType &j)
hash a JSON value
Definition json.hpp:6386
void unescape(StringType &s)
string unescaping as described in RFC 6901 (Sect. 4)
Definition json.hpp:3136
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
Definition json.hpp:3033
error_handler_t
how to treat decoding errors
Definition json.hpp:18870
@ strict
throw a type_error exception in case of invalid UTF-8
Definition json.hpp:18871
@ replace
replace invalid UTF-8 sequences with U+FFFD
Definition json.hpp:18872
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition json.hpp:13633
bjdata_version_t
how to encode BJData
Definition json.hpp:15865
StringType escape(StringType s)
string escaping as described in RFC 6901 (Sect. 4)
Definition json.hpp:3121
an iterator value
Definition json.hpp:13631
Default base class of the basic_json class.
Definition json.hpp:14579
namespace for Niels Lohmann
Definition json.hpp:6197
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:6221
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:6211
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:6201
Definition json.hpp:17783
static diyfp mul(const diyfp &x, const diyfp &y) noexcept
returns x * y
Definition json.hpp:17807
static diyfp normalize_to(const diyfp &x, const int target_exponent) noexcept
normalize x such that the result has the exponent E
Definition json.hpp:17889
static diyfp normalize(diyfp x) noexcept
normalize x such that the significand is >= 2^(q-1)
Definition json.hpp:17872
static diyfp sub(const diyfp &x, const diyfp &y) noexcept
returns x - y
Definition json.hpp:17795
struct to capture the start position of the current token
Definition json.hpp:3167
std::size_t chars_read_current_line
the number of characters read in the current line
Definition json.hpp:3171
std::size_t lines_read
the number of lines read
Definition json.hpp:3173
std::size_t chars_read_total
the total number of characters read
Definition json.hpp:3169
SAX interface.
Definition json.hpp:8745
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:19852
bool operator()(::nlohmann::detail::value_t lhs, ::nlohmann::detail::value_t rhs) const noexcept
compare two value_t enum values
Definition json.hpp:25464