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>
176#ifdef JSON_HAS_CPP_17
181#include <type_traits>
182#include <unordered_map>
245#include <type_traits>
261NLOHMANN_JSON_NAMESPACE_BEGIN
269template<
typename ...Ts>
using void_t =
typename make_void<Ts...>::type;
272NLOHMANN_JSON_NAMESPACE_END
275NLOHMANN_JSON_NAMESPACE_BEGIN
286 void operator=(
nonesuch const&) =
delete;
287 void operator=(
nonesuch&&) =
delete;
290template<
class Default,
292 template<
class...>
class Op,
296 using value_t = std::false_type;
297 using type = Default;
300template<
class Default,
template<
class...>
class Op,
class... Args>
301struct detector<Default, void_t<Op<Args...>>, Op, Args...>
303 using value_t = std::true_type;
304 using type = Op<Args...>;
307template<
template<
class...>
class Op,
class... Args>
310template<
template<
class...>
class Op,
class... Args>
313template<
template<
class...>
class Op,
class... Args>
316template<
class Default,
template<
class...>
class Op,
class... Args>
319template<
class Default,
template<
class...>
class Op,
class... Args>
320using detected_or_t =
typename detected_or<Default, Op, Args...>::type;
322template<
class Expected,
template<
class...>
class Op,
class... Args>
323using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
325template<
class To,
template<
class...>
class Op,
class... Args>
326using is_detected_convertible =
327 std::is_convertible<detected_t<Op, Args...>, To>;
330NLOHMANN_JSON_NAMESPACE_END
348#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15)
349#if defined(JSON_HEDLEY_VERSION)
350 #undef JSON_HEDLEY_VERSION
352#define JSON_HEDLEY_VERSION 15
354#if defined(JSON_HEDLEY_STRINGIFY_EX)
355 #undef JSON_HEDLEY_STRINGIFY_EX
357#define JSON_HEDLEY_STRINGIFY_EX(x) #x
359#if defined(JSON_HEDLEY_STRINGIFY)
360 #undef JSON_HEDLEY_STRINGIFY
362#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
364#if defined(JSON_HEDLEY_CONCAT_EX)
365 #undef JSON_HEDLEY_CONCAT_EX
367#define JSON_HEDLEY_CONCAT_EX(a,b) a##b
369#if defined(JSON_HEDLEY_CONCAT)
370 #undef JSON_HEDLEY_CONCAT
372#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
374#if defined(JSON_HEDLEY_CONCAT3_EX)
375 #undef JSON_HEDLEY_CONCAT3_EX
377#define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c
379#if defined(JSON_HEDLEY_CONCAT3)
380 #undef JSON_HEDLEY_CONCAT3
382#define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c)
384#if defined(JSON_HEDLEY_VERSION_ENCODE)
385 #undef JSON_HEDLEY_VERSION_ENCODE
387#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
389#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
390 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
392#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
394#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
395 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
397#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
399#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
400 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
402#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
404#if defined(JSON_HEDLEY_GNUC_VERSION)
405 #undef JSON_HEDLEY_GNUC_VERSION
407#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
408 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
409#elif defined(__GNUC__)
410 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
413#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
414 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
416#if defined(JSON_HEDLEY_GNUC_VERSION)
417 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
419 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
422#if defined(JSON_HEDLEY_MSVC_VERSION)
423 #undef JSON_HEDLEY_MSVC_VERSION
425#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL)
426 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
427#elif defined(_MSC_FULL_VER) && !defined(__ICL)
428 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
429#elif defined(_MSC_VER) && !defined(__ICL)
430 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
433#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
434 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
436#if !defined(JSON_HEDLEY_MSVC_VERSION)
437 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
438#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
439 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
440#elif defined(_MSC_VER) && (_MSC_VER >= 1200)
441 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
443 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))
446#if defined(JSON_HEDLEY_INTEL_VERSION)
447 #undef JSON_HEDLEY_INTEL_VERSION
449#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL)
450 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
451#elif defined(__INTEL_COMPILER) && !defined(__ICL)
452 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
455#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
456 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
458#if defined(JSON_HEDLEY_INTEL_VERSION)
459 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
461 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
464#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
465 #undef JSON_HEDLEY_INTEL_CL_VERSION
467#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL)
468 #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0)
471#if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK)
472 #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
474#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
475 #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
477 #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0)
480#if defined(JSON_HEDLEY_PGI_VERSION)
481 #undef JSON_HEDLEY_PGI_VERSION
483#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
484 #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
487#if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
488 #undef JSON_HEDLEY_PGI_VERSION_CHECK
490#if defined(JSON_HEDLEY_PGI_VERSION)
491 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
493 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
496#if defined(JSON_HEDLEY_SUNPRO_VERSION)
497 #undef JSON_HEDLEY_SUNPRO_VERSION
499#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
500 #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)
501#elif defined(__SUNPRO_C)
502 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
503#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
504 #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)
505#elif defined(__SUNPRO_CC)
506 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
509#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
510 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
512#if defined(JSON_HEDLEY_SUNPRO_VERSION)
513 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
515 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
518#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
519 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
521#if defined(__EMSCRIPTEN__)
522 #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
525#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
526 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
528#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
529 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
531 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
534#if defined(JSON_HEDLEY_ARM_VERSION)
535 #undef JSON_HEDLEY_ARM_VERSION
537#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
538 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)
539#elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
540 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
543#if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
544 #undef JSON_HEDLEY_ARM_VERSION_CHECK
546#if defined(JSON_HEDLEY_ARM_VERSION)
547 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
549 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
552#if defined(JSON_HEDLEY_IBM_VERSION)
553 #undef JSON_HEDLEY_IBM_VERSION
555#if defined(__ibmxl__)
556 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
557#elif defined(__xlC__) && defined(__xlC_ver__)
558 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
559#elif defined(__xlC__)
560 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
563#if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
564 #undef JSON_HEDLEY_IBM_VERSION_CHECK
566#if defined(JSON_HEDLEY_IBM_VERSION)
567 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
569 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
572#if defined(JSON_HEDLEY_TI_VERSION)
573 #undef JSON_HEDLEY_TI_VERSION
576 defined(__TI_COMPILER_VERSION__) && \
578 defined(__TMS470__) || defined(__TI_ARM__) || \
579 defined(__MSP430__) || \
580 defined(__TMS320C2000__) \
582#if (__TI_COMPILER_VERSION__ >= 16000000)
583 #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
587#if defined(JSON_HEDLEY_TI_VERSION_CHECK)
588 #undef JSON_HEDLEY_TI_VERSION_CHECK
590#if defined(JSON_HEDLEY_TI_VERSION)
591 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
593 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
596#if defined(JSON_HEDLEY_TI_CL2000_VERSION)
597 #undef JSON_HEDLEY_TI_CL2000_VERSION
599#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
600 #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
603#if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK)
604 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
606#if defined(JSON_HEDLEY_TI_CL2000_VERSION)
607 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
609 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0)
612#if defined(JSON_HEDLEY_TI_CL430_VERSION)
613 #undef JSON_HEDLEY_TI_CL430_VERSION
615#if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__)
616 #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
619#if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK)
620 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
622#if defined(JSON_HEDLEY_TI_CL430_VERSION)
623 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
625 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0)
628#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
629 #undef JSON_HEDLEY_TI_ARMCL_VERSION
631#if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__))
632 #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
635#if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK)
636 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
638#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
639 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
641 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0)
644#if defined(JSON_HEDLEY_TI_CL6X_VERSION)
645 #undef JSON_HEDLEY_TI_CL6X_VERSION
647#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__)
648 #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
651#if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK)
652 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
654#if defined(JSON_HEDLEY_TI_CL6X_VERSION)
655 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
657 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0)
660#if defined(JSON_HEDLEY_TI_CL7X_VERSION)
661 #undef JSON_HEDLEY_TI_CL7X_VERSION
663#if defined(__TI_COMPILER_VERSION__) && defined(__C7000__)
664 #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
667#if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK)
668 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
670#if defined(JSON_HEDLEY_TI_CL7X_VERSION)
671 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
673 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0)
676#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
677 #undef JSON_HEDLEY_TI_CLPRU_VERSION
679#if defined(__TI_COMPILER_VERSION__) && defined(__PRU__)
680 #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
683#if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK)
684 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
686#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
687 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
689 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0)
692#if defined(JSON_HEDLEY_CRAY_VERSION)
693 #undef JSON_HEDLEY_CRAY_VERSION
696 #if defined(_RELEASE_PATCHLEVEL)
697 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
699 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
703#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
704 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
706#if defined(JSON_HEDLEY_CRAY_VERSION)
707 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
709 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
712#if defined(JSON_HEDLEY_IAR_VERSION)
713 #undef JSON_HEDLEY_IAR_VERSION
715#if defined(__IAR_SYSTEMS_ICC__)
717 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
719 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0)
723#if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
724 #undef JSON_HEDLEY_IAR_VERSION_CHECK
726#if defined(JSON_HEDLEY_IAR_VERSION)
727 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
729 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
732#if defined(JSON_HEDLEY_TINYC_VERSION)
733 #undef JSON_HEDLEY_TINYC_VERSION
735#if defined(__TINYC__)
736 #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
739#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
740 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
742#if defined(JSON_HEDLEY_TINYC_VERSION)
743 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
745 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
748#if defined(JSON_HEDLEY_DMC_VERSION)
749 #undef JSON_HEDLEY_DMC_VERSION
752 #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
755#if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
756 #undef JSON_HEDLEY_DMC_VERSION_CHECK
758#if defined(JSON_HEDLEY_DMC_VERSION)
759 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
761 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
764#if defined(JSON_HEDLEY_COMPCERT_VERSION)
765 #undef JSON_HEDLEY_COMPCERT_VERSION
767#if defined(__COMPCERT_VERSION__)
768 #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)
771#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
772 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
774#if defined(JSON_HEDLEY_COMPCERT_VERSION)
775 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
777 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
780#if defined(JSON_HEDLEY_PELLES_VERSION)
781 #undef JSON_HEDLEY_PELLES_VERSION
784 #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
787#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
788 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
790#if defined(JSON_HEDLEY_PELLES_VERSION)
791 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
793 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
796#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
797 #undef JSON_HEDLEY_MCST_LCC_VERSION
799#if defined(__LCC__) && defined(__LCC_MINOR__)
800 #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__)
803#if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK)
804 #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
806#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
807 #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
809 #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0)
812#if defined(JSON_HEDLEY_GCC_VERSION)
813 #undef JSON_HEDLEY_GCC_VERSION
816 defined(JSON_HEDLEY_GNUC_VERSION) && \
817 !defined(__clang__) && \
818 !defined(JSON_HEDLEY_INTEL_VERSION) && \
819 !defined(JSON_HEDLEY_PGI_VERSION) && \
820 !defined(JSON_HEDLEY_ARM_VERSION) && \
821 !defined(JSON_HEDLEY_CRAY_VERSION) && \
822 !defined(JSON_HEDLEY_TI_VERSION) && \
823 !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \
824 !defined(JSON_HEDLEY_TI_CL430_VERSION) && \
825 !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \
826 !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \
827 !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \
828 !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \
829 !defined(__COMPCERT__) && \
830 !defined(JSON_HEDLEY_MCST_LCC_VERSION)
831 #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
834#if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
835 #undef JSON_HEDLEY_GCC_VERSION_CHECK
837#if defined(JSON_HEDLEY_GCC_VERSION)
838 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
840 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
843#if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
844 #undef JSON_HEDLEY_HAS_ATTRIBUTE
847 defined(__has_attribute) && \
849 (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \
851# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
853# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
856#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
857 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
859#if defined(__has_attribute)
860 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
862 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
865#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
866 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
868#if defined(__has_attribute)
869 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
871 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
874#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
875 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
878 defined(__has_cpp_attribute) && \
879 defined(__cplusplus) && \
880 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0))
881 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
883 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
886#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
887 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
889#if !defined(__cplusplus) || !defined(__has_cpp_attribute)
890 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
892 !defined(JSON_HEDLEY_PGI_VERSION) && \
893 !defined(JSON_HEDLEY_IAR_VERSION) && \
894 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \
895 (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0))
896 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)
898 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
901#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
902 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
904#if defined(__has_cpp_attribute) && defined(__cplusplus)
905 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
907 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
910#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
911 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
913#if defined(__has_cpp_attribute) && defined(__cplusplus)
914 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
916 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
919#if defined(JSON_HEDLEY_HAS_BUILTIN)
920 #undef JSON_HEDLEY_HAS_BUILTIN
922#if defined(__has_builtin)
923 #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
925 #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
928#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
929 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
931#if defined(__has_builtin)
932 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
934 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
937#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
938 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
940#if defined(__has_builtin)
941 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
943 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
946#if defined(JSON_HEDLEY_HAS_FEATURE)
947 #undef JSON_HEDLEY_HAS_FEATURE
949#if defined(__has_feature)
950 #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
952 #define JSON_HEDLEY_HAS_FEATURE(feature) (0)
955#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
956 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
958#if defined(__has_feature)
959 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
961 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
964#if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
965 #undef JSON_HEDLEY_GCC_HAS_FEATURE
967#if defined(__has_feature)
968 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
970 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
973#if defined(JSON_HEDLEY_HAS_EXTENSION)
974 #undef JSON_HEDLEY_HAS_EXTENSION
976#if defined(__has_extension)
977 #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
979 #define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
982#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
983 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
985#if defined(__has_extension)
986 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
988 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
991#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
992 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
994#if defined(__has_extension)
995 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
997 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
1000#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
1001 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
1003#if defined(__has_declspec_attribute)
1004 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
1006 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
1009#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
1010 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
1012#if defined(__has_declspec_attribute)
1013 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
1015 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
1018#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
1019 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
1021#if defined(__has_declspec_attribute)
1022 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
1024 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
1027#if defined(JSON_HEDLEY_HAS_WARNING)
1028 #undef JSON_HEDLEY_HAS_WARNING
1030#if defined(__has_warning)
1031 #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
1033 #define JSON_HEDLEY_HAS_WARNING(warning) (0)
1036#if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
1037 #undef JSON_HEDLEY_GNUC_HAS_WARNING
1039#if defined(__has_warning)
1040 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
1042 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
1045#if defined(JSON_HEDLEY_GCC_HAS_WARNING)
1046 #undef JSON_HEDLEY_GCC_HAS_WARNING
1048#if defined(__has_warning)
1049 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
1051 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
1055 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1056 defined(__clang__) || \
1057 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1058 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1059 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1060 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
1061 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1062 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1063 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1064 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1065 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1066 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \
1067 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1068 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1069 JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
1070 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
1071 JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
1072 (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
1073 #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
1074#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1075 #define JSON_HEDLEY_PRAGMA(value) __pragma(value)
1077 #define JSON_HEDLEY_PRAGMA(value)
1080#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
1081 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
1083#if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
1084 #undef JSON_HEDLEY_DIAGNOSTIC_POP
1086#if defined(__clang__)
1087 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
1088 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
1089#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1090 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
1091 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
1092#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1093 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
1094 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
1096 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
1097 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1098 #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
1099 #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
1100#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
1101 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
1102 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
1104 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1105 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1106 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \
1107 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1108 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1109 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1110 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
1111 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
1112#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
1113 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
1114 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
1116 #define JSON_HEDLEY_DIAGNOSTIC_PUSH
1117 #define JSON_HEDLEY_DIAGNOSTIC_POP
1122#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
1123 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
1125#if defined(__cplusplus)
1126# if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
1127# if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions")
1128# if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions")
1129# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1130 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1131 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1132 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
1133 _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \
1135 JSON_HEDLEY_DIAGNOSTIC_POP
1137# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1138 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1139 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1140 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
1142 JSON_HEDLEY_DIAGNOSTIC_POP
1145# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1146 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1147 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1149 JSON_HEDLEY_DIAGNOSTIC_POP
1153#if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
1154 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
1157#if defined(JSON_HEDLEY_CONST_CAST)
1158 #undef JSON_HEDLEY_CONST_CAST
1160#if defined(__cplusplus)
1161# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
1163 JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
1164 JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \
1165 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1166# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \
1167 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1168 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
1170 JSON_HEDLEY_DIAGNOSTIC_POP \
1173# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
1176#if defined(JSON_HEDLEY_REINTERPRET_CAST)
1177 #undef JSON_HEDLEY_REINTERPRET_CAST
1179#if defined(__cplusplus)
1180 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
1182 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr))
1185#if defined(JSON_HEDLEY_STATIC_CAST)
1186 #undef JSON_HEDLEY_STATIC_CAST
1188#if defined(__cplusplus)
1189 #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
1191 #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
1194#if defined(JSON_HEDLEY_CPP_CAST)
1195 #undef JSON_HEDLEY_CPP_CAST
1197#if defined(__cplusplus)
1198# if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
1199# define JSON_HEDLEY_CPP_CAST(T, expr) \
1200 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1201 _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \
1203 JSON_HEDLEY_DIAGNOSTIC_POP
1204# elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0)
1205# define JSON_HEDLEY_CPP_CAST(T, expr) \
1206 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1207 _Pragma("diag_suppress=Pe137") \
1208 JSON_HEDLEY_DIAGNOSTIC_POP
1210# define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr))
1213# define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
1216#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
1217 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1219#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
1220 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
1221#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1222 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
1223#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1224 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786))
1225#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1226 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445")
1227#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1228 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1229#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1230 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1231#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1232 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
1233#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1234 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1236 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1237 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1238 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1239 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1240 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1241 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1242 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1243 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1244 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1245 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1246 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1247 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
1248#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
1249 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
1250#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
1251 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
1252#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1253 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
1254#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
1255 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
1257 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1260#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
1261 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1263#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1264 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
1265#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1266 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
1267#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1268 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161))
1269#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1270 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
1271#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1272 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
1273#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1274 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))
1276 JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \
1277 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1278 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1279 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)
1280 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1281#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0)
1282 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1283#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1284 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
1285#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1286 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161")
1288 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1291#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
1292 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1294#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
1295 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"")
1296#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1297 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1298#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
1299 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
1300#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1301 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292))
1302#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
1303 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))
1304#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1305 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098")
1306#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1307 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1308#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
1309 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
1311 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1312 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1313 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0)
1314 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
1315#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1316 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097")
1317#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1318 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1320 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1323#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
1324 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1326#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
1327 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
1328#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1329 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
1330#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
1331 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
1333 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1336#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION)
1337 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1339#if JSON_HEDLEY_HAS_WARNING("-Wunused-function")
1340 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"")
1341#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0)
1342 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"")
1343#elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0)
1344 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505))
1345#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1346 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142")
1348 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1351#if defined(JSON_HEDLEY_DEPRECATED)
1352 #undef JSON_HEDLEY_DEPRECATED
1354#if defined(JSON_HEDLEY_DEPRECATED_FOR)
1355 #undef JSON_HEDLEY_DEPRECATED_FOR
1358 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1359 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1360 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
1361 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
1363 (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1364 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1365 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1366 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1367 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \
1368 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1369 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1370 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \
1371 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1372 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1373 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \
1374 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1375 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
1376 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
1377#elif defined(__cplusplus) && (__cplusplus >= 201402L)
1378 #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
1379 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
1381 JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
1382 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1383 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1384 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1385 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1386 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1387 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1388 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1389 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1390 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1391 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1392 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1393 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1394 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1395 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1396 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1397 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
1398 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
1400 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1401 JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \
1402 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1403 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
1404 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
1405#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1406 #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
1407 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
1409 #define JSON_HEDLEY_DEPRECATED(since)
1410 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
1413#if defined(JSON_HEDLEY_UNAVAILABLE)
1414 #undef JSON_HEDLEY_UNAVAILABLE
1417 JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
1418 JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
1419 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1420 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1421 #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
1423 #define JSON_HEDLEY_UNAVAILABLE(available_since)
1426#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT)
1427 #undef JSON_HEDLEY_WARN_UNUSED_RESULT
1429#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG)
1430 #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
1433 JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
1434 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1435 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1436 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1437 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1438 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1439 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1440 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1441 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1442 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1443 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1444 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1445 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1446 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1447 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1448 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1449 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1450 #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
1451 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__))
1452#elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)
1453 #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1454 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
1455#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
1456 #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1457 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1458#elif defined(_Check_return_)
1459 #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_
1460 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_
1462 #define JSON_HEDLEY_WARN_UNUSED_RESULT
1463 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg)
1466#if defined(JSON_HEDLEY_SENTINEL)
1467 #undef JSON_HEDLEY_SENTINEL
1470 JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
1471 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1472 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1473 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1474 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1475 #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
1477 #define JSON_HEDLEY_SENTINEL(position)
1480#if defined(JSON_HEDLEY_NO_RETURN)
1481 #undef JSON_HEDLEY_NO_RETURN
1483#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1484 #define JSON_HEDLEY_NO_RETURN __noreturn
1486 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1487 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1488 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1489#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
1490 #define JSON_HEDLEY_NO_RETURN _Noreturn
1491#elif defined(__cplusplus) && (__cplusplus >= 201103L)
1492 #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
1494 JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
1495 JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \
1496 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1497 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1498 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1499 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1500 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1501 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1502 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1503 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1504 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1505 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1506 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1507 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1508 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1509 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1510 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1511 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1512#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1513 #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
1515 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1516 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1517 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1518#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1519 #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
1520#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1521 #define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
1522#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1523 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1525 #define JSON_HEDLEY_NO_RETURN
1528#if defined(JSON_HEDLEY_NO_ESCAPE)
1529 #undef JSON_HEDLEY_NO_ESCAPE
1531#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
1532 #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
1534 #define JSON_HEDLEY_NO_ESCAPE
1537#if defined(JSON_HEDLEY_UNREACHABLE)
1538 #undef JSON_HEDLEY_UNREACHABLE
1540#if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
1541 #undef JSON_HEDLEY_UNREACHABLE_RETURN
1543#if defined(JSON_HEDLEY_ASSUME)
1544 #undef JSON_HEDLEY_ASSUME
1547 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1548 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1549 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1550 #define JSON_HEDLEY_ASSUME(expr) __assume(expr)
1551#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
1552 #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
1554 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1555 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1556 #if defined(__cplusplus)
1557 #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
1559 #define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
1563 (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
1564 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1565 JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \
1566 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1567 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \
1568 JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \
1569 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1570 #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
1571#elif defined(JSON_HEDLEY_ASSUME)
1572 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1574#if !defined(JSON_HEDLEY_ASSUME)
1575 #if defined(JSON_HEDLEY_UNREACHABLE)
1576 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1)))
1578 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr)
1581#if defined(JSON_HEDLEY_UNREACHABLE)
1583 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1584 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1585 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))
1587 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
1590 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value)
1592#if !defined(JSON_HEDLEY_UNREACHABLE)
1593 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1596JSON_HEDLEY_DIAGNOSTIC_PUSH
1597#if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
1598 #pragma clang diagnostic ignored "-Wpedantic"
1600#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
1601 #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
1603#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0)
1604 #if defined(__clang__)
1605 #pragma clang diagnostic ignored "-Wvariadic-macros"
1606 #elif defined(JSON_HEDLEY_GCC_VERSION)
1607 #pragma GCC diagnostic ignored "-Wvariadic-macros"
1610#if defined(JSON_HEDLEY_NON_NULL)
1611 #undef JSON_HEDLEY_NON_NULL
1614 JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
1615 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1616 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1617 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1618 #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
1620 #define JSON_HEDLEY_NON_NULL(...)
1622JSON_HEDLEY_DIAGNOSTIC_POP
1624#if defined(JSON_HEDLEY_PRINTF_FORMAT)
1625 #undef JSON_HEDLEY_PRINTF_FORMAT
1627#if 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__(ms_printf, string_idx, first_to_check)))
1629#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO)
1630 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
1632 JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
1633 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1634 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1635 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1636 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1637 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1638 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1639 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1640 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1641 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1642 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1643 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1644 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1645 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1646 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1647 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1648 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1649 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
1650#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
1651 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
1653 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
1656#if defined(JSON_HEDLEY_CONSTEXPR)
1657 #undef JSON_HEDLEY_CONSTEXPR
1659#if defined(__cplusplus)
1660 #if __cplusplus >= 201103L
1661 #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)
1664#if !defined(JSON_HEDLEY_CONSTEXPR)
1665 #define JSON_HEDLEY_CONSTEXPR
1668#if defined(JSON_HEDLEY_PREDICT)
1669 #undef JSON_HEDLEY_PREDICT
1671#if defined(JSON_HEDLEY_LIKELY)
1672 #undef JSON_HEDLEY_LIKELY
1674#if defined(JSON_HEDLEY_UNLIKELY)
1675 #undef JSON_HEDLEY_UNLIKELY
1677#if defined(JSON_HEDLEY_UNPREDICTABLE)
1678 #undef JSON_HEDLEY_UNPREDICTABLE
1680#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
1681 #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
1684 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
1685 JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \
1686 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1687# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability))
1688# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability))
1689# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability))
1690# define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 )
1691# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 )
1693 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
1694 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1695 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1696 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1697 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1698 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1699 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1700 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1701 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1702 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1703 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1704 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1705 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1706 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \
1707 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1708 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1709# define JSON_HEDLEY_PREDICT(expr, expected, probability) \
1710 (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))
1711# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
1713 double hedley_probability_ = (probability); \
1714 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
1716# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
1718 double hedley_probability_ = (probability); \
1719 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
1721# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1722# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1724# define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))
1725# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
1726# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
1727# define JSON_HEDLEY_LIKELY(expr) (!!(expr))
1728# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
1730#if !defined(JSON_HEDLEY_UNPREDICTABLE)
1731 #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
1734#if defined(JSON_HEDLEY_MALLOC)
1735 #undef JSON_HEDLEY_MALLOC
1738 JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
1739 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1740 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1741 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1742 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1743 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1744 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1745 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1746 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1747 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1748 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1749 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1750 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1751 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1752 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1753 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1754 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1755 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1756 #define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
1757#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1758 #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
1760 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1761 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1762 #define JSON_HEDLEY_MALLOC __declspec(restrict)
1764 #define JSON_HEDLEY_MALLOC
1767#if defined(JSON_HEDLEY_PURE)
1768 #undef JSON_HEDLEY_PURE
1771 JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
1772 JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \
1773 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1774 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1775 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1776 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1777 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1778 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1779 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1780 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1781 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1782 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1783 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1784 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1785 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1786 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1787 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1788 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1789 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1790# define JSON_HEDLEY_PURE __attribute__((__pure__))
1791#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1792# define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
1793#elif defined(__cplusplus) && \
1795 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1796 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \
1797 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \
1799# define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
1801# define JSON_HEDLEY_PURE
1804#if defined(JSON_HEDLEY_CONST)
1805 #undef JSON_HEDLEY_CONST
1808 JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
1809 JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \
1810 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1811 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1812 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1813 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1814 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1815 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1816 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1817 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1818 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1819 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1820 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1821 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1822 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1823 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1824 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1825 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1826 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1827 #define JSON_HEDLEY_CONST __attribute__((__const__))
1829 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1830 #define JSON_HEDLEY_CONST _Pragma("no_side_effect")
1832 #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
1835#if defined(JSON_HEDLEY_RESTRICT)
1836 #undef JSON_HEDLEY_RESTRICT
1838#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
1839 #define JSON_HEDLEY_RESTRICT restrict
1841 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1842 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1843 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1844 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1845 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1846 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1847 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1848 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1849 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \
1850 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1851 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1852 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
1853 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1854 defined(__clang__) || \
1855 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1856 #define JSON_HEDLEY_RESTRICT __restrict
1857#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
1858 #define JSON_HEDLEY_RESTRICT _Restrict
1860 #define JSON_HEDLEY_RESTRICT
1863#if defined(JSON_HEDLEY_INLINE)
1864 #undef JSON_HEDLEY_INLINE
1867 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1868 (defined(__cplusplus) && (__cplusplus >= 199711L))
1869 #define JSON_HEDLEY_INLINE inline
1871 defined(JSON_HEDLEY_GCC_VERSION) || \
1872 JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
1873 #define JSON_HEDLEY_INLINE __inline__
1875 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1876 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1877 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1878 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \
1879 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1880 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1881 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1882 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1883 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1884 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1885 #define JSON_HEDLEY_INLINE __inline
1887 #define JSON_HEDLEY_INLINE
1890#if defined(JSON_HEDLEY_ALWAYS_INLINE)
1891 #undef JSON_HEDLEY_ALWAYS_INLINE
1894 JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
1895 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1896 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1897 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1898 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1899 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1900 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1901 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1902 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1903 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1904 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1905 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1906 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1907 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1908 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1909 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1910 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1911 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1912 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1913# define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
1915 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1916 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1917# define JSON_HEDLEY_ALWAYS_INLINE __forceinline
1918#elif defined(__cplusplus) && \
1920 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1921 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1922 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1923 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1924 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1925 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \
1927# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
1928#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1929# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
1931# define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
1934#if defined(JSON_HEDLEY_NEVER_INLINE)
1935 #undef JSON_HEDLEY_NEVER_INLINE
1938 JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
1939 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1940 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1941 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1942 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1943 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1944 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1945 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1946 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1947 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1948 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1949 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1950 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1951 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1952 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1953 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1954 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1955 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1956 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1957 #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
1959 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1960 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1961 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1962#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
1963 #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
1964#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1965 #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
1966#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1967 #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
1968#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1969 #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
1970#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1971 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1973 #define JSON_HEDLEY_NEVER_INLINE
1976#if defined(JSON_HEDLEY_PRIVATE)
1977 #undef JSON_HEDLEY_PRIVATE
1979#if defined(JSON_HEDLEY_PUBLIC)
1980 #undef JSON_HEDLEY_PUBLIC
1982#if defined(JSON_HEDLEY_IMPORT)
1983 #undef JSON_HEDLEY_IMPORT
1985#if defined(_WIN32) || defined(__CYGWIN__)
1986# define JSON_HEDLEY_PRIVATE
1987# define JSON_HEDLEY_PUBLIC __declspec(dllexport)
1988# define JSON_HEDLEY_IMPORT __declspec(dllimport)
1991 JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
1992 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1993 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1994 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1995 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1996 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1998 defined(__TI_EABI__) && \
2000 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
2001 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \
2004 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2005# define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
2006# define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
2008# define JSON_HEDLEY_PRIVATE
2009# define JSON_HEDLEY_PUBLIC
2011# define JSON_HEDLEY_IMPORT extern
2014#if defined(JSON_HEDLEY_NO_THROW)
2015 #undef JSON_HEDLEY_NO_THROW
2018 JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
2019 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
2020 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2021 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2022 #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
2024 JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
2025 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
2026 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
2027 #define JSON_HEDLEY_NO_THROW __declspec(nothrow)
2029 #define JSON_HEDLEY_NO_THROW
2032#if defined(JSON_HEDLEY_FALL_THROUGH)
2033 #undef JSON_HEDLEY_FALL_THROUGH
2036 JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
2037 JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \
2038 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2039 #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
2040#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
2041 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
2042#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
2043 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])
2044#elif defined(__fallthrough)
2045 #define JSON_HEDLEY_FALL_THROUGH __fallthrough
2047 #define JSON_HEDLEY_FALL_THROUGH
2050#if defined(JSON_HEDLEY_RETURNS_NON_NULL)
2051 #undef JSON_HEDLEY_RETURNS_NON_NULL
2054 JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
2055 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
2056 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2057 #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__))
2058#elif defined(_Ret_notnull_)
2059 #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_
2061 #define JSON_HEDLEY_RETURNS_NON_NULL
2064#if defined(JSON_HEDLEY_ARRAY_PARAM)
2065 #undef JSON_HEDLEY_ARRAY_PARAM
2068 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
2069 !defined(__STDC_NO_VLA__) && \
2070 !defined(__cplusplus) && \
2071 !defined(JSON_HEDLEY_PGI_VERSION) && \
2072 !defined(JSON_HEDLEY_TINYC_VERSION)
2073 #define JSON_HEDLEY_ARRAY_PARAM(name) (name)
2075 #define JSON_HEDLEY_ARRAY_PARAM(name)
2078#if defined(JSON_HEDLEY_IS_CONSTANT)
2079 #undef JSON_HEDLEY_IS_CONSTANT
2081#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
2082 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
2086#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
2087 #undef JSON_HEDLEY_IS_CONSTEXPR_
2090 JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
2091 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
2092 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2093 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
2094 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
2095 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
2096 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
2097 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
2098 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
2099 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2100 #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
2102#if !defined(__cplusplus)
2104 JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
2105 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
2106 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2107 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
2108 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
2109 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
2110 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
2111#if defined(__INTPTR_TYPE__)
2112 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
2115 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
2119 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
2120 !defined(JSON_HEDLEY_SUNPRO_VERSION) && \
2121 !defined(JSON_HEDLEY_PGI_VERSION) && \
2122 !defined(JSON_HEDLEY_IAR_VERSION)) || \
2123 (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
2124 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
2125 JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
2126 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
2127 JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
2128#if defined(__INTPTR_TYPE__)
2129 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
2132 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)
2135 defined(JSON_HEDLEY_GCC_VERSION) || \
2136 defined(JSON_HEDLEY_INTEL_VERSION) || \
2137 defined(JSON_HEDLEY_TINYC_VERSION) || \
2138 defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
2139 JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \
2140 defined(JSON_HEDLEY_TI_CL2000_VERSION) || \
2141 defined(JSON_HEDLEY_TI_CL6X_VERSION) || \
2142 defined(JSON_HEDLEY_TI_CL7X_VERSION) || \
2143 defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \
2145# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
2149 ((void*) ((expr) * 0L) ) : \
2150((struct { char v[sizeof(void) * 2]; } *) 1) \
2156#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
2157 #if !defined(JSON_HEDLEY_IS_CONSTANT)
2158 #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
2160 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))
2162 #if !defined(JSON_HEDLEY_IS_CONSTANT)
2163 #define JSON_HEDLEY_IS_CONSTANT(expr) (0)
2165 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
2168#if defined(JSON_HEDLEY_BEGIN_C_DECLS)
2169 #undef JSON_HEDLEY_BEGIN_C_DECLS
2171#if defined(JSON_HEDLEY_END_C_DECLS)
2172 #undef JSON_HEDLEY_END_C_DECLS
2174#if defined(JSON_HEDLEY_C_DECL)
2175 #undef JSON_HEDLEY_C_DECL
2177#if defined(__cplusplus)
2178 #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
2179 #define JSON_HEDLEY_END_C_DECLS }
2180 #define JSON_HEDLEY_C_DECL extern "C"
2182 #define JSON_HEDLEY_BEGIN_C_DECLS
2183 #define JSON_HEDLEY_END_C_DECLS
2184 #define JSON_HEDLEY_C_DECL
2187#if defined(JSON_HEDLEY_STATIC_ASSERT)
2188 #undef JSON_HEDLEY_STATIC_ASSERT
2191 !defined(__cplusplus) && ( \
2192 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
2193 (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
2194 JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
2195 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2196 defined(_Static_assert) \
2198# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
2200 (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
2201 JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \
2202 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2203# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
2205# define JSON_HEDLEY_STATIC_ASSERT(expr, message)
2208#if defined(JSON_HEDLEY_NULL)
2209 #undef JSON_HEDLEY_NULL
2211#if defined(__cplusplus)
2212 #if __cplusplus >= 201103L
2213 #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)
2215 #define JSON_HEDLEY_NULL NULL
2217 #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
2220 #define JSON_HEDLEY_NULL NULL
2222 #define JSON_HEDLEY_NULL ((void*) 0)
2225#if defined(JSON_HEDLEY_MESSAGE)
2226 #undef JSON_HEDLEY_MESSAGE
2228#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2229# define JSON_HEDLEY_MESSAGE(msg) \
2230 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2231 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2232 JSON_HEDLEY_PRAGMA(message msg) \
2233 JSON_HEDLEY_DIAGNOSTIC_POP
2235 JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
2236 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2237# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
2238#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
2239# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
2240#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
2241# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2242#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
2243# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2245# define JSON_HEDLEY_MESSAGE(msg)
2248#if defined(JSON_HEDLEY_WARNING)
2249 #undef JSON_HEDLEY_WARNING
2251#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2252# define JSON_HEDLEY_WARNING(msg) \
2253 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2254 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2255 JSON_HEDLEY_PRAGMA(clang warning msg) \
2256 JSON_HEDLEY_DIAGNOSTIC_POP
2258 JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
2259 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
2260 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2261# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
2263 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
2264 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2265# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
2267# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
2270#if defined(JSON_HEDLEY_REQUIRE)
2271 #undef JSON_HEDLEY_REQUIRE
2273#if defined(JSON_HEDLEY_REQUIRE_MSG)
2274 #undef JSON_HEDLEY_REQUIRE_MSG
2276#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
2277# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
2278# define JSON_HEDLEY_REQUIRE(expr) \
2279 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2280 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2281 __attribute__((diagnose_if(!(expr), #expr, "error"))) \
2282 JSON_HEDLEY_DIAGNOSTIC_POP
2283# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \
2284 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2285 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2286 __attribute__((diagnose_if(!(expr), msg, "error"))) \
2287 JSON_HEDLEY_DIAGNOSTIC_POP
2289# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error")))
2290# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error")))
2293# define JSON_HEDLEY_REQUIRE(expr)
2294# define JSON_HEDLEY_REQUIRE_MSG(expr,msg)
2297#if defined(JSON_HEDLEY_FLAGS)
2298 #undef JSON_HEDLEY_FLAGS
2300#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion"))
2301 #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
2303 #define JSON_HEDLEY_FLAGS
2306#if defined(JSON_HEDLEY_FLAGS_CAST)
2307 #undef JSON_HEDLEY_FLAGS_CAST
2309#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)
2310# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \
2311 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2312 _Pragma("warning(disable:188)") \
2314 JSON_HEDLEY_DIAGNOSTIC_POP \
2317# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
2320#if defined(JSON_HEDLEY_EMPTY_BASES)
2321 #undef JSON_HEDLEY_EMPTY_BASES
2324 (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \
2325 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2326 #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
2328 #define JSON_HEDLEY_EMPTY_BASES
2333#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
2334 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
2336#if defined(__clang__)
2337 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
2339 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
2342#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
2343 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
2345#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
2347#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
2348 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
2350#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
2352#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
2353 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
2355#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
2357#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
2358 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
2360#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
2362#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
2363 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
2365#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
2367#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
2368 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
2370#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
2372#if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
2373 #undef JSON_HEDLEY_CLANG_HAS_WARNING
2375#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
2387#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
2388 #if defined(__clang__)
2389 #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
2390 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
2392 #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
2393 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
2394 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
2401#if !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)
2402 #if (defined(__cplusplus) && __cplusplus > 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG > 202002L)
2403 #define JSON_HAS_CPP_23
2404 #define JSON_HAS_CPP_20
2405 #define JSON_HAS_CPP_17
2406 #define JSON_HAS_CPP_14
2407 #elif (defined(__cplusplus) && __cplusplus > 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG > 201703L)
2408 #define JSON_HAS_CPP_20
2409 #define JSON_HAS_CPP_17
2410 #define JSON_HAS_CPP_14
2411 #elif (defined(__cplusplus) && __cplusplus > 201402L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1)
2412 #define JSON_HAS_CPP_17
2413 #define JSON_HAS_CPP_14
2414 #elif (defined(__cplusplus) && __cplusplus > 201103L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
2415 #define JSON_HAS_CPP_14
2418 #define JSON_HAS_CPP_11
2422 #if __has_include(<version>)
2427#if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM)
2428 #ifdef JSON_HAS_CPP_17
2429 #if defined(__cpp_lib_filesystem)
2430 #define JSON_HAS_FILESYSTEM 1
2431 #elif defined(__cpp_lib_experimental_filesystem)
2432 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2433 #elif !defined(__has_include)
2434 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2435 #elif __has_include(<filesystem>)
2436 #define JSON_HAS_FILESYSTEM 1
2437 #elif __has_include(<experimental/filesystem>)
2438 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2442 #if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8
2443 #undef JSON_HAS_FILESYSTEM
2444 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2448 #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 8
2449 #undef JSON_HAS_FILESYSTEM
2450 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2454 #if defined(__clang_major__) && __clang_major__ < 7
2455 #undef JSON_HAS_FILESYSTEM
2456 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2460 #if defined(_MSC_VER) && _MSC_VER < 1914
2461 #undef JSON_HAS_FILESYSTEM
2462 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2466 #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000
2467 #undef JSON_HAS_FILESYSTEM
2468 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2472 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
2473 #undef JSON_HAS_FILESYSTEM
2474 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2479#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2480 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0
2483#ifndef JSON_HAS_FILESYSTEM
2484 #define JSON_HAS_FILESYSTEM 0
2487#ifndef JSON_HAS_THREE_WAY_COMPARISON
2488 #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L \
2489 && defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L
2490 #define JSON_HAS_THREE_WAY_COMPARISON 1
2492 #define JSON_HAS_THREE_WAY_COMPARISON 0
2496#ifndef JSON_HAS_RANGES
2498 #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427
2499 #define JSON_HAS_RANGES 0
2500 #elif defined(__cpp_lib_ranges)
2501 #define JSON_HAS_RANGES 1
2503 #define JSON_HAS_RANGES 0
2507#ifndef JSON_HAS_STATIC_RTTI
2508 #if !defined(_HAS_STATIC_RTTI) || _HAS_STATIC_RTTI != 0
2509 #define JSON_HAS_STATIC_RTTI 1
2511 #define JSON_HAS_STATIC_RTTI 0
2515#ifdef JSON_HAS_CPP_17
2516 #define JSON_INLINE_VARIABLE inline
2518 #define JSON_INLINE_VARIABLE
2521#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address)
2522 #define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]]
2524 #define JSON_NO_UNIQUE_ADDRESS
2528#if defined(__clang__)
2529 #pragma clang diagnostic push
2530 #pragma clang diagnostic ignored "-Wdocumentation"
2531 #pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
2535#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
2536 #define JSON_THROW(exception) throw exception
2537 #define JSON_TRY try
2538 #define JSON_CATCH(exception) catch(exception)
2539 #define JSON_INTERNAL_CATCH(exception) catch(exception)
2542 #define JSON_THROW(exception) std::abort()
2543 #define JSON_TRY if(true)
2544 #define JSON_CATCH(exception) if(false)
2545 #define JSON_INTERNAL_CATCH(exception) if(false)
2549#if defined(JSON_THROW_USER)
2551 #define JSON_THROW JSON_THROW_USER
2553#if defined(JSON_TRY_USER)
2555 #define JSON_TRY JSON_TRY_USER
2557#if defined(JSON_CATCH_USER)
2559 #define JSON_CATCH JSON_CATCH_USER
2560 #undef JSON_INTERNAL_CATCH
2561 #define JSON_INTERNAL_CATCH JSON_CATCH_USER
2563#if defined(JSON_INTERNAL_CATCH_USER)
2564 #undef JSON_INTERNAL_CATCH
2565 #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2569#if !defined(JSON_ASSERT)
2571 #define JSON_ASSERT(x) assert(x)
2575#if defined(JSON_TESTS_PRIVATE)
2576 #define JSON_PRIVATE_UNLESS_TESTED public
2578 #define JSON_PRIVATE_UNLESS_TESTED private
2586#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2587 template<typename BasicJsonType> \
2588 inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
2591 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2593 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2594 auto it = std::find_if(std::begin(m), std::end(m), \
2595 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2597 return ej_pair.first == e; \
2599 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2601 template<typename BasicJsonType> \
2602 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
2605 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2607 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2608 auto it = std::find_if(std::begin(m), std::end(m), \
2609 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2611 return ej_pair.second == j; \
2613 e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2619#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2620 template<template<typename, typename, typename...> class ObjectType, \
2621 template<typename, typename...> class ArrayType, \
2622 class StringType, class BooleanType, class NumberIntegerType, \
2623 class NumberUnsignedType, class NumberFloatType, \
2624 template<typename> class AllocatorType, \
2625 template<typename, typename = void> class JSONSerializer, \
2627 class CustomBaseClass>
2629#define NLOHMANN_BASIC_JSON_TPL \
2630 basic_json<ObjectType, ArrayType, StringType, BooleanType, \
2631 NumberIntegerType, NumberUnsignedType, NumberFloatType, \
2632 AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>
2636#define NLOHMANN_JSON_EXPAND( x ) x
2637#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
2638#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
2639 NLOHMANN_JSON_PASTE64, \
2640 NLOHMANN_JSON_PASTE63, \
2641 NLOHMANN_JSON_PASTE62, \
2642 NLOHMANN_JSON_PASTE61, \
2643 NLOHMANN_JSON_PASTE60, \
2644 NLOHMANN_JSON_PASTE59, \
2645 NLOHMANN_JSON_PASTE58, \
2646 NLOHMANN_JSON_PASTE57, \
2647 NLOHMANN_JSON_PASTE56, \
2648 NLOHMANN_JSON_PASTE55, \
2649 NLOHMANN_JSON_PASTE54, \
2650 NLOHMANN_JSON_PASTE53, \
2651 NLOHMANN_JSON_PASTE52, \
2652 NLOHMANN_JSON_PASTE51, \
2653 NLOHMANN_JSON_PASTE50, \
2654 NLOHMANN_JSON_PASTE49, \
2655 NLOHMANN_JSON_PASTE48, \
2656 NLOHMANN_JSON_PASTE47, \
2657 NLOHMANN_JSON_PASTE46, \
2658 NLOHMANN_JSON_PASTE45, \
2659 NLOHMANN_JSON_PASTE44, \
2660 NLOHMANN_JSON_PASTE43, \
2661 NLOHMANN_JSON_PASTE42, \
2662 NLOHMANN_JSON_PASTE41, \
2663 NLOHMANN_JSON_PASTE40, \
2664 NLOHMANN_JSON_PASTE39, \
2665 NLOHMANN_JSON_PASTE38, \
2666 NLOHMANN_JSON_PASTE37, \
2667 NLOHMANN_JSON_PASTE36, \
2668 NLOHMANN_JSON_PASTE35, \
2669 NLOHMANN_JSON_PASTE34, \
2670 NLOHMANN_JSON_PASTE33, \
2671 NLOHMANN_JSON_PASTE32, \
2672 NLOHMANN_JSON_PASTE31, \
2673 NLOHMANN_JSON_PASTE30, \
2674 NLOHMANN_JSON_PASTE29, \
2675 NLOHMANN_JSON_PASTE28, \
2676 NLOHMANN_JSON_PASTE27, \
2677 NLOHMANN_JSON_PASTE26, \
2678 NLOHMANN_JSON_PASTE25, \
2679 NLOHMANN_JSON_PASTE24, \
2680 NLOHMANN_JSON_PASTE23, \
2681 NLOHMANN_JSON_PASTE22, \
2682 NLOHMANN_JSON_PASTE21, \
2683 NLOHMANN_JSON_PASTE20, \
2684 NLOHMANN_JSON_PASTE19, \
2685 NLOHMANN_JSON_PASTE18, \
2686 NLOHMANN_JSON_PASTE17, \
2687 NLOHMANN_JSON_PASTE16, \
2688 NLOHMANN_JSON_PASTE15, \
2689 NLOHMANN_JSON_PASTE14, \
2690 NLOHMANN_JSON_PASTE13, \
2691 NLOHMANN_JSON_PASTE12, \
2692 NLOHMANN_JSON_PASTE11, \
2693 NLOHMANN_JSON_PASTE10, \
2694 NLOHMANN_JSON_PASTE9, \
2695 NLOHMANN_JSON_PASTE8, \
2696 NLOHMANN_JSON_PASTE7, \
2697 NLOHMANN_JSON_PASTE6, \
2698 NLOHMANN_JSON_PASTE5, \
2699 NLOHMANN_JSON_PASTE4, \
2700 NLOHMANN_JSON_PASTE3, \
2701 NLOHMANN_JSON_PASTE2, \
2702 NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
2703#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
2704#define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
2705#define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
2706#define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
2707#define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
2708#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)
2709#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)
2710#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)
2711#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)
2712#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)
2713#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)
2714#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)
2715#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)
2716#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)
2717#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)
2718#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)
2719#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)
2720#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)
2721#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)
2722#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)
2723#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)
2724#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)
2725#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)
2726#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)
2727#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)
2728#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)
2729#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)
2730#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)
2731#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)
2732#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)
2733#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)
2734#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)
2735#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)
2736#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)
2737#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)
2738#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)
2739#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)
2740#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)
2741#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)
2742#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)
2743#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)
2744#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)
2745#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)
2746#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)
2747#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)
2748#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)
2749#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)
2750#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)
2751#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)
2752#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)
2753#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)
2754#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)
2755#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)
2756#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)
2757#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)
2758#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)
2759#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)
2760#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)
2761#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)
2762#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)
2763#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)
2764#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)
2765#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)
2767#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2768#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2769#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;
2777#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
2778 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2779 friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2780 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2781 friend void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2789#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \
2790 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2791 friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2792 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2793 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__)) }
2801#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \
2802 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2803 friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) }
2811#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
2812 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2813 void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2814 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2815 void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2823#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \
2824 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2825 void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2826 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2827 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__)) }
2835#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \
2836 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2837 void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) }
2845#define NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE(Type, BaseType, ...) \
2846 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2847 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__)) } \
2848 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2849 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__)) }
2857#define NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT(Type, BaseType, ...) \
2858 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2859 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__)) } \
2860 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2861 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__)) }
2869#define NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, BaseType, ...) \
2870 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2871 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__)) }
2879#define NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE(Type, BaseType, ...) \
2880 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2881 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__)) } \
2882 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2883 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__)) }
2891#define NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, BaseType, ...) \
2892 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2893 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__)) } \
2894 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2895 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__)) }
2903#define NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, BaseType, ...) \
2904 template<typename BasicJsonType, nlohmann::detail::enable_if_t<nlohmann::detail::is_basic_json<BasicJsonType>::value, int> = 0> \
2905 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__)) }
2913#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \
2914 namespace detail { \
2915 using std::std_name; \
2917 template<typename... T> \
2918 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2921 namespace detail2 { \
2922 struct std_name##_tag \
2926 template<typename... T> \
2927 std_name##_tag std_name(T&&...); \
2929 template<typename... T> \
2930 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2932 template<typename... T> \
2933 struct would_call_std_##std_name \
2935 static constexpr auto const value = ::nlohmann::detail:: \
2936 is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \
2940 template<typename... T> \
2941 struct would_call_std_##std_name : detail2::would_call_std_##std_name<T...> \
2945#ifndef JSON_USE_IMPLICIT_CONVERSIONS
2946 #define JSON_USE_IMPLICIT_CONVERSIONS 1
2949#if JSON_USE_IMPLICIT_CONVERSIONS
2950 #define JSON_EXPLICIT
2952 #define JSON_EXPLICIT explicit
2955#ifndef JSON_DISABLE_ENUM_SERIALIZATION
2956 #define JSON_DISABLE_ENUM_SERIALIZATION 0
2959#ifndef JSON_USE_GLOBAL_UDLS
2960 #define JSON_USE_GLOBAL_UDLS 1
2963#if JSON_HAS_THREE_WAY_COMPARISON
2967NLOHMANN_JSON_NAMESPACE_BEGIN
3026#if JSON_HAS_THREE_WAY_COMPARISON
3027 inline std::partial_ordering operator<=>(
const value_t lhs,
const value_t rhs)
noexcept
3032 static constexpr std::array<std::uint8_t, 9> order = {{
3039 const auto l_index =
static_cast<std::size_t
>(lhs);
3040 const auto r_index =
static_cast<std::size_t
>(rhs);
3041#if JSON_HAS_THREE_WAY_COMPARISON
3042 if (l_index < order.size() && r_index < order.size())
3044 return order[l_index] <=> order[r_index];
3046 return std::partial_ordering::unordered;
3048 return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
3056#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__)
3059 return std::is_lt(lhs <=> rhs);
3064NLOHMANN_JSON_NAMESPACE_END
3080NLOHMANN_JSON_NAMESPACE_BEGIN
3097template<
typename StringType>
3099 const StringType& t)
3101 JSON_ASSERT(!f.empty());
3102 for (
auto pos = s.find(f);
3103 pos != StringType::npos;
3104 s.replace(pos, f.size(), t),
3105 pos = s.find(f, pos + t.size()))
3116template<
typename StringType>
3117inline StringType
escape(StringType s)
3131template<
typename StringType>
3132static void unescape(StringType& s)
3139NLOHMANN_JSON_NAMESPACE_END
3157NLOHMANN_JSON_NAMESPACE_BEGIN
3172 constexpr operator size_t()
const
3179NLOHMANN_JSON_NAMESPACE_END
3197#include <type_traits>
3203NLOHMANN_JSON_NAMESPACE_BEGIN
3208using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
3210#ifdef JSON_HAS_CPP_14
3213using std::enable_if_t;
3214using std::index_sequence;
3215using std::make_index_sequence;
3216using std::index_sequence_for;
3221template<
bool B,
typename T =
void>
3222using enable_if_t =
typename std::enable_if<B, T>::type;
3248template <
typename T, T... Ints>
3251 using value_type = T;
3252 static constexpr std::size_t size()
noexcept
3254 return sizeof...(Ints);
3263template <
size_t... Ints>
3266namespace utility_internal
3269template <
typename Seq,
size_t SeqSize,
size_t Rem>
3273template <
typename T, T... Ints,
size_t SeqSize>
3279template <
typename T, T... Ints,
size_t SeqSize>
3287template <
typename T,
size_t N>
3291 typename Extend <
typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
3294template <
typename T>
3309template <
typename T, T N>
3310using make_integer_sequence =
typename utility_internal::Gen<T, N>::type;
3318using make_index_sequence = make_integer_sequence<size_t, N>;
3325template <
typename... Ts>
3326using index_sequence_for = make_index_sequence<
sizeof...(Ts)>;
3340 static JSON_INLINE_VARIABLE
constexpr T value{};
3343#ifndef JSON_HAS_CPP_17
3344 template<
typename T>
3348template<
typename T,
typename... Args>
3349constexpr std::array<T,
sizeof...(Args)> make_array(Args&& ... args)
3351 return std::array<T,
sizeof...(Args)> {{
static_cast<T
>(std::forward<Args>(args))...}};
3355NLOHMANN_JSON_NAMESPACE_END
3371#include <type_traits>
3394NLOHMANN_JSON_NAMESPACE_BEGIN
3398template<
typename It,
typename =
void>
3401template<
typename It>
3404 void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
3405 typename It::reference, typename It::iterator_category >>
3407 using difference_type =
typename It::difference_type;
3408 using value_type =
typename It::value_type;
3409 using pointer =
typename It::pointer;
3410 using reference =
typename It::reference;
3411 using iterator_category =
typename It::iterator_category;
3416template<
typename T,
typename =
void>
3430 using iterator_category = std::random_access_iterator_tag;
3431 using value_type = T;
3432 using difference_type = ptrdiff_t;
3434 using reference = T&;
3438NLOHMANN_JSON_NAMESPACE_END
3456NLOHMANN_JSON_NAMESPACE_BEGIN
3458NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin);
3460NLOHMANN_JSON_NAMESPACE_END
3476NLOHMANN_JSON_NAMESPACE_BEGIN
3478NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end);
3480NLOHMANN_JSON_NAMESPACE_END
3495#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
3496 #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
3512 NLOHMANN_JSON_NAMESPACE_BEGIN
3521 template<
typename T =
void,
typename SFINAE =
void>
3526 template<
template<
typename U,
typename V,
typename... Args>
class ObjectType =
3528 template<
typename U,
typename... Args>
class ArrayType = std::vector,
3529 class StringType = std::string,
class BooleanType = bool,
3530 class NumberIntegerType = std::int64_t,
3531 class NumberUnsignedType = std::uint64_t,
3532 class NumberFloatType = double,
3533 template<
typename U>
class AllocatorType = std::allocator,
3534 template<
typename T,
typename SFINAE =
void>
class JSONSerializer =
3536 class BinaryType = std::vector<std::uint8_t>,
3537 class CustomBaseClass =
void>
3542 template<
typename RefStringType>
3553 template<
class Key,
class T,
class IgnoredLess,
class Allocator>
3560 NLOHMANN_JSON_NAMESPACE_END
3565NLOHMANN_JSON_NAMESPACE_BEGIN
3592NLOHMANN_BASIC_JSON_TPL_DECLARATION
3598template<
typename BasicJsonContext>
3600 std::integral_constant < bool,
3601 is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value
3602 || std::is_same<BasicJsonContext, std::nullptr_t>::value >
3623using mapped_type_t =
typename T::mapped_type;
3626using key_type_t =
typename T::key_type;
3629using value_type_t =
typename T::value_type;
3632using difference_type_t =
typename T::difference_type;
3635using pointer_t =
typename T::pointer;
3638using reference_t =
typename T::reference;
3641using iterator_category_t =
typename T::iterator_category;
3643template<
typename T,
typename... Args>
3644using to_json_function =
decltype(T::to_json(std::declval<Args>()...));
3646template<
typename T,
typename... Args>
3647using from_json_function =
decltype(T::from_json(std::declval<Args>()...));
3649template<
typename T,
typename U>
3650using get_template_function =
decltype(std::declval<T>().template get<U>());
3653template<
typename BasicJsonType,
typename T,
typename =
void>
3660template <
typename BasicJsonType,
typename T>
3663 static constexpr bool value = is_detected<get_template_function, const BasicJsonType&, T>::value;
3666template<
typename BasicJsonType,
typename T>
3669 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3671 static constexpr bool value =
3672 is_detected_exact<void, from_json_function, serializer,
3673 const BasicJsonType&, T&>
::value;
3678template<
typename BasicJsonType,
typename T,
typename =
void>
3681template<
typename BasicJsonType,
typename T>
3684 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3686 static constexpr bool value =
3687 is_detected_exact<T, from_json_function, serializer,
3693template<
typename BasicJsonType,
typename T,
typename =
void>
3696template<
typename BasicJsonType,
typename T>
3699 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3701 static constexpr bool value =
3702 is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
3707using detect_key_compare =
typename T::key_compare;
3710struct has_key_compare : std::integral_constant<bool, is_detected<detect_key_compare, T>::value> {};
3713template<
typename BasicJsonType>
3716 using object_t =
typename BasicJsonType::object_t;
3717 using object_comparator_t =
typename BasicJsonType::default_object_comparator_t;
3718 using type =
typename std::conditional < has_key_compare<object_t>::value,
3719 typename object_t::key_compare, object_comparator_t>::type;
3722template<
typename BasicJsonType>
3723using actual_object_comparator_t =
typename actual_object_comparator<BasicJsonType>::type;
3738 using char_type =
unsigned char;
3739 using int_type = uint64_t;
3742 static int_type to_int_type(char_type c)
noexcept
3744 return static_cast<int_type
>(c);
3747 static char_type to_char_type(int_type i)
noexcept
3749 return static_cast<char_type
>(i);
3752 static constexpr int_type eof()
noexcept
3754 return static_cast<int_type
>(std::char_traits<char>::eof());
3762 using char_type =
signed char;
3763 using int_type = uint64_t;
3766 static int_type to_int_type(char_type c)
noexcept
3768 return static_cast<int_type
>(c);
3771 static char_type to_char_type(int_type i)
noexcept
3773 return static_cast<char_type
>(i);
3776 static constexpr int_type eof()
noexcept
3778 return static_cast<int_type
>(std::char_traits<char>::eof());
3789template<
class B,
class... Bn>
3791: std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {};
3794template<
class B>
struct negation : std::integral_constant < bool, !B::value > { };
3799template <
typename T>
3802template <
typename T1,
typename T2>
3804 :
conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3806template <
typename T1,
typename T2>
3808 :
conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3810template <
typename... Ts>
3812 :
conjunction<is_default_constructible<Ts>...> {};
3814template <
typename... Ts>
3816 :
conjunction<is_default_constructible<Ts>...> {};
3818template <
typename T,
typename... Args>
3821template <
typename T1,
typename T2>
3824template <
typename T1,
typename T2>
3827template <
typename... Ts>
3830template <
typename... Ts>
3833template<
typename T,
typename =
void>
3843 static constexpr auto value =
3844 is_detected<value_type_t, traits>::value &&
3845 is_detected<difference_type_t, traits>::value &&
3846 is_detected<pointer_t, traits>::value &&
3847 is_detected<iterator_category_t, traits>::value &&
3848 is_detected<reference_t, traits>::value;
3855 using t_ref =
typename std::add_lvalue_reference<T>::type;
3857 using iterator = detected_t<result_of_begin, t_ref>;
3858 using sentinel = detected_t<result_of_end, t_ref>;
3863 static constexpr auto is_iterator_begin =
3867 static constexpr bool value = !std::is_same<iterator, nonesuch>::value && !std::is_same<sentinel, nonesuch>::value && is_iterator_begin;
3871using iterator_t = enable_if_t<is_range<R>::value, result_of_begin<decltype(std::declval<R&>())>>;
3874using range_value_t = value_type_t<iterator_traits<iterator_t<T>>>;
3880template<
typename T,
typename =
void>
3886template<
typename BasicJsonType,
typename CompatibleObjectType,
3890template<
typename BasicJsonType,
typename CompatibleObjectType>
3892 BasicJsonType, CompatibleObjectType,
3893 enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
3894 is_detected<key_type_t, CompatibleObjectType>::value >>
3896 using object_t =
typename BasicJsonType::object_t;
3899 static constexpr bool value =
3901 typename CompatibleObjectType::key_type>::value &&
3903 typename CompatibleObjectType::mapped_type>
::value;
3906template<
typename BasicJsonType,
typename CompatibleObjectType>
3910template<
typename BasicJsonType,
typename ConstructibleObjectType,
3914template<
typename BasicJsonType,
typename ConstructibleObjectType>
3916 BasicJsonType, ConstructibleObjectType,
3917 enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&&
3918 is_detected<key_type_t, ConstructibleObjectType>::value >>
3920 using object_t =
typename BasicJsonType::object_t;
3922 static constexpr bool value =
3924 (std::is_move_assignable<ConstructibleObjectType>::value ||
3925 std::is_copy_assignable<ConstructibleObjectType>::value) &&
3927 typename object_t::key_type>::value &&
3929 typename object_t::mapped_type,
3930 typename ConstructibleObjectType::mapped_type >
::value)) ||
3932 typename ConstructibleObjectType::mapped_type>::value ||
3935 typename ConstructibleObjectType::mapped_type >::value);
3938template<
typename BasicJsonType,
typename ConstructibleObjectType>
3941 ConstructibleObjectType> {};
3943template<
typename BasicJsonType,
typename CompatibleStringType>
3946 static constexpr auto value =
3950template<
typename BasicJsonType,
typename ConstructibleStringType>
3954#ifdef __INTEL_COMPILER
3955 using laundered_type =
decltype(std::declval<ConstructibleStringType>());
3957 using laundered_type = ConstructibleStringType;
3960 static constexpr auto value =
3963 is_detected_exact<
typename BasicJsonType::string_t::value_type,
3964 value_type_t, laundered_type >>::value;
3967template<
typename BasicJsonType,
typename CompatibleArrayType,
typename =
void>
3970template<
typename BasicJsonType,
typename CompatibleArrayType>
3972 BasicJsonType, CompatibleArrayType,
3974 is_detected<iterator_t, CompatibleArrayType>::value&&
3975 is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value&&
3978 !std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value >>
3980 static constexpr bool value =
3982 range_value_t<CompatibleArrayType>>
::value;
3985template<
typename BasicJsonType,
typename CompatibleArrayType>
3989template<
typename BasicJsonType,
typename ConstructibleArrayType,
typename =
void>
3992template<
typename BasicJsonType,
typename ConstructibleArrayType>
3994 BasicJsonType, ConstructibleArrayType,
3995 enable_if_t<std::is_same<ConstructibleArrayType,
3996 typename BasicJsonType::value_type>::value >>
3997 : std::true_type {};
3999template<
typename BasicJsonType,
typename ConstructibleArrayType>
4001 BasicJsonType, ConstructibleArrayType,
4002 enable_if_t < !std::is_same<ConstructibleArrayType,
4003 typename BasicJsonType::value_type>::value&&
4006(std::is_move_assignable<ConstructibleArrayType>::value ||
4007 std::is_copy_assignable<ConstructibleArrayType>::value)&&
4008is_detected<iterator_t, ConstructibleArrayType>::value&&
4009is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value&&
4010is_detected<range_value_t, ConstructibleArrayType>::value&&
4013!std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>::value&&
4015detected_t<range_value_t, ConstructibleArrayType >>::value >>
4017 using value_type = range_value_t<ConstructibleArrayType>;
4019 static constexpr bool value =
4020 std::is_same<value_type,
4021 typename BasicJsonType::array_t::value_type>::value ||
4023 value_type>::value ||
4029template<
typename BasicJsonType,
typename ConstructibleArrayType>
4033template<
typename RealIntegerType,
typename CompatibleNumberIntegerType,
4037template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
4039 RealIntegerType, CompatibleNumberIntegerType,
4040 enable_if_t < std::is_integral<RealIntegerType>::value&&
4041 std::is_integral<CompatibleNumberIntegerType>::value&&
4042 !std::is_same<bool, CompatibleNumberIntegerType>::value >>
4045 using RealLimits = std::numeric_limits<RealIntegerType>;
4046 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
4048 static constexpr auto value =
4050 CompatibleNumberIntegerType>::value &&
4051 CompatibleLimits::is_integer &&
4052 RealLimits::is_signed == CompatibleLimits::is_signed;
4055template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
4058 CompatibleNumberIntegerType> {};
4060template<
typename BasicJsonType,
typename CompatibleType,
typename =
void>
4063template<
typename BasicJsonType,
typename CompatibleType>
4065 BasicJsonType, CompatibleType,
4068 static constexpr bool value =
4072template<
typename BasicJsonType,
typename CompatibleType>
4076template<
typename T1,
typename T2>
4079template<
typename T1,
typename... Args>
4082template<
typename BasicJsonType,
typename T>
4085template<
typename BasicJsonType>
4088template<
typename BasicJsonType>
4093template<
template <
typename...>
class Primary,
typename T>
4096template<
template <
typename...>
class Primary,
typename... Args>
4103template<
typename Compare,
typename A,
typename B,
typename =
void>
4106template<
typename Compare,
typename A,
typename B>
4108decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())),
4109decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))
4110>> : std::true_type {};
4113using detect_is_transparent =
typename T::is_transparent;
4117template<
typename Comparator,
typename ObjectKeyType,
typename KeyTypeCVRef,
bool RequireTransparentComparator =
true,
4118 bool ExcludeObjectKeyType = RequireTransparentComparator,
typename KeyType = uncvref_t<KeyTypeCVRef>>
4119using is_usable_as_key_type =
typename std::conditional <
4121 && !(ExcludeObjectKeyType && std::is_same<KeyType,
4123 && (!RequireTransparentComparator
4124 || is_detected <detect_is_transparent, Comparator>::value)
4127 std::false_type >::type;
4135template<
typename BasicJsonType,
typename KeyTypeCVRef,
bool RequireTransparentComparator =
true,
4136 bool ExcludeObjectKeyType = RequireTransparentComparator,
typename KeyType = uncvref_t<KeyTypeCVRef>>
4137using is_usable_as_basic_json_key_type =
typename std::conditional <
4138 is_usable_as_key_type<
typename BasicJsonType::object_comparator_t,
4139 typename BasicJsonType::object_t::key_type, KeyTypeCVRef,
4140 RequireTransparentComparator, ExcludeObjectKeyType>::value
4143 std::false_type >::type;
4145template<
typename ObjectType,
typename KeyType>
4146using detect_erase_with_key_type =
decltype(std::declval<ObjectType&>().erase(std::declval<KeyType>()));
4149template<
typename BasicJsonType,
typename KeyType>
4150using has_erase_with_key_type =
typename std::conditional <
4152 detect_erase_with_key_type,
4153 typename BasicJsonType::object_t, KeyType >
::value,
4155 std::false_type >::type;
4159template <
typename T>
4169 template <
typename C>
static one test(
decltype(&C::capacity) ) ;
4170 template <
typename C>
static two test(...);
4172 enum { value =
sizeof(test<T>(
nullptr)) ==
sizeof(
char) };
4176template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value,
int > = 0 >
4177T conditional_static_cast(U value)
4179 return static_cast<T
>(
value);
4182template<typename T, typename U, enable_if_t<std::is_same<T, U>::value,
int> = 0>
4183T conditional_static_cast(U value)
4188template<
typename... Types>
4189using all_integral = conjunction<std::is_integral<Types>...>;
4191template<
typename... Types>
4192using all_signed = conjunction<std::is_signed<Types>...>;
4194template<
typename... Types>
4195using all_unsigned = conjunction<std::is_unsigned<Types>...>;
4198template<
typename... Types>
4199using same_sign = std::integral_constant < bool,
4200 all_signed<Types...>::value || all_unsigned<Types...>::value >;
4202template<
typename OfType,
typename T>
4203using never_out_of_range = std::integral_constant < bool,
4204 (std::is_signed<OfType>::value && (
sizeof(T) <
sizeof(OfType)))
4205 || (same_sign<OfType, T>::value &&
sizeof(OfType) ==
sizeof(T)) >;
4207template<
typename OfType,
typename T,
4208 bool OfTypeSigned = std::is_signed<OfType>::value,
4209 bool TSigned = std::is_signed<T>::value>
4212template<
typename OfType,
typename T>
4215 static constexpr bool test(T val)
4217 using CommonType =
typename std::common_type<OfType, T>::type;
4218 return static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4222template<
typename OfType,
typename T>
4225 static constexpr bool test(T val)
4227 using CommonType =
typename std::common_type<OfType, T>::type;
4228 return static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4232template<
typename OfType,
typename T>
4235 static constexpr bool test(T val)
4237 using CommonType =
typename std::common_type<OfType, T>::type;
4238 return val >= 0 &&
static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4242template<
typename OfType,
typename T>
4245 static constexpr bool test(T val)
4247 using CommonType =
typename std::common_type<OfType, T>::type;
4248 return static_cast<CommonType
>(val) >=
static_cast<CommonType
>((std::numeric_limits<OfType>::min)())
4249 &&
static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4253template<
typename OfType,
typename T,
4254 bool NeverOutOfRange = never_out_of_range<OfType, T>::value,
4255 typename = detail::enable_if_t<all_integral<OfType, T>::value>>
4258template<
typename OfType,
typename T>
4261 static constexpr bool test(T val)
4267template<
typename OfType,
typename T>
4270 static constexpr bool test(T )
4276template<
typename OfType,
typename T>
4277constexpr bool value_in_range_of(T val)
4283using bool_constant = std::integral_constant<bool, Value>;
4293constexpr bool is_c_string()
4295 using TUnExt =
typename std::remove_extent<T>::type;
4296 using TUnCVExt =
typename std::remove_cv<TUnExt>::type;
4297 using TUnPtr =
typename std::remove_pointer<T>::type;
4298 using TUnCVPtr =
typename std::remove_cv<TUnPtr>::type;
4300 (std::is_array<T>::value && std::is_same<TUnCVExt, char>::value)
4301 || (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value);
4323 return is_detected<detect_is_transparent, T>::value;
4335NLOHMANN_JSON_NAMESPACE_END
4357NLOHMANN_JSON_NAMESPACE_BEGIN
4361inline std::size_t concat_length()
4366template<
typename... Args>
4367inline std::size_t concat_length(
const char* cstr,
const Args& ... rest);
4369template<
typename StringType,
typename... Args>
4370inline std::size_t concat_length(
const StringType& str,
const Args& ... rest);
4372template<
typename... Args>
4373inline std::size_t concat_length(
const char ,
const Args& ... rest)
4375 return 1 + concat_length(rest...);
4378template<
typename... Args>
4379inline std::size_t concat_length(
const char* cstr,
const Args& ... rest)
4382 return ::strlen(cstr) + concat_length(rest...);
4385template<
typename StringType,
typename... Args>
4386inline std::size_t concat_length(
const StringType& str,
const Args& ... rest)
4388 return str.size() + concat_length(rest...);
4391template<
typename OutStringType>
4392inline void concat_into(OutStringType& )
4395template<
typename StringType,
typename Arg>
4396using string_can_append =
decltype(std::declval<StringType&>().append(std::declval < Arg && > ()));
4398template<
typename StringType,
typename Arg>
4399using detect_string_can_append = is_detected<string_can_append, StringType, Arg>;
4401template<
typename StringType,
typename Arg>
4402using string_can_append_op =
decltype(std::declval<StringType&>() += std::declval < Arg && > ());
4404template<
typename StringType,
typename Arg>
4405using detect_string_can_append_op = is_detected<string_can_append_op, StringType, Arg>;
4407template<
typename StringType,
typename Arg>
4408using string_can_append_iter =
decltype(std::declval<StringType&>().append(std::declval<const Arg&>().begin(), std::declval<const Arg&>().end()));
4410template<
typename StringType,
typename Arg>
4411using detect_string_can_append_iter = is_detected<string_can_append_iter, StringType, Arg>;
4413template<
typename StringType,
typename Arg>
4414using string_can_append_data =
decltype(std::declval<StringType&>().append(std::declval<const Arg&>().data(), std::declval<const Arg&>().size()));
4416template<
typename StringType,
typename Arg>
4417using detect_string_can_append_data = is_detected<string_can_append_data, StringType, Arg>;
4419template <
typename OutStringType,
typename Arg,
typename... Args,
4420 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4421 && detect_string_can_append_op<OutStringType, Arg>::value,
int > = 0 >
4422inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest);
4424template <
typename OutStringType,
typename Arg,
typename... Args,
4425 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4426 && !detect_string_can_append_op<OutStringType, Arg>::value
4427 && detect_string_can_append_iter<OutStringType, Arg>::value,
int > = 0 >
4428inline void concat_into(OutStringType& out,
const Arg& arg, Args && ... rest);
4430template <
typename OutStringType,
typename Arg,
typename... Args,
4431 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4432 && !detect_string_can_append_op<OutStringType, Arg>::value
4433 && !detect_string_can_append_iter<OutStringType, Arg>::value
4434 && detect_string_can_append_data<OutStringType, Arg>::value,
int > = 0 >
4435inline void concat_into(OutStringType& out,
const Arg& arg, Args && ... rest);
4437template<
typename OutStringType,
typename Arg,
typename... Args,
4438 enable_if_t<detect_string_can_append<OutStringType, Arg>::value,
int> = 0>
4439inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest)
4441 out.append(std::forward<Arg>(arg));
4442 concat_into(out, std::forward<Args>(rest)...);
4445template <
typename OutStringType,
typename Arg,
typename... Args,
4446 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4447 && detect_string_can_append_op<OutStringType, Arg>::value,
int > >
4448inline void concat_into(OutStringType& out, Arg&& arg, Args&& ... rest)
4450 out += std::forward<Arg>(arg);
4451 concat_into(out, std::forward<Args>(rest)...);
4454template <
typename OutStringType,
typename Arg,
typename... Args,
4455 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4456 && !detect_string_can_append_op<OutStringType, Arg>::value
4457 && detect_string_can_append_iter<OutStringType, Arg>::value,
int > >
4458inline void concat_into(OutStringType& out,
const Arg& arg, Args&& ... rest)
4460 out.append(arg.begin(), arg.end());
4461 concat_into(out, std::forward<Args>(rest)...);
4464template <
typename OutStringType,
typename Arg,
typename... Args,
4465 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4466 && !detect_string_can_append_op<OutStringType, Arg>::value
4467 && !detect_string_can_append_iter<OutStringType, Arg>::value
4468 && detect_string_can_append_data<OutStringType, Arg>::value,
int > >
4469inline void concat_into(OutStringType& out,
const Arg& arg, Args&& ... rest)
4471 out.append(arg.data(), arg.size());
4472 concat_into(out, std::forward<Args>(rest)...);
4475template<
typename OutStringType = std::string,
typename... Args>
4476inline OutStringType concat(Args && ... args)
4479 str.reserve(concat_length(args...));
4480 concat_into(str, std::forward<Args>(args)...);
4485NLOHMANN_JSON_NAMESPACE_END
4495#if defined(__clang__)
4496 #pragma clang diagnostic push
4497 #pragma clang diagnostic ignored "-Wweak-vtables"
4500NLOHMANN_JSON_NAMESPACE_BEGIN
4514 const char*
what() const noexcept
override
4523 JSON_HEDLEY_NON_NULL(3)
4524 exception(
int id_, const
char* what_arg) :
id(id_), m(what_arg) {}
4526 static std::string name(
const std::string& ename,
int id_)
4528 return concat(
"[json.exception.", ename,
'.', std::to_string(id_),
"] ");
4531 static std::string diagnostics(std::nullptr_t )
4536 template<
typename BasicJsonType>
4537 static std::string diagnostics(
const BasicJsonType* leaf_element)
4540 std::vector<std::string> tokens;
4541 for (
const auto* current = leaf_element; current !=
nullptr && current->m_parent !=
nullptr; current = current->m_parent)
4543 switch (current->m_parent->type())
4547 for (std::size_t i = 0; i < current->m_parent->m_data.m_value.array->size(); ++i)
4549 if (¤t->m_parent->m_data.m_value.array->operator[](i) == current)
4551 tokens.emplace_back(std::to_string(i));
4560 for (
const auto& element : *current->m_parent->m_data.m_value.object)
4562 if (&element.second == current)
4564 tokens.emplace_back(element.first.c_str());
4589 auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
4590 [](
const std::string & a,
const std::string & b)
4592 return concat(a,
'/', detail::escape(b));
4595 return concat(
'(', str,
") ", get_byte_positions(leaf_element));
4597 return get_byte_positions(leaf_element);
4603 std::runtime_error m;
4604#if JSON_DIAGNOSTIC_POSITIONS
4605 template<
typename BasicJsonType>
4606 static std::string get_byte_positions(
const BasicJsonType* leaf_element)
4608 if ((leaf_element->start_pos() != std::string::npos) && (leaf_element->end_pos() != std::string::npos))
4610 return concat(
"(bytes ", std::to_string(leaf_element->start_pos()),
"-", std::to_string(leaf_element->end_pos()),
") ");
4615 template<
typename BasicJsonType>
4616 static std::string get_byte_positions(
const BasicJsonType* leaf_element)
4618 static_cast<void>(leaf_element);
4638 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4641 const std::string w = concat(exception::name(
"parse_error", id_),
"parse error",
4642 position_string(pos),
": ", exception::diagnostics(context), what_arg);
4646 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4647 static parse_error create(
int id_, std::size_t byte_,
const std::string& what_arg, BasicJsonContext context)
4649 const std::string w = concat(exception::name(
"parse_error", id_),
"parse error",
4650 (byte_ != 0 ? (concat(
" at byte ", std::to_string(byte_))) :
""),
4651 ": ", exception::diagnostics(context), what_arg);
4652 return {id_, byte_, w.c_str()};
4664 const std::size_t
byte;
4667 parse_error(
int id_, std::size_t byte_,
const char* what_arg)
4668 : exception(id_, what_arg),
byte(byte_) {}
4670 static std::string position_string(
const position_t& pos)
4672 return concat(
" at line ", std::to_string(pos.lines_read + 1),
4673 ", column ", std::to_string(pos.chars_read_current_line));
4682 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4683 static invalid_iterator create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4685 const std::string w = concat(exception::name(
"invalid_iterator", id_), exception::diagnostics(context), what_arg);
4686 return {id_, w.c_str()};
4690 JSON_HEDLEY_NON_NULL(3)
4700 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4701 static type_error create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4703 const std::string w = concat(exception::name(
"type_error", id_), exception::diagnostics(context), what_arg);
4704 return {id_, w.c_str()};
4708 JSON_HEDLEY_NON_NULL(3)
4717 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4718 static out_of_range create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4720 const std::string w = concat(exception::name(
"out_of_range", id_), exception::diagnostics(context), what_arg);
4721 return {id_, w.c_str()};
4725 JSON_HEDLEY_NON_NULL(3)
4734 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4735 static other_error create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4737 const std::string w = concat(exception::name(
"other_error", id_), exception::diagnostics(context), what_arg);
4738 return {id_, w.c_str()};
4742 JSON_HEDLEY_NON_NULL(3)
4747NLOHMANN_JSON_NAMESPACE_END
4749#if defined(__clang__)
4750 #pragma clang diagnostic pop
4771NLOHMANN_JSON_NAMESPACE_BEGIN
4779NLOHMANN_JSON_NAMESPACE_END
4795#if JSON_HAS_EXPERIMENTAL_FILESYSTEM
4796#include <experimental/filesystem>
4797NLOHMANN_JSON_NAMESPACE_BEGIN
4800namespace std_fs = std::experimental::filesystem;
4802NLOHMANN_JSON_NAMESPACE_END
4803#elif JSON_HAS_FILESYSTEM
4804#include <filesystem>
4805NLOHMANN_JSON_NAMESPACE_BEGIN
4808namespace std_fs = std::filesystem;
4810NLOHMANN_JSON_NAMESPACE_END
4820NLOHMANN_JSON_NAMESPACE_BEGIN
4824template<
typename BasicJsonType>
4825inline void from_json(
const BasicJsonType& j,
typename std::nullptr_t& n)
4827 if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
4829 JSON_THROW(type_error::create(302, concat(
"type must be null, but is ", j.type_name()), &j));
4834#ifdef JSON_HAS_CPP_17
4835#ifndef JSON_USE_IMPLICIT_CONVERSIONS
4836template<
typename BasicJsonType,
typename T>
4837void from_json(
const BasicJsonType& j, std::optional<T>& opt)
4845 opt.emplace(j.template get<T>());
4853template <
typename BasicJsonType,
typename ArithmeticType,
4854 enable_if_t < std::is_arithmetic<ArithmeticType>::value&&
4855 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4857void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val)
4859 switch (
static_cast<value_t>(j))
4863 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4868 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4873 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4885 JSON_THROW(type_error::create(302, concat(
"type must be number, but is ", j.type_name()), &j));
4889template<
typename BasicJsonType>
4890inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::boolean_t& b)
4892 if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
4894 JSON_THROW(type_error::create(302, concat(
"type must be boolean, but is ", j.type_name()), &j));
4896 b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
4899template<
typename BasicJsonType>
4900inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::string_t& s)
4902 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
4904 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
4906 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4910 typename BasicJsonType,
typename StringType,
4912 std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value
4913 && is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value
4914 && !std::is_same<typename BasicJsonType::string_t, StringType>::value
4915 && !is_json_ref<StringType>::value,
int > = 0 >
4916inline void from_json(
const BasicJsonType& j, StringType& s)
4918 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
4920 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
4923 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4926template<
typename BasicJsonType>
4927inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_float_t& val)
4929 get_arithmetic_value(j, val);
4932template<
typename BasicJsonType>
4933inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_unsigned_t& val)
4935 get_arithmetic_value(j, val);
4938template<
typename BasicJsonType>
4939inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_integer_t& val)
4941 get_arithmetic_value(j, val);
4944#if !JSON_DISABLE_ENUM_SERIALIZATION
4945template<
typename BasicJsonType,
typename EnumType,
4946 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
4947inline void from_json(
const BasicJsonType& j, EnumType& e)
4949 typename std::underlying_type<EnumType>::type val;
4950 get_arithmetic_value(j, val);
4951 e =
static_cast<EnumType
>(val);
4956template<
typename BasicJsonType,
typename T,
typename Allocator,
4957 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4958inline void from_json(
const BasicJsonType& j, std::forward_list<T, Allocator>& l)
4960 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4962 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4965 std::transform(j.rbegin(), j.rend(),
4966 std::front_inserter(l), [](
const BasicJsonType & i)
4968 return i.template get<T>();
4973template<
typename BasicJsonType,
typename T,
4974 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4975inline void from_json(
const BasicJsonType& j, std::valarray<T>& l)
4977 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4979 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4982 std::transform(j.begin(), j.end(), std::begin(l),
4983 [](
const BasicJsonType & elem)
4985 return elem.template get<T>();
4989template<
typename BasicJsonType,
typename T, std::
size_t N>
4990auto from_json(
const BasicJsonType& j, T (&arr)[N])
4991->
decltype(j.template get<T>(), void())
4993 for (std::size_t i = 0; i < N; ++i)
4995 arr[i] = j.at(i).template get<T>();
4999template<
typename BasicJsonType,
typename T, std::
size_t N1, std::
size_t N2>
5000auto from_json(
const BasicJsonType& j, T (&arr)[N1][N2])
5001->
decltype(j.template get<T>(), void())
5003 for (std::size_t i1 = 0; i1 < N1; ++i1)
5005 for (std::size_t i2 = 0; i2 < N2; ++i2)
5007 arr[i1][i2] = j.at(i1).at(i2).template get<T>();
5012template<
typename BasicJsonType,
typename T, std::
size_t N1, std::
size_t N2, std::
size_t N3>
5013auto from_json(
const BasicJsonType& j, T (&arr)[N1][N2][N3])
5014->
decltype(j.template get<T>(), void())
5016 for (std::size_t i1 = 0; i1 < N1; ++i1)
5018 for (std::size_t i2 = 0; i2 < N2; ++i2)
5020 for (std::size_t i3 = 0; i3 < N3; ++i3)
5022 arr[i1][i2][i3] = j.at(i1).at(i2).at(i3).template get<T>();
5028template<
typename BasicJsonType,
typename T, std::
size_t N1, std::
size_t N2, std::
size_t N3, std::
size_t N4>
5029auto from_json(
const BasicJsonType& j, T (&arr)[N1][N2][N3][N4])
5030->
decltype(j.template get<T>(), void())
5032 for (std::size_t i1 = 0; i1 < N1; ++i1)
5034 for (std::size_t i2 = 0; i2 < N2; ++i2)
5036 for (std::size_t i3 = 0; i3 < N3; ++i3)
5038 for (std::size_t i4 = 0; i4 < N4; ++i4)
5040 arr[i1][i2][i3][i4] = j.at(i1).at(i2).at(i3).at(i4).template get<T>();
5047template<
typename BasicJsonType>
5048inline void from_json_array_impl(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr, priority_tag<3> )
5050 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
5053template<
typename BasicJsonType,
typename T, std::
size_t N>
5054auto from_json_array_impl(
const BasicJsonType& j, std::array<T, N>& arr,
5056->
decltype(j.template get<T>(), void())
5058 for (std::size_t i = 0; i < N; ++i)
5060 arr[i] = j.at(i).template get<T>();
5064template<
typename BasicJsonType,
typename ConstructibleArrayType,
5066 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
5068auto from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> )
5070 arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
5071 j.template get<typename ConstructibleArrayType::value_type>(),
5076 ConstructibleArrayType ret;
5077 ret.reserve(j.size());
5078 std::transform(j.begin(), j.end(),
5079 std::inserter(ret, end(ret)), [](
const BasicJsonType & i)
5083 return i.template get<typename ConstructibleArrayType::value_type>();
5085 arr = std::move(ret);
5088template<
typename BasicJsonType,
typename ConstructibleArrayType,
5090 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
5092inline void from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
5097 ConstructibleArrayType ret;
5099 j.begin(), j.end(), std::inserter(ret, end(ret)),
5100 [](
const BasicJsonType & i)
5104 return i.template get<typename ConstructibleArrayType::value_type>();
5106 arr = std::move(ret);
5109template <
typename BasicJsonType,
typename ConstructibleArrayType,
5111 is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&&
5112 !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&&
5113 !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
5114 !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&&
5115 !is_basic_json<ConstructibleArrayType>::value,
5117auto from_json(
const BasicJsonType& j, ConstructibleArrayType& arr)
5118->
decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
5119j.template get<typename ConstructibleArrayType::value_type>(),
5122 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5124 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5127 from_json_array_impl(j, arr, priority_tag<3> {});
5130template <
typename BasicJsonType,
typename T, std::size_t... Idx >
5131std::array<T,
sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j,
5132 identity_tag<std::array<T,
sizeof...(Idx)>> , index_sequence<Idx...> )
5134 return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
5137template <
typename BasicJsonType,
typename T, std::
size_t N >
5138auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag)
5139->
decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}))
5141 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5143 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5146 return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {});
5149template<
typename BasicJsonType>
5150inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::binary_t& bin)
5152 if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
5154 JSON_THROW(type_error::create(302, concat(
"type must be binary, but is ", j.type_name()), &j));
5157 bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
5160template<
typename BasicJsonType,
typename ConstructibleObjectType,
5161 enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value,
int> = 0>
5162inline void from_json(
const BasicJsonType& j, ConstructibleObjectType& obj)
5164 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
5166 JSON_THROW(type_error::create(302, concat(
"type must be object, but is ", j.type_name()), &j));
5169 ConstructibleObjectType ret;
5170 const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
5171 using value_type =
typename ConstructibleObjectType::value_type;
5173 inner_object->begin(), inner_object->end(),
5174 std::inserter(ret, ret.begin()),
5175 [](
typename BasicJsonType::object_t::value_type
const & p)
5177 return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
5179 obj = std::move(ret);
5186template <
typename BasicJsonType,
typename ArithmeticType,
5188 std::is_arithmetic<ArithmeticType>::value&&
5189 !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&&
5190 !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&&
5191 !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&&
5192 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
5194inline void from_json(
const BasicJsonType& j, ArithmeticType& val)
5196 switch (
static_cast<value_t>(j))
5200 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
5205 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
5210 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
5215 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
5226 JSON_THROW(type_error::create(302, concat(
"type must be number, but is ", j.type_name()), &j));
5230template<
typename BasicJsonType,
typename... Args, std::size_t... Idx>
5231std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<Idx...> )
5233 return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).
template get<Args>()...);
5236template<
typename BasicJsonType>
5237std::tuple<> from_json_tuple_impl_base(BasicJsonType& , index_sequence<> )
5242template <
typename BasicJsonType,
class A1,
class A2 >
5243std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> , priority_tag<0> )
5245 return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
5246 std::forward<BasicJsonType>(j).at(1).template get<A2>()};
5249template<
typename BasicJsonType,
typename A1,
typename A2>
5250inline void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> )
5252 p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {});
5255template<
typename BasicJsonType,
typename... Args>
5256std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> , priority_tag<2> )
5258 return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
5261template<
typename BasicJsonType,
typename... Args>
5262inline void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> )
5264 t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
5267template<
typename BasicJsonType,
typename TupleRelated>
5268auto from_json(BasicJsonType&& j, TupleRelated&& t)
5269->
decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}))
5271 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5273 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5276 return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {});
5279template <
typename BasicJsonType,
typename Key,
typename Value,
typename Compare,
typename Allocator,
5280 typename = enable_if_t < !std::is_constructible <
5281 typename BasicJsonType::string_t, Key >::value >>
5282inline void from_json(
const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
5284 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5286 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5289 for (
const auto& p : j)
5291 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
5293 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", p.type_name()), &j));
5295 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
5299template <
typename BasicJsonType,
typename Key,
typename Value,
typename Hash,
typename KeyEqual,
typename Allocator,
5300 typename = enable_if_t < !std::is_constructible <
5301 typename BasicJsonType::string_t, Key >::value >>
5302inline void from_json(
const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
5304 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5306 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5309 for (
const auto& p : j)
5311 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
5313 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", p.type_name()), &j));
5315 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
5319#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
5320template<
typename BasicJsonType>
5321inline void from_json(
const BasicJsonType& j, std_fs::path& p)
5323 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
5325 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
5327 const auto& s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
5328#ifdef JSON_HAS_CPP_20
5329 p = std_fs::path(std::u8string_view(
reinterpret_cast<const char8_t*
>(s.data()), s.size()));
5331 p = std_fs::u8path(s);
5338 template<
typename BasicJsonType,
typename T>
5339 auto operator()(
const BasicJsonType& j, T&& val)
const
5340 noexcept(
noexcept(from_json(j, std::forward<T>(val))))
5341 ->
decltype(from_json(j, std::forward<T>(val)))
5343 return from_json(j, std::forward<T>(val));
5349#ifndef JSON_HAS_CPP_17
5356JSON_INLINE_VARIABLE
constexpr const auto& from_json =
5358#ifndef JSON_HAS_CPP_17
5362NLOHMANN_JSON_NAMESPACE_END
5377#ifdef JSON_HAS_CPP_17
5385#include <type_traits>
5431NLOHMANN_JSON_NAMESPACE_BEGIN
5435template<
typename StringType>
5436void int_to_string(StringType& target, std::size_t value)
5439 using std::to_string;
5443template<
typename StringType>
5447 int_to_string(result, value);
5452NLOHMANN_JSON_NAMESPACE_END
5457NLOHMANN_JSON_NAMESPACE_BEGIN
5461template<
typename IteratorType>
class iteration_proxy_value
5464 using difference_type = std::ptrdiff_t;
5465 using value_type = iteration_proxy_value;
5466 using pointer = value_type *;
5467 using reference = value_type &;
5468 using iterator_category = std::forward_iterator_tag;
5469 using string_type =
typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
5473 IteratorType anchor{};
5475 std::size_t array_index = 0;
5477 mutable std::size_t array_index_last = 0;
5479 mutable string_type array_index_str =
"0";
5481 string_type empty_str{};
5484 explicit iteration_proxy_value() =
default;
5485 explicit iteration_proxy_value(IteratorType it, std::size_t array_index_ = 0)
5486 noexcept(std::is_nothrow_move_constructible<IteratorType>::value
5487 && std::is_nothrow_default_constructible<string_type>::value)
5488 : anchor(std::move(it))
5489 , array_index(array_index_)
5492 iteration_proxy_value(iteration_proxy_value
const&) =
default;
5493 iteration_proxy_value& operator=(iteration_proxy_value
const&) =
default;
5495 iteration_proxy_value(iteration_proxy_value&&)
5496 noexcept(std::is_nothrow_move_constructible<IteratorType>::value
5497 && std::is_nothrow_move_constructible<string_type>::value) = default;
5498 iteration_proxy_value& operator=(iteration_proxy_value&&)
5499 noexcept(std::is_nothrow_move_assignable<IteratorType>::value
5500 && std::is_nothrow_move_assignable<string_type>::value) = default;
5501 ~iteration_proxy_value() = default;
5529 return anchor == o.anchor;
5535 return anchor != o.anchor;
5539 const string_type&
key()
const
5541 JSON_ASSERT(anchor.m_object !=
nullptr);
5543 switch (anchor.m_object->type())
5548 if (array_index != array_index_last)
5550 int_to_string( array_index_str, array_index );
5551 array_index_last = array_index;
5553 return array_index_str;
5558 return anchor.key();
5575 typename IteratorType::reference
value()
const
5577 return anchor.value();
5582template<
typename IteratorType>
class iteration_proxy
5586 typename IteratorType::pointer container =
nullptr;
5589 explicit iteration_proxy() =
default;
5593 : container(&cont) {}
5617template<std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
5618auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.key())
5625template<std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
5626auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.value())
5632NLOHMANN_JSON_NAMESPACE_END
5641#if defined(__clang__)
5643 #pragma clang diagnostic push
5644 #pragma clang diagnostic ignored "-Wmismatched-tags"
5646template<
typename IteratorType>
5647class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
5648 :
public std::integral_constant<std::size_t, 2> {};
5650template<std::
size_t N,
typename IteratorType>
5651class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
5654 using type =
decltype(
5655 get<N>(std::declval <
5656 ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));
5658#if defined(__clang__)
5659 #pragma clang diagnostic pop
5665 template <
typename IteratorType>
5666 inline constexpr bool ::std::ranges::enable_borrowed_range<::nlohmann::detail::iteration_proxy<IteratorType>> =
true;
5678NLOHMANN_JSON_NAMESPACE_BEGIN
5698 template<
typename BasicJsonType>
5699 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t b)
noexcept
5701 j.m_data.m_value.destroy(j.m_data.m_type);
5703 j.m_data.m_value = b;
5704 j.assert_invariant();
5711 template<
typename BasicJsonType>
5712 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t& s)
5714 j.m_data.m_value.destroy(j.m_data.m_type);
5716 j.m_data.m_value = s;
5717 j.assert_invariant();
5720 template<
typename BasicJsonType>
5721 static void construct(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
5723 j.m_data.m_value.destroy(j.m_data.m_type);
5725 j.m_data.m_value = std::move(s);
5726 j.assert_invariant();
5729 template <
typename BasicJsonType,
typename CompatibleStringType,
5730 enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
5732 static void construct(BasicJsonType& j,
const CompatibleStringType& str)
5734 j.m_data.m_value.destroy(j.m_data.m_type);
5736 j.m_data.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
5737 j.assert_invariant();
5744 template<
typename BasicJsonType>
5745 static void construct(BasicJsonType& j,
const typename BasicJsonType::binary_t& b)
5747 j.m_data.m_value.destroy(j.m_data.m_type);
5749 j.m_data.m_value =
typename BasicJsonType::binary_t(b);
5750 j.assert_invariant();
5753 template<
typename BasicJsonType>
5754 static void construct(BasicJsonType& j,
typename BasicJsonType::binary_t&& b)
5756 j.m_data.m_value.destroy(j.m_data.m_type);
5758 j.m_data.m_value =
typename BasicJsonType::binary_t(std::move(b));
5759 j.assert_invariant();
5766 template<
typename BasicJsonType>
5767 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val)
noexcept
5769 j.m_data.m_value.destroy(j.m_data.m_type);
5771 j.m_data.m_value = val;
5772 j.assert_invariant();
5779 template<
typename BasicJsonType>
5780 static void construct(BasicJsonType& j,
typename BasicJsonType::number_unsigned_t val)
noexcept
5782 j.m_data.m_value.destroy(j.m_data.m_type);
5784 j.m_data.m_value = val;
5785 j.assert_invariant();
5792 template<
typename BasicJsonType>
5793 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val)
noexcept
5795 j.m_data.m_value.destroy(j.m_data.m_type);
5797 j.m_data.m_value = val;
5798 j.assert_invariant();
5805 template<
typename BasicJsonType>
5806 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
5808 j.m_data.m_value.destroy(j.m_data.m_type);
5810 j.m_data.m_value = arr;
5812 j.assert_invariant();
5815 template<
typename BasicJsonType>
5816 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
5818 j.m_data.m_value.destroy(j.m_data.m_type);
5820 j.m_data.m_value = std::move(arr);
5822 j.assert_invariant();
5825 template <
typename BasicJsonType,
typename CompatibleArrayType,
5826 enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
5828 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
5833 j.m_data.m_value.destroy(j.m_data.m_type);
5835 j.m_data.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
5837 j.assert_invariant();
5840 template<
typename BasicJsonType>
5841 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
5843 j.m_data.m_value.destroy(j.m_data.m_type);
5846 j.m_data.m_value.array->reserve(arr.size());
5847 for (
const bool x : arr)
5849 j.m_data.m_value.array->push_back(x);
5850 j.set_parent(j.m_data.m_value.array->back());
5852 j.assert_invariant();
5855 template<
typename BasicJsonType,
typename T,
5856 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
5857 static void construct(BasicJsonType& j,
const std::valarray<T>& arr)
5859 j.m_data.m_value.destroy(j.m_data.m_type);
5862 j.m_data.m_value.array->resize(arr.size());
5865 std::copy(std::begin(arr), std::end(arr), j.m_data.m_value.array->begin());
5868 j.assert_invariant();
5875 template<
typename BasicJsonType>
5876 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
5878 j.m_data.m_value.destroy(j.m_data.m_type);
5880 j.m_data.m_value = obj;
5882 j.assert_invariant();
5885 template<
typename BasicJsonType>
5886 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
5888 j.m_data.m_value.destroy(j.m_data.m_type);
5890 j.m_data.m_value = std::move(obj);
5892 j.assert_invariant();
5895 template <
typename BasicJsonType,
typename CompatibleObjectType,
5896 enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
int > = 0 >
5897 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
5902 j.m_data.m_value.destroy(j.m_data.m_type);
5904 j.m_data.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
5906 j.assert_invariant();
5914#ifdef JSON_HAS_CPP_17
5915template<
typename BasicJsonType,
typename T,
5916 enable_if_t<std::is_constructible<BasicJsonType, T>::value,
int> = 0>
5917void to_json(BasicJsonType& j,
const std::optional<T>& opt)
5919 if (opt.has_value())
5930template<
typename BasicJsonType,
typename T,
5931 enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value,
int> = 0>
5932inline void to_json(BasicJsonType& j, T b)
noexcept
5934 external_constructor<value_t::boolean>::construct(j, b);
5937template <
typename BasicJsonType,
typename BoolRef,
5939 ((std::is_same<std::vector<bool>::reference, BoolRef>::value
5940 && !std::is_same <std::vector<bool>::reference,
typename BasicJsonType::boolean_t&>
::value)
5941 || (std::is_same<std::vector<bool>::const_reference, BoolRef>::value
5942 && !std::is_same <detail::uncvref_t<std::vector<bool>::const_reference>,
5943 typename BasicJsonType::boolean_t >
::value))
5944 && std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value,
int > = 0 >
5945inline void to_json(BasicJsonType& j,
const BoolRef& b)
noexcept
5947 external_constructor<value_t::boolean>::construct(j,
static_cast<typename BasicJsonType::boolean_t
>(b));
5950template<
typename BasicJsonType,
typename CompatibleString,
5951 enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value,
int> = 0>
5952inline void to_json(BasicJsonType& j,
const CompatibleString& s)
5954 external_constructor<value_t::string>::construct(j, s);
5957template<
typename BasicJsonType>
5958inline void to_json(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
5960 external_constructor<value_t::string>::construct(j, std::move(s));
5963template<
typename BasicJsonType,
typename FloatType,
5964 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
5965inline void to_json(BasicJsonType& j, FloatType val)
noexcept
5967 external_constructor<value_t::number_float>::construct(j,
static_cast<typename BasicJsonType::number_float_t
>(val));
5970template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
5971 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value,
int> = 0>
5972inline void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val)
noexcept
5974 external_constructor<value_t::number_unsigned>::construct(j,
static_cast<typename BasicJsonType::number_unsigned_t
>(val));
5977template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
5978 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value,
int> = 0>
5979inline void to_json(BasicJsonType& j, CompatibleNumberIntegerType val)
noexcept
5981 external_constructor<value_t::number_integer>::construct(j,
static_cast<typename BasicJsonType::number_integer_t
>(val));
5984#if !JSON_DISABLE_ENUM_SERIALIZATION
5985template<
typename BasicJsonType,
typename EnumType,
5986 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
5987inline void to_json(BasicJsonType& j, EnumType e)
noexcept
5989 using underlying_type =
typename std::underlying_type<EnumType>::type;
5991 external_constructor<integral_value_t>::construct(j,
static_cast<underlying_type
>(e));
5995template<
typename BasicJsonType>
5996inline void to_json(BasicJsonType& j,
const std::vector<bool>& e)
5998 external_constructor<value_t::array>::construct(j, e);
6001template <
typename BasicJsonType,
typename CompatibleArrayType,
6002 enable_if_t < is_compatible_array_type<BasicJsonType,
6003 CompatibleArrayType>::value&&
6004 !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&&
6005 !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&&
6006 !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
6007 !is_basic_json<CompatibleArrayType>::value,
6009inline void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
6011 external_constructor<value_t::array>::construct(j, arr);
6014template<
typename BasicJsonType>
6015inline void to_json(BasicJsonType& j,
const typename BasicJsonType::binary_t& bin)
6017 external_constructor<value_t::binary>::construct(j, bin);
6020template<
typename BasicJsonType,
typename T,
6021 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
6022inline void to_json(BasicJsonType& j,
const std::valarray<T>& arr)
6024 external_constructor<value_t::array>::construct(j, std::move(arr));
6027template<
typename BasicJsonType>
6028inline void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
6030 external_constructor<value_t::array>::construct(j, std::move(arr));
6033template <
typename BasicJsonType,
typename CompatibleObjectType,
6034 enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value,
int > = 0 >
6035inline void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
6037 external_constructor<value_t::object>::construct(j, obj);
6040template<
typename BasicJsonType>
6041inline void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
6043 external_constructor<value_t::object>::construct(j, std::move(obj));
6047 typename BasicJsonType,
typename T, std::size_t N,
6048 enable_if_t < !std::is_constructible<
typename BasicJsonType::string_t,
6051inline void to_json(BasicJsonType& j,
const T(&arr)[N])
6053 external_constructor<value_t::array>::construct(j, arr);
6056template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value,
int > = 0 >
6057inline void to_json(BasicJsonType& j,
const std::pair<T1, T2>& p)
6059 j = { p.first, p.second };
6063template<
typename BasicJsonType,
typename T,
6064 enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>
::value,
int> = 0>
6065inline void to_json(BasicJsonType& j,
const T& b)
6067 j = { {b.key(), b.value()} };
6070template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
6071inline void to_json_tuple_impl(BasicJsonType& j,
const Tuple& t, index_sequence<Idx...> )
6073 j = { std::get<Idx>(t)... };
6076template<
typename BasicJsonType,
typename Tuple>
6077inline void to_json_tuple_impl(BasicJsonType& j,
const Tuple& , index_sequence<> )
6079 using array_t =
typename BasicJsonType::array_t;
6083template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value,
int > = 0>
6084inline void to_json(BasicJsonType& j,
const T& t)
6086 to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
6089#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
6090template<
typename BasicJsonType>
6091inline void to_json(BasicJsonType& j,
const std_fs::path& p)
6093#ifdef JSON_HAS_CPP_20
6094 const std::u8string s = p.u8string();
6095 j = std::string(s.begin(), s.end());
6104 template<
typename BasicJsonType,
typename T>
6105 auto operator()(BasicJsonType& j, T&& val)
const noexcept(
noexcept(to_json(j, std::forward<T>(val))))
6106 ->
decltype(to_json(j, std::forward<T>(val)),
void())
6108 return to_json(j, std::forward<T>(val));
6113#ifndef JSON_HAS_CPP_17
6120JSON_INLINE_VARIABLE
constexpr const auto& to_json =
6122#ifndef JSON_HAS_CPP_17
6126NLOHMANN_JSON_NAMESPACE_END
6131NLOHMANN_JSON_NAMESPACE_BEGIN
6134template<
typename ValueType,
typename>
6139 template<
typename BasicJsonType,
typename TargetType = ValueType>
6140 static auto from_json(BasicJsonType && j, TargetType& val)
noexcept(
6141 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
6142 ->
decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val),
void())
6144 ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
6149 template<
typename BasicJsonType,
typename TargetType = ValueType>
6159 template<
typename BasicJsonType,
typename TargetType = ValueType>
6160 static auto to_json(BasicJsonType& j, TargetType && val)
noexcept(
6161 noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
6162 ->
decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)),
void())
6164 ::nlohmann::to_json(j, std::forward<TargetType>(val));
6168NLOHMANN_JSON_NAMESPACE_END
6188NLOHMANN_JSON_NAMESPACE_BEGIN
6192template<
typename BinaryType>
6196 using container_type = BinaryType;
6197 using subtype_type = std::uint64_t;
6211 : container_type(std::move(b))
6217 , m_subtype(subtype_)
6218 , m_has_subtype(true)
6223 : container_type(std::move(b))
6224 , m_subtype(subtype_)
6225 , m_has_subtype(true)
6230 return std::tie(
static_cast<const BinaryType&
>(*
this), m_subtype, m_has_subtype) ==
6231 std::tie(
static_cast<const BinaryType&
>(rhs), rhs.m_subtype, rhs.m_has_subtype);
6236 return !(rhs == *
this);
6243 m_subtype = subtype_;
6244 m_has_subtype =
true;
6251 return m_has_subtype ? m_subtype :
static_cast<subtype_type
>(-1);
6258 return m_has_subtype;
6266 m_has_subtype =
false;
6270 subtype_type m_subtype = 0;
6271 bool m_has_subtype =
false;
6274NLOHMANN_JSON_NAMESPACE_END
6295#include <functional>
6302NLOHMANN_JSON_NAMESPACE_BEGIN
6307inline std::size_t combine(std::size_t seed, std::size_t h)
noexcept
6309 seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
6324template<
typename BasicJsonType>
6325std::size_t
hash(
const BasicJsonType& j)
6327 using string_t =
typename BasicJsonType::string_t;
6328 using number_integer_t =
typename BasicJsonType::number_integer_t;
6329 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6330 using number_float_t =
typename BasicJsonType::number_float_t;
6332 const auto type =
static_cast<std::size_t
>(j.type());
6335 case BasicJsonType::value_t::null:
6336 case BasicJsonType::value_t::discarded:
6338 return combine(type, 0);
6341 case BasicJsonType::value_t::object:
6343 auto seed = combine(type, j.size());
6344 for (
const auto& element : j.items())
6346 const auto h = std::hash<string_t> {}(element.key());
6347 seed = combine(seed, h);
6348 seed = combine(seed,
hash(element.value()));
6353 case BasicJsonType::value_t::array:
6355 auto seed = combine(type, j.size());
6356 for (
const auto& element : j)
6358 seed = combine(seed,
hash(element));
6363 case BasicJsonType::value_t::string:
6365 const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
6366 return combine(type, h);
6369 case BasicJsonType::value_t::boolean:
6371 const auto h = std::hash<bool> {}(j.template get<bool>());
6372 return combine(type, h);
6375 case BasicJsonType::value_t::number_integer:
6377 const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
6378 return combine(type, h);
6381 case BasicJsonType::value_t::number_unsigned:
6383 const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
6384 return combine(type, h);
6387 case BasicJsonType::value_t::number_float:
6389 const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
6390 return combine(type, h);
6393 case BasicJsonType::value_t::binary:
6395 auto seed = combine(type, j.get_binary().size());
6396 const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
6397 seed = combine(seed, h);
6398 seed = combine(seed,
static_cast<std::size_t
>(j.get_binary().subtype()));
6399 for (
const auto byte : j.get_binary())
6401 seed = combine(seed, std::hash<std::uint8_t> {}(
byte));
6413NLOHMANN_JSON_NAMESPACE_END
6438#ifdef __cpp_lib_byteswap
6462#include <type_traits>
6479NLOHMANN_JSON_NAMESPACE_BEGIN
6498 using char_type = char;
6500 JSON_HEDLEY_NON_NULL(2)
6504 JSON_ASSERT(m_file !=
nullptr);
6514 std::char_traits<char>::int_type get_character()
noexcept
6516 return std::fgetc(m_file);
6521 std::size_t get_elements(T* dest, std::size_t count = 1)
6523 return fread(dest, 1,
sizeof(T) * count, m_file);
6543 using char_type = char;
6551 is->clear(is->rdstate() & std::ios::eofbit);
6556 : is(&i), sb(i.rdbuf())
6565 : is(rhs.is), sb(rhs.sb)
6574 std::char_traits<char>::int_type get_character()
6576 auto res = sb->sbumpc();
6578 if (JSON_HEDLEY_UNLIKELY(res == std::char_traits<char>::eof()))
6580 is->clear(is->rdstate() | std::ios::eofbit);
6586 std::size_t get_elements(T* dest, std::size_t count = 1)
6588 auto res =
static_cast<std::size_t
>(sb->sgetn(
reinterpret_cast<char*
>(dest),
static_cast<std::streamsize
>(count *
sizeof(T))));
6589 if (JSON_HEDLEY_UNLIKELY(res < count *
sizeof(T)))
6591 is->clear(is->rdstate() | std::ios::eofbit);
6598 std::istream* is =
nullptr;
6599 std::streambuf* sb =
nullptr;
6605template<
typename IteratorType>
6609 using char_type =
typename std::iterator_traits<IteratorType>::value_type;
6612 : current(std::move(first)), end(std::move(last))
6617 if (JSON_HEDLEY_LIKELY(current != end))
6620 std::advance(current, 1);
6629 std::size_t get_elements(T* dest, std::size_t count = 1)
6631 auto* ptr =
reinterpret_cast<char*
>(dest);
6632 for (std::size_t read_index = 0; read_index < count *
sizeof(T); ++read_index)
6634 if (JSON_HEDLEY_LIKELY(current != end))
6636 ptr[read_index] =
static_cast<char>(*current);
6637 std::advance(current, 1);
6644 return count *
sizeof(T);
6648 IteratorType current;
6651 template<
typename BaseInputAdapter,
size_t T>
6656 return current == end;
6660template<
typename BaseInputAdapter,
size_t T>
6663template<
typename BaseInputAdapter>
6667 static void fill_buffer(BaseInputAdapter& input,
6668 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
6669 size_t& utf8_bytes_index,
6670 size_t& utf8_bytes_filled)
6672 utf8_bytes_index = 0;
6674 if (JSON_HEDLEY_UNLIKELY(input.empty()))
6676 utf8_bytes[0] = std::char_traits<char>::eof();
6677 utf8_bytes_filled = 1;
6682 const auto wc = input.get_character();
6687 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6688 utf8_bytes_filled = 1;
6690 else if (wc <= 0x7FF)
6692 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
6693 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6694 utf8_bytes_filled = 2;
6696 else if (wc <= 0xFFFF)
6698 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
6699 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6700 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6701 utf8_bytes_filled = 3;
6703 else if (wc <= 0x10FFFF)
6705 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | ((
static_cast<unsigned int>(wc) >> 18u) & 0x07u));
6706 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
6707 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6708 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6709 utf8_bytes_filled = 4;
6714 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6715 utf8_bytes_filled = 1;
6721template<
typename BaseInputAdapter>
6725 static void fill_buffer(BaseInputAdapter& input,
6726 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
6727 size_t& utf8_bytes_index,
6728 size_t& utf8_bytes_filled)
6730 utf8_bytes_index = 0;
6732 if (JSON_HEDLEY_UNLIKELY(input.empty()))
6734 utf8_bytes[0] = std::char_traits<char>::eof();
6735 utf8_bytes_filled = 1;
6740 const auto wc = input.get_character();
6745 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6746 utf8_bytes_filled = 1;
6748 else if (wc <= 0x7FF)
6750 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u)));
6751 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6752 utf8_bytes_filled = 2;
6754 else if (0xD800 > wc || wc >= 0xE000)
6756 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u)));
6757 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6758 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6759 utf8_bytes_filled = 3;
6763 if (JSON_HEDLEY_UNLIKELY(!input.empty()))
6765 const auto wc2 =
static_cast<unsigned int>(input.get_character());
6766 const auto charcode = 0x10000u + (((
static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
6767 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | (charcode >> 18u));
6768 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 12u) & 0x3Fu));
6769 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 6u) & 0x3Fu));
6770 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (charcode & 0x3Fu));
6771 utf8_bytes_filled = 4;
6775 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6776 utf8_bytes_filled = 1;
6784template<
typename BaseInputAdapter,
typename W
ideCharType>
6788 using char_type = char;
6791 : base_adapter(base) {}
6793 typename std::char_traits<char>::int_type get_character()
noexcept
6796 if (utf8_bytes_index == utf8_bytes_filled)
6798 fill_buffer<sizeof(WideCharType)>();
6800 JSON_ASSERT(utf8_bytes_filled > 0);
6801 JSON_ASSERT(utf8_bytes_index == 0);
6805 JSON_ASSERT(utf8_bytes_filled > 0);
6806 JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);
6807 return utf8_bytes[utf8_bytes_index++];
6812 std::size_t get_elements(T* , std::size_t = 1)
6814 JSON_THROW(
parse_error::create(112, 1,
"wide string type cannot be interpreted as binary data",
nullptr));
6818 BaseInputAdapter base_adapter;
6827 std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
6830 std::size_t utf8_bytes_index = 0;
6832 std::size_t utf8_bytes_filled = 0;
6835template<
typename IteratorType,
typename Enable =
void>
6838 using iterator_type = IteratorType;
6839 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
6842 static adapter_type create(IteratorType first, IteratorType last)
6844 return adapter_type(std::move(first), std::move(last));
6851 using value_type =
typename std::iterator_traits<T>::value_type;
6854 value =
sizeof(value_type) > 1
6858template<
typename IteratorType>
6861 using iterator_type = IteratorType;
6862 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
6866 static adapter_type create(IteratorType first, IteratorType last)
6873template<
typename IteratorType>
6877 return factory_type::create(first, last);
6884namespace container_input_adapter_factory_impl
6890template<
typename ContainerType,
typename Enable =
void>
6893template<
typename ContainerType>
6895 void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
6897 using adapter_type =
decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
6899 static adapter_type create(
const ContainerType& container)
6901 return input_adapter(begin(container), end(container));
6907template<
typename ContainerType>
6914using string_input_adapter_type =
decltype(input_adapter(std::declval<std::string>()));
6918inline file_input_adapter input_adapter(std::FILE* file)
6920 if (file ==
nullptr)
6922 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));
6924 return file_input_adapter(file);
6927inline input_stream_adapter input_adapter(std::istream& stream)
6929 return input_stream_adapter(stream);
6932inline input_stream_adapter input_adapter(std::istream&& stream)
6934 return input_stream_adapter(stream);
6938using contiguous_bytes_input_adapter =
decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
6941template <
typename CharT,
6942 typename std::enable_if <
6943 std::is_pointer<CharT>::value&&
6944 !std::is_array<CharT>::value&&
6945 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
6946 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
6948contiguous_bytes_input_adapter input_adapter(CharT b)
6952 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));
6954 auto length = std::strlen(
reinterpret_cast<const char*
>(b));
6955 const auto* ptr =
reinterpret_cast<const char*
>(b);
6956 return input_adapter(ptr, ptr + length);
6959template<
typename T, std::
size_t N>
6960auto input_adapter(T (&array)[N]) ->
decltype(input_adapter(array, array + N))
6962 return input_adapter(array, array + N);
6971 template <
typename CharT,
6972 typename std::enable_if <
6973 std::is_pointer<CharT>::value&&
6974 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
6975 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
6978 : ia(
reinterpret_cast<const char*
>(b),
reinterpret_cast<const char*
>(b) + l) {}
6980 template<
class IteratorType,
6981 typename std::enable_if<
6982 std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>
::value,
6985 : ia(input_adapter(first, last)) {}
6987 contiguous_bytes_input_adapter&& get()
6989 return std::move(ia);
6993 contiguous_bytes_input_adapter ia;
6997NLOHMANN_JSON_NAMESPACE_END
7012#include <type_traits>
7034#include <initializer_list>
7048NLOHMANN_JSON_NAMESPACE_BEGIN
7056template<
typename BasicJsonType>
7083 JSON_HEDLEY_RETURNS_NON_NULL
7090 return "<uninitialized>";
7092 return "true literal";
7094 return "false literal";
7096 return "null literal";
7098 return "string literal";
7102 return "number literal";
7116 return "<parse error>";
7118 return "end of input";
7120 return "'[', '{', or a literal";
7123 return "unknown token";
7133template<
typename BasicJsonType,
typename InputAdapterType>
7136 using number_integer_t =
typename BasicJsonType::number_integer_t;
7137 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7138 using number_float_t =
typename BasicJsonType::number_float_t;
7139 using string_t =
typename BasicJsonType::string_t;
7140 using char_type =
typename InputAdapterType::char_type;
7146 explicit lexer(InputAdapterType&& adapter,
bool ignore_comments_ =
false) noexcept
7147 : ia(std::move(adapter))
7148 , ignore_comments(ignore_comments_)
7149 , decimal_point_char(
static_cast<char_int_type
>(get_decimal_point()))
7166 static char get_decimal_point()
noexcept
7168 const auto* loc = localeconv();
7169 JSON_ASSERT(loc !=
nullptr);
7170 return (loc->decimal_point ==
nullptr) ?
'.' : *(loc->decimal_point);
7195 JSON_ASSERT(current ==
'u');
7198 const auto factors = { 12u, 8u, 4u, 0u };
7199 for (
const auto factor : factors)
7203 if (current >=
'0' && current <=
'9')
7205 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x30u) << factor);
7207 else if (current >=
'A' && current <=
'F')
7209 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x37u) << factor);
7211 else if (current >=
'a' && current <=
'f')
7213 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x57u) << factor);
7221 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
7240 bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
7242 JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
7245 for (
auto range = ranges.begin(); range != ranges.end(); ++range)
7248 if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range)))
7254 error_message =
"invalid string: ill-formed UTF-8 byte";
7277 token_type scan_string()
7283 JSON_ASSERT(current ==
'\"');
7293 error_message =
"invalid string: missing closing quote";
7294 return token_type::parse_error;
7300 return token_type::value_string;
7344 const int codepoint1 = get_codepoint();
7345 int codepoint = codepoint1;
7347 if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
7349 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7350 return token_type::parse_error;
7354 if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
7357 if (JSON_HEDLEY_LIKELY(get() ==
'\\' && get() ==
'u'))
7359 const int codepoint2 = get_codepoint();
7361 if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
7363 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7364 return token_type::parse_error;
7368 if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))
7371 codepoint =
static_cast<int>(
7373 (
static_cast<unsigned int>(codepoint1) << 10u)
7375 +
static_cast<unsigned int>(codepoint2)
7383 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
7384 return token_type::parse_error;
7389 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
7390 return token_type::parse_error;
7395 if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))
7397 error_message =
"invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
7398 return token_type::parse_error;
7403 JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
7406 if (codepoint < 0x80)
7409 add(
static_cast<char_int_type
>(codepoint));
7411 else if (codepoint <= 0x7FF)
7414 add(
static_cast<char_int_type
>(0xC0u | (
static_cast<unsigned int>(codepoint) >> 6u)));
7415 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7417 else if (codepoint <= 0xFFFF)
7420 add(
static_cast<char_int_type
>(0xE0u | (
static_cast<unsigned int>(codepoint) >> 12u)));
7421 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7422 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7427 add(
static_cast<char_int_type
>(0xF0u | (
static_cast<unsigned int>(codepoint) >> 18u)));
7428 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
7429 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7430 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7438 error_message =
"invalid string: forbidden character after backslash";
7439 return token_type::parse_error;
7448 error_message =
"invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
7449 return token_type::parse_error;
7454 error_message =
"invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
7455 return token_type::parse_error;
7460 error_message =
"invalid string: control character U+0002 (STX) must be escaped to \\u0002";
7461 return token_type::parse_error;
7466 error_message =
"invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
7467 return token_type::parse_error;
7472 error_message =
"invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
7473 return token_type::parse_error;
7478 error_message =
"invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
7479 return token_type::parse_error;
7484 error_message =
"invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
7485 return token_type::parse_error;
7490 error_message =
"invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
7491 return token_type::parse_error;
7496 error_message =
"invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
7497 return token_type::parse_error;
7502 error_message =
"invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
7503 return token_type::parse_error;
7508 error_message =
"invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
7509 return token_type::parse_error;
7514 error_message =
"invalid string: control character U+000B (VT) must be escaped to \\u000B";
7515 return token_type::parse_error;
7520 error_message =
"invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
7521 return token_type::parse_error;
7526 error_message =
"invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
7527 return token_type::parse_error;
7532 error_message =
"invalid string: control character U+000E (SO) must be escaped to \\u000E";
7533 return token_type::parse_error;
7538 error_message =
"invalid string: control character U+000F (SI) must be escaped to \\u000F";
7539 return token_type::parse_error;
7544 error_message =
"invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
7545 return token_type::parse_error;
7550 error_message =
"invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
7551 return token_type::parse_error;
7556 error_message =
"invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
7557 return token_type::parse_error;
7562 error_message =
"invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
7563 return token_type::parse_error;
7568 error_message =
"invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
7569 return token_type::parse_error;
7574 error_message =
"invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
7575 return token_type::parse_error;
7580 error_message =
"invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
7581 return token_type::parse_error;
7586 error_message =
"invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
7587 return token_type::parse_error;
7592 error_message =
"invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
7593 return token_type::parse_error;
7598 error_message =
"invalid string: control character U+0019 (EM) must be escaped to \\u0019";
7599 return token_type::parse_error;
7604 error_message =
"invalid string: control character U+001A (SUB) must be escaped to \\u001A";
7605 return token_type::parse_error;
7610 error_message =
"invalid string: control character U+001B (ESC) must be escaped to \\u001B";
7611 return token_type::parse_error;
7616 error_message =
"invalid string: control character U+001C (FS) must be escaped to \\u001C";
7617 return token_type::parse_error;
7622 error_message =
"invalid string: control character U+001D (GS) must be escaped to \\u001D";
7623 return token_type::parse_error;
7628 error_message =
"invalid string: control character U+001E (RS) must be escaped to \\u001E";
7629 return token_type::parse_error;
7634 error_message =
"invalid string: control character U+001F (US) must be escaped to \\u001F";
7635 return token_type::parse_error;
7770 if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
7772 return token_type::parse_error;
7780 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
7782 return token_type::parse_error;
7804 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
7806 return token_type::parse_error;
7814 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
7816 return token_type::parse_error;
7824 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7826 return token_type::parse_error;
7836 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7838 return token_type::parse_error;
7846 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
7848 return token_type::parse_error;
7856 error_message =
"invalid string: ill-formed UTF-8 byte";
7857 return token_type::parse_error;
7900 error_message =
"invalid comment; missing closing '*/'";
7928 error_message =
"invalid comment; expecting '/' or '*' after '/'";
7934 JSON_HEDLEY_NON_NULL(2)
7935 static void strtof(
float& f,
const char* str,
char** endptr)
noexcept
7937 f = std::strtof(str, endptr);
7940 JSON_HEDLEY_NON_NULL(2)
7941 static void strtof(
double& f,
const char* str,
char** endptr)
noexcept
7943 f = std::strtod(str, endptr);
7946 JSON_HEDLEY_NON_NULL(2)
7947 static void strtof(
long double& f,
const char* str,
char** endptr)
noexcept
7949 f = std::strtold(str, endptr);
7992 token_type scan_number()
7999 token_type number_type = token_type::value_unsigned;
8007 goto scan_number_minus;
8013 goto scan_number_zero;
8027 goto scan_number_any1;
8037 number_type = token_type::value_integer;
8043 goto scan_number_zero;
8057 goto scan_number_any1;
8062 error_message =
"invalid number; expected digit after '-'";
8063 return token_type::parse_error;
8073 add(decimal_point_char);
8074 decimal_point_position = token_buffer.size() - 1;
8075 goto scan_number_decimal1;
8082 goto scan_number_exponent;
8086 goto scan_number_done;
8105 goto scan_number_any1;
8110 add(decimal_point_char);
8111 decimal_point_position = token_buffer.size() - 1;
8112 goto scan_number_decimal1;
8119 goto scan_number_exponent;
8123 goto scan_number_done;
8126scan_number_decimal1:
8128 number_type = token_type::value_float;
8143 goto scan_number_decimal2;
8148 error_message =
"invalid number; expected digit after '.'";
8149 return token_type::parse_error;
8153scan_number_decimal2:
8169 goto scan_number_decimal2;
8176 goto scan_number_exponent;
8180 goto scan_number_done;
8183scan_number_exponent:
8185 number_type = token_type::value_float;
8192 goto scan_number_sign;
8207 goto scan_number_any2;
8213 "invalid number; expected '+', '-', or digit after exponent";
8214 return token_type::parse_error;
8234 goto scan_number_any2;
8239 error_message =
"invalid number; expected digit after exponent sign";
8240 return token_type::parse_error;
8260 goto scan_number_any2;
8264 goto scan_number_done;
8272 char* endptr =
nullptr;
8276 if (number_type == token_type::value_unsigned)
8278 const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
8281 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8283 if (errno != ERANGE)
8285 value_unsigned =
static_cast<number_unsigned_t
>(x);
8286 if (value_unsigned == x)
8288 return token_type::value_unsigned;
8292 else if (number_type == token_type::value_integer)
8294 const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
8297 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8299 if (errno != ERANGE)
8301 value_integer =
static_cast<number_integer_t
>(x);
8302 if (value_integer == x)
8304 return token_type::value_integer;
8311 strtof(value_float, token_buffer.data(), &endptr);
8314 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8316 return token_type::value_float;
8324 JSON_HEDLEY_NON_NULL(2)
8325 token_type scan_literal(
const char_type* literal_text,
const std::size_t length,
8326 token_type return_type)
8329 for (std::size_t i = 1; i < length; ++i)
8333 error_message =
"invalid literal";
8334 return token_type::parse_error;
8345 void reset()
noexcept
8347 token_buffer.clear();
8348 token_string.clear();
8349 decimal_point_position = std::string::npos;
8375 current = ia.get_character();
8383 if (current ==
'\n')
8421 JSON_ASSERT(!token_string.empty());
8422 token_string.pop_back();
8427 void add(char_int_type c)
8429 token_buffer.push_back(
static_cast<typename string_t::value_type
>(c));
8440 return value_integer;
8446 return value_unsigned;
8459 if (decimal_point_char !=
'.' && decimal_point_position != std::string::npos)
8461 token_buffer[decimal_point_position] =
'.';
8463 return token_buffer;
8483 for (
const auto c : token_string)
8485 if (
static_cast<unsigned char>(c) <=
'\x1F')
8488 std::array<char, 9> cs{{}};
8489 static_cast<void>((std::snprintf)(cs.data(), cs.size(),
"<U+%.4X>",
static_cast<unsigned char>(c)));
8490 result += cs.data();
8495 result.push_back(
static_cast<std::string::value_type
>(c));
8503 JSON_HEDLEY_RETURNS_NON_NULL
8506 return error_message;
8522 return get() == 0xBB && get() == 0xBF;
8531 void skip_whitespace()
8537 while (current ==
' ' || current ==
'\t' || current ==
'\n' || current ==
'\r');
8545 error_message =
"invalid BOM; must be 0xEF 0xBB 0xBF if given";
8546 return token_type::parse_error;
8553 while (ignore_comments && current ==
'/')
8555 if (!scan_comment())
8557 return token_type::parse_error;
8568 return token_type::begin_array;
8570 return token_type::end_array;
8572 return token_type::begin_object;
8574 return token_type::end_object;
8576 return token_type::name_separator;
8578 return token_type::value_separator;
8583 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')}};
8584 return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
8588 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')}};
8589 return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
8593 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')}};
8594 return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
8599 return scan_string();
8613 return scan_number();
8618 case char_traits<char_type>::eof():
8623 error_message =
"invalid literal";
8624 return token_type::parse_error;
8630 InputAdapterType ia;
8633 const bool ignore_comments =
false;
8636 char_int_type current = char_traits<char_type>::eof();
8639 bool next_unget =
false;
8642 position_t position {};
8645 std::vector<char_type> token_string {};
8648 string_t token_buffer {};
8651 const char* error_message =
"";
8654 number_integer_t value_integer = 0;
8655 number_unsigned_t value_unsigned = 0;
8656 number_float_t value_float = 0;
8659 const char_int_type decimal_point_char =
'.';
8661 std::size_t decimal_point_position = std::string::npos;
8665NLOHMANN_JSON_NAMESPACE_END
8671NLOHMANN_JSON_NAMESPACE_BEGIN
8681template<
typename BasicJsonType>
8684 using number_integer_t =
typename BasicJsonType::number_integer_t;
8685 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8686 using number_float_t =
typename BasicJsonType::number_float_t;
8687 using string_t =
typename BasicJsonType::string_t;
8688 using binary_t =
typename BasicJsonType::binary_t;
8755 virtual bool key(string_t& val) = 0;
8785 const std::string& last_token,
8798constexpr std::size_t unknown_size()
8800 return (std::numeric_limits<std::size_t>::max)();
8816template<
typename BasicJsonType,
typename InputAdapterType>
8820 using number_integer_t =
typename BasicJsonType::number_integer_t;
8821 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8822 using number_float_t =
typename BasicJsonType::number_float_t;
8823 using string_t =
typename BasicJsonType::string_t;
8824 using binary_t =
typename BasicJsonType::binary_t;
8833 : root(r), allow_exceptions(allow_exceptions_), m_lexer_ref(lexer_)
8845 handle_value(
nullptr);
8849 bool boolean(
bool val)
8867 bool number_float(number_float_t val,
const string_t& )
8873 bool string(string_t& val)
8879 bool binary(binary_t& val)
8881 handle_value(std::move(val));
8885 bool start_object(std::size_t len)
8887 ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
8889#if JSON_DIAGNOSTIC_POSITIONS
8896 ref_stack.back()->start_position = m_lexer_ref->get_position() - 1;
8900 if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
8902 JSON_THROW(out_of_range::create(408, concat(
"excessive object size: ", std::to_string(len)), ref_stack.back()));
8908 bool key(string_t& val)
8910 JSON_ASSERT(!ref_stack.empty());
8911 JSON_ASSERT(ref_stack.back()->is_object());
8914 object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val));
8920 JSON_ASSERT(!ref_stack.empty());
8921 JSON_ASSERT(ref_stack.back()->is_object());
8923#if JSON_DIAGNOSTIC_POSITIONS
8927 ref_stack.back()->end_position = m_lexer_ref->get_position();
8931 ref_stack.back()->set_parents();
8932 ref_stack.pop_back();
8936 bool start_array(std::size_t len)
8938 ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
8940#if JSON_DIAGNOSTIC_POSITIONS
8945 ref_stack.back()->start_position = m_lexer_ref->get_position() - 1;
8949 if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
8951 JSON_THROW(out_of_range::create(408, concat(
"excessive array size: ", std::to_string(len)), ref_stack.back()));
8959 JSON_ASSERT(!ref_stack.empty());
8960 JSON_ASSERT(ref_stack.back()->is_array());
8962#if JSON_DIAGNOSTIC_POSITIONS
8966 ref_stack.back()->end_position = m_lexer_ref->get_position();
8970 ref_stack.back()->set_parents();
8971 ref_stack.pop_back();
8975 template<
class Exception>
8976 bool parse_error(std::size_t ,
const std::string& ,
8977 const Exception& ex)
8980 static_cast<void>(ex);
8981 if (allow_exceptions)
8988 constexpr bool is_errored()
const
8995#if JSON_DIAGNOSTIC_POSITIONS
8996 void handle_diagnostic_positions_for_json_value(BasicJsonType& v)
9003 v.end_position = m_lexer_ref->get_position();
9007 case value_t::boolean:
9010 v.start_position = v.end_position - (v.m_data.m_value.boolean ? 4 : 5);
9017 v.start_position = v.end_position - 4;
9021 case value_t::string:
9024 v.start_position = v.end_position - v.m_data.m_value.string->size() - 2;
9033 case value_t::discarded:
9035 v.end_position = std::string::npos;
9036 v.start_position = v.end_position;
9040 case value_t::binary:
9041 case value_t::number_integer:
9042 case value_t::number_unsigned:
9043 case value_t::number_float:
9045 v.start_position = v.end_position - m_lexer_ref->get_string().size();
9048 case value_t::object:
9049 case value_t::array:
9069 template<
typename Value>
9070 JSON_HEDLEY_RETURNS_NON_NULL
9071 BasicJsonType* handle_value(Value&& v)
9073 if (ref_stack.empty())
9075 root = BasicJsonType(std::forward<Value>(v));
9077#if JSON_DIAGNOSTIC_POSITIONS
9078 handle_diagnostic_positions_for_json_value(root);
9084 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
9086 if (ref_stack.back()->is_array())
9088 ref_stack.back()->m_data.m_value.array->emplace_back(std::forward<Value>(v));
9090#if JSON_DIAGNOSTIC_POSITIONS
9091 handle_diagnostic_positions_for_json_value(ref_stack.back()->m_data.m_value.array->back());
9094 return &(ref_stack.back()->m_data.m_value.array->back());
9097 JSON_ASSERT(ref_stack.back()->is_object());
9098 JSON_ASSERT(object_element);
9099 *object_element = BasicJsonType(std::forward<Value>(v));
9101#if JSON_DIAGNOSTIC_POSITIONS
9102 handle_diagnostic_positions_for_json_value(*object_element);
9105 return object_element;
9109 BasicJsonType& root;
9111 std::vector<BasicJsonType*> ref_stack {};
9113 BasicJsonType* object_element =
nullptr;
9115 bool errored =
false;
9117 const bool allow_exceptions =
true;
9119 lexer_t* m_lexer_ref =
nullptr;
9122template<
typename BasicJsonType,
typename InputAdapterType>
9126 using number_integer_t =
typename BasicJsonType::number_integer_t;
9127 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9128 using number_float_t =
typename BasicJsonType::number_float_t;
9129 using string_t =
typename BasicJsonType::string_t;
9130 using binary_t =
typename BasicJsonType::binary_t;
9131 using parser_callback_t =
typename BasicJsonType::parser_callback_t;
9132 using parse_event_t =
typename BasicJsonType::parse_event_t;
9136 parser_callback_t cb,
9137 const bool allow_exceptions_ =
true,
9139 : root(r), callback(std::move(cb)), allow_exceptions(allow_exceptions_), m_lexer_ref(lexer_)
9141 keep_stack.push_back(
true);
9153 handle_value(
nullptr);
9175 bool number_float(number_float_t val,
const string_t& )
9181 bool string(string_t& val)
9187 bool binary(binary_t& val)
9189 handle_value(std::move(val));
9193 bool start_object(std::size_t len)
9196 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::object_start,
discarded);
9197 keep_stack.push_back(keep);
9199 auto val = handle_value(BasicJsonType::value_t::object,
true);
9200 ref_stack.push_back(val.second);
9202 if (ref_stack.back())
9205#if JSON_DIAGNOSTIC_POSITIONS
9212 ref_stack.back()->start_position = m_lexer_ref->get_position() - 1;
9217 if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
9219 JSON_THROW(out_of_range::create(408, concat(
"excessive object size: ", std::to_string(len)), ref_stack.back()));
9225 bool key(string_t& val)
9227 BasicJsonType k = BasicJsonType(val);
9230 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::key, k);
9231 key_keep_stack.push_back(keep);
9234 if (keep && ref_stack.back())
9236 object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val) =
discarded);
9244 if (ref_stack.back())
9246 if (!callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
9251#if JSON_DIAGNOSTIC_POSITIONS
9253 handle_diagnostic_positions_for_json_value(*ref_stack.back());
9259#if JSON_DIAGNOSTIC_POSITIONS
9263 ref_stack.back()->end_position = m_lexer_ref->get_position();
9267 ref_stack.back()->set_parents();
9271 JSON_ASSERT(!ref_stack.empty());
9272 JSON_ASSERT(!keep_stack.empty());
9273 ref_stack.pop_back();
9274 keep_stack.pop_back();
9276 if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
9279 for (
auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
9281 if (it->is_discarded())
9283 ref_stack.back()->erase(it);
9292 bool start_array(std::size_t len)
9294 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::array_start,
discarded);
9295 keep_stack.push_back(keep);
9297 auto val = handle_value(BasicJsonType::value_t::array,
true);
9298 ref_stack.push_back(val.second);
9300 if (ref_stack.back())
9303#if JSON_DIAGNOSTIC_POSITIONS
9310 ref_stack.back()->start_position = m_lexer_ref->get_position() - 1;
9315 if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
9317 JSON_THROW(out_of_range::create(408, concat(
"excessive array size: ", std::to_string(len)), ref_stack.back()));
9328 if (ref_stack.back())
9330 keep = callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
9334#if JSON_DIAGNOSTIC_POSITIONS
9338 ref_stack.back()->end_position = m_lexer_ref->get_position();
9342 ref_stack.back()->set_parents();
9349#if JSON_DIAGNOSTIC_POSITIONS
9351 handle_diagnostic_positions_for_json_value(*ref_stack.back());
9356 JSON_ASSERT(!ref_stack.empty());
9357 JSON_ASSERT(!keep_stack.empty());
9358 ref_stack.pop_back();
9359 keep_stack.pop_back();
9362 if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
9364 ref_stack.back()->m_data.m_value.array->pop_back();
9370 template<
class Exception>
9371 bool parse_error(std::size_t ,
const std::string& ,
9372 const Exception& ex)
9375 static_cast<void>(ex);
9376 if (allow_exceptions)
9383 constexpr bool is_errored()
const
9390#if JSON_DIAGNOSTIC_POSITIONS
9391 void handle_diagnostic_positions_for_json_value(BasicJsonType& v)
9398 v.end_position = m_lexer_ref->get_position();
9402 case value_t::boolean:
9405 v.start_position = v.end_position - (v.m_data.m_value.boolean ? 4 : 5);
9412 v.start_position = v.end_position - 4;
9416 case value_t::string:
9419 v.start_position = v.end_position - v.m_data.m_value.string->size() - 2;
9423 case value_t::discarded:
9425 v.end_position = std::string::npos;
9426 v.start_position = v.end_position;
9430 case value_t::binary:
9431 case value_t::number_integer:
9432 case value_t::number_unsigned:
9433 case value_t::number_float:
9435 v.start_position = v.end_position - m_lexer_ref->get_string().size();
9439 case value_t::object:
9440 case value_t::array:
9469 template<
typename Value>
9470 std::pair<bool, BasicJsonType*> handle_value(Value&& v,
const bool skip_callback =
false)
9472 JSON_ASSERT(!keep_stack.empty());
9476 if (!keep_stack.back())
9478 return {
false,
nullptr};
9482 auto value = BasicJsonType(std::forward<Value>(v));
9484#if JSON_DIAGNOSTIC_POSITIONS
9485 handle_diagnostic_positions_for_json_value(value);
9489 const bool keep = skip_callback || callback(
static_cast<int>(ref_stack.size()), parse_event_t::value, value);
9494 return {
false,
nullptr};
9497 if (ref_stack.empty())
9499 root = std::move(value);
9500 return {
true, & root};
9505 if (!ref_stack.back())
9507 return {
false,
nullptr};
9511 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
9514 if (ref_stack.back()->is_array())
9516 ref_stack.back()->m_data.m_value.array->emplace_back(std::move(value));
9517 return {
true, & (ref_stack.back()->m_data.m_value.array->back())};
9521 JSON_ASSERT(ref_stack.back()->is_object());
9523 JSON_ASSERT(!key_keep_stack.empty());
9524 const bool store_element = key_keep_stack.back();
9525 key_keep_stack.pop_back();
9529 return {
false,
nullptr};
9532 JSON_ASSERT(object_element);
9533 *object_element = std::move(value);
9534 return {
true, object_element};
9538 BasicJsonType& root;
9540 std::vector<BasicJsonType*> ref_stack {};
9542 std::vector<bool> keep_stack {};
9544 std::vector<bool> key_keep_stack {};
9546 BasicJsonType* object_element =
nullptr;
9548 bool errored =
false;
9550 const parser_callback_t callback =
nullptr;
9552 const bool allow_exceptions =
true;
9554 BasicJsonType
discarded = BasicJsonType::value_t::discarded;
9556 lexer_t* m_lexer_ref =
nullptr;
9559template<
typename BasicJsonType>
9563 using number_integer_t =
typename BasicJsonType::number_integer_t;
9564 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9565 using number_float_t =
typename BasicJsonType::number_float_t;
9566 using string_t =
typename BasicJsonType::string_t;
9567 using binary_t =
typename BasicJsonType::binary_t;
9594 bool string(string_t& )
9599 bool binary(binary_t& )
9604 bool start_object(std::size_t = detail::unknown_size())
9609 bool key(string_t& )
9619 bool start_array(std::size_t = detail::unknown_size())
9636NLOHMANN_JSON_NAMESPACE_END
9664NLOHMANN_JSON_NAMESPACE_BEGIN
9669using null_function_t =
decltype(std::declval<T&>().null());
9672using boolean_function_t =
9673 decltype(std::declval<T&>().boolean(std::declval<bool>()));
9675template<
typename T,
typename Integer>
9676using number_integer_function_t =
9677 decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
9679template<
typename T,
typename Un
signed>
9680using number_unsigned_function_t =
9681 decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
9683template<
typename T,
typename Float,
typename String>
9684using number_float_function_t =
decltype(std::declval<T&>().number_float(
9685 std::declval<Float>(), std::declval<const String&>()));
9687template<
typename T,
typename String>
9688using string_function_t =
9689 decltype(std::declval<T&>().string(std::declval<String&>()));
9691template<
typename T,
typename Binary>
9692using binary_function_t =
9693 decltype(std::declval<T&>().binary(std::declval<Binary&>()));
9696using start_object_function_t =
9697 decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
9699template<
typename T,
typename String>
9700using key_function_t =
9701 decltype(std::declval<T&>().key(std::declval<String&>()));
9704using end_object_function_t =
decltype(std::declval<T&>().end_object());
9707using start_array_function_t =
9708 decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
9711using end_array_function_t =
decltype(std::declval<T&>().end_array());
9713template<
typename T,
typename Exception>
9714using parse_error_function_t =
decltype(std::declval<T&>().parse_error(
9715 std::declval<std::size_t>(), std::declval<const std::string&>(),
9716 std::declval<const Exception&>()));
9718template<
typename SAX,
typename BasicJsonType>
9723 "BasicJsonType must be of type basic_json<...>");
9725 using number_integer_t =
typename BasicJsonType::number_integer_t;
9726 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9727 using number_float_t =
typename BasicJsonType::number_float_t;
9728 using string_t =
typename BasicJsonType::string_t;
9729 using binary_t =
typename BasicJsonType::binary_t;
9730 using exception_t =
typename BasicJsonType::exception;
9733 static constexpr bool value =
9734 is_detected_exact<bool, null_function_t, SAX>::value &&
9735 is_detected_exact<bool, boolean_function_t, SAX>::value &&
9736 is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
9737 is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
9738 is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
9739 is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
9740 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
9741 is_detected_exact<bool, start_object_function_t, SAX>::value &&
9742 is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
9743 is_detected_exact<bool, end_object_function_t, SAX>::value &&
9744 is_detected_exact<bool, start_array_function_t, SAX>::value &&
9745 is_detected_exact<bool, end_array_function_t, SAX>::value &&
9746 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
9749template<
typename SAX,
typename BasicJsonType>
9754 "BasicJsonType must be of type basic_json<...>");
9756 using number_integer_t =
typename BasicJsonType::number_integer_t;
9757 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9758 using number_float_t =
typename BasicJsonType::number_float_t;
9759 using string_t =
typename BasicJsonType::string_t;
9760 using binary_t =
typename BasicJsonType::binary_t;
9761 using exception_t =
typename BasicJsonType::exception;
9764 static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
9765 "Missing/invalid function: bool null()");
9766 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
9767 "Missing/invalid function: bool boolean(bool)");
9768 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
9769 "Missing/invalid function: bool boolean(bool)");
9771 is_detected_exact<bool, number_integer_function_t, SAX,
9772 number_integer_t>::value,
9773 "Missing/invalid function: bool number_integer(number_integer_t)");
9775 is_detected_exact<bool, number_unsigned_function_t, SAX,
9776 number_unsigned_t>::value,
9777 "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
9778 static_assert(is_detected_exact<bool, number_float_function_t, SAX,
9779 number_float_t, string_t>::value,
9780 "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
9782 is_detected_exact<bool, string_function_t, SAX, string_t>::value,
9783 "Missing/invalid function: bool string(string_t&)");
9785 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
9786 "Missing/invalid function: bool binary(binary_t&)");
9787 static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
9788 "Missing/invalid function: bool start_object(std::size_t)");
9789 static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
9790 "Missing/invalid function: bool key(string_t&)");
9791 static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
9792 "Missing/invalid function: bool end_object()");
9793 static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
9794 "Missing/invalid function: bool start_array(std::size_t)");
9795 static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
9796 "Missing/invalid function: bool end_array()");
9798 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
9799 "Missing/invalid function: bool parse_error(std::size_t, const "
9800 "std::string&, const exception&)");
9804NLOHMANN_JSON_NAMESPACE_END
9813NLOHMANN_JSON_NAMESPACE_BEGIN
9832static inline bool little_endianness(
int num = 1) noexcept
9834 return *
reinterpret_cast<char*
>(&num) == 1;
9844template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX = json_sax_dom_parser<BasicJsonType, InputAdapterType>>
9847 using number_integer_t =
typename BasicJsonType::number_integer_t;
9848 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9849 using number_float_t =
typename BasicJsonType::number_float_t;
9850 using string_t =
typename BasicJsonType::string_t;
9851 using binary_t =
typename BasicJsonType::binary_t;
9852 using json_sax_t = SAX;
9853 using char_type =
typename InputAdapterType::char_type;
9862 explicit binary_reader(InputAdapterType&& adapter,
const input_format_t format = input_format_t::json) noexcept : ia(std::move(adapter)), input_format(format)
9882 JSON_HEDLEY_NON_NULL(3)
9885 const
bool strict = true,
9889 bool result =
false;
9893 case input_format_t::bson:
9894 result = parse_bson_internal();
9897 case input_format_t::cbor:
9898 result = parse_cbor_internal(
true, tag_handler);
9901 case input_format_t::msgpack:
9902 result = parse_msgpack_internal();
9905 case input_format_t::ubjson:
9906 case input_format_t::bjdata:
9907 result = parse_ubjson_internal();
9910 case input_format_t::json:
9918 if (input_format == input_format_t::ubjson || input_format == input_format_t::bjdata)
9929 return sax->parse_error(chars_read, get_token_string(), parse_error::create(110, chars_read,
9930 exception_message(input_format, concat(
"expected end of input; last byte: 0x", get_token_string()),
"value"),
nullptr));
9946 bool parse_bson_internal()
9948 std::int32_t document_size{};
9949 get_number<std::int32_t, true>(input_format_t::bson, document_size);
9951 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
9956 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
false)))
9961 return sax->end_object();
9971 bool get_bson_cstr(string_t& result)
9973 auto out = std::back_inserter(result);
9977 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"cstring")))
9981 if (current == 0x00)
9985 *out++ =
static_cast<typename string_t::value_type
>(current);
10000 template<
typename NumberType>
10001 bool get_bson_string(
const NumberType len, string_t& result)
10003 if (JSON_HEDLEY_UNLIKELY(len < 1))
10005 auto last_token = get_token_string();
10006 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
10007 exception_message(input_format_t::bson, concat(
"string length must be at least 1, is ", std::to_string(len)),
"string"),
nullptr));
10010 return get_string(input_format_t::bson, len -
static_cast<NumberType
>(1), result) && get() != char_traits<char_type>::eof();
10022 template<
typename NumberType>
10023 bool get_bson_binary(
const NumberType len, binary_t& result)
10025 if (JSON_HEDLEY_UNLIKELY(len < 0))
10027 auto last_token = get_token_string();
10028 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
10029 exception_message(input_format_t::bson, concat(
"byte array length cannot be negative, is ", std::to_string(len)),
"binary"),
nullptr));
10033 std::uint8_t subtype{};
10034 get_number<std::uint8_t>(input_format_t::bson, subtype);
10035 result.set_subtype(subtype);
10037 return get_binary(input_format_t::bson, len, result);
10050 bool parse_bson_element_internal(
const char_int_type element_type,
10051 const std::size_t element_type_parse_position)
10053 switch (element_type)
10058 return get_number<double, true>(input_format_t::bson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10063 std::int32_t len{};
10065 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
10070 return parse_bson_internal();
10075 return parse_bson_array();
10080 std::int32_t len{};
10082 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
10087 return sax->boolean(get() != 0);
10092 return sax->null();
10097 std::int32_t value{};
10098 return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
10103 std::int64_t value{};
10104 return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
10109 std::uint64_t value{};
10110 return get_number<std::uint64_t, true>(input_format_t::bson, value) && sax->number_unsigned(value);
10115 std::array<char, 3> cr{{}};
10116 static_cast<void>((std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(element_type)));
10117 const std::string cr_str{cr.data()};
10118 return sax->parse_error(element_type_parse_position, cr_str,
10119 parse_error::create(114, element_type_parse_position, concat(
"Unsupported BSON record type 0x", cr_str),
nullptr));
10136 bool parse_bson_element_list(
const bool is_array)
10140 while (
auto element_type = get())
10142 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"element list")))
10147 const std::size_t element_type_parse_position = chars_read;
10148 if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key)))
10153 if (!is_array && !sax->key(key))
10158 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
10174 bool parse_bson_array()
10176 std::int32_t document_size{};
10177 get_number<std::int32_t, true>(input_format_t::bson, document_size);
10179 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
10184 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
true)))
10189 return sax->end_array();
10204 bool parse_cbor_internal(
const bool get_char,
10205 const cbor_tag_handler_t tag_handler)
10207 switch (get_char ? get() : current)
10210 case char_traits<char_type>::eof():
10238 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
10242 std::uint8_t number{};
10243 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
10248 std::uint16_t number{};
10249 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
10254 std::uint32_t number{};
10255 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
10260 std::uint64_t number{};
10261 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
10289 return sax->number_integer(
static_cast<std::int8_t
>(0x20 - 1 - current));
10293 std::uint8_t number{};
10294 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
10299 std::uint16_t number{};
10300 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
10305 std::uint32_t number{};
10306 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
10311 std::uint64_t number{};
10312 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1)
10313 -
static_cast<number_integer_t
>(number));
10348 return get_cbor_binary(b) && sax->binary(b);
10383 return get_cbor_string(s) && sax->string(s);
10411 return get_cbor_array(
10412 conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
10416 std::uint8_t len{};
10417 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
10422 std::uint16_t len{};
10423 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
10428 std::uint32_t len{};
10429 return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
10434 std::uint64_t len{};
10435 return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
10439 return get_cbor_array(detail::unknown_size(), tag_handler);
10466 return get_cbor_object(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
10470 std::uint8_t len{};
10471 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
10476 std::uint16_t len{};
10477 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
10482 std::uint32_t len{};
10483 return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
10488 std::uint64_t len{};
10489 return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
10493 return get_cbor_object(detail::unknown_size(), tag_handler);
10515 switch (tag_handler)
10517 case cbor_tag_handler_t::error:
10519 auto last_token = get_token_string();
10520 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
10521 exception_message(input_format_t::cbor, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
10524 case cbor_tag_handler_t::ignore:
10531 std::uint8_t subtype_to_ignore{};
10532 get_number(input_format_t::cbor, subtype_to_ignore);
10537 std::uint16_t subtype_to_ignore{};
10538 get_number(input_format_t::cbor, subtype_to_ignore);
10543 std::uint32_t subtype_to_ignore{};
10544 get_number(input_format_t::cbor, subtype_to_ignore);
10549 std::uint64_t subtype_to_ignore{};
10550 get_number(input_format_t::cbor, subtype_to_ignore);
10556 return parse_cbor_internal(
true, tag_handler);
10559 case cbor_tag_handler_t::store:
10567 std::uint8_t subtype{};
10568 get_number(input_format_t::cbor, subtype);
10569 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
10574 std::uint16_t subtype{};
10575 get_number(input_format_t::cbor, subtype);
10576 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
10581 std::uint32_t subtype{};
10582 get_number(input_format_t::cbor, subtype);
10583 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
10588 std::uint64_t subtype{};
10589 get_number(input_format_t::cbor, subtype);
10590 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
10594 return parse_cbor_internal(
true, tag_handler);
10597 return get_cbor_binary(b) && sax->binary(b);
10601 JSON_ASSERT(
false);
10607 return sax->boolean(
false);
10610 return sax->boolean(
true);
10613 return sax->null();
10617 const auto byte1_raw = get();
10618 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
10622 const auto byte2_raw = get();
10623 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
10628 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
10629 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
10639 const auto half =
static_cast<unsigned int>((byte1 << 8u) + byte2);
10640 const double val = [&half]
10642 const int exp = (half >> 10u) & 0x1Fu;
10643 const unsigned int mant = half & 0x3FFu;
10644 JSON_ASSERT(0 <= exp&& exp <= 32);
10645 JSON_ASSERT(mant <= 1024);
10649 return std::ldexp(mant, -24);
10652 ? std::numeric_limits<double>::infinity()
10653 : std::numeric_limits<double>::quiet_NaN();
10655 return std::ldexp(mant + 1024, exp - 25);
10658 return sax->number_float((half & 0x8000u) != 0
10659 ?
static_cast<number_float_t
>(-val)
10660 :
static_cast<number_float_t
>(val),
"");
10666 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10672 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10677 auto last_token = get_token_string();
10678 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
10679 exception_message(input_format_t::cbor, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
10695 bool get_cbor_string(string_t& result)
10697 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"string")))
10730 return get_string(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
10735 std::uint8_t len{};
10736 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10741 std::uint16_t len{};
10742 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10747 std::uint32_t len{};
10748 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10753 std::uint64_t len{};
10754 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10759 while (get() != 0xFF)
10762 if (!get_cbor_string(chunk))
10766 result.append(chunk);
10773 auto last_token = get_token_string();
10774 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
10775 exception_message(input_format_t::cbor, concat(
"expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token),
"string"),
nullptr));
10791 bool get_cbor_binary(binary_t& result)
10793 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"binary")))
10826 return get_binary(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
10831 std::uint8_t len{};
10832 return get_number(input_format_t::cbor, len) &&
10833 get_binary(input_format_t::cbor, len, result);
10838 std::uint16_t len{};
10839 return get_number(input_format_t::cbor, len) &&
10840 get_binary(input_format_t::cbor, len, result);
10845 std::uint32_t len{};
10846 return get_number(input_format_t::cbor, len) &&
10847 get_binary(input_format_t::cbor, len, result);
10852 std::uint64_t len{};
10853 return get_number(input_format_t::cbor, len) &&
10854 get_binary(input_format_t::cbor, len, result);
10859 while (get() != 0xFF)
10862 if (!get_cbor_binary(chunk))
10866 result.insert(result.end(), chunk.begin(), chunk.end());
10873 auto last_token = get_token_string();
10874 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
10875 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));
10886 bool get_cbor_array(
const std::size_t len,
10887 const cbor_tag_handler_t tag_handler)
10889 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
10894 if (len != detail::unknown_size())
10896 for (std::size_t i = 0; i < len; ++i)
10898 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
10906 while (get() != 0xFF)
10908 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
false, tag_handler)))
10915 return sax->end_array();
10924 bool get_cbor_object(
const std::size_t len,
10925 const cbor_tag_handler_t tag_handler)
10927 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
10935 if (len != detail::unknown_size())
10937 for (std::size_t i = 0; i < len; ++i)
10940 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
10945 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
10954 while (get() != 0xFF)
10956 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
10961 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
10970 return sax->end_object();
10980 bool parse_msgpack_internal()
10985 case char_traits<char_type>::eof():
11117 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
11136 return get_msgpack_object(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x0Fu));
11155 return get_msgpack_array(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x0Fu));
11195 return get_msgpack_string(s) && sax->string(s);
11199 return sax->null();
11202 return sax->boolean(
false);
11205 return sax->boolean(
true);
11220 return get_msgpack_binary(b) && sax->binary(b);
11226 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
11232 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
11237 std::uint8_t number{};
11238 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
11243 std::uint16_t number{};
11244 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
11249 std::uint32_t number{};
11250 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
11255 std::uint64_t number{};
11256 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
11261 std::int8_t number{};
11262 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
11267 std::int16_t number{};
11268 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
11273 std::int32_t number{};
11274 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
11279 std::int64_t number{};
11280 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
11285 std::uint16_t len{};
11286 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
11291 std::uint32_t len{};
11292 return get_number(input_format_t::msgpack, len) && get_msgpack_array(conditional_static_cast<std::size_t>(len));
11297 std::uint16_t len{};
11298 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
11303 std::uint32_t len{};
11304 return get_number(input_format_t::msgpack, len) && get_msgpack_object(conditional_static_cast<std::size_t>(len));
11340 return sax->number_integer(
static_cast<std::int8_t
>(current));
11344 auto last_token = get_token_string();
11345 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
11346 exception_message(input_format_t::msgpack, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
11361 bool get_msgpack_string(string_t& result)
11363 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack,
"string")))
11404 return get_string(input_format_t::msgpack,
static_cast<unsigned int>(current) & 0x1Fu, result);
11409 std::uint8_t len{};
11410 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
11415 std::uint16_t len{};
11416 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
11421 std::uint32_t len{};
11422 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
11427 auto last_token = get_token_string();
11428 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
11429 exception_message(input_format_t::msgpack, concat(
"expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token),
"string"),
nullptr));
11444 bool get_msgpack_binary(binary_t& result)
11447 auto assign_and_return_true = [&result](std::int8_t subtype)
11449 result.set_subtype(
static_cast<std::uint8_t
>(subtype));
11457 std::uint8_t len{};
11458 return get_number(input_format_t::msgpack, len) &&
11459 get_binary(input_format_t::msgpack, len, result);
11464 std::uint16_t len{};
11465 return get_number(input_format_t::msgpack, len) &&
11466 get_binary(input_format_t::msgpack, len, result);
11471 std::uint32_t len{};
11472 return get_number(input_format_t::msgpack, len) &&
11473 get_binary(input_format_t::msgpack, len, result);
11478 std::uint8_t len{};
11479 std::int8_t subtype{};
11480 return get_number(input_format_t::msgpack, len) &&
11481 get_number(input_format_t::msgpack, subtype) &&
11482 get_binary(input_format_t::msgpack, len, result) &&
11483 assign_and_return_true(subtype);
11488 std::uint16_t len{};
11489 std::int8_t subtype{};
11490 return get_number(input_format_t::msgpack, len) &&
11491 get_number(input_format_t::msgpack, subtype) &&
11492 get_binary(input_format_t::msgpack, len, result) &&
11493 assign_and_return_true(subtype);
11498 std::uint32_t len{};
11499 std::int8_t subtype{};
11500 return get_number(input_format_t::msgpack, len) &&
11501 get_number(input_format_t::msgpack, subtype) &&
11502 get_binary(input_format_t::msgpack, len, result) &&
11503 assign_and_return_true(subtype);
11508 std::int8_t subtype{};
11509 return get_number(input_format_t::msgpack, subtype) &&
11510 get_binary(input_format_t::msgpack, 1, result) &&
11511 assign_and_return_true(subtype);
11516 std::int8_t subtype{};
11517 return get_number(input_format_t::msgpack, subtype) &&
11518 get_binary(input_format_t::msgpack, 2, result) &&
11519 assign_and_return_true(subtype);
11524 std::int8_t subtype{};
11525 return get_number(input_format_t::msgpack, subtype) &&
11526 get_binary(input_format_t::msgpack, 4, result) &&
11527 assign_and_return_true(subtype);
11532 std::int8_t subtype{};
11533 return get_number(input_format_t::msgpack, subtype) &&
11534 get_binary(input_format_t::msgpack, 8, result) &&
11535 assign_and_return_true(subtype);
11540 std::int8_t subtype{};
11541 return get_number(input_format_t::msgpack, subtype) &&
11542 get_binary(input_format_t::msgpack, 16, result) &&
11543 assign_and_return_true(subtype);
11555 bool get_msgpack_array(
const std::size_t len)
11557 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
11562 for (std::size_t i = 0; i < len; ++i)
11564 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
11570 return sax->end_array();
11577 bool get_msgpack_object(
const std::size_t len)
11579 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
11585 for (std::size_t i = 0; i < len; ++i)
11588 if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key)))
11593 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
11600 return sax->end_object();
11614 bool parse_ubjson_internal(
const bool get_char =
true)
11616 return get_ubjson_value(get_char ? get_ignore_noop() : current);
11633 bool get_ubjson_string(string_t& result,
const bool get_char =
true)
11640 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"value")))
11649 std::uint8_t len{};
11650 return get_number(input_format, len) && get_string(input_format, len, result);
11656 return get_number(input_format, len) && get_string(input_format, len, result);
11661 std::int16_t len{};
11662 return get_number(input_format, len) && get_string(input_format, len, result);
11667 std::int32_t len{};
11668 return get_number(input_format, len) && get_string(input_format, len, result);
11673 std::int64_t len{};
11674 return get_number(input_format, len) && get_string(input_format, len, result);
11679 if (input_format != input_format_t::bjdata)
11683 std::uint16_t len{};
11684 return get_number(input_format, len) && get_string(input_format, len, result);
11689 if (input_format != input_format_t::bjdata)
11693 std::uint32_t len{};
11694 return get_number(input_format, len) && get_string(input_format, len, result);
11699 if (input_format != input_format_t::bjdata)
11703 std::uint64_t len{};
11704 return get_number(input_format, len) && get_string(input_format, len, result);
11710 auto last_token = get_token_string();
11711 std::string message;
11713 if (input_format != input_format_t::bjdata)
11715 message =
"expected length type specification (U, i, I, l, L); last byte: 0x" + last_token;
11719 message =
"expected length type specification (U, i, u, I, m, l, M, L); last byte: 0x" + last_token;
11721 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message,
"string"),
nullptr));
11728 bool get_ubjson_ndarray_size(std::vector<size_t>& dim)
11730 std::pair<std::size_t, char_int_type> size_and_type;
11732 bool no_ndarray =
true;
11734 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type, no_ndarray)))
11739 if (size_and_type.first != npos)
11741 if (size_and_type.second != 0)
11743 if (size_and_type.second !=
'N')
11745 for (std::size_t i = 0; i < size_and_type.first; ++i)
11747 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, size_and_type.second)))
11751 dim.push_back(dimlen);
11757 for (std::size_t i = 0; i < size_and_type.first; ++i)
11759 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray)))
11763 dim.push_back(dimlen);
11769 while (current !=
']')
11771 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, current)))
11775 dim.push_back(dimlen);
11793 bool get_ubjson_size_value(std::size_t& result,
bool& is_ndarray, char_int_type prefix = 0)
11797 prefix = get_ignore_noop();
11804 std::uint8_t number{};
11805 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11809 result =
static_cast<std::size_t
>(number);
11815 std::int8_t number{};
11816 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11822 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11823 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11825 result =
static_cast<std::size_t
>(number);
11831 std::int16_t number{};
11832 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11838 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11839 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11841 result =
static_cast<std::size_t
>(number);
11847 std::int32_t number{};
11848 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11854 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11855 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11857 result =
static_cast<std::size_t
>(number);
11863 std::int64_t number{};
11864 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11870 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11871 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11873 if (!value_in_range_of<std::size_t>(number))
11875 return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,
11876 exception_message(input_format,
"integer value overflow",
"size"),
nullptr));
11878 result =
static_cast<std::size_t
>(number);
11884 if (input_format != input_format_t::bjdata)
11888 std::uint16_t number{};
11889 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11893 result =
static_cast<std::size_t
>(number);
11899 if (input_format != input_format_t::bjdata)
11903 std::uint32_t number{};
11904 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11908 result = conditional_static_cast<std::size_t>(number);
11914 if (input_format != input_format_t::bjdata)
11918 std::uint64_t number{};
11919 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11923 if (!value_in_range_of<std::size_t>(number))
11925 return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,
11926 exception_message(input_format,
"integer value overflow",
"size"),
nullptr));
11928 result = detail::conditional_static_cast<std::size_t>(number);
11934 if (input_format != input_format_t::bjdata)
11940 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));
11942 std::vector<size_t> dim;
11943 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_ndarray_size(dim)))
11947 if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1))
11949 result = dim.at(dim.size() - 1);
11963 string_t
key =
"_ArraySize_";
11964 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(3) || !sax->key(key) || !sax->start_array(dim.size())))
11972 if (result == 0 || result == npos)
11974 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));
11976 if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(
static_cast<number_unsigned_t
>(i))))
11982 return sax->end_array();
11991 auto last_token = get_token_string();
11992 std::string message;
11994 if (input_format != input_format_t::bjdata)
11996 message =
"expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token;
12000 message =
"expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x" + last_token;
12002 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message,
"size"),
nullptr));
12016 bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result,
bool inside_ndarray =
false)
12018 result.first = npos;
12020 bool is_ndarray =
false;
12024 if (current ==
'$')
12026 result.second = get();
12027 if (input_format == input_format_t::bjdata
12028 && JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second)))
12030 auto last_token = get_token_string();
12031 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
12032 exception_message(input_format, concat(
"marker 0x", last_token,
" is not a permitted optimized array type"),
"type"),
nullptr));
12035 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"type")))
12041 if (JSON_HEDLEY_UNLIKELY(current !=
'#'))
12043 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"value")))
12047 auto last_token = get_token_string();
12048 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
12049 exception_message(input_format, concat(
"expected '#' after type information; last byte: 0x", last_token),
"size"),
nullptr));
12052 const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
12053 if (input_format == input_format_t::bjdata && is_ndarray)
12055 if (inside_ndarray)
12057 return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
12058 exception_message(input_format,
"ndarray can not be recursive",
"size"),
nullptr));
12060 result.second |= (1 << 8);
12065 if (current ==
'#')
12067 const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
12068 if (input_format == input_format_t::bjdata && is_ndarray)
12070 return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
12071 exception_message(input_format,
"ndarray requires both type and size",
"size"),
nullptr));
12083 bool get_ubjson_value(
const char_int_type prefix)
12087 case char_traits<char_type>::eof():
12088 return unexpect_eof(input_format,
"value");
12091 return sax->boolean(
true);
12093 return sax->boolean(
false);
12096 return sax->null();
12100 if (input_format != input_format_t::bjdata)
12104 std::uint8_t number{};
12105 return get_number(input_format, number) && sax->number_unsigned(number);
12110 std::uint8_t number{};
12111 return get_number(input_format, number) && sax->number_unsigned(number);
12116 std::int8_t number{};
12117 return get_number(input_format, number) && sax->number_integer(number);
12122 std::int16_t number{};
12123 return get_number(input_format, number) && sax->number_integer(number);
12128 std::int32_t number{};
12129 return get_number(input_format, number) && sax->number_integer(number);
12134 std::int64_t number{};
12135 return get_number(input_format, number) && sax->number_integer(number);
12140 if (input_format != input_format_t::bjdata)
12144 std::uint16_t number{};
12145 return get_number(input_format, number) && sax->number_unsigned(number);
12150 if (input_format != input_format_t::bjdata)
12154 std::uint32_t number{};
12155 return get_number(input_format, number) && sax->number_unsigned(number);
12160 if (input_format != input_format_t::bjdata)
12164 std::uint64_t number{};
12165 return get_number(input_format, number) && sax->number_unsigned(number);
12170 if (input_format != input_format_t::bjdata)
12174 const auto byte1_raw = get();
12175 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
12179 const auto byte2_raw = get();
12180 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
12185 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
12186 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
12196 const auto half =
static_cast<unsigned int>((byte2 << 8u) + byte1);
12197 const double val = [&half]
12199 const int exp = (half >> 10u) & 0x1Fu;
12200 const unsigned int mant = half & 0x3FFu;
12201 JSON_ASSERT(0 <= exp&& exp <= 32);
12202 JSON_ASSERT(mant <= 1024);
12206 return std::ldexp(mant, -24);
12209 ? std::numeric_limits<double>::infinity()
12210 : std::numeric_limits<double>::quiet_NaN();
12212 return std::ldexp(mant + 1024, exp - 25);
12215 return sax->number_float((half & 0x8000u) != 0
12216 ?
static_cast<number_float_t
>(-val)
12217 :
static_cast<number_float_t
>(val),
"");
12223 return get_number(input_format, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
12229 return get_number(input_format, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
12234 return get_ubjson_high_precision_number();
12240 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"char")))
12244 if (JSON_HEDLEY_UNLIKELY(current > 127))
12246 auto last_token = get_token_string();
12247 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
12248 exception_message(input_format, concat(
"byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token),
"char"),
nullptr));
12250 string_t s(1,
static_cast<typename string_t::value_type
>(current));
12251 return sax->string(s);
12257 return get_ubjson_string(s) && sax->string(s);
12261 return get_ubjson_array();
12264 return get_ubjson_object();
12269 auto last_token = get_token_string();
12270 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));
12276 bool get_ubjson_array()
12278 std::pair<std::size_t, char_int_type> size_and_type;
12279 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
12287 if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
12289 size_and_type.second &= ~(
static_cast<char_int_type
>(1) << 8);
12290 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)
12292 return p.first < t;
12294 string_t
key =
"_ArrayType_";
12295 if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second))
12297 auto last_token = get_token_string();
12298 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
12299 exception_message(input_format,
"invalid byte: 0x" + last_token,
"type"),
nullptr));
12302 string_t type = it->second;
12303 if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type)))
12308 if (size_and_type.second ==
'C' || size_and_type.second ==
'B')
12310 size_and_type.second =
'U';
12313 key =
"_ArrayData_";
12314 if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->start_array(size_and_type.first) ))
12319 for (std::size_t i = 0; i < size_and_type.first; ++i)
12321 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
12327 return (sax->end_array() && sax->end_object());
12331 if (input_format == input_format_t::bjdata && size_and_type.first != npos && size_and_type.second ==
'B')
12334 return get_binary(input_format, size_and_type.first, result) && sax->binary(result);
12337 if (size_and_type.first != npos)
12339 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
12344 if (size_and_type.second != 0)
12346 if (size_and_type.second !=
'N')
12348 for (std::size_t i = 0; i < size_and_type.first; ++i)
12350 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
12359 for (std::size_t i = 0; i < size_and_type.first; ++i)
12361 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
12370 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
12375 while (current !=
']')
12377 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(
false)))
12385 return sax->end_array();
12391 bool get_ubjson_object()
12393 std::pair<std::size_t, char_int_type> size_and_type;
12394 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
12400 if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
12402 auto last_token = get_token_string();
12403 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
12404 exception_message(input_format,
"BJData object does not support ND-array size in optimized format",
"object"),
nullptr));
12408 if (size_and_type.first != npos)
12410 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))
12415 if (size_and_type.second != 0)
12417 for (std::size_t i = 0; i < size_and_type.first; ++i)
12419 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
12423 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
12432 for (std::size_t i = 0; i < size_and_type.first; ++i)
12434 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
12438 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
12448 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
12453 while (current !=
'}')
12455 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key,
false) || !sax->key(key)))
12459 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
12468 return sax->end_object();
12474 bool get_ubjson_high_precision_number()
12477 std::size_t size{};
12478 bool no_ndarray =
true;
12479 auto res = get_ubjson_size_value(size, no_ndarray);
12480 if (JSON_HEDLEY_UNLIKELY(!res))
12486 std::vector<char> number_vector;
12487 for (std::size_t i = 0; i < size; ++i)
12490 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
12494 number_vector.push_back(
static_cast<char>(current));
12498 using ia_type =
decltype(detail::input_adapter(number_vector));
12500 const auto result_number = number_lexer.scan();
12501 const auto number_string = number_lexer.get_token_string();
12502 const auto result_remainder = number_lexer.scan();
12506 if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
12508 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
12509 exception_message(input_format, concat(
"invalid number text: ", number_lexer.get_token_string()),
"high-precision number"),
nullptr));
12512 switch (result_number)
12514 case token_type::value_integer:
12515 return sax->number_integer(number_lexer.get_number_integer());
12516 case token_type::value_unsigned:
12517 return sax->number_unsigned(number_lexer.get_number_unsigned());
12518 case token_type::value_float:
12519 return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
12520 case token_type::uninitialized:
12521 case token_type::literal_true:
12522 case token_type::literal_false:
12523 case token_type::literal_null:
12524 case token_type::value_string:
12525 case token_type::begin_array:
12526 case token_type::begin_object:
12527 case token_type::end_array:
12528 case token_type::end_object:
12529 case token_type::name_separator:
12530 case token_type::value_separator:
12531 case token_type::parse_error:
12532 case token_type::end_of_input:
12533 case token_type::literal_or_value:
12535 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
12536 exception_message(input_format, concat(
"invalid number text: ", number_lexer.get_token_string()),
"high-precision number"),
nullptr));
12553 char_int_type get()
12556 return current = ia.get_character();
12568 bool get_to(T& dest,
const input_format_t format,
const char* context)
12570 auto new_chars_read = ia.get_elements(&dest);
12571 chars_read += new_chars_read;
12572 if (JSON_HEDLEY_UNLIKELY(new_chars_read <
sizeof(T)))
12576 sax->parse_error(chars_read,
"<end of file>", parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context),
nullptr));
12585 char_int_type get_ignore_noop()
12591 while (current ==
'N');
12596 template<
class NumberType>
12597 static void byte_swap(NumberType& number)
12599 constexpr std::size_t sz =
sizeof(number);
12600#ifdef __cpp_lib_byteswap
12601 if constexpr (sz == 1)
12605 if constexpr(std::is_integral_v<NumberType>)
12607 number = std::byteswap(number);
12611 auto* ptr =
reinterpret_cast<std::uint8_t*
>(&number);
12612 for (std::size_t i = 0; i < sz / 2; ++i)
12614 std::swap(ptr[i], ptr[sz - i - 1]);
12633 template<
typename NumberType,
bool InputIsLittleEndian = false>
12634 bool get_number(
const input_format_t format, NumberType& result)
12638 if (JSON_HEDLEY_UNLIKELY(!get_to(result, format,
"number")))
12642 if (is_little_endian != (InputIsLittleEndian || format == input_format_t::bjdata))
12663 template<
typename NumberType>
12664 bool get_string(
const input_format_t format,
12665 const NumberType len,
12668 bool success =
true;
12669 for (NumberType i = 0; i < len; i++)
12672 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"string")))
12677 result.push_back(
static_cast<typename string_t::value_type
>(current));
12696 template<
typename NumberType>
12697 bool get_binary(
const input_format_t format,
12698 const NumberType len,
12701 bool success =
true;
12702 for (NumberType i = 0; i < len; i++)
12705 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"binary")))
12710 result.push_back(
static_cast<std::uint8_t
>(current));
12720 JSON_HEDLEY_NON_NULL(3)
12721 bool unexpect_eof(const input_format_t format, const
char* context)
const
12723 if (JSON_HEDLEY_UNLIKELY(current == char_traits<char_type>::eof()))
12725 return sax->parse_error(chars_read,
"<end of file>",
12726 parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context),
nullptr));
12734 std::string get_token_string()
const
12736 std::array<char, 3> cr{{}};
12737 static_cast<void>((std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(current)));
12738 return std::string{cr.data()};
12747 std::string exception_message(
const input_format_t format,
12748 const std::string&
detail,
12749 const std::string& context)
const
12751 std::string error_msg =
"syntax error while parsing ";
12755 case input_format_t::cbor:
12756 error_msg +=
"CBOR";
12759 case input_format_t::msgpack:
12760 error_msg +=
"MessagePack";
12763 case input_format_t::ubjson:
12764 error_msg +=
"UBJSON";
12767 case input_format_t::bson:
12768 error_msg +=
"BSON";
12771 case input_format_t::bjdata:
12772 error_msg +=
"BJData";
12775 case input_format_t::json:
12777 JSON_ASSERT(
false);
12780 return concat(error_msg,
' ', context,
": ",
detail);
12784 static JSON_INLINE_VARIABLE
constexpr std::size_t npos = detail::unknown_size();
12787 InputAdapterType ia;
12790 char_int_type current = char_traits<char_type>::eof();
12793 std::size_t chars_read = 0;
12796 const bool is_little_endian = little_endianness();
12802 json_sax_t* sax =
nullptr;
12805#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ \
12806 make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
12808#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
12809 make_array<bjd_type>( \
12810 bjd_type{'B', "byte"}, \
12811 bjd_type{'C', "char"}, \
12812 bjd_type{'D', "double"}, \
12813 bjd_type{'I', "int16"}, \
12814 bjd_type{'L', "int64"}, \
12815 bjd_type{'M', "uint64"}, \
12816 bjd_type{'U', "uint8"}, \
12817 bjd_type{'d', "single"}, \
12818 bjd_type{'i', "int8"}, \
12819 bjd_type{'l', "int32"}, \
12820 bjd_type{'m', "uint32"}, \
12821 bjd_type{'u', "uint16"})
12823 JSON_PRIVATE_UNLESS_TESTED:
12826 const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers =
12827 JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_;
12829 using bjd_type = std::pair<char_int_type, string_t>;
12831 const decltype(JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_) bjd_types_map =
12832 JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_;
12834#undef JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_
12835#undef JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_
12838#ifndef JSON_HAS_CPP_17
12839 template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX>
12840 constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos;
12844NLOHMANN_JSON_NAMESPACE_END
12863#include <functional>
12885NLOHMANN_JSON_NAMESPACE_BEGIN
12908template<
typename BasicJsonType>
12909using parser_callback_t =
12910 std::function<bool(
int , parse_event_t , BasicJsonType& )>;
12917template<
typename BasicJsonType,
typename InputAdapterType>
12920 using number_integer_t =
typename BasicJsonType::number_integer_t;
12921 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
12922 using number_float_t =
typename BasicJsonType::number_float_t;
12923 using string_t =
typename BasicJsonType::string_t;
12925 using token_type =
typename lexer_t::token_type;
12930 parser_callback_t<BasicJsonType> cb =
nullptr,
12931 const bool allow_exceptions_ =
true,
12932 const bool skip_comments =
false)
12933 : callback(std::move(cb))
12934 , m_lexer(std::move(adapter), skip_comments)
12935 , allow_exceptions(allow_exceptions_)
12951 void parse(
const bool strict, BasicJsonType& result)
12956 sax_parse_internal(&sdp);
12959 if (
strict && (get_token() != token_type::end_of_input))
12961 sdp.parse_error(m_lexer.get_position(),
12962 m_lexer.get_token_string(),
12963 parse_error::create(101, m_lexer.get_position(),
12964 exception_message(token_type::end_of_input,
"value"),
nullptr));
12968 if (sdp.is_errored())
12970 result = value_t::discarded;
12976 if (result.is_discarded())
12984 sax_parse_internal(&sdp);
12987 if (
strict && (get_token() != token_type::end_of_input))
12989 sdp.parse_error(m_lexer.get_position(),
12990 m_lexer.get_token_string(),
12991 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"),
nullptr));
12995 if (sdp.is_errored())
12997 result = value_t::discarded;
13002 result.assert_invariant();
13014 return sax_parse(&sax_acceptor,
strict);
13017 template<
typename SAX>
13018 JSON_HEDLEY_NON_NULL(2)
13019 bool sax_parse(SAX* sax, const
bool strict = true)
13022 const bool result = sax_parse_internal(sax);
13025 if (result && strict && (get_token() != token_type::end_of_input))
13027 return sax->parse_error(m_lexer.get_position(),
13028 m_lexer.get_token_string(),
13029 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"),
nullptr));
13036 template<
typename SAX>
13037 JSON_HEDLEY_NON_NULL(2)
13038 bool sax_parse_internal(SAX* sax)
13042 std::vector<bool> states;
13044 bool skip_to_state_evaluation =
false;
13048 if (!skip_to_state_evaluation)
13051 switch (last_token)
13053 case token_type::begin_object:
13055 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
13061 if (get_token() == token_type::end_object)
13063 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
13071 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
13073 return sax->parse_error(m_lexer.get_position(),
13074 m_lexer.get_token_string(),
13075 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"),
nullptr));
13077 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
13083 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
13085 return sax->parse_error(m_lexer.get_position(),
13086 m_lexer.get_token_string(),
13087 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"),
nullptr));
13091 states.push_back(
false);
13098 case token_type::begin_array:
13100 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
13106 if (get_token() == token_type::end_array)
13108 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
13116 states.push_back(
true);
13122 case token_type::value_float:
13124 const auto res = m_lexer.get_number_float();
13126 if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))
13128 return sax->parse_error(m_lexer.get_position(),
13129 m_lexer.get_token_string(),
13130 out_of_range::create(406, concat(
"number overflow parsing '", m_lexer.get_token_string(),
'\''),
nullptr));
13133 if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
13141 case token_type::literal_false:
13143 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
false)))
13150 case token_type::literal_null:
13152 if (JSON_HEDLEY_UNLIKELY(!sax->null()))
13159 case token_type::literal_true:
13161 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
true)))
13168 case token_type::value_integer:
13170 if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer())))
13177 case token_type::value_string:
13179 if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))
13186 case token_type::value_unsigned:
13188 if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned())))
13195 case token_type::parse_error:
13198 return sax->parse_error(m_lexer.get_position(),
13199 m_lexer.get_token_string(),
13200 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized,
"value"),
nullptr));
13202 case token_type::end_of_input:
13204 if (JSON_HEDLEY_UNLIKELY(m_lexer.get_position().chars_read_total == 1))
13206 return sax->parse_error(m_lexer.get_position(),
13207 m_lexer.get_token_string(),
13208 parse_error::create(101, m_lexer.get_position(),
13209 "attempting to parse an empty input; check that your input string or stream contains the expected JSON",
nullptr));
13212 return sax->parse_error(m_lexer.get_position(),
13213 m_lexer.get_token_string(),
13214 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value,
"value"),
nullptr));
13216 case token_type::uninitialized:
13217 case token_type::end_array:
13218 case token_type::end_object:
13219 case token_type::name_separator:
13220 case token_type::value_separator:
13221 case token_type::literal_or_value:
13224 return sax->parse_error(m_lexer.get_position(),
13225 m_lexer.get_token_string(),
13226 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value,
"value"),
nullptr));
13232 skip_to_state_evaluation =
false;
13236 if (states.empty())
13245 if (get_token() == token_type::value_separator)
13253 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
13255 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
13264 JSON_ASSERT(!states.empty());
13266 skip_to_state_evaluation =
true;
13270 return sax->parse_error(m_lexer.get_position(),
13271 m_lexer.get_token_string(),
13272 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array,
"array"),
nullptr));
13278 if (get_token() == token_type::value_separator)
13281 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
13283 return sax->parse_error(m_lexer.get_position(),
13284 m_lexer.get_token_string(),
13285 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"),
nullptr));
13288 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
13294 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
13296 return sax->parse_error(m_lexer.get_position(),
13297 m_lexer.get_token_string(),
13298 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"),
nullptr));
13307 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
13309 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
13318 JSON_ASSERT(!states.empty());
13320 skip_to_state_evaluation =
true;
13324 return sax->parse_error(m_lexer.get_position(),
13325 m_lexer.get_token_string(),
13326 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object,
"object"),
nullptr));
13331 token_type get_token()
13333 return last_token = m_lexer.scan();
13336 std::string exception_message(
const token_type expected,
const std::string& context)
13338 std::string error_msg =
"syntax error ";
13340 if (!context.empty())
13342 error_msg += concat(
"while parsing ", context,
' ');
13347 if (last_token == token_type::parse_error)
13349 error_msg += concat(m_lexer.get_error_message(),
"; last read: '",
13350 m_lexer.get_token_string(),
'\'');
13354 error_msg += concat(
"unexpected ", lexer_t::token_type_name(last_token));
13357 if (expected != token_type::uninitialized)
13359 error_msg += concat(
"; expected ", lexer_t::token_type_name(expected));
13367 const parser_callback_t<BasicJsonType> callback =
nullptr;
13369 token_type last_token = token_type::uninitialized;
13373 const bool allow_exceptions =
true;
13377NLOHMANN_JSON_NAMESPACE_END
13409NLOHMANN_JSON_NAMESPACE_BEGIN
13425 using difference_type = std::ptrdiff_t;
13426 static constexpr difference_type begin_value = 0;
13427 static constexpr difference_type end_value = begin_value + 1;
13429 JSON_PRIVATE_UNLESS_TESTED:
13431 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
13434 constexpr difference_type get_value()
const noexcept
13442 m_it = begin_value;
13454 return m_it == begin_value;
13460 return m_it == end_value;
13465 return lhs.m_it == rhs.m_it;
13468 friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
13470 return lhs.m_it < rhs.m_it;
13473 primitive_iterator_t operator+(difference_type n)
noexcept
13475 auto result = *
this;
13480 friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
13482 return lhs.m_it - rhs.m_it;
13485 primitive_iterator_t& operator++() noexcept
13491 primitive_iterator_t operator++(
int)&
noexcept
13493 auto result = *
this;
13498 primitive_iterator_t& operator--() noexcept
13504 primitive_iterator_t operator--(
int)&
noexcept
13506 auto result = *
this;
13511 primitive_iterator_t& operator+=(difference_type n)
noexcept
13517 primitive_iterator_t& operator-=(difference_type n)
noexcept
13525NLOHMANN_JSON_NAMESPACE_END
13528NLOHMANN_JSON_NAMESPACE_BEGIN
13541 typename BasicJsonType::object_t::iterator object_iterator {};
13543 typename BasicJsonType::array_t::iterator array_iterator {};
13549NLOHMANN_JSON_NAMESPACE_END
13563#include <type_traits>
13580NLOHMANN_JSON_NAMESPACE_BEGIN
13604template<
typename BasicJsonType>
13611 friend BasicJsonType;
13615 using object_t =
typename BasicJsonType::object_t;
13616 using array_t =
typename BasicJsonType::array_t;
13619 "iter_impl only accepts (const) basic_json");
13621 static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value
13622 && std::is_base_of<std::bidirectional_iterator_tag, typename std::iterator_traits<typename array_t::iterator>::iterator_category>::value,
13623 "basic_json iterator assumes array and object type iterators satisfy the LegacyBidirectionalIterator named requirement.");
13634 using value_type =
typename BasicJsonType::value_type;
13638 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
13639 typename BasicJsonType::const_pointer,
13640 typename BasicJsonType::pointer>::type;
13643 typename std::conditional<std::is_const<BasicJsonType>::value,
13644 typename BasicJsonType::const_reference,
13645 typename BasicJsonType::reference>::type;
13660 JSON_ASSERT(m_object !=
nullptr);
13662 switch (m_object->m_data.m_type)
13664 case value_t::object:
13666 m_it.object_iterator =
typename object_t::iterator();
13670 case value_t::array:
13672 m_it.array_iterator =
typename array_t::iterator();
13676 case value_t::null:
13677 case value_t::string:
13678 case value_t::boolean:
13679 case value_t::number_integer:
13680 case value_t::number_unsigned:
13681 case value_t::number_float:
13682 case value_t::binary:
13683 case value_t::discarded:
13709 : m_object(other.m_object), m_it(other.m_it)
13720 if (&other !=
this)
13722 m_object = other.m_object;
13734 : m_object(other.m_object), m_it(other.m_it)
13745 m_object = other.m_object;
13750 JSON_PRIVATE_UNLESS_TESTED:
13755 void set_begin() noexcept
13757 JSON_ASSERT(m_object !=
nullptr);
13759 switch (m_object->m_data.m_type)
13761 case value_t::object:
13763 m_it.object_iterator = m_object->m_data.m_value.object->begin();
13767 case value_t::array:
13769 m_it.array_iterator = m_object->m_data.m_value.array->begin();
13773 case value_t::null:
13776 m_it.primitive_iterator.set_end();
13780 case value_t::string:
13781 case value_t::boolean:
13782 case value_t::number_integer:
13783 case value_t::number_unsigned:
13784 case value_t::number_float:
13785 case value_t::binary:
13786 case value_t::discarded:
13789 m_it.primitive_iterator.set_begin();
13801 JSON_ASSERT(m_object !=
nullptr);
13803 switch (m_object->m_data.m_type)
13805 case value_t::object:
13807 m_it.object_iterator = m_object->m_data.m_value.object->end();
13811 case value_t::array:
13813 m_it.array_iterator = m_object->m_data.m_value.array->end();
13817 case value_t::null:
13818 case value_t::string:
13819 case value_t::boolean:
13820 case value_t::number_integer:
13821 case value_t::number_unsigned:
13822 case value_t::number_float:
13823 case value_t::binary:
13824 case value_t::discarded:
13827 m_it.primitive_iterator.set_end();
13840 JSON_ASSERT(m_object !=
nullptr);
13842 switch (m_object->m_data.m_type)
13844 case value_t::object:
13846 JSON_ASSERT(m_it.object_iterator != m_object->m_data.m_value.object->end());
13847 return m_it.object_iterator->second;
13850 case value_t::array:
13852 JSON_ASSERT(m_it.array_iterator != m_object->m_data.m_value.array->end());
13853 return *m_it.array_iterator;
13856 case value_t::null:
13857 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13859 case value_t::string:
13860 case value_t::boolean:
13861 case value_t::number_integer:
13862 case value_t::number_unsigned:
13863 case value_t::number_float:
13864 case value_t::binary:
13865 case value_t::discarded:
13868 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
13873 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13884 JSON_ASSERT(m_object !=
nullptr);
13886 switch (m_object->m_data.m_type)
13888 case value_t::object:
13890 JSON_ASSERT(m_it.object_iterator != m_object->m_data.m_value.object->end());
13891 return &(m_it.object_iterator->second);
13894 case value_t::array:
13896 JSON_ASSERT(m_it.array_iterator != m_object->m_data.m_value.array->end());
13897 return &*m_it.array_iterator;
13900 case value_t::null:
13901 case value_t::string:
13902 case value_t::boolean:
13903 case value_t::number_integer:
13904 case value_t::number_unsigned:
13905 case value_t::number_float:
13906 case value_t::binary:
13907 case value_t::discarded:
13910 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
13915 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13926 auto result = *
this;
13937 JSON_ASSERT(m_object !=
nullptr);
13939 switch (m_object->m_data.m_type)
13941 case value_t::object:
13943 std::advance(m_it.object_iterator, 1);
13947 case value_t::array:
13949 std::advance(m_it.array_iterator, 1);
13953 case value_t::null:
13954 case value_t::string:
13955 case value_t::boolean:
13956 case value_t::number_integer:
13957 case value_t::number_unsigned:
13958 case value_t::number_float:
13959 case value_t::binary:
13960 case value_t::discarded:
13963 ++m_it.primitive_iterator;
13977 auto result = *
this;
13988 JSON_ASSERT(m_object !=
nullptr);
13990 switch (m_object->m_data.m_type)
13992 case value_t::object:
13994 std::advance(m_it.object_iterator, -1);
13998 case value_t::array:
14000 std::advance(m_it.array_iterator, -1);
14004 case value_t::null:
14005 case value_t::string:
14006 case value_t::boolean:
14007 case value_t::number_integer:
14008 case value_t::number_unsigned:
14009 case value_t::number_float:
14010 case value_t::binary:
14011 case value_t::discarded:
14014 --m_it.primitive_iterator;
14026 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 >
14030 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
14032 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", m_object));
14036 if (m_object ==
nullptr)
14041 switch (m_object->m_data.m_type)
14043 case value_t::object:
14044 return (m_it.object_iterator == other.m_it.object_iterator);
14046 case value_t::array:
14047 return (m_it.array_iterator == other.m_it.array_iterator);
14049 case value_t::null:
14050 case value_t::string:
14051 case value_t::boolean:
14052 case value_t::number_integer:
14053 case value_t::number_unsigned:
14054 case value_t::number_float:
14055 case value_t::binary:
14056 case value_t::discarded:
14058 return (m_it.primitive_iterator == other.m_it.primitive_iterator);
14066 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 >
14069 return !operator==(other);
14079 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
14081 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", m_object));
14085 if (m_object ==
nullptr)
14091 switch (m_object->m_data.m_type)
14093 case value_t::object:
14094 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators", m_object));
14096 case value_t::array:
14097 return (m_it.array_iterator < other.
m_it.array_iterator);
14099 case value_t::null:
14100 case value_t::string:
14101 case value_t::boolean:
14102 case value_t::number_integer:
14103 case value_t::number_unsigned:
14104 case value_t::number_float:
14105 case value_t::binary:
14106 case value_t::discarded:
14108 return (m_it.primitive_iterator < other.
m_it.primitive_iterator);
14118 return !other.operator < (*this);
14127 return !operator<=(other);
14136 return !operator<(other);
14145 JSON_ASSERT(m_object !=
nullptr);
14147 switch (m_object->m_data.m_type)
14149 case value_t::object:
14150 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", m_object));
14152 case value_t::array:
14154 std::advance(m_it.array_iterator, i);
14158 case value_t::null:
14159 case value_t::string:
14160 case value_t::boolean:
14161 case value_t::number_integer:
14162 case value_t::number_unsigned:
14163 case value_t::number_float:
14164 case value_t::binary:
14165 case value_t::discarded:
14168 m_it.primitive_iterator += i;
14182 return operator+=(-i);
14191 auto result = *
this;
14213 auto result = *
this;
14224 JSON_ASSERT(m_object !=
nullptr);
14226 switch (m_object->m_data.m_type)
14228 case value_t::object:
14229 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", m_object));
14231 case value_t::array:
14232 return m_it.array_iterator - other.
m_it.array_iterator;
14234 case value_t::null:
14235 case value_t::string:
14236 case value_t::boolean:
14237 case value_t::number_integer:
14238 case value_t::number_unsigned:
14239 case value_t::number_float:
14240 case value_t::binary:
14241 case value_t::discarded:
14243 return m_it.primitive_iterator - other.
m_it.primitive_iterator;
14253 JSON_ASSERT(m_object !=
nullptr);
14255 switch (m_object->m_data.m_type)
14257 case value_t::object:
14258 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators", m_object));
14260 case value_t::array:
14261 return *std::next(m_it.array_iterator, n);
14263 case value_t::null:
14264 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
14266 case value_t::string:
14267 case value_t::boolean:
14268 case value_t::number_integer:
14269 case value_t::number_unsigned:
14270 case value_t::number_float:
14271 case value_t::binary:
14272 case value_t::discarded:
14275 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n))
14280 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
14289 const typename object_t::key_type&
key()
const
14291 JSON_ASSERT(m_object !=
nullptr);
14293 if (JSON_HEDLEY_LIKELY(m_object->is_object()))
14295 return m_it.object_iterator->first;
14298 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators", m_object));
14307 return operator*();
14310 JSON_PRIVATE_UNLESS_TESTED:
14312 pointer m_object =
nullptr;
14318NLOHMANN_JSON_NAMESPACE_END
14340NLOHMANN_JSON_NAMESPACE_BEGIN
14366template<
typename Base>
14370 using difference_type = std::ptrdiff_t;
14374 using reference =
typename Base::reference;
14434 return *(this->operator+(n));
14438 auto key() const -> decltype(std::declval<Base>().key())
14440 auto it = --this->base();
14447 auto it = --this->base();
14448 return it.operator * ();
14453NLOHMANN_JSON_NAMESPACE_END
14468#include <type_traits>
14473NLOHMANN_JSON_NAMESPACE_BEGIN
14490using json_base_class =
typename std::conditional <
14491 std::is_same<T, void>::value,
14497NLOHMANN_JSON_NAMESPACE_END
14510#include <algorithm>
14534NLOHMANN_JSON_NAMESPACE_BEGIN
14538template<
typename RefStringType>
14542 NLOHMANN_BASIC_JSON_TPL_DECLARATION
14548 template<
typename T>
14549 struct string_t_helper
14554 NLOHMANN_BASIC_JSON_TPL_DECLARATION
14555 struct string_t_helper<NLOHMANN_BASIC_JSON_TPL>
14557 using type = StringType;
14562 using string_t =
typename string_t_helper<RefStringType>::type;
14567 : reference_tokens(split(s))
14574 return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
14576 [](
const string_t& a,
const string_t& b)
14578 return detail::concat(a,
'/', detail::escape(b));
14584 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, to_string())
14585 operator string_t()
const
14587 return to_string();
14604 reference_tokens.insert(reference_tokens.end(),
14605 ptr.reference_tokens.begin(),
14606 ptr.reference_tokens.end());
14614 push_back(std::move(token));
14622 return *
this /= std::to_string(array_idx);
14665 if (JSON_HEDLEY_UNLIKELY(empty()))
14667 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
14670 reference_tokens.pop_back();
14677 if (JSON_HEDLEY_UNLIKELY(empty()))
14679 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
14682 return reference_tokens.back();
14689 reference_tokens.push_back(token);
14696 reference_tokens.push_back(std::move(token));
14703 return reference_tokens.empty();
14717 template<
typename BasicJsonType>
14718 static typename BasicJsonType::size_type array_index(
const string_t& s)
14720 using size_type =
typename BasicJsonType::size_type;
14723 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] ==
'0'))
14729 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >=
'1' && s[0] <=
'9')))
14734 const char* p = s.c_str();
14735 char* p_end =
nullptr;
14737 const unsigned long long res = std::strtoull(p, &p_end, 10);
14740 || JSON_HEDLEY_UNLIKELY(
static_cast<std::size_t
>(p_end - p) != s.size()))
14742 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", s,
"'"),
nullptr));
14747 if (res >=
static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))
14749 JSON_THROW(detail::out_of_range::create(410, detail::concat(
"array index ", s,
" exceeds size_type"),
nullptr));
14752 return static_cast<size_type
>(res);
14755 JSON_PRIVATE_UNLESS_TESTED:
14758 if (JSON_HEDLEY_UNLIKELY(empty()))
14760 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
14764 result.reference_tokens = {reference_tokens[0]};
14777 template<
typename BasicJsonType>
14778 BasicJsonType& get_and_create(BasicJsonType& j)
const
14784 for (
const auto& reference_token : reference_tokens)
14786 switch (result->type())
14790 if (reference_token ==
"0")
14793 result = &result->operator[](0);
14798 result = &result->operator[](reference_token);
14806 result = &result->operator[](reference_token);
14813 result = &result->operator[](array_index<BasicJsonType>(reference_token));
14831 JSON_THROW(detail::type_error::create(313,
"invalid value to unflatten", &j));
14857 template<
typename BasicJsonType>
14858 BasicJsonType& get_unchecked(BasicJsonType* ptr)
const
14860 for (
const auto& reference_token : reference_tokens)
14863 if (ptr->is_null())
14867 std::all_of(reference_token.begin(), reference_token.end(),
14868 [](
const unsigned char x)
14870 return std::isdigit(x);
14874 *ptr = (nums || reference_token ==
"-")
14879 switch (ptr->type())
14884 ptr = &ptr->operator[](reference_token);
14890 if (reference_token ==
"-")
14893 ptr = &ptr->operator[](ptr->m_data.m_value.array->size());
14898 ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));
14912 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
14925 template<
typename BasicJsonType>
14926 BasicJsonType& get_checked(BasicJsonType* ptr)
const
14928 for (
const auto& reference_token : reference_tokens)
14930 switch (ptr->type())
14935 ptr = &ptr->at(reference_token);
14941 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
14944 JSON_THROW(detail::out_of_range::create(402, detail::concat(
14945 "array index '-' (", std::to_string(ptr->m_data.m_value.array->size()),
14946 ") is out of range"), ptr));
14950 ptr = &ptr->at(array_index<BasicJsonType>(reference_token));
14963 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
14983 template<
typename BasicJsonType>
14984 const BasicJsonType& get_unchecked(
const BasicJsonType* ptr)
const
14986 for (
const auto& reference_token : reference_tokens)
14988 switch (ptr->type())
14993 ptr = &ptr->operator[](reference_token);
14999 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
15002 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));
15006 ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));
15019 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
15032 template<
typename BasicJsonType>
15033 const BasicJsonType& get_checked(
const BasicJsonType* ptr)
const
15035 for (
const auto& reference_token : reference_tokens)
15037 switch (ptr->type())
15042 ptr = &ptr->at(reference_token);
15048 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
15051 JSON_THROW(detail::out_of_range::create(402, detail::concat(
15052 "array index '-' (", std::to_string(ptr->m_data.m_value.array->size()),
15053 ") is out of range"), ptr));
15057 ptr = &ptr->at(array_index<BasicJsonType>(reference_token));
15070 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
15081 template<
typename BasicJsonType>
15082 bool contains(
const BasicJsonType* ptr)
const
15084 for (
const auto& reference_token : reference_tokens)
15086 switch (ptr->type())
15090 if (!ptr->contains(reference_token))
15096 ptr = &ptr->operator[](reference_token);
15102 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
15107 if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !(
"0" <= reference_token && reference_token <=
"9")))
15112 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
15114 if (JSON_HEDLEY_UNLIKELY(!(
'1' <= reference_token[0] && reference_token[0] <=
'9')))
15119 for (std::size_t i = 1; i < reference_token.size(); i++)
15121 if (JSON_HEDLEY_UNLIKELY(!(
'0' <= reference_token[i] && reference_token[i] <=
'9')))
15129 const auto idx = array_index<BasicJsonType>(reference_token);
15130 if (idx >= ptr->size())
15136 ptr = &ptr->operator[](idx);
15170 static std::vector<string_t> split(
const string_t& reference_string)
15172 std::vector<string_t> result;
15175 if (reference_string.empty())
15181 if (JSON_HEDLEY_UNLIKELY(reference_string[0] !=
'/'))
15183 JSON_THROW(
detail::parse_error::create(107, 1, detail::concat(
"JSON pointer must be empty or begin with '/' - was: '", reference_string,
"'"),
nullptr));
15191 std::size_t slash = reference_string.find_first_of(
'/', 1),
15198 start = (slash == string_t::npos) ? 0 : slash + 1,
15200 slash = reference_string.find_first_of(
'/', start))
15204 auto reference_token = reference_string.substr(start, slash - start);
15207 for (std::size_t pos = reference_token.find_first_of(
'~');
15208 pos != string_t::npos;
15209 pos = reference_token.find_first_of(
'~', pos + 1))
15211 JSON_ASSERT(reference_token[pos] ==
'~');
15214 if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
15215 (reference_token[pos + 1] !=
'0' &&
15216 reference_token[pos + 1] !=
'1')))
15223 detail::unescape(reference_token);
15224 result.push_back(reference_token);
15238 template<
typename BasicJsonType>
15239 static void flatten(
const string_t& reference_string,
15240 const BasicJsonType& value,
15241 BasicJsonType& result)
15243 switch (value.type())
15247 if (value.m_data.m_value.array->empty())
15250 result[reference_string] =
nullptr;
15255 for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i)
15257 flatten(detail::concat<string_t>(reference_string,
'/', std::to_string(i)),
15258 value.m_data.m_value.array->operator[](i), result);
15266 if (value.m_data.m_value.object->empty())
15269 result[reference_string] =
nullptr;
15274 for (
const auto& element : *value.m_data.m_value.object)
15276 flatten(detail::concat<string_t>(reference_string,
'/',
detail::escape(element.first)), element.second, result);
15293 result[reference_string] = value;
15309 template<
typename BasicJsonType>
15310 static BasicJsonType
15311 unflatten(
const BasicJsonType& value)
15313 if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
15315 JSON_THROW(detail::type_error::create(314,
"only objects can be unflattened", &value));
15318 BasicJsonType result;
15321 for (
const auto& element : *value.m_data.m_value.object)
15323 if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
15325 JSON_THROW(detail::type_error::create(315,
"values in object must be primitive", &element.second));
15332 json_pointer(element.first).get_and_create(result) = element.second;
15342 result.reference_tokens = reference_tokens;
15349 result.reference_tokens = std::move(reference_tokens);
15354#if JSON_HAS_THREE_WAY_COMPARISON
15357 template<
typename RefStringTypeRhs>
15360 return reference_tokens == rhs.reference_tokens;
15365 JSON_HEDLEY_DEPRECATED_FOR(3.11.2,
operator==(
json_pointer))
15366 bool operator==(
const string_t& rhs)
const
15372 template<
typename RefStringTypeRhs>
15375 return reference_tokens <=> rhs.reference_tokens;
15380 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15387 template<
typename RefStringTypeLhs,
typename StringType>
15390 const StringType& rhs);
15394 template<
typename RefStringTypeRhs,
typename StringType>
15396 friend bool operator==(
const StringType& lhs,
15401 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15408 template<
typename RefStringTypeLhs,
typename StringType>
15411 const StringType& rhs);
15415 template<
typename RefStringTypeRhs,
typename StringType>
15417 friend bool operator!=(
const StringType& lhs,
15421 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15429 std::vector<string_t> reference_tokens;
15432#if !JSON_HAS_THREE_WAY_COMPARISON
15434template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15438 return lhs.reference_tokens == rhs.reference_tokens;
15441template<
typename RefStringTypeLhs,
15442 typename StringType =
typename json_pointer<RefStringTypeLhs>::string_t>
15445 const StringType& rhs)
15450template<
typename RefStringTypeRhs,
15451 typename StringType =
typename json_pointer<RefStringTypeRhs>::string_t>
15453inline bool operator==(
const StringType& lhs,
15459template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15463 return !(lhs == rhs);
15466template<
typename RefStringTypeLhs,
15467 typename StringType =
typename json_pointer<RefStringTypeLhs>::string_t>
15470 const StringType& rhs)
15472 return !(lhs == rhs);
15475template<
typename RefStringTypeRhs,
15476 typename StringType =
typename json_pointer<RefStringTypeRhs>::string_t>
15478inline bool operator!=(
const StringType& lhs,
15481 return !(lhs == rhs);
15484template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
15488 return lhs.reference_tokens < rhs.reference_tokens;
15492NLOHMANN_JSON_NAMESPACE_END
15505#include <initializer_list>
15513NLOHMANN_JSON_NAMESPACE_BEGIN
15517template<
typename BasicJsonType>
15521 using value_type = BasicJsonType;
15524 : owned_value(std::move(value))
15528 : value_ref(&value)
15531 json_ref(std::initializer_list<json_ref> init)
15532 : owned_value(init)
15537 enable_if_t<std::is_constructible<value_type, Args...>::value,
int> = 0 >
15539 : owned_value(std::forward<Args>(args)...)
15549 value_type moved_or_copied()
const
15551 if (value_ref ==
nullptr)
15553 return std::move(owned_value);
15558 value_type
const& operator*()
const
15560 return value_ref ? *value_ref : owned_value;
15563 value_type
const* operator->()
const
15569 mutable value_type owned_value =
nullptr;
15570 value_type
const* value_ref =
nullptr;
15574NLOHMANN_JSON_NAMESPACE_END
15599#include <algorithm>
15625#include <algorithm>
15640NLOHMANN_JSON_NAMESPACE_BEGIN
15647 virtual void write_character(CharType c) = 0;
15648 virtual void write_characters(
const CharType* s, std::size_t length) = 0;
15659template<
typename CharType>
15660using output_adapter_t = std::shared_ptr<output_adapter_protocol<CharType>>;
15663template<
typename CharType,
typename AllocatorType = std::allocator<CharType>>
15671 void write_character(CharType c)
override
15676 JSON_HEDLEY_NON_NULL(2)
15677 void write_characters(
const CharType* s, std::size_t length)
override
15679 v.insert(v.end(), s, s + length);
15683 std::vector<CharType, AllocatorType>& v;
15688template<
typename CharType>
15696 void write_character(CharType c)
override
15701 JSON_HEDLEY_NON_NULL(2)
15702 void write_characters(
const CharType* s, std::size_t length)
override
15704 stream.write(s,
static_cast<std::streamsize
>(length));
15708 std::basic_ostream<CharType>& stream;
15713template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
15721 void write_character(CharType c)
override
15726 JSON_HEDLEY_NON_NULL(2)
15727 void write_characters(
const CharType* s, std::size_t length)
override
15729 str.append(s, length);
15736template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
15740 template<
typename AllocatorType = std::allocator<CharType>>
15762NLOHMANN_JSON_NAMESPACE_END
15767NLOHMANN_JSON_NAMESPACE_BEGIN
15785template<
typename BasicJsonType,
typename CharType>
15788 using string_t =
typename BasicJsonType::string_t;
15789 using binary_t =
typename BasicJsonType::binary_t;
15790 using number_float_t =
typename BasicJsonType::number_float_t;
15811 case value_t::object:
15813 write_bson_object(*j.m_data.m_value.object);
15817 case value_t::null:
15818 case value_t::array:
15819 case value_t::string:
15820 case value_t::boolean:
15821 case value_t::number_integer:
15822 case value_t::number_unsigned:
15823 case value_t::number_float:
15824 case value_t::binary:
15825 case value_t::discarded:
15828 JSON_THROW(type_error::create(317, concat(
"to serialize to BSON, top-level type must be object, but is ", j.type_name()), &j));
15840 case value_t::null:
15842 oa->write_character(to_char_type(0xF6));
15846 case value_t::boolean:
15848 oa->write_character(j.m_data.m_value.boolean
15849 ? to_char_type(0xF5)
15850 : to_char_type(0xF4));
15854 case value_t::number_integer:
15856 if (j.m_data.m_value.number_integer >= 0)
15861 if (j.m_data.m_value.number_integer <= 0x17)
15863 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15865 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
15867 oa->write_character(to_char_type(0x18));
15868 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15870 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
15872 oa->write_character(to_char_type(0x19));
15873 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
15875 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
15877 oa->write_character(to_char_type(0x1A));
15878 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
15882 oa->write_character(to_char_type(0x1B));
15883 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
15890 const auto positive_number = -1 - j.m_data.m_value.number_integer;
15891 if (j.m_data.m_value.number_integer >= -24)
15893 write_number(
static_cast<std::uint8_t
>(0x20 + positive_number));
15895 else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
15897 oa->write_character(to_char_type(0x38));
15898 write_number(
static_cast<std::uint8_t
>(positive_number));
15900 else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
15902 oa->write_character(to_char_type(0x39));
15903 write_number(
static_cast<std::uint16_t
>(positive_number));
15905 else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
15907 oa->write_character(to_char_type(0x3A));
15908 write_number(
static_cast<std::uint32_t
>(positive_number));
15912 oa->write_character(to_char_type(0x3B));
15913 write_number(
static_cast<std::uint64_t
>(positive_number));
15919 case value_t::number_unsigned:
15921 if (j.m_data.m_value.number_unsigned <= 0x17)
15923 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_unsigned));
15925 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
15927 oa->write_character(to_char_type(0x18));
15928 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_unsigned));
15930 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
15932 oa->write_character(to_char_type(0x19));
15933 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_unsigned));
15935 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
15937 oa->write_character(to_char_type(0x1A));
15938 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_unsigned));
15942 oa->write_character(to_char_type(0x1B));
15943 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_unsigned));
15948 case value_t::number_float:
15950 if (std::isnan(j.m_data.m_value.number_float))
15953 oa->write_character(to_char_type(0xF9));
15954 oa->write_character(to_char_type(0x7E));
15955 oa->write_character(to_char_type(0x00));
15957 else if (std::isinf(j.m_data.m_value.number_float))
15960 oa->write_character(to_char_type(0xf9));
15961 oa->write_character(j.m_data.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
15962 oa->write_character(to_char_type(0x00));
15966 write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::cbor);
15971 case value_t::string:
15974 const auto N = j.m_data.m_value.string->size();
15977 write_number(
static_cast<std::uint8_t
>(0x60 + N));
15979 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15981 oa->write_character(to_char_type(0x78));
15982 write_number(
static_cast<std::uint8_t
>(N));
15984 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15986 oa->write_character(to_char_type(0x79));
15987 write_number(
static_cast<std::uint16_t
>(N));
15989 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15991 oa->write_character(to_char_type(0x7A));
15992 write_number(
static_cast<std::uint32_t
>(N));
15995 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15997 oa->write_character(to_char_type(0x7B));
15998 write_number(
static_cast<std::uint64_t
>(N));
16003 oa->write_characters(
16004 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
16005 j.m_data.m_value.string->size());
16009 case value_t::array:
16012 const auto N = j.m_data.m_value.array->size();
16015 write_number(
static_cast<std::uint8_t
>(0x80 + N));
16017 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
16019 oa->write_character(to_char_type(0x98));
16020 write_number(
static_cast<std::uint8_t
>(N));
16022 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16024 oa->write_character(to_char_type(0x99));
16025 write_number(
static_cast<std::uint16_t
>(N));
16027 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16029 oa->write_character(to_char_type(0x9A));
16030 write_number(
static_cast<std::uint32_t
>(N));
16033 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
16035 oa->write_character(to_char_type(0x9B));
16036 write_number(
static_cast<std::uint64_t
>(N));
16041 for (
const auto& el : *j.m_data.m_value.array)
16048 case value_t::binary:
16050 if (j.m_data.m_value.binary->has_subtype())
16052 if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)())
16054 write_number(
static_cast<std::uint8_t
>(0xd8));
16055 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.binary->subtype()));
16057 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint16_t>::max)())
16059 write_number(
static_cast<std::uint8_t
>(0xd9));
16060 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.binary->subtype()));
16062 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint32_t>::max)())
16064 write_number(
static_cast<std::uint8_t
>(0xda));
16065 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.binary->subtype()));
16067 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint64_t>::max)())
16069 write_number(
static_cast<std::uint8_t
>(0xdb));
16070 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.binary->subtype()));
16075 const auto N = j.m_data.m_value.binary->size();
16078 write_number(
static_cast<std::uint8_t
>(0x40 + N));
16080 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
16082 oa->write_character(to_char_type(0x58));
16083 write_number(
static_cast<std::uint8_t
>(N));
16085 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16087 oa->write_character(to_char_type(0x59));
16088 write_number(
static_cast<std::uint16_t
>(N));
16090 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16092 oa->write_character(to_char_type(0x5A));
16093 write_number(
static_cast<std::uint32_t
>(N));
16096 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
16098 oa->write_character(to_char_type(0x5B));
16099 write_number(
static_cast<std::uint64_t
>(N));
16104 oa->write_characters(
16105 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
16111 case value_t::object:
16114 const auto N = j.m_data.m_value.object->size();
16117 write_number(
static_cast<std::uint8_t
>(0xA0 + N));
16119 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
16121 oa->write_character(to_char_type(0xB8));
16122 write_number(
static_cast<std::uint8_t
>(N));
16124 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16126 oa->write_character(to_char_type(0xB9));
16127 write_number(
static_cast<std::uint16_t
>(N));
16129 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16131 oa->write_character(to_char_type(0xBA));
16132 write_number(
static_cast<std::uint32_t
>(N));
16135 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
16137 oa->write_character(to_char_type(0xBB));
16138 write_number(
static_cast<std::uint64_t
>(N));
16143 for (
const auto& el : *j.m_data.m_value.object)
16145 write_cbor(el.first);
16146 write_cbor(el.second);
16151 case value_t::discarded:
16164 case value_t::null:
16166 oa->write_character(to_char_type(0xC0));
16170 case value_t::boolean:
16172 oa->write_character(j.m_data.m_value.boolean
16173 ? to_char_type(0xC3)
16174 : to_char_type(0xC2));
16178 case value_t::number_integer:
16180 if (j.m_data.m_value.number_integer >= 0)
16185 if (j.m_data.m_value.number_unsigned < 128)
16188 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
16190 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
16193 oa->write_character(to_char_type(0xCC));
16194 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
16196 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
16199 oa->write_character(to_char_type(0xCD));
16200 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
16202 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
16205 oa->write_character(to_char_type(0xCE));
16206 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
16208 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
16211 oa->write_character(to_char_type(0xCF));
16212 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
16217 if (j.m_data.m_value.number_integer >= -32)
16220 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.number_integer));
16222 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&
16223 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
16226 oa->write_character(to_char_type(0xD0));
16227 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.number_integer));
16229 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&
16230 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
16233 oa->write_character(to_char_type(0xD1));
16234 write_number(
static_cast<std::int16_t
>(j.m_data.m_value.number_integer));
16236 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&
16237 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
16240 oa->write_character(to_char_type(0xD2));
16241 write_number(
static_cast<std::int32_t
>(j.m_data.m_value.number_integer));
16243 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&
16244 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
16247 oa->write_character(to_char_type(0xD3));
16248 write_number(
static_cast<std::int64_t
>(j.m_data.m_value.number_integer));
16254 case value_t::number_unsigned:
16256 if (j.m_data.m_value.number_unsigned < 128)
16259 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
16261 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
16264 oa->write_character(to_char_type(0xCC));
16265 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
16267 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
16270 oa->write_character(to_char_type(0xCD));
16271 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
16273 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
16276 oa->write_character(to_char_type(0xCE));
16277 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
16279 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
16282 oa->write_character(to_char_type(0xCF));
16283 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
16288 case value_t::number_float:
16290 write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::msgpack);
16294 case value_t::string:
16297 const auto N = j.m_data.m_value.string->size();
16301 write_number(
static_cast<std::uint8_t
>(0xA0 | N));
16303 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
16306 oa->write_character(to_char_type(0xD9));
16307 write_number(
static_cast<std::uint8_t
>(N));
16309 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16312 oa->write_character(to_char_type(0xDA));
16313 write_number(
static_cast<std::uint16_t
>(N));
16315 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16318 oa->write_character(to_char_type(0xDB));
16319 write_number(
static_cast<std::uint32_t
>(N));
16323 oa->write_characters(
16324 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
16325 j.m_data.m_value.string->size());
16329 case value_t::array:
16332 const auto N = j.m_data.m_value.array->size();
16336 write_number(
static_cast<std::uint8_t
>(0x90 | N));
16338 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16341 oa->write_character(to_char_type(0xDC));
16342 write_number(
static_cast<std::uint16_t
>(N));
16344 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16347 oa->write_character(to_char_type(0xDD));
16348 write_number(
static_cast<std::uint32_t
>(N));
16352 for (
const auto& el : *j.m_data.m_value.array)
16359 case value_t::binary:
16363 const bool use_ext = j.m_data.m_value.binary->has_subtype();
16366 const auto N = j.m_data.m_value.binary->size();
16367 if (N <= (std::numeric_limits<std::uint8_t>::max)())
16369 std::uint8_t output_type{};
16376 output_type = 0xD4;
16379 output_type = 0xD5;
16382 output_type = 0xD6;
16385 output_type = 0xD7;
16388 output_type = 0xD8;
16391 output_type = 0xC7;
16399 output_type = 0xC4;
16403 oa->write_character(to_char_type(output_type));
16406 write_number(
static_cast<std::uint8_t
>(N));
16409 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16411 const std::uint8_t output_type = use_ext
16415 oa->write_character(to_char_type(output_type));
16416 write_number(
static_cast<std::uint16_t
>(N));
16418 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16420 const std::uint8_t output_type = use_ext
16424 oa->write_character(to_char_type(output_type));
16425 write_number(
static_cast<std::uint32_t
>(N));
16431 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.binary->subtype()));
16435 oa->write_characters(
16436 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
16442 case value_t::object:
16445 const auto N = j.m_data.m_value.object->size();
16449 write_number(
static_cast<std::uint8_t
>(0x80 | (N & 0xF)));
16451 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
16454 oa->write_character(to_char_type(0xDE));
16455 write_number(
static_cast<std::uint16_t
>(N));
16457 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
16460 oa->write_character(to_char_type(0xDF));
16461 write_number(
static_cast<std::uint32_t
>(N));
16465 for (
const auto& el : *j.m_data.m_value.object)
16467 write_msgpack(el.first);
16468 write_msgpack(el.second);
16473 case value_t::discarded:
16488 const bool use_type,
const bool add_prefix =
true,
16489 const bool use_bjdata =
false,
const bjdata_version_t bjdata_version = bjdata_version_t::draft2)
16491 const bool bjdata_draft3 = use_bjdata && bjdata_version == bjdata_version_t::draft3;
16495 case value_t::null:
16499 oa->write_character(to_char_type(
'Z'));
16504 case value_t::boolean:
16508 oa->write_character(j.m_data.m_value.boolean
16509 ? to_char_type(
'T')
16510 : to_char_type(
'F'));
16515 case value_t::number_integer:
16517 write_number_with_ubjson_prefix(j.m_data.m_value.number_integer, add_prefix, use_bjdata);
16521 case value_t::number_unsigned:
16523 write_number_with_ubjson_prefix(j.m_data.m_value.number_unsigned, add_prefix, use_bjdata);
16527 case value_t::number_float:
16529 write_number_with_ubjson_prefix(j.m_data.m_value.number_float, add_prefix, use_bjdata);
16533 case value_t::string:
16537 oa->write_character(to_char_type(
'S'));
16539 write_number_with_ubjson_prefix(j.m_data.m_value.string->size(),
true, use_bjdata);
16540 oa->write_characters(
16541 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
16542 j.m_data.m_value.string->size());
16546 case value_t::array:
16550 oa->write_character(to_char_type(
'['));
16553 bool prefix_required =
true;
16554 if (use_type && !j.m_data.m_value.array->empty())
16556 JSON_ASSERT(use_count);
16557 const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
16558 const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
16559 [
this, first_prefix, use_bjdata](
const BasicJsonType & v)
16561 return ubjson_prefix(v, use_bjdata) == first_prefix;
16564 std::vector<CharType> bjdx = {
'[',
'{',
'S',
'H',
'T',
'F',
'N',
'Z'};
16566 if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
16568 prefix_required =
false;
16569 oa->write_character(to_char_type(
'$'));
16570 oa->write_character(first_prefix);
16576 oa->write_character(to_char_type(
'#'));
16577 write_number_with_ubjson_prefix(j.m_data.m_value.array->size(),
true, use_bjdata);
16580 for (
const auto& el : *j.m_data.m_value.array)
16582 write_ubjson(el, use_count, use_type, prefix_required, use_bjdata, bjdata_version);
16587 oa->write_character(to_char_type(
']'));
16593 case value_t::binary:
16597 oa->write_character(to_char_type(
'['));
16600 if (use_type && (bjdata_draft3 || !j.m_data.m_value.binary->empty()))
16602 JSON_ASSERT(use_count);
16603 oa->write_character(to_char_type(
'$'));
16604 oa->write_character(bjdata_draft3 ?
'B' :
'U');
16609 oa->write_character(to_char_type(
'#'));
16610 write_number_with_ubjson_prefix(j.m_data.m_value.binary->size(),
true, use_bjdata);
16615 oa->write_characters(
16616 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
16617 j.m_data.m_value.binary->size());
16621 for (
size_t i = 0; i < j.m_data.m_value.binary->size(); ++i)
16623 oa->write_character(to_char_type(bjdata_draft3 ?
'B' :
'U'));
16624 oa->write_character(j.m_data.m_value.binary->data()[i]);
16630 oa->write_character(to_char_type(
']'));
16636 case value_t::object:
16638 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())
16640 if (!write_bjdata_ndarray(*j.m_data.m_value.object, use_count, use_type, bjdata_version))
16648 oa->write_character(to_char_type(
'{'));
16651 bool prefix_required =
true;
16652 if (use_type && !j.m_data.m_value.object->empty())
16654 JSON_ASSERT(use_count);
16655 const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
16656 const bool same_prefix = std::all_of(j.begin(), j.end(),
16657 [
this, first_prefix, use_bjdata](
const BasicJsonType & v)
16659 return ubjson_prefix(v, use_bjdata) == first_prefix;
16662 std::vector<CharType> bjdx = {
'[',
'{',
'S',
'H',
'T',
'F',
'N',
'Z'};
16664 if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
16666 prefix_required =
false;
16667 oa->write_character(to_char_type(
'$'));
16668 oa->write_character(first_prefix);
16674 oa->write_character(to_char_type(
'#'));
16675 write_number_with_ubjson_prefix(j.m_data.m_value.object->size(),
true, use_bjdata);
16678 for (
const auto& el : *j.m_data.m_value.object)
16680 write_number_with_ubjson_prefix(el.first.size(),
true, use_bjdata);
16681 oa->write_characters(
16682 reinterpret_cast<const CharType*
>(el.first.c_str()),
16684 write_ubjson(el.second, use_count, use_type, prefix_required, use_bjdata, bjdata_version);
16689 oa->write_character(to_char_type(
'}'));
16695 case value_t::discarded:
16710 static std::size_t calc_bson_entry_header_size(
const string_t& name,
const BasicJsonType& j)
16712 const auto it = name.find(
static_cast<typename string_t::value_type
>(0));
16713 if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
16715 JSON_THROW(out_of_range::create(409, concat(
"BSON key cannot contain code point U+0000 (at byte ", std::to_string(it),
")"), &j));
16716 static_cast<void>(j);
16719 return 1ul + name.size() + 1u;
16725 void write_bson_entry_header(
const string_t& name,
16726 const std::uint8_t element_type)
16728 oa->write_character(to_char_type(element_type));
16729 oa->write_characters(
16730 reinterpret_cast<const CharType*
>(name.c_str()),
16737 void write_bson_boolean(
const string_t& name,
16740 write_bson_entry_header(name, 0x08);
16741 oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
16747 void write_bson_double(
const string_t& name,
16748 const double value)
16750 write_bson_entry_header(name, 0x01);
16751 write_number<double>(value,
true);
16757 static std::size_t calc_bson_string_size(
const string_t& value)
16759 return sizeof(std::int32_t) + value.size() + 1ul;
16765 void write_bson_string(
const string_t& name,
16766 const string_t& value)
16768 write_bson_entry_header(name, 0x02);
16770 write_number<std::int32_t>(
static_cast<std::int32_t
>(value.size() + 1ul),
true);
16771 oa->write_characters(
16772 reinterpret_cast<const CharType*
>(value.c_str()),
16779 void write_bson_null(
const string_t& name)
16781 write_bson_entry_header(name, 0x0A);
16787 static std::size_t calc_bson_integer_size(
const std::int64_t value)
16789 return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()
16790 ?
sizeof(std::int32_t)
16791 :
sizeof(std::int64_t);
16797 void write_bson_integer(
const string_t& name,
16798 const std::int64_t value)
16800 if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
16802 write_bson_entry_header(name, 0x10);
16803 write_number<std::int32_t>(
static_cast<std::int32_t
>(value),
true);
16807 write_bson_entry_header(name, 0x12);
16808 write_number<std::int64_t>(
static_cast<std::int64_t
>(value),
true);
16815 static constexpr std::size_t calc_bson_unsigned_size(
const std::uint64_t value)
noexcept
16817 return (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16818 ?
sizeof(std::int32_t)
16825 void write_bson_unsigned(
const string_t& name,
16826 const BasicJsonType& j)
16828 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16830 write_bson_entry_header(name, 0x10 );
16831 write_number<std::int32_t>(
static_cast<std::int32_t
>(j.m_data.m_value.number_unsigned),
true);
16833 else if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
16835 write_bson_entry_header(name, 0x12 );
16836 write_number<std::int64_t>(
static_cast<std::int64_t
>(j.m_data.m_value.number_unsigned),
true);
16840 write_bson_entry_header(name, 0x11 );
16841 write_number<std::uint64_t>(
static_cast<std::uint64_t
>(j.m_data.m_value.number_unsigned),
true);
16848 void write_bson_object_entry(
const string_t& name,
16849 const typename BasicJsonType::object_t& value)
16851 write_bson_entry_header(name, 0x03);
16852 write_bson_object(value);
16858 static std::size_t calc_bson_array_size(
const typename BasicJsonType::array_t& value)
16860 std::size_t array_index = 0ul;
16862 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)
16864 return result + calc_bson_element_size(std::to_string(array_index++), el);
16867 return sizeof(std::int32_t) + embedded_document_size + 1ul;
16873 static std::size_t calc_bson_binary_size(
const typename BasicJsonType::binary_t& value)
16875 return sizeof(std::int32_t) + value.size() + 1ul;
16881 void write_bson_array(
const string_t& name,
16882 const typename BasicJsonType::array_t& value)
16884 write_bson_entry_header(name, 0x04);
16885 write_number<std::int32_t>(
static_cast<std::int32_t
>(calc_bson_array_size(value)),
true);
16887 std::size_t array_index = 0ul;
16889 for (
const auto& el : value)
16891 write_bson_element(std::to_string(array_index++), el);
16894 oa->write_character(to_char_type(0x00));
16900 void write_bson_binary(
const string_t& name,
16901 const binary_t& value)
16903 write_bson_entry_header(name, 0x05);
16905 write_number<std::int32_t>(
static_cast<std::int32_t
>(value.size()),
true);
16906 write_number(value.has_subtype() ?
static_cast<std::uint8_t
>(value.subtype()) :
static_cast<std::uint8_t
>(0x00));
16908 oa->write_characters(
reinterpret_cast<const CharType*
>(value.data()), value.size());
16915 static std::size_t calc_bson_element_size(
const string_t& name,
16916 const BasicJsonType& j)
16918 const auto header_size = calc_bson_entry_header_size(name, j);
16921 case value_t::object:
16922 return header_size + calc_bson_object_size(*j.m_data.m_value.object);
16924 case value_t::array:
16925 return header_size + calc_bson_array_size(*j.m_data.m_value.array);
16927 case value_t::binary:
16928 return header_size + calc_bson_binary_size(*j.m_data.m_value.binary);
16930 case value_t::boolean:
16931 return header_size + 1ul;
16933 case value_t::number_float:
16934 return header_size + 8ul;
16936 case value_t::number_integer:
16937 return header_size + calc_bson_integer_size(j.m_data.m_value.number_integer);
16939 case value_t::number_unsigned:
16940 return header_size + calc_bson_unsigned_size(j.m_data.m_value.number_unsigned);
16942 case value_t::string:
16943 return header_size + calc_bson_string_size(*j.m_data.m_value.string);
16945 case value_t::null:
16946 return header_size + 0ul;
16949 case value_t::discarded:
16951 JSON_ASSERT(
false);
16963 void write_bson_element(
const string_t& name,
16964 const BasicJsonType& j)
16968 case value_t::object:
16969 return write_bson_object_entry(name, *j.m_data.m_value.object);
16971 case value_t::array:
16972 return write_bson_array(name, *j.m_data.m_value.array);
16974 case value_t::binary:
16975 return write_bson_binary(name, *j.m_data.m_value.binary);
16977 case value_t::boolean:
16978 return write_bson_boolean(name, j.m_data.m_value.boolean);
16980 case value_t::number_float:
16981 return write_bson_double(name, j.m_data.m_value.number_float);
16983 case value_t::number_integer:
16984 return write_bson_integer(name, j.m_data.m_value.number_integer);
16986 case value_t::number_unsigned:
16987 return write_bson_unsigned(name, j);
16989 case value_t::string:
16990 return write_bson_string(name, *j.m_data.m_value.string);
16992 case value_t::null:
16993 return write_bson_null(name);
16996 case value_t::discarded:
16998 JSON_ASSERT(
false);
17010 static std::size_t calc_bson_object_size(
const typename BasicJsonType::object_t& value)
17012 const std::size_t document_size = std::accumulate(value.begin(), value.end(),
static_cast<std::size_t
>(0),
17013 [](
size_t result,
const typename BasicJsonType::object_t::value_type & el)
17015 return result += calc_bson_element_size(el.first, el.second);
17018 return sizeof(std::int32_t) + document_size + 1ul;
17025 void write_bson_object(
const typename BasicJsonType::object_t& value)
17027 write_number<std::int32_t>(
static_cast<std::int32_t
>(calc_bson_object_size(value)),
true);
17029 for (
const auto& el : value)
17031 write_bson_element(el.first, el.second);
17034 oa->write_character(to_char_type(0x00));
17041 static constexpr CharType get_cbor_float_prefix(
float )
17043 return to_char_type(0xFA);
17046 static constexpr CharType get_cbor_float_prefix(
double )
17048 return to_char_type(0xFB);
17055 static constexpr CharType get_msgpack_float_prefix(
float )
17057 return to_char_type(0xCA);
17060 static constexpr CharType get_msgpack_float_prefix(
double )
17062 return to_char_type(0xCB);
17070 template<
typename NumberType,
typename std::enable_if<
17071 std::is_floating_point<NumberType>::value,
int>::type = 0>
17072 void write_number_with_ubjson_prefix(
const NumberType n,
17073 const bool add_prefix,
17074 const bool use_bjdata)
17078 oa->write_character(get_ubjson_float_prefix(n));
17080 write_number(n, use_bjdata);
17084 template<
typename NumberType,
typename std::enable_if<
17085 std::is_unsigned<NumberType>::value,
int>::type = 0>
17086 void write_number_with_ubjson_prefix(
const NumberType n,
17087 const bool add_prefix,
17088 const bool use_bjdata)
17090 if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
17094 oa->write_character(to_char_type(
'i'));
17096 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
17098 else if (n <= (std::numeric_limits<std::uint8_t>::max)())
17102 oa->write_character(to_char_type(
'U'));
17104 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
17106 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
17110 oa->write_character(to_char_type(
'I'));
17112 write_number(
static_cast<std::int16_t
>(n), use_bjdata);
17114 else if (use_bjdata && n <=
static_cast<uint64_t>((std::numeric_limits<uint16_t>::max)()))
17118 oa->write_character(to_char_type(
'u'));
17120 write_number(
static_cast<std::uint16_t
>(n), use_bjdata);
17122 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
17126 oa->write_character(to_char_type(
'l'));
17128 write_number(
static_cast<std::int32_t
>(n), use_bjdata);
17130 else if (use_bjdata && n <=
static_cast<uint64_t>((std::numeric_limits<uint32_t>::max)()))
17134 oa->write_character(to_char_type(
'm'));
17136 write_number(
static_cast<std::uint32_t
>(n), use_bjdata);
17138 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
17142 oa->write_character(to_char_type(
'L'));
17144 write_number(
static_cast<std::int64_t
>(n), use_bjdata);
17146 else if (use_bjdata && n <= (std::numeric_limits<uint64_t>::max)())
17150 oa->write_character(to_char_type(
'M'));
17152 write_number(
static_cast<std::uint64_t
>(n), use_bjdata);
17158 oa->write_character(to_char_type(
'H'));
17161 const auto number = BasicJsonType(n).dump();
17162 write_number_with_ubjson_prefix(number.size(),
true, use_bjdata);
17163 for (std::size_t i = 0; i < number.size(); ++i)
17165 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
17171 template <
typename NumberType,
typename std::enable_if <
17172 std::is_signed<NumberType>::value&&
17173 !std::is_floating_point<NumberType>::value,
int >::type = 0 >
17174 void write_number_with_ubjson_prefix(
const NumberType n,
17175 const bool add_prefix,
17176 const bool use_bjdata)
17178 if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
17182 oa->write_character(to_char_type(
'i'));
17184 write_number(
static_cast<std::int8_t
>(n), use_bjdata);
17186 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)()))
17190 oa->write_character(to_char_type(
'U'));
17192 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
17194 else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
17198 oa->write_character(to_char_type(
'I'));
17200 write_number(
static_cast<std::int16_t
>(n), use_bjdata);
17202 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)())))
17206 oa->write_character(to_char_type(
'u'));
17208 write_number(
static_cast<uint16_t>(n), use_bjdata);
17210 else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
17214 oa->write_character(to_char_type(
'l'));
17216 write_number(
static_cast<std::int32_t
>(n), use_bjdata);
17218 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)())))
17222 oa->write_character(to_char_type(
'm'));
17224 write_number(
static_cast<uint32_t>(n), use_bjdata);
17226 else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
17230 oa->write_character(to_char_type(
'L'));
17232 write_number(
static_cast<std::int64_t
>(n), use_bjdata);
17239 oa->write_character(to_char_type(
'H'));
17242 const auto number = BasicJsonType(n).dump();
17243 write_number_with_ubjson_prefix(number.size(),
true, use_bjdata);
17244 for (std::size_t i = 0; i < number.size(); ++i)
17246 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
17255 CharType ubjson_prefix(
const BasicJsonType& j,
const bool use_bjdata)
const noexcept
17259 case value_t::null:
17262 case value_t::boolean:
17263 return j.m_data.m_value.boolean ?
'T' :
'F';
17265 case value_t::number_integer:
17267 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)())
17271 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)())
17275 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)())
17279 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)()))
17283 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)())
17287 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)()))
17291 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)())
17299 case value_t::number_unsigned:
17301 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
17305 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint8_t>::max)()))
17309 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
17313 if (use_bjdata && j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint16_t>::max)()))
17317 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
17321 if (use_bjdata && j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint32_t>::max)()))
17325 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
17329 if (use_bjdata && j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
17337 case value_t::number_float:
17338 return get_ubjson_float_prefix(j.m_data.m_value.number_float);
17340 case value_t::string:
17343 case value_t::array:
17344 case value_t::binary:
17347 case value_t::object:
17350 case value_t::discarded:
17356 static constexpr CharType get_ubjson_float_prefix(
float )
17361 static constexpr CharType get_ubjson_float_prefix(
double )
17369 bool write_bjdata_ndarray(
const typename BasicJsonType::object_t& value,
const bool use_count,
const bool use_type,
const bjdata_version_t bjdata_version)
17371 std::map<string_t, CharType> bjdtype = {{
"uint8",
'U'}, {
"int8",
'i'}, {
"uint16",
'u'}, {
"int16",
'I'},
17372 {
"uint32",
'm'}, {
"int32",
'l'}, {
"uint64",
'M'}, {
"int64",
'L'}, {
"single",
'd'}, {
"double",
'D'},
17373 {
"char",
'C'}, {
"byte",
'B'}
17376 string_t
key =
"_ArrayType_";
17377 auto it = bjdtype.find(
static_cast<string_t
>(value.at(key)));
17378 if (it == bjdtype.end())
17382 CharType dtype = it->second;
17384 key =
"_ArraySize_";
17385 std::size_t len = (value.at(key).empty() ? 0 : 1);
17386 for (
const auto& el : value.at(key))
17388 len *=
static_cast<std::size_t
>(el.m_data.m_value.number_unsigned);
17391 key =
"_ArrayData_";
17392 if (value.at(key).size() != len)
17397 oa->write_character(
'[');
17398 oa->write_character(
'$');
17399 oa->write_character(dtype);
17400 oa->write_character(
'#');
17402 key =
"_ArraySize_";
17403 write_ubjson(value.at(key), use_count, use_type,
true,
true, bjdata_version);
17405 key =
"_ArrayData_";
17406 if (dtype ==
'U' || dtype ==
'C' || dtype ==
'B')
17408 for (
const auto& el : value.at(key))
17410 write_number(
static_cast<std::uint8_t
>(el.m_data.m_value.number_unsigned),
true);
17413 else if (dtype ==
'i')
17415 for (
const auto& el : value.at(key))
17417 write_number(
static_cast<std::int8_t
>(el.m_data.m_value.number_integer),
true);
17420 else if (dtype ==
'u')
17422 for (
const auto& el : value.at(key))
17424 write_number(
static_cast<std::uint16_t
>(el.m_data.m_value.number_unsigned),
true);
17427 else if (dtype ==
'I')
17429 for (
const auto& el : value.at(key))
17431 write_number(
static_cast<std::int16_t
>(el.m_data.m_value.number_integer),
true);
17434 else if (dtype ==
'm')
17436 for (
const auto& el : value.at(key))
17438 write_number(
static_cast<std::uint32_t
>(el.m_data.m_value.number_unsigned),
true);
17441 else if (dtype ==
'l')
17443 for (
const auto& el : value.at(key))
17445 write_number(
static_cast<std::int32_t
>(el.m_data.m_value.number_integer),
true);
17448 else if (dtype ==
'M')
17450 for (
const auto& el : value.at(key))
17452 write_number(
static_cast<std::uint64_t
>(el.m_data.m_value.number_unsigned),
true);
17455 else if (dtype ==
'L')
17457 for (
const auto& el : value.at(key))
17459 write_number(
static_cast<std::int64_t
>(el.m_data.m_value.number_integer),
true);
17462 else if (dtype ==
'd')
17464 for (
const auto& el : value.at(key))
17466 write_number(
static_cast<float>(el.m_data.m_value.number_float),
true);
17469 else if (dtype ==
'D')
17471 for (
const auto& el : value.at(key))
17473 write_number(
static_cast<double>(el.m_data.m_value.number_float),
true);
17496 template<
typename NumberType>
17497 void write_number(
const NumberType n,
const bool OutputIsLittleEndian =
false)
17500 std::array<CharType,
sizeof(NumberType)> vec{};
17501 std::memcpy(vec.data(), &n,
sizeof(NumberType));
17504 if (is_little_endian != OutputIsLittleEndian)
17507 std::reverse(vec.begin(), vec.end());
17510 oa->write_characters(vec.data(),
sizeof(NumberType));
17516#pragma GCC diagnostic push
17517#pragma GCC diagnostic ignored "-Wfloat-equal"
17519 if (
static_cast<double>(n) >=
static_cast<double>(std::numeric_limits<float>::lowest()) &&
17520 static_cast<double>(n) <=
static_cast<double>((std::numeric_limits<float>::max)()) &&
17521 static_cast<double>(
static_cast<float>(n)) ==
static_cast<double>(n))
17523 oa->write_character(format == detail::input_format_t::cbor
17524 ? get_cbor_float_prefix(
static_cast<float>(n))
17525 : get_msgpack_float_prefix(
static_cast<float>(n)));
17526 write_number(
static_cast<float>(n));
17530 oa->write_character(format == detail::input_format_t::cbor
17531 ? get_cbor_float_prefix(n)
17532 : get_msgpack_float_prefix(n));
17536#pragma GCC diagnostic pop
17545 template <
typename C = CharType,
17546 enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * =
nullptr >
17547 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
17549 return *
reinterpret_cast<char*
>(&x);
17552 template <
typename C = CharType,
17553 enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * =
nullptr >
17554 static CharType to_char_type(std::uint8_t x)
noexcept
17556 static_assert(
sizeof(std::uint8_t) ==
sizeof(CharType),
"size of CharType must be equal to std::uint8_t");
17557 static_assert(std::is_trivial<CharType>::value,
"CharType must be trivial");
17559 std::memcpy(&result, &x,
sizeof(x));
17563 template<
typename C = CharType,
17564 enable_if_t<std::is_unsigned<C>::value>* =
nullptr>
17565 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
17570 template <
typename InputCharType,
typename C = CharType,
17572 std::is_signed<C>::value &&
17573 std::is_signed<char>::value &&
17574 std::is_same<char, typename std::remove_cv<InputCharType>::type>::value
17576 static constexpr CharType to_char_type(InputCharType x)
noexcept
17583 const bool is_little_endian = little_endianness();
17586 output_adapter_t<CharType> oa =
nullptr;
17590NLOHMANN_JSON_NAMESPACE_END
17606#include <algorithm>
17616#include <type_traits>
17636#include <type_traits>
17641NLOHMANN_JSON_NAMESPACE_BEGIN
17667template<
typename Target,
typename Source>
17668Target reinterpret_bits(
const Source source)
17670 static_assert(
sizeof(Target) ==
sizeof(Source),
"size mismatch");
17673 std::memcpy(&target, &source,
sizeof(Source));
17679 static constexpr int kPrecision = 64;
17681 std::uint64_t f = 0;
17684 constexpr diyfp(std::uint64_t f_,
int e_) noexcept : f(f_), e(e_) {}
17692 JSON_ASSERT(x.e == y.e);
17693 JSON_ASSERT(x.f >= y.f);
17695 return {x.f - y.f, x.e};
17704 static_assert(kPrecision == 64,
"internal error");
17729 const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
17730 const std::uint64_t u_hi = x.f >> 32u;
17731 const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
17732 const std::uint64_t v_hi = y.f >> 32u;
17734 const std::uint64_t p0 = u_lo * v_lo;
17735 const std::uint64_t p1 = u_lo * v_hi;
17736 const std::uint64_t p2 = u_hi * v_lo;
17737 const std::uint64_t p3 = u_hi * v_hi;
17739 const std::uint64_t p0_hi = p0 >> 32u;
17740 const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
17741 const std::uint64_t p1_hi = p1 >> 32u;
17742 const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
17743 const std::uint64_t p2_hi = p2 >> 32u;
17745 std::uint64_t Q = p0_hi + p1_lo + p2_lo;
17756 Q += std::uint64_t{1} << (64u - 32u - 1u);
17758 const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
17760 return {h, x.e + y.e + 64};
17769 JSON_ASSERT(x.f != 0);
17771 while ((x.f >> 63u) == 0)
17786 const int delta = x.e - target_exponent;
17788 JSON_ASSERT(delta >= 0);
17789 JSON_ASSERT(((x.f << delta) >> delta) == x.f);
17791 return {x.f << delta, target_exponent};
17808template<
typename FloatType>
17811 JSON_ASSERT(std::isfinite(value));
17812 JSON_ASSERT(value > 0);
17821 static_assert(std::numeric_limits<FloatType>::is_iec559,
17822 "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
17824 constexpr int kPrecision = std::numeric_limits<FloatType>::digits;
17825 constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
17826 constexpr int kMinExp = 1 - kBias;
17827 constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
17829 using bits_type =
typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
17831 const auto bits =
static_cast<std::uint64_t
>(reinterpret_bits<bits_type>(value));
17832 const std::uint64_t E = bits >> (kPrecision - 1);
17833 const std::uint64_t F = bits & (kHiddenBit - 1);
17835 const bool is_denormal = E == 0;
17836 const diyfp v = is_denormal
17837 ? diyfp(F, kMinExp)
17838 : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias);
17861 const bool lower_boundary_is_closer = F == 0 && E > 1;
17862 const diyfp m_plus = diyfp((2 * v.f) + 1, v.e - 1);
17863 const diyfp m_minus = lower_boundary_is_closer
17864 ? diyfp((4 * v.f) - 1, v.e - 2)
17865 : diyfp((2 * v.f) - 1, v.e - 1);
17868 const diyfp w_plus = diyfp::normalize(m_plus);
17871 const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
17873 return {diyfp::normalize(v), w_minus, w_plus};
17931constexpr int kAlpha = -60;
17932constexpr int kGamma = -32;
18000 constexpr int kCachedPowersMinDecExp = -300;
18001 constexpr int kCachedPowersDecStep = 8;
18003 static constexpr std::array<cached_power, 79> kCachedPowers =
18006 { 0xAB70FE17C79AC6CA, -1060, -300 },
18007 { 0xFF77B1FCBEBCDC4F, -1034, -292 },
18008 { 0xBE5691EF416BD60C, -1007, -284 },
18009 { 0x8DD01FAD907FFC3C, -980, -276 },
18010 { 0xD3515C2831559A83, -954, -268 },
18011 { 0x9D71AC8FADA6C9B5, -927, -260 },
18012 { 0xEA9C227723EE8BCB, -901, -252 },
18013 { 0xAECC49914078536D, -874, -244 },
18014 { 0x823C12795DB6CE57, -847, -236 },
18015 { 0xC21094364DFB5637, -821, -228 },
18016 { 0x9096EA6F3848984F, -794, -220 },
18017 { 0xD77485CB25823AC7, -768, -212 },
18018 { 0xA086CFCD97BF97F4, -741, -204 },
18019 { 0xEF340A98172AACE5, -715, -196 },
18020 { 0xB23867FB2A35B28E, -688, -188 },
18021 { 0x84C8D4DFD2C63F3B, -661, -180 },
18022 { 0xC5DD44271AD3CDBA, -635, -172 },
18023 { 0x936B9FCEBB25C996, -608, -164 },
18024 { 0xDBAC6C247D62A584, -582, -156 },
18025 { 0xA3AB66580D5FDAF6, -555, -148 },
18026 { 0xF3E2F893DEC3F126, -529, -140 },
18027 { 0xB5B5ADA8AAFF80B8, -502, -132 },
18028 { 0x87625F056C7C4A8B, -475, -124 },
18029 { 0xC9BCFF6034C13053, -449, -116 },
18030 { 0x964E858C91BA2655, -422, -108 },
18031 { 0xDFF9772470297EBD, -396, -100 },
18032 { 0xA6DFBD9FB8E5B88F, -369, -92 },
18033 { 0xF8A95FCF88747D94, -343, -84 },
18034 { 0xB94470938FA89BCF, -316, -76 },
18035 { 0x8A08F0F8BF0F156B, -289, -68 },
18036 { 0xCDB02555653131B6, -263, -60 },
18037 { 0x993FE2C6D07B7FAC, -236, -52 },
18038 { 0xE45C10C42A2B3B06, -210, -44 },
18039 { 0xAA242499697392D3, -183, -36 },
18040 { 0xFD87B5F28300CA0E, -157, -28 },
18041 { 0xBCE5086492111AEB, -130, -20 },
18042 { 0x8CBCCC096F5088CC, -103, -12 },
18043 { 0xD1B71758E219652C, -77, -4 },
18044 { 0x9C40000000000000, -50, 4 },
18045 { 0xE8D4A51000000000, -24, 12 },
18046 { 0xAD78EBC5AC620000, 3, 20 },
18047 { 0x813F3978F8940984, 30, 28 },
18048 { 0xC097CE7BC90715B3, 56, 36 },
18049 { 0x8F7E32CE7BEA5C70, 83, 44 },
18050 { 0xD5D238A4ABE98068, 109, 52 },
18051 { 0x9F4F2726179A2245, 136, 60 },
18052 { 0xED63A231D4C4FB27, 162, 68 },
18053 { 0xB0DE65388CC8ADA8, 189, 76 },
18054 { 0x83C7088E1AAB65DB, 216, 84 },
18055 { 0xC45D1DF942711D9A, 242, 92 },
18056 { 0x924D692CA61BE758, 269, 100 },
18057 { 0xDA01EE641A708DEA, 295, 108 },
18058 { 0xA26DA3999AEF774A, 322, 116 },
18059 { 0xF209787BB47D6B85, 348, 124 },
18060 { 0xB454E4A179DD1877, 375, 132 },
18061 { 0x865B86925B9BC5C2, 402, 140 },
18062 { 0xC83553C5C8965D3D, 428, 148 },
18063 { 0x952AB45CFA97A0B3, 455, 156 },
18064 { 0xDE469FBD99A05FE3, 481, 164 },
18065 { 0xA59BC234DB398C25, 508, 172 },
18066 { 0xF6C69A72A3989F5C, 534, 180 },
18067 { 0xB7DCBF5354E9BECE, 561, 188 },
18068 { 0x88FCF317F22241E2, 588, 196 },
18069 { 0xCC20CE9BD35C78A5, 614, 204 },
18070 { 0x98165AF37B2153DF, 641, 212 },
18071 { 0xE2A0B5DC971F303A, 667, 220 },
18072 { 0xA8D9D1535CE3B396, 694, 228 },
18073 { 0xFB9B7CD9A4A7443C, 720, 236 },
18074 { 0xBB764C4CA7A44410, 747, 244 },
18075 { 0x8BAB8EEFB6409C1A, 774, 252 },
18076 { 0xD01FEF10A657842C, 800, 260 },
18077 { 0x9B10A4E5E9913129, 827, 268 },
18078 { 0xE7109BFBA19C0C9D, 853, 276 },
18079 { 0xAC2820D9623BF429, 880, 284 },
18080 { 0x80444B5E7AA7CF85, 907, 292 },
18081 { 0xBF21E44003ACDD2D, 933, 300 },
18082 { 0x8E679C2F5E44FF8F, 960, 308 },
18083 { 0xD433179D9C8CB841, 986, 316 },
18084 { 0x9E19DB92B4E31BA9, 1013, 324 },
18092 JSON_ASSERT(e >= -1500);
18093 JSON_ASSERT(e <= 1500);
18094 const int f = kAlpha -
e - 1;
18095 const int k = ((f * 78913) / (1 << 18)) +
static_cast<int>(f > 0);
18097 const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
18098 JSON_ASSERT(index >= 0);
18099 JSON_ASSERT(
static_cast<std::size_t
>(index) < kCachedPowers.size());
18101 const cached_power cached = kCachedPowers[
static_cast<std::size_t
>(index)];
18102 JSON_ASSERT(kAlpha <= cached.e + e + 64);
18103 JSON_ASSERT(kGamma >= cached.e + e + 64);
18115 if (n >= 1000000000)
18117 pow10 = 1000000000;
18121 if (n >= 100000000)
18166inline void grisu2_round(
char* buf,
int len, std::uint64_t dist, std::uint64_t delta,
18167 std::uint64_t rest, std::uint64_t ten_k)
18169 JSON_ASSERT(len >= 1);
18170 JSON_ASSERT(dist <= delta);
18171 JSON_ASSERT(rest <= delta);
18172 JSON_ASSERT(ten_k > 0);
18194 && delta - rest >= ten_k
18195 && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
18197 JSON_ASSERT(buf[len - 1] !=
'0');
18207inline void grisu2_digit_gen(
char* buffer,
int& length,
int& decimal_exponent,
18208 diyfp M_minus, diyfp w, diyfp M_plus)
18210 static_assert(kAlpha >= -60,
"internal error");
18211 static_assert(kGamma <= -32,
"internal error");
18225 JSON_ASSERT(M_plus.e >= kAlpha);
18226 JSON_ASSERT(M_plus.e <= kGamma);
18228 std::uint64_t delta = diyfp::sub(M_plus, M_minus).f;
18229 std::uint64_t dist = diyfp::sub(M_plus, w ).f;
18238 const diyfp
one(std::uint64_t{1} << -M_plus.e, M_plus.e);
18240 auto p1 =
static_cast<std::uint32_t
>(M_plus.f >> -
one.e);
18241 std::uint64_t p2 = M_plus.f & (
one.f - 1);
18247 JSON_ASSERT(p1 > 0);
18249 std::uint32_t pow10{};
18277 const std::uint32_t d = p1 / pow10;
18278 const std::uint32_t r = p1 % pow10;
18283 JSON_ASSERT(d <= 9);
18284 buffer[length++] =
static_cast<char>(
'0' + d);
18303 const std::uint64_t rest = (std::uint64_t{p1} << -
one.e) + p2;
18308 decimal_exponent += n;
18319 const std::uint64_t ten_n = std::uint64_t{pow10} << -
one.e;
18320 grisu2_round(buffer, length, dist, delta, rest, ten_n);
18370 JSON_ASSERT(p2 > delta);
18381 JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
18383 const std::uint64_t d = p2 >> -
one.e;
18384 const std::uint64_t r = p2 & (
one.f - 1);
18390 JSON_ASSERT(d <= 9);
18391 buffer[length++] =
static_cast<char>(
'0' + d);
18416 decimal_exponent -= m;
18424 const std::uint64_t ten_m =
one.f;
18425 grisu2_round(buffer, length, dist, delta, p2, ten_m);
18447JSON_HEDLEY_NON_NULL(1)
18448inline
void grisu2(
char* buf,
int& len,
int& decimal_exponent,
18449 diyfp m_minus, diyfp v, diyfp m_plus)
18451 JSON_ASSERT(m_plus.e == m_minus.e);
18452 JSON_ASSERT(m_plus.e == v.e);
18465 const diyfp c_minus_k(cached.f, cached.e);
18468 const diyfp w = diyfp::mul(v, c_minus_k);
18469 const diyfp w_minus = diyfp::mul(m_minus, c_minus_k);
18470 const diyfp w_plus = diyfp::mul(m_plus, c_minus_k);
18493 const diyfp M_minus(w_minus.f + 1, w_minus.e);
18494 const diyfp M_plus (w_plus.f - 1, w_plus.e );
18496 decimal_exponent = -cached.k;
18506template<
typename FloatType>
18507JSON_HEDLEY_NON_NULL(1)
18508void grisu2(
char* buf,
int& len,
int& decimal_exponent, FloatType value)
18510 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
18511 "internal error: not enough precision");
18513 JSON_ASSERT(std::isfinite(value));
18514 JSON_ASSERT(value > 0);
18538 grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
18546JSON_HEDLEY_NON_NULL(1)
18547JSON_HEDLEY_RETURNS_NON_NULL
18548inline
char* append_exponent(
char* buf,
int e)
18550 JSON_ASSERT(e > -1000);
18551 JSON_ASSERT(e < 1000);
18563 auto k =
static_cast<std::uint32_t
>(
e);
18569 *buf++ =
static_cast<char>(
'0' + k);
18573 *buf++ =
static_cast<char>(
'0' + (k / 10));
18575 *buf++ =
static_cast<char>(
'0' + k);
18579 *buf++ =
static_cast<char>(
'0' + (k / 100));
18581 *buf++ =
static_cast<char>(
'0' + (k / 10));
18583 *buf++ =
static_cast<char>(
'0' + k);
18598JSON_HEDLEY_NON_NULL(1)
18599JSON_HEDLEY_RETURNS_NON_NULL
18600inline
char* format_buffer(
char* buf,
int len,
int decimal_exponent,
18601 int min_exp,
int max_exp)
18603 JSON_ASSERT(min_exp < 0);
18604 JSON_ASSERT(max_exp > 0);
18607 const int n = len + decimal_exponent;
18613 if (k <= n && n <= max_exp)
18618 std::memset(buf + k,
'0',
static_cast<size_t>(n) -
static_cast<size_t>(k));
18622 return buf + (
static_cast<size_t>(n) + 2);
18625 if (0 < n && n <= max_exp)
18630 JSON_ASSERT(k > n);
18632 std::memmove(buf + (
static_cast<size_t>(n) + 1), buf + n,
static_cast<size_t>(k) -
static_cast<size_t>(n));
18634 return buf + (
static_cast<size_t>(k) + 1U);
18637 if (min_exp < n && n <= 0)
18642 std::memmove(buf + (2 +
static_cast<size_t>(-n)), buf,
static_cast<size_t>(k));
18645 std::memset(buf + 2,
'0',
static_cast<size_t>(-n));
18646 return buf + (2U +
static_cast<size_t>(-n) +
static_cast<size_t>(k));
18661 std::memmove(buf + 2, buf + 1,
static_cast<size_t>(k) - 1);
18663 buf += 1 +
static_cast<size_t>(k);
18682template<
typename FloatType>
18683JSON_HEDLEY_NON_NULL(1, 2)
18684JSON_HEDLEY_RETURNS_NON_NULL
18685char* to_chars(
char* first, const
char* last, FloatType value)
18687 static_cast<void>(last);
18688 JSON_ASSERT(std::isfinite(value));
18691 if (std::signbit(value))
18698#pragma GCC diagnostic push
18699#pragma GCC diagnostic ignored "-Wfloat-equal"
18710#pragma GCC diagnostic pop
18713 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
18720 int decimal_exponent = 0;
18721 dtoa_impl::grisu2(first, len, decimal_exponent, value);
18723 JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
18726 constexpr int kMinExp = -4;
18728 constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10;
18730 JSON_ASSERT(last - first >= kMaxExp + 2);
18731 JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
18732 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
18734 return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);
18738NLOHMANN_JSON_NAMESPACE_END
18755NLOHMANN_JSON_NAMESPACE_BEGIN
18771template<
typename BasicJsonType>
18774 using string_t =
typename BasicJsonType::string_t;
18775 using number_float_t =
typename BasicJsonType::number_float_t;
18776 using number_integer_t =
typename BasicJsonType::number_integer_t;
18777 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
18778 using binary_char_t =
typename BasicJsonType::binary_t::value_type;
18779 static constexpr std::uint8_t UTF8_ACCEPT = 0;
18780 static constexpr std::uint8_t UTF8_REJECT = 1;
18791 , loc(std::localeconv())
18792 , thousands_sep(loc->thousands_sep == nullptr ?
'\0' : std::
char_traits<char>::to_char_type(* (loc->thousands_sep)))
18793 , decimal_point(loc->decimal_point == nullptr ?
'\0' : std::
char_traits<char>::to_char_type(* (loc->decimal_point)))
18794 , indent_char(ichar)
18795 , indent_string(512, indent_char)
18796 , error_handler(error_handler_)
18829 const bool pretty_print,
18830 const bool ensure_ascii,
18831 const unsigned int indent_step,
18832 const unsigned int current_indent = 0)
18834 switch (val.m_data.m_type)
18836 case value_t::object:
18838 if (val.m_data.m_value.object->empty())
18840 o->write_characters(
"{}", 2);
18846 o->write_characters(
"{\n", 2);
18849 const auto new_indent = current_indent + indent_step;
18850 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
18852 indent_string.resize(indent_string.size() * 2,
' ');
18856 auto i = val.m_data.m_value.object->cbegin();
18857 for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)
18859 o->write_characters(indent_string.c_str(), new_indent);
18860 o->write_character(
'\"');
18861 dump_escaped(i->first, ensure_ascii);
18862 o->write_characters(
"\": ", 3);
18863 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
18864 o->write_characters(
",\n", 2);
18868 JSON_ASSERT(i != val.m_data.m_value.object->cend());
18869 JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
18870 o->write_characters(indent_string.c_str(), new_indent);
18871 o->write_character(
'\"');
18872 dump_escaped(i->first, ensure_ascii);
18873 o->write_characters(
"\": ", 3);
18874 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
18876 o->write_character(
'\n');
18877 o->write_characters(indent_string.c_str(), current_indent);
18878 o->write_character(
'}');
18882 o->write_character(
'{');
18885 auto i = val.m_data.m_value.object->cbegin();
18886 for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)
18888 o->write_character(
'\"');
18889 dump_escaped(i->first, ensure_ascii);
18890 o->write_characters(
"\":", 2);
18891 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
18892 o->write_character(
',');
18896 JSON_ASSERT(i != val.m_data.m_value.object->cend());
18897 JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
18898 o->write_character(
'\"');
18899 dump_escaped(i->first, ensure_ascii);
18900 o->write_characters(
"\":", 2);
18901 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
18903 o->write_character(
'}');
18909 case value_t::array:
18911 if (val.m_data.m_value.array->empty())
18913 o->write_characters(
"[]", 2);
18919 o->write_characters(
"[\n", 2);
18922 const auto new_indent = current_indent + indent_step;
18923 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
18925 indent_string.resize(indent_string.size() * 2,
' ');
18929 for (
auto i = val.m_data.m_value.array->cbegin();
18930 i != val.m_data.m_value.array->cend() - 1; ++i)
18932 o->write_characters(indent_string.c_str(), new_indent);
18933 dump(*i,
true, ensure_ascii, indent_step, new_indent);
18934 o->write_characters(
",\n", 2);
18938 JSON_ASSERT(!val.m_data.m_value.array->empty());
18939 o->write_characters(indent_string.c_str(), new_indent);
18940 dump(val.m_data.m_value.array->back(),
true, ensure_ascii, indent_step, new_indent);
18942 o->write_character(
'\n');
18943 o->write_characters(indent_string.c_str(), current_indent);
18944 o->write_character(
']');
18948 o->write_character(
'[');
18951 for (
auto i = val.m_data.m_value.array->cbegin();
18952 i != val.m_data.m_value.array->cend() - 1; ++i)
18954 dump(*i,
false, ensure_ascii, indent_step, current_indent);
18955 o->write_character(
',');
18959 JSON_ASSERT(!val.m_data.m_value.array->empty());
18960 dump(val.m_data.m_value.array->back(),
false, ensure_ascii, indent_step, current_indent);
18962 o->write_character(
']');
18968 case value_t::string:
18970 o->write_character(
'\"');
18971 dump_escaped(*val.m_data.m_value.string, ensure_ascii);
18972 o->write_character(
'\"');
18976 case value_t::binary:
18980 o->write_characters(
"{\n", 2);
18983 const auto new_indent = current_indent + indent_step;
18984 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
18986 indent_string.resize(indent_string.size() * 2,
' ');
18989 o->write_characters(indent_string.c_str(), new_indent);
18991 o->write_characters(
"\"bytes\": [", 10);
18993 if (!val.m_data.m_value.binary->empty())
18995 for (
auto i = val.m_data.m_value.binary->cbegin();
18996 i != val.m_data.m_value.binary->cend() - 1; ++i)
18999 o->write_characters(
", ", 2);
19001 dump_integer(val.m_data.m_value.binary->back());
19004 o->write_characters(
"],\n", 3);
19005 o->write_characters(indent_string.c_str(), new_indent);
19007 o->write_characters(
"\"subtype\": ", 11);
19008 if (val.m_data.m_value.binary->has_subtype())
19010 dump_integer(val.m_data.m_value.binary->subtype());
19014 o->write_characters(
"null", 4);
19016 o->write_character(
'\n');
19017 o->write_characters(indent_string.c_str(), current_indent);
19018 o->write_character(
'}');
19022 o->write_characters(
"{\"bytes\":[", 10);
19024 if (!val.m_data.m_value.binary->empty())
19026 for (
auto i = val.m_data.m_value.binary->cbegin();
19027 i != val.m_data.m_value.binary->cend() - 1; ++i)
19030 o->write_character(
',');
19032 dump_integer(val.m_data.m_value.binary->back());
19035 o->write_characters(
"],\"subtype\":", 12);
19036 if (val.m_data.m_value.binary->has_subtype())
19038 dump_integer(val.m_data.m_value.binary->subtype());
19039 o->write_character(
'}');
19043 o->write_characters(
"null}", 5);
19049 case value_t::boolean:
19051 if (val.m_data.m_value.boolean)
19053 o->write_characters(
"true", 4);
19057 o->write_characters(
"false", 5);
19062 case value_t::number_integer:
19064 dump_integer(val.m_data.m_value.number_integer);
19068 case value_t::number_unsigned:
19070 dump_integer(val.m_data.m_value.number_unsigned);
19074 case value_t::number_float:
19076 dump_float(val.m_data.m_value.number_float);
19080 case value_t::discarded:
19082 o->write_characters(
"<discarded>", 11);
19086 case value_t::null:
19088 o->write_characters(
"null", 4);
19093 JSON_ASSERT(
false);
19097 JSON_PRIVATE_UNLESS_TESTED:
19112 void dump_escaped(
const string_t& s,
const bool ensure_ascii)
19114 std::uint32_t codepoint{};
19115 std::uint8_t state = UTF8_ACCEPT;
19116 std::size_t bytes = 0;
19119 std::size_t bytes_after_last_accept = 0;
19120 std::size_t undumped_chars = 0;
19122 for (std::size_t i = 0; i < s.size(); ++i)
19124 const auto byte =
static_cast<std::uint8_t
>(s[i]);
19126 switch (decode(state, codepoint,
byte))
19134 string_buffer[bytes++] =
'\\';
19135 string_buffer[bytes++] =
'b';
19141 string_buffer[bytes++] =
'\\';
19142 string_buffer[bytes++] =
't';
19148 string_buffer[bytes++] =
'\\';
19149 string_buffer[bytes++] =
'n';
19155 string_buffer[bytes++] =
'\\';
19156 string_buffer[bytes++] =
'f';
19162 string_buffer[bytes++] =
'\\';
19163 string_buffer[bytes++] =
'r';
19169 string_buffer[bytes++] =
'\\';
19170 string_buffer[bytes++] =
'\"';
19176 string_buffer[bytes++] =
'\\';
19177 string_buffer[bytes++] =
'\\';
19185 if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
19187 if (codepoint <= 0xFFFF)
19190 static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 7,
"\\u%04x",
19191 static_cast<std::uint16_t
>(codepoint)));
19197 static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 13,
"\\u%04x\\u%04x",
19198 static_cast<std::uint16_t
>(0xD7C0u + (codepoint >> 10u)),
19199 static_cast<std::uint16_t
>(0xDC00u + (codepoint & 0x3FFu))));
19207 string_buffer[bytes++] = s[i];
19216 if (string_buffer.size() - bytes < 13)
19218 o->write_characters(string_buffer.data(), bytes);
19223 bytes_after_last_accept = bytes;
19224 undumped_chars = 0;
19230 switch (error_handler)
19232 case error_handler_t::strict:
19234 JSON_THROW(type_error::create(316, concat(
"invalid UTF-8 byte at index ", std::to_string(i),
": 0x", hex_bytes(
byte | 0)),
nullptr));
19237 case error_handler_t::ignore:
19238 case error_handler_t::replace:
19244 if (undumped_chars > 0)
19251 bytes = bytes_after_last_accept;
19253 if (error_handler == error_handler_t::replace)
19258 string_buffer[bytes++] =
'\\';
19259 string_buffer[bytes++] =
'u';
19260 string_buffer[bytes++] =
'f';
19261 string_buffer[bytes++] =
'f';
19262 string_buffer[bytes++] =
'f';
19263 string_buffer[bytes++] =
'd';
19275 if (string_buffer.size() - bytes < 13)
19277 o->write_characters(string_buffer.data(), bytes);
19281 bytes_after_last_accept = bytes;
19284 undumped_chars = 0;
19287 state = UTF8_ACCEPT;
19292 JSON_ASSERT(
false);
19302 string_buffer[bytes++] = s[i];
19311 if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
19316 o->write_characters(string_buffer.data(), bytes);
19322 switch (error_handler)
19324 case error_handler_t::strict:
19326 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));
19329 case error_handler_t::ignore:
19332 o->write_characters(string_buffer.data(), bytes_after_last_accept);
19336 case error_handler_t::replace:
19339 o->write_characters(string_buffer.data(), bytes_after_last_accept);
19343 o->write_characters(
"\\ufffd", 6);
19347 o->write_characters(
"\xEF\xBF\xBD", 3);
19353 JSON_ASSERT(
false);
19367 unsigned int count_digits(number_unsigned_t x)
noexcept
19369 unsigned int n_digits = 1;
19378 return n_digits + 1;
19382 return n_digits + 2;
19386 return n_digits + 3;
19398 static std::string hex_bytes(std::uint8_t
byte)
19400 std::string result =
"FF";
19401 constexpr const char* nibble_to_hex =
"0123456789ABCDEF";
19402 result[0] = nibble_to_hex[
byte / 16];
19403 result[1] = nibble_to_hex[
byte % 16];
19408 template <typename NumberType, enable_if_t<std::is_signed<NumberType>::value,
int> = 0>
19409 bool is_negative_number(NumberType x)
19414 template < typename NumberType, enable_if_t <std::is_unsigned<NumberType>::value,
int > = 0 >
19415 bool is_negative_number(NumberType )
19429 template <
typename NumberType, detail::enable_if_t <
19430 std::is_integral<NumberType>::value ||
19431 std::is_same<NumberType, number_unsigned_t>::value ||
19432 std::is_same<NumberType, number_integer_t>::value ||
19433 std::is_same<NumberType, binary_char_t>::value,
19435 void dump_integer(NumberType x)
19437 static constexpr std::array<std::array<char, 2>, 100> digits_to_99
19440 {{
'0',
'0'}}, {{
'0',
'1'}}, {{
'0',
'2'}}, {{
'0',
'3'}}, {{
'0',
'4'}}, {{
'0',
'5'}}, {{
'0',
'6'}}, {{
'0',
'7'}}, {{
'0',
'8'}}, {{
'0',
'9'}},
19441 {{
'1',
'0'}}, {{
'1',
'1'}}, {{
'1',
'2'}}, {{
'1',
'3'}}, {{
'1',
'4'}}, {{
'1',
'5'}}, {{
'1',
'6'}}, {{
'1',
'7'}}, {{
'1',
'8'}}, {{
'1',
'9'}},
19442 {{
'2',
'0'}}, {{
'2',
'1'}}, {{
'2',
'2'}}, {{
'2',
'3'}}, {{
'2',
'4'}}, {{
'2',
'5'}}, {{
'2',
'6'}}, {{
'2',
'7'}}, {{
'2',
'8'}}, {{
'2',
'9'}},
19443 {{
'3',
'0'}}, {{
'3',
'1'}}, {{
'3',
'2'}}, {{
'3',
'3'}}, {{
'3',
'4'}}, {{
'3',
'5'}}, {{
'3',
'6'}}, {{
'3',
'7'}}, {{
'3',
'8'}}, {{
'3',
'9'}},
19444 {{
'4',
'0'}}, {{
'4',
'1'}}, {{
'4',
'2'}}, {{
'4',
'3'}}, {{
'4',
'4'}}, {{
'4',
'5'}}, {{
'4',
'6'}}, {{
'4',
'7'}}, {{
'4',
'8'}}, {{
'4',
'9'}},
19445 {{
'5',
'0'}}, {{
'5',
'1'}}, {{
'5',
'2'}}, {{
'5',
'3'}}, {{
'5',
'4'}}, {{
'5',
'5'}}, {{
'5',
'6'}}, {{
'5',
'7'}}, {{
'5',
'8'}}, {{
'5',
'9'}},
19446 {{
'6',
'0'}}, {{
'6',
'1'}}, {{
'6',
'2'}}, {{
'6',
'3'}}, {{
'6',
'4'}}, {{
'6',
'5'}}, {{
'6',
'6'}}, {{
'6',
'7'}}, {{
'6',
'8'}}, {{
'6',
'9'}},
19447 {{
'7',
'0'}}, {{
'7',
'1'}}, {{
'7',
'2'}}, {{
'7',
'3'}}, {{
'7',
'4'}}, {{
'7',
'5'}}, {{
'7',
'6'}}, {{
'7',
'7'}}, {{
'7',
'8'}}, {{
'7',
'9'}},
19448 {{
'8',
'0'}}, {{
'8',
'1'}}, {{
'8',
'2'}}, {{
'8',
'3'}}, {{
'8',
'4'}}, {{
'8',
'5'}}, {{
'8',
'6'}}, {{
'8',
'7'}}, {{
'8',
'8'}}, {{
'8',
'9'}},
19449 {{
'9',
'0'}}, {{
'9',
'1'}}, {{
'9',
'2'}}, {{
'9',
'3'}}, {{
'9',
'4'}}, {{
'9',
'5'}}, {{
'9',
'6'}}, {{
'9',
'7'}}, {{
'9',
'8'}}, {{
'9',
'9'}},
19456 o->write_character(
'0');
19461 auto buffer_ptr = number_buffer.begin();
19463 number_unsigned_t abs_value;
19465 unsigned int n_chars{};
19467 if (is_negative_number(x))
19470 abs_value = remove_sign(
static_cast<number_integer_t
>(x));
19473 n_chars = 1 + count_digits(abs_value);
19477 abs_value =
static_cast<number_unsigned_t
>(x);
19478 n_chars = count_digits(abs_value);
19482 JSON_ASSERT(n_chars < number_buffer.size() - 1);
19486 buffer_ptr += n_chars;
19490 while (abs_value >= 100)
19492 const auto digits_index =
static_cast<unsigned>((abs_value % 100));
19494 *(--buffer_ptr) = digits_to_99[digits_index][1];
19495 *(--buffer_ptr) = digits_to_99[digits_index][0];
19498 if (abs_value >= 10)
19500 const auto digits_index =
static_cast<unsigned>(abs_value);
19501 *(--buffer_ptr) = digits_to_99[digits_index][1];
19502 *(--buffer_ptr) = digits_to_99[digits_index][0];
19506 *(--buffer_ptr) =
static_cast<char>(
'0' + abs_value);
19509 o->write_characters(number_buffer.data(), n_chars);
19520 void dump_float(number_float_t x)
19523 if (!std::isfinite(x))
19525 o->write_characters(
"null", 4);
19534 static constexpr bool is_ieee_single_or_double
19535 = (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) ||
19536 (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);
19538 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
19541 void dump_float(number_float_t x, std::true_type )
19543 auto* begin = number_buffer.data();
19544 auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
19546 o->write_characters(begin,
static_cast<size_t>(end - begin));
19549 void dump_float(number_float_t x, std::false_type )
19552 static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
19556 std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(),
"%.*g", d, x);
19559 JSON_ASSERT(len > 0);
19561 JSON_ASSERT(
static_cast<std::size_t
>(len) < number_buffer.size());
19564 if (thousands_sep !=
'\0')
19567 const auto end = std::remove(number_buffer.begin(), number_buffer.begin() + len, thousands_sep);
19568 std::fill(end, number_buffer.end(),
'\0');
19569 JSON_ASSERT((end - number_buffer.begin()) <= len);
19570 len = (end - number_buffer.begin());
19574 if (decimal_point !=
'\0' && decimal_point !=
'.')
19577 const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
19578 if (dec_pos != number_buffer.end())
19584 o->write_characters(number_buffer.data(),
static_cast<std::size_t
>(len));
19587 const bool value_is_int_like =
19588 std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
19591 return c ==
'.' || c ==
'e';
19594 if (value_is_int_like)
19596 o->write_characters(
".0", 2);
19621 static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep,
const std::uint8_t
byte)
noexcept
19623 static const std::array<std::uint8_t, 400> utf8d =
19626 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,
19627 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,
19628 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,
19629 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,
19630 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,
19631 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,
19632 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,
19633 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3,
19634 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
19635 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1,
19636 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,
19637 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,
19638 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,
19639 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
19643 JSON_ASSERT(
byte < utf8d.size());
19644 const std::uint8_t type = utf8d[
byte];
19646 codep = (state != UTF8_ACCEPT)
19647 ? (
byte & 0x3fu) | (codep << 6u)
19648 : (0xFFu >> type) & (
byte);
19650 const std::size_t index = 256u + (
static_cast<size_t>(state) * 16u) +
static_cast<size_t>(type);
19651 JSON_ASSERT(index < utf8d.size());
19652 state = utf8d[index];
19661 number_unsigned_t remove_sign(number_unsigned_t x)
19663 JSON_ASSERT(
false);
19676 number_unsigned_t remove_sign(number_integer_t x)
noexcept
19678 JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)());
19679 return static_cast<number_unsigned_t
>(-(x + 1)) + 1;
19684 output_adapter_t<char> o =
nullptr;
19687 std::array<char, 64> number_buffer{{}};
19690 const std::lconv* loc =
nullptr;
19692 const char thousands_sep =
'\0';
19694 const char decimal_point =
'\0';
19697 std::array<char, 512> string_buffer{{}};
19700 const char indent_char;
19702 string_t indent_string;
19709NLOHMANN_JSON_NAMESPACE_END
19726#include <functional>
19727#include <initializer_list>
19730#include <stdexcept>
19731#include <type_traits>
19740NLOHMANN_JSON_NAMESPACE_BEGIN
19744template <
class Key,
class T,
class IgnoredLess = std::less<Key>,
19745 class Allocator = std::allocator<std::pair<const Key, T>>>
19748 using key_type = Key;
19749 using mapped_type = T;
19750 using Container = std::vector<std::pair<const Key, T>, Allocator>;
19751 using iterator =
typename Container::iterator;
19752 using const_iterator =
typename Container::const_iterator;
19753 using size_type =
typename Container::size_type;
19754 using value_type =
typename Container::value_type;
19755#ifdef JSON_HAS_CPP_14
19756 using key_compare = std::equal_to<>;
19758 using key_compare = std::equal_to<Key>;
19763 ordered_map()
noexcept(
noexcept(Container())) : Container{} {}
19764 explicit ordered_map(
const Allocator& alloc)
noexcept(
noexcept(Container(alloc))) : Container{alloc} {}
19765 template <
class It>
19766 ordered_map(It first, It last,
const Allocator& alloc = Allocator())
19767 : Container{first, last, alloc} {}
19768 ordered_map(std::initializer_list<value_type> init,
const Allocator& alloc = Allocator() )
19769 : Container{init, alloc} {}
19771 std::pair<iterator, bool> emplace(
const key_type& key, T&& t)
19773 for (
auto it = this->begin(); it != this->end(); ++it)
19775 if (m_compare(it->first, key))
19777 return {it,
false};
19780 Container::emplace_back(key, std::forward<T>(t));
19781 return {std::prev(this->end()),
true};
19784 template<
class KeyType, detail::enable_if_t<
19785 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19786 std::pair<iterator, bool> emplace(KeyType && key, T && t)
19788 for (
auto it = this->begin(); it != this->end(); ++it)
19790 if (m_compare(it->first, key))
19792 return {it,
false};
19795 Container::emplace_back(std::forward<KeyType>(key), std::forward<T>(t));
19796 return {std::prev(this->end()),
true};
19799 T& operator[](
const key_type& key)
19801 return emplace(key, T{}).first->second;
19804 template<
class KeyType, detail::enable_if_t<
19805 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19806 T & operator[](KeyType && key)
19808 return emplace(std::forward<KeyType>(key), T{}).first->second;
19811 const T& operator[](
const key_type& key)
const
19816 template<
class KeyType, detail::enable_if_t<
19817 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19818 const T & operator[](KeyType && key)
const
19820 return at(std::forward<KeyType>(key));
19823 T& at(
const key_type& key)
19825 for (
auto it = this->begin(); it != this->end(); ++it)
19827 if (m_compare(it->first, key))
19833 JSON_THROW(std::out_of_range(
"key not found"));
19836 template<
class KeyType, detail::enable_if_t<
19837 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19838 T & at(KeyType && key)
19840 for (
auto it = this->begin(); it != this->end(); ++it)
19842 if (m_compare(it->first, key))
19848 JSON_THROW(std::out_of_range(
"key not found"));
19851 const T& at(
const key_type& key)
const
19853 for (
auto it = this->begin(); it != this->end(); ++it)
19855 if (m_compare(it->first, key))
19861 JSON_THROW(std::out_of_range(
"key not found"));
19864 template<
class KeyType, detail::enable_if_t<
19865 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19866 const T & at(KeyType && key)
const
19868 for (
auto it = this->begin(); it != this->end(); ++it)
19870 if (m_compare(it->first, key))
19876 JSON_THROW(std::out_of_range(
"key not found"));
19879 size_type erase(
const key_type& key)
19881 for (
auto it = this->begin(); it != this->end(); ++it)
19883 if (m_compare(it->first, key))
19886 for (
auto next = it; ++next != this->end(); ++it)
19889 new (&*it) value_type{std::move(*next)};
19891 Container::pop_back();
19898 template<
class KeyType, detail::enable_if_t<
19899 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19900 size_type erase(KeyType && key)
19902 for (
auto it = this->begin(); it != this->end(); ++it)
19904 if (m_compare(it->first, key))
19907 for (
auto next = it; ++next != this->end(); ++it)
19910 new (&*it) value_type{std::move(*next)};
19912 Container::pop_back();
19919 iterator erase(iterator pos)
19921 return erase(pos, std::next(pos));
19924 iterator erase(iterator first, iterator last)
19931 const auto elements_affected = std::distance(first, last);
19932 const auto offset = std::distance(Container::begin(), first);
19954 for (
auto it = first; std::next(it, elements_affected) != Container::end(); ++it)
19957 new (&*it) value_type{std::move(*std::next(it, elements_affected))};
19965 Container::resize(this->size() -
static_cast<size_type
>(elements_affected));
19974 return Container::begin() + offset;
19977 size_type count(
const key_type& key)
const
19979 for (
auto it = this->begin(); it != this->end(); ++it)
19981 if (m_compare(it->first, key))
19989 template<
class KeyType, detail::enable_if_t<
19990 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19991 size_type count(KeyType && key)
const
19993 for (
auto it = this->begin(); it != this->end(); ++it)
19995 if (m_compare(it->first, key))
20003 iterator find(
const key_type& key)
20005 for (
auto it = this->begin(); it != this->end(); ++it)
20007 if (m_compare(it->first, key))
20012 return Container::end();
20015 template<
class KeyType, detail::enable_if_t<
20016 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
20017 iterator find(KeyType && key)
20019 for (
auto it = this->begin(); it != this->end(); ++it)
20021 if (m_compare(it->first, key))
20026 return Container::end();
20029 const_iterator find(
const key_type& key)
const
20031 for (
auto it = this->begin(); it != this->end(); ++it)
20033 if (m_compare(it->first, key))
20038 return Container::end();
20041 std::pair<iterator, bool> insert( value_type&& value )
20043 return emplace(value.first, std::move(value.second));
20046 std::pair<iterator, bool> insert(
const value_type& value )
20048 for (
auto it = this->begin(); it != this->end(); ++it)
20050 if (m_compare(it->first, value.first))
20052 return {it,
false};
20055 Container::push_back(value);
20056 return {--this->end(),
true};
20059 template<
typename InputIt>
20060 using require_input_iter =
typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
20061 std::input_iterator_tag>::value>::type;
20063 template<
typename InputIt,
typename = require_input_iter<InputIt>>
20064 void insert(InputIt first, InputIt last)
20066 for (
auto it = first; it != last; ++it)
20073 JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare();
20076NLOHMANN_JSON_NAMESPACE_END
20079#if defined(JSON_HAS_CPP_17)
20080 #if JSON_HAS_STATIC_RTTI
20083 #include <string_view>
20091NLOHMANN_JSON_NAMESPACE_BEGIN
20111NLOHMANN_BASIC_JSON_TPL_DECLARATION
20113 :
public ::nlohmann::detail::json_base_class<CustomBaseClass>
20119 friend class ::nlohmann::json_pointer;
20123 template<
typename BasicJsonType,
typename InputType>
20124 friend class ::nlohmann::detail::parser;
20125 friend ::nlohmann::detail::serializer<basic_json>;
20126 template<
typename BasicJsonType>
20127 friend class ::nlohmann::detail::iter_impl;
20128 template<
typename BasicJsonType,
typename CharType>
20129 friend class ::nlohmann::detail::binary_writer;
20130 template<
typename BasicJsonType,
typename InputType,
typename SAX>
20131 friend class ::nlohmann::detail::binary_reader;
20132 template<
typename BasicJsonType,
typename InputAdapterType>
20133 friend class ::nlohmann::detail::json_sax_dom_parser;
20134 template<
typename BasicJsonType,
typename InputAdapterType>
20135 friend class ::nlohmann::detail::json_sax_dom_callback_parser;
20136 friend class ::nlohmann::detail::exception;
20139 using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
20140 using json_base_class_t = ::nlohmann::detail::json_base_class<CustomBaseClass>;
20142 JSON_PRIVATE_UNLESS_TESTED:
20144 using lexer = ::nlohmann::detail::lexer_base<basic_json>;
20146 template<
typename InputAdapterType>
20147 static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
20148 InputAdapterType adapter,
20149 detail::parser_callback_t<basic_json>cb =
nullptr,
20150 const bool allow_exceptions =
true,
20151 const bool ignore_comments =
false
20154 return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
20155 std::move(cb), allow_exceptions, ignore_comments);
20159 using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
20160 template<
typename BasicJsonType>
20161 using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
20162 template<
typename BasicJsonType>
20163 using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>;
20164 template<
typename Iterator>
20165 using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>;
20166 template<
typename Base>
using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>;
20168 template<
typename CharType>
20169 using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>;
20171 template<
typename InputType>
20172 using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
20173 template<
typename CharType>
using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
20175 JSON_PRIVATE_UNLESS_TESTED:
20176 using serializer = ::nlohmann::detail::serializer<basic_json>;
20181 using json_pointer = ::nlohmann::json_pointer<StringType>;
20182 template<
typename T,
typename SFINAE>
20183 using json_serializer = JSONSerializer<T, SFINAE>;
20240 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
20242 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
20245 using iterator = iter_impl<basic_json>;
20249 using reverse_iterator = json_reverse_iterator<typename basic_json::iterator>;
20264 JSON_HEDLEY_WARN_UNUSED_RESULT
20269 result[
"copyright"] =
"(C) 2013-2025 Niels Lohmann";
20270 result[
"name"] =
"JSON for Modern C++";
20271 result[
"url"] =
"https://github.com/nlohmann/json";
20272 result[
"version"][
"string"] =
20273 detail::concat(std::to_string(NLOHMANN_JSON_VERSION_MAJOR),
'.',
20274 std::to_string(NLOHMANN_JSON_VERSION_MINOR),
'.',
20275 std::to_string(NLOHMANN_JSON_VERSION_PATCH));
20276 result[
"version"][
"major"] = NLOHMANN_JSON_VERSION_MAJOR;
20277 result[
"version"][
"minor"] = NLOHMANN_JSON_VERSION_MINOR;
20278 result[
"version"][
"patch"] = NLOHMANN_JSON_VERSION_PATCH;
20281 result[
"platform"] =
"win32";
20282#elif defined __linux__
20283 result[
"platform"] =
"linux";
20284#elif defined __APPLE__
20285 result[
"platform"] =
"apple";
20286#elif defined __unix__
20287 result[
"platform"] =
"unix";
20289 result[
"platform"] =
"unknown";
20292#if defined(__ICC) || defined(__INTEL_COMPILER)
20293 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
20294#elif defined(__clang__)
20295 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
20296#elif defined(__GNUC__) || defined(__GNUG__)
20297 result[
"compiler"] = {{
"family",
"gcc"}, {
"version", detail::concat(
20298 std::to_string(__GNUC__),
'.',
20299 std::to_string(__GNUC_MINOR__),
'.',
20300 std::to_string(__GNUC_PATCHLEVEL__))
20303#elif defined(__HP_cc) || defined(__HP_aCC)
20304 result[
"compiler"] =
"hp"
20305#elif defined(__IBMCPP__)
20306 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
20307#elif defined(_MSC_VER)
20308 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
20309#elif defined(__PGI)
20310 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
20311#elif defined(__SUNPRO_CC)
20312 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
20314 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
20317#if defined(_MSVC_LANG)
20318 result[
"compiler"][
"c++"] = std::to_string(_MSVC_LANG);
20319#elif defined(__cplusplus)
20320 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
20322 result[
"compiler"][
"c++"] =
"unknown";
20340#if defined(JSON_HAS_CPP_14)
20343 using default_object_comparator_t = std::less<>;
20345 using default_object_comparator_t = std::less<StringType>;
20350 using object_t = ObjectType<StringType,
20352 default_object_comparator_t,
20353 AllocatorType<std::pair<
const StringType,
20358 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
20362 using string_t = StringType;
20366 using boolean_t = BooleanType;
20370 using number_integer_t = NumberIntegerType;
20374 using number_unsigned_t = NumberUnsignedType;
20378 using number_float_t = NumberFloatType;
20382 using binary_t = nlohmann::byte_container_with_subtype<BinaryType>;
20386 using object_comparator_t = detail::actual_object_comparator_t<basic_json>;
20393 template<
typename T,
typename... Args>
20394 JSON_HEDLEY_RETURNS_NON_NULL
20395 static T* create(Args&& ... args)
20397 AllocatorType<T> alloc;
20398 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
20400 auto deleter = [&](T * obj)
20402 AllocatorTraits::deallocate(alloc, obj, 1);
20404 std::unique_ptr<T,
decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
20405 AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
20406 JSON_ASSERT(obj !=
nullptr);
20407 return obj.release();
20414 JSON_PRIVATE_UNLESS_TESTED:
20460 json_value() =
default;
20462 json_value(boolean_t v) noexcept :
boolean(v) {}
20468 json_value(number_float_t v) noexcept :
number_float(v) {}
20470 json_value(value_t t)
20474 case value_t::object:
20476 object = create<object_t>();
20480 case value_t::array:
20482 array = create<array_t>();
20486 case value_t::string:
20488 string = create<string_t>(
"");
20492 case value_t::binary:
20494 binary = create<binary_t>();
20498 case value_t::boolean:
20500 boolean =
static_cast<boolean_t
>(
false);
20504 case value_t::number_integer:
20510 case value_t::number_unsigned:
20516 case value_t::number_float:
20522 case value_t::null:
20528 case value_t::discarded:
20532 if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
20534 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.12.0",
nullptr));
20542 json_value(
const string_t& value) : string(create<string_t>(value)) {}
20545 json_value(string_t&& value) : string(create<string_t>(std::move(value))) {}
20548 json_value(
const object_t& value) :
object(create<object_t>(value)) {}
20551 json_value(object_t&& value) :
object(create<object_t>(std::move(value))) {}
20554 json_value(
const array_t& value) : array(create<array_t>(value)) {}
20557 json_value(array_t&& value) : array(create<array_t>(std::move(value))) {}
20560 json_value(
const typename binary_t::container_type& value) : binary(create<binary_t>(value)) {}
20563 json_value(
typename binary_t::container_type&& value) : binary(create<binary_t>(std::move(value))) {}
20566 json_value(
const binary_t& value) : binary(create<binary_t>(value)) {}
20569 json_value(binary_t&& value) : binary(create<binary_t>(std::move(value))) {}
20571 void destroy(value_t t)
20574 (t == value_t::object &&
object ==
nullptr) ||
20575 (t == value_t::array && array ==
nullptr) ||
20576 (t == value_t::string &&
string ==
nullptr) ||
20577 (t == value_t::binary && binary ==
nullptr)
20583 if (t == value_t::array || t == value_t::object)
20586 std::vector<basic_json> stack;
20589 if (t == value_t::array)
20591 stack.reserve(array->size());
20592 std::move(array->begin(), array->end(), std::back_inserter(stack));
20596 stack.reserve(
object->size());
20597 for (
auto&& it : *
object)
20599 stack.push_back(std::move(it.second));
20603 while (!stack.empty())
20606 basic_json current_item(std::move(stack.back()));
20611 if (current_item.is_array())
20613 std::move(current_item.m_data.m_value.array->begin(), current_item.m_data.m_value.array->end(), std::back_inserter(stack));
20615 current_item.m_data.m_value.array->clear();
20617 else if (current_item.is_object())
20619 for (
auto&& it : *current_item.m_data.m_value.object)
20621 stack.push_back(std::move(it.second));
20624 current_item.m_data.m_value.object->clear();
20634 case value_t::object:
20636 AllocatorType<object_t> alloc;
20637 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
object);
20638 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
object, 1);
20642 case value_t::array:
20644 AllocatorType<array_t> alloc;
20645 std::allocator_traits<
decltype(alloc)>::destroy(alloc, array);
20646 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, array, 1);
20650 case value_t::string:
20652 AllocatorType<string_t> alloc;
20653 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
string);
20654 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
string, 1);
20658 case value_t::binary:
20660 AllocatorType<binary_t> alloc;
20661 std::allocator_traits<
decltype(alloc)>::destroy(alloc, binary);
20662 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, binary, 1);
20666 case value_t::null:
20667 case value_t::boolean:
20668 case value_t::number_integer:
20669 case value_t::number_unsigned:
20670 case value_t::number_float:
20671 case value_t::discarded:
20699 void assert_invariant(
bool check_parents =
true) const noexcept
20701 JSON_ASSERT(m_data.m_type != value_t::object || m_data.m_value.object !=
nullptr);
20702 JSON_ASSERT(m_data.m_type != value_t::array || m_data.m_value.array !=
nullptr);
20703 JSON_ASSERT(m_data.m_type != value_t::string || m_data.m_value.string !=
nullptr);
20704 JSON_ASSERT(m_data.m_type != value_t::binary || m_data.m_value.binary !=
nullptr);
20706#if JSON_DIAGNOSTICS
20710 JSON_ASSERT(!check_parents || !is_structured() || std::all_of(begin(), end(), [
this](
const basic_json & j)
20712 return j.m_parent ==
this;
20717 static_cast<void>(check_parents);
20722#if JSON_DIAGNOSTICS
20723 switch (m_data.m_type)
20725 case value_t::array:
20727 for (
auto& element : *m_data.m_value.array)
20729 element.m_parent =
this;
20734 case value_t::object:
20736 for (
auto& element : *m_data.m_value.object)
20738 element.second.m_parent =
this;
20743 case value_t::null:
20744 case value_t::string:
20745 case value_t::boolean:
20746 case value_t::number_integer:
20747 case value_t::number_unsigned:
20748 case value_t::number_float:
20749 case value_t::binary:
20750 case value_t::discarded:
20757 iterator set_parents(iterator it,
typename iterator::difference_type count_set_parents)
20759#if JSON_DIAGNOSTICS
20760 for (
typename iterator::difference_type i = 0; i < count_set_parents; ++i)
20762 (it + i)->m_parent =
this;
20765 static_cast<void>(count_set_parents);
20770 reference set_parent(reference j, std::size_t old_capacity = detail::unknown_size())
20772#if JSON_DIAGNOSTICS
20773 if (old_capacity != detail::unknown_size())
20776 JSON_ASSERT(type() == value_t::array);
20777 if (JSON_HEDLEY_UNLIKELY(m_data.m_value.array->capacity() != old_capacity))
20787#ifdef JSON_HEDLEY_MSVC_VERSION
20788#pragma warning(push )
20789#pragma warning(disable : 4127)
20796#ifdef JSON_HEDLEY_MSVC_VERSION
20797#pragma warning( pop )
20802 static_cast<void>(j);
20803 static_cast<void>(old_capacity);
20819 using parser_callback_t = detail::parser_callback_t<basic_json>;
20835 assert_invariant();
20843 assert_invariant();
20848 template <
typename CompatibleType,
20849 typename U = detail::uncvref_t<CompatibleType>,
20850 detail::enable_if_t <
20853 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
20854 std::forward<CompatibleType>(val))))
20856 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
20858 assert_invariant();
20863 template <
typename BasicJsonType,
20864 detail::enable_if_t <
20867#if JSON_DIAGNOSTIC_POSITIONS
20868 : start_position(val.start_pos()),
20869 end_position(val.end_pos())
20872 using other_boolean_t =
typename BasicJsonType::boolean_t;
20873 using other_number_float_t =
typename BasicJsonType::number_float_t;
20874 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
20875 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
20876 using other_string_t =
typename BasicJsonType::string_t;
20877 using other_object_t =
typename BasicJsonType::object_t;
20878 using other_array_t =
typename BasicJsonType::array_t;
20879 using other_binary_t =
typename BasicJsonType::binary_t;
20881 switch (val.type())
20883 case value_t::boolean:
20884 JSONSerializer<other_boolean_t>::to_json(*
this, val.template get<other_boolean_t>());
20886 case value_t::number_float:
20887 JSONSerializer<other_number_float_t>::to_json(*
this, val.template get<other_number_float_t>());
20889 case value_t::number_integer:
20890 JSONSerializer<other_number_integer_t>::to_json(*
this, val.template get<other_number_integer_t>());
20892 case value_t::number_unsigned:
20893 JSONSerializer<other_number_unsigned_t>::to_json(*
this, val.template get<other_number_unsigned_t>());
20895 case value_t::string:
20896 JSONSerializer<other_string_t>::to_json(*
this, val.template get_ref<const other_string_t&>());
20898 case value_t::object:
20899 JSONSerializer<other_object_t>::to_json(*
this, val.template get_ref<const other_object_t&>());
20901 case value_t::array:
20902 JSONSerializer<other_array_t>::to_json(*
this, val.template get_ref<const other_array_t&>());
20904 case value_t::binary:
20905 JSONSerializer<other_binary_t>::to_json(*
this, val.template get_ref<const other_binary_t&>());
20907 case value_t::null:
20910 case value_t::discarded:
20911 m_data.m_type = value_t::discarded;
20914 JSON_ASSERT(
false);
20916 JSON_ASSERT(m_data.m_type == val.type());
20919 assert_invariant();
20925 bool type_deduction =
true,
20926 value_t manual_type = value_t::array)
20930 bool is_an_object = std::all_of(init.begin(), init.end(),
20936 return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[static_cast<size_type>(0)].is_string();
20940 if (!type_deduction)
20943 if (manual_type == value_t::array)
20945 is_an_object =
false;
20949 if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))
20951 JSON_THROW(type_error::create(301,
"cannot create object from initializer list",
nullptr));
20958 m_data.m_type = value_t::object;
20959 m_data.m_value = value_t::object;
20961 for (
auto& element_ref : init)
20963 auto element = element_ref.moved_or_copied();
20964 m_data.m_value.object->emplace(
20965 std::move(*((*element.m_data.m_value.array)[0].m_data.m_value.string)),
20966 std::move((*element.m_data.m_value.array)[1]));
20972 m_data.m_type = value_t::array;
20973 m_data.m_value.array = create<array_t>(init.begin(), init.end());
20977 assert_invariant();
20982 JSON_HEDLEY_WARN_UNUSED_RESULT
20986 res.m_data.m_type = value_t::binary;
20987 res.m_data.m_value = init;
20993 JSON_HEDLEY_WARN_UNUSED_RESULT
20994 static basic_json binary(
const typename binary_t::container_type& init,
typename binary_t::subtype_type subtype)
20997 res.m_data.m_type = value_t::binary;
20998 res.m_data.m_value =
binary_t(init, subtype);
21004 JSON_HEDLEY_WARN_UNUSED_RESULT
21008 res.m_data.m_type = value_t::binary;
21009 res.m_data.m_value = std::move(init);
21015 JSON_HEDLEY_WARN_UNUSED_RESULT
21016 static basic_json binary(
typename binary_t::container_type&& init,
typename binary_t::subtype_type subtype)
21019 res.m_data.m_type = value_t::binary;
21020 res.m_data.m_value =
binary_t(std::move(init), subtype);
21026 JSON_HEDLEY_WARN_UNUSED_RESULT
21029 return basic_json(init,
false, value_t::array);
21034 JSON_HEDLEY_WARN_UNUSED_RESULT
21037 return basic_json(init,
false, value_t::object);
21046 assert_invariant();
21051 template <
class InputIT,
typename std::enable_if <
21052 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
21053 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int >::type = 0 >
21056 JSON_ASSERT(first.m_object !=
nullptr);
21057 JSON_ASSERT(last.m_object !=
nullptr);
21060 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
21062 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible",
nullptr));
21066 m_data.m_type = first.m_object->m_data.m_type;
21069 switch (m_data.m_type)
21071 case value_t::boolean:
21072 case value_t::number_float:
21073 case value_t::number_integer:
21074 case value_t::number_unsigned:
21075 case value_t::string:
21077 if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
21078 || !last.m_it.primitive_iterator.is_end()))
21080 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", first.m_object));
21085 case value_t::null:
21086 case value_t::object:
21087 case value_t::array:
21088 case value_t::binary:
21089 case value_t::discarded:
21094 switch (m_data.m_type)
21096 case value_t::number_integer:
21098 m_data.m_value.number_integer = first.m_object->m_data.m_value.number_integer;
21102 case value_t::number_unsigned:
21104 m_data.m_value.number_unsigned = first.m_object->m_data.m_value.number_unsigned;
21108 case value_t::number_float:
21110 m_data.m_value.number_float = first.m_object->m_data.m_value.number_float;
21114 case value_t::boolean:
21116 m_data.m_value.boolean = first.m_object->m_data.m_value.boolean;
21120 case value_t::string:
21122 m_data.m_value = *first.m_object->m_data.m_value.string;
21126 case value_t::object:
21128 m_data.m_value.object = create<object_t>(first.m_it.object_iterator,
21129 last.m_it.object_iterator);
21133 case value_t::array:
21135 m_data.m_value.array = create<array_t>(first.m_it.array_iterator,
21136 last.m_it.array_iterator);
21140 case value_t::binary:
21142 m_data.m_value = *first.m_object->m_data.m_value.binary;
21146 case value_t::null:
21147 case value_t::discarded:
21149 JSON_THROW(invalid_iterator::create(206, detail::concat(
"cannot construct with iterators from ", first.m_object->type_name()), first.m_object));
21153 assert_invariant();
21160 template<
typename JsonRef,
21161 detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
21162 std::is_same<typename JsonRef::value_type, basic_json>>::value,
int> = 0 >
21168 : json_base_class_t(other)
21169#if JSON_DIAGNOSTIC_POSITIONS
21170 , start_position(other.start_position)
21171 , end_position(other.end_position)
21174 m_data.m_type = other.m_data.m_type;
21176 other.assert_invariant();
21178 switch (m_data.m_type)
21180 case value_t::object:
21182 m_data.m_value = *other.m_data.m_value.object;
21186 case value_t::array:
21188 m_data.m_value = *other.m_data.m_value.array;
21192 case value_t::string:
21194 m_data.m_value = *other.m_data.m_value.string;
21198 case value_t::boolean:
21200 m_data.m_value = other.m_data.m_value.boolean;
21204 case value_t::number_integer:
21206 m_data.m_value = other.m_data.m_value.number_integer;
21210 case value_t::number_unsigned:
21212 m_data.m_value = other.m_data.m_value.number_unsigned;
21216 case value_t::number_float:
21218 m_data.m_value = other.m_data.m_value.number_float;
21222 case value_t::binary:
21224 m_data.m_value = *other.m_data.m_value.binary;
21228 case value_t::null:
21229 case value_t::discarded:
21235 assert_invariant();
21241 : json_base_class_t(std::forward<json_base_class_t>(other)),
21242 m_data(std::move(other.m_data))
21243#if JSON_DIAGNOSTIC_POSITIONS
21244 , start_position(other.start_position)
21245 , end_position(other.end_position)
21249 other.assert_invariant(
false);
21252 other.m_data.m_type = value_t::null;
21253 other.m_data.m_value = {};
21255#if JSON_DIAGNOSTIC_POSITIONS
21256 other.start_position = std::string::npos;
21257 other.end_position = std::string::npos;
21261 assert_invariant();
21267 std::is_nothrow_move_constructible<value_t>::value&&
21268 std::is_nothrow_move_assignable<value_t>::value&&
21269 std::is_nothrow_move_constructible<json_value>::value&&
21270 std::is_nothrow_move_assignable<json_value>::value&&
21271 std::is_nothrow_move_assignable<json_base_class_t>::value
21275 other.assert_invariant();
21278 swap(m_data.m_type, other.m_data.m_type);
21279 swap(m_data.m_value, other.m_data.m_value);
21281#if JSON_DIAGNOSTIC_POSITIONS
21282 swap(start_position, other.start_position);
21283 swap(end_position, other.end_position);
21286 json_base_class_t::operator=(std::move(other));
21289 assert_invariant();
21297 assert_invariant(
false);
21314 const char indent_char =
' ',
21315 const bool ensure_ascii =
false,
21323 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
21327 s.dump(*
this,
false, ensure_ascii, 0);
21337 return m_data.m_type;
21344 return is_null() || is_string() || is_boolean() || is_number() || is_binary();
21351 return is_array() || is_object();
21358 return m_data.m_type == value_t::null;
21365 return m_data.m_type == value_t::boolean;
21372 return is_number_integer() || is_number_float();
21379 return m_data.m_type == value_t::number_integer || m_data.m_type == value_t::number_unsigned;
21386 return m_data.m_type == value_t::number_unsigned;
21393 return m_data.m_type == value_t::number_float;
21400 return m_data.m_type == value_t::object;
21407 return m_data.m_type == value_t::array;
21414 return m_data.m_type == value_t::string;
21421 return m_data.m_type == value_t::binary;
21428 return m_data.m_type == value_t::discarded;
21435 return m_data.m_type;
21446 boolean_t get_impl(boolean_t* )
const
21448 if (JSON_HEDLEY_LIKELY(is_boolean()))
21450 return m_data.m_value.boolean;
21453 JSON_THROW(type_error::create(302, detail::concat(
"type must be boolean, but is ", type_name()),
this));
21457 object_t* get_impl_ptr(object_t* )
noexcept
21459 return is_object() ? m_data.m_value.object :
nullptr;
21463 constexpr const object_t* get_impl_ptr(
const object_t* )
const noexcept
21465 return is_object() ? m_data.m_value.object :
nullptr;
21469 array_t* get_impl_ptr(array_t* )
noexcept
21471 return is_array() ? m_data.m_value.array :
nullptr;
21475 constexpr const array_t* get_impl_ptr(
const array_t* )
const noexcept
21477 return is_array() ? m_data.m_value.array :
nullptr;
21481 string_t* get_impl_ptr(string_t* )
noexcept
21483 return is_string() ? m_data.m_value.string :
nullptr;
21487 constexpr const string_t* get_impl_ptr(
const string_t* )
const noexcept
21489 return is_string() ? m_data.m_value.string :
nullptr;
21493 boolean_t* get_impl_ptr(boolean_t* )
noexcept
21495 return is_boolean() ? &m_data.m_value.boolean :
nullptr;
21499 constexpr const boolean_t* get_impl_ptr(
const boolean_t* )
const noexcept
21501 return is_boolean() ? &m_data.m_value.boolean :
nullptr;
21505 number_integer_t* get_impl_ptr(number_integer_t* )
noexcept
21507 return m_data.m_type == value_t::number_integer ? &m_data.m_value.number_integer :
nullptr;
21511 constexpr const number_integer_t* get_impl_ptr(
const number_integer_t* )
const noexcept
21513 return m_data.m_type == value_t::number_integer ? &m_data.m_value.number_integer :
nullptr;
21517 number_unsigned_t* get_impl_ptr(number_unsigned_t* )
noexcept
21519 return is_number_unsigned() ? &m_data.m_value.number_unsigned :
nullptr;
21523 constexpr const number_unsigned_t* get_impl_ptr(
const number_unsigned_t* )
const noexcept
21525 return is_number_unsigned() ? &m_data.m_value.number_unsigned :
nullptr;
21529 number_float_t* get_impl_ptr(number_float_t* )
noexcept
21531 return is_number_float() ? &m_data.m_value.number_float :
nullptr;
21535 constexpr const number_float_t* get_impl_ptr(
const number_float_t* )
const noexcept
21537 return is_number_float() ? &m_data.m_value.number_float :
nullptr;
21541 binary_t* get_impl_ptr(binary_t* )
noexcept
21543 return is_binary() ? m_data.m_value.binary :
nullptr;
21547 constexpr const binary_t* get_impl_ptr(
const binary_t* )
const noexcept
21549 return is_binary() ? m_data.m_value.binary :
nullptr;
21563 template<
typename ReferenceType,
typename ThisType>
21564 static ReferenceType get_ref_impl(ThisType& obj)
21567 auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
21569 if (JSON_HEDLEY_LIKELY(ptr !=
nullptr))
21574 JSON_THROW(type_error::create(303, detail::concat(
"incompatible ReferenceType for get_ref, actual type is ", obj.type_name()), &obj));
21584 template<
typename PointerType,
typename std::enable_if<
21585 std::is_pointer<PointerType>::value,
int>::type = 0>
21586 auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
21589 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
21594 template <
typename PointerType,
typename std::enable_if <
21595 std::is_pointer<PointerType>::value&&
21596 std::is_const<typename std::remove_pointer<PointerType>::type>::value,
int >::type = 0 >
21597 constexpr auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
21600 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
21642 template <
typename ValueType,
21643 detail::enable_if_t <
21648 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
21650 auto ret = ValueType();
21651 JSONSerializer<ValueType>::from_json(*
this, ret);
21685 template <
typename ValueType,
21686 detail::enable_if_t <
21690 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
21692 return JSONSerializer<ValueType>::from_json(*
this);
21710 template <
typename BasicJsonType,
21711 detail::enable_if_t <
21733 template<
typename BasicJsonType,
21734 detail::enable_if_t<
21735 std::is_same<BasicJsonType, basic_json_t>::value,
21746 template<
typename PointerType,
21747 detail::enable_if_t<
21748 std::is_pointer<PointerType>::value,
21751 ->
decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>())
21754 return get_ptr<PointerType>();
21781 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>>
21782#if defined(JSON_HAS_CPP_14)
21786 noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(
detail::priority_tag<4> {})))
21792 static_assert(!std::is_reference<ValueTypeCV>::value,
21793 "get() cannot be used with reference types, you might want to use get_ref()");
21824 template<
typename PointerType,
typename std::enable_if<
21825 std::is_pointer<PointerType>::value,
int>::type = 0>
21826 auto get() noexcept -> decltype(std::declval<basic_json_t&>().template get_ptr<PointerType>())
21829 return get_ptr<PointerType>();
21834 template <
typename ValueType,
21835 detail::enable_if_t <
21839 ValueType &
get_to(ValueType& v)
const noexcept(
noexcept(
21840 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
21842 JSONSerializer<ValueType>::from_json(*
this, v);
21848 template<
typename ValueType,
21849 detail::enable_if_t <
21852 ValueType & get_to(ValueType& v)
const
21859 typename T, std::size_t N,
21860 typename Array = T (&)[N],
21861 detail::enable_if_t <
21863 Array get_to(T (&v)[N])
const
21864 noexcept(
noexcept(JSONSerializer<Array>::from_json(
21865 std::declval<const basic_json_t&>(), v)))
21867 JSONSerializer<Array>::from_json(*
this, v);
21873 template<
typename ReferenceType,
typename std::enable_if<
21874 std::is_reference<ReferenceType>::value,
int>::type = 0>
21878 return get_ref_impl<ReferenceType>(*
this);
21883 template <
typename ReferenceType,
typename std::enable_if <
21884 std::is_reference<ReferenceType>::value&&
21885 std::is_const<typename std::remove_reference<ReferenceType>::type>::value,
int >::type = 0 >
21889 return get_ref_impl<ReferenceType>(*
this);
21921 template <
typename ValueType,
typename std::enable_if <
21929#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
21932#if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI
21936 >::value,
int >::type = 0 >
21937 JSON_EXPLICIT
operator ValueType()
const
21940 return get<ValueType>();
21949 JSON_THROW(type_error::create(302, detail::concat(
"type must be binary, but is ", type_name()),
this));
21952 return *get_ptr<binary_t*>();
21961 JSON_THROW(type_error::create(302, detail::concat(
"type must be binary, but is ", type_name()),
this));
21964 return *get_ptr<const binary_t*>();
21982 if (JSON_HEDLEY_LIKELY(is_array()))
21986 return set_parent(m_data.m_value.array->at(idx));
21988 JSON_CATCH (std::out_of_range&)
21991 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
21996 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
22005 if (JSON_HEDLEY_LIKELY(is_array()))
22009 return m_data.m_value.array->at(idx);
22011 JSON_CATCH (std::out_of_range&)
22014 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
22019 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
22028 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22030 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
22034 if (it == m_data.m_value.object->end())
22036 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
key,
"' not found"),
this));
22038 return set_parent(it->second);
22043 template<
class KeyType, detail::enable_if_t<
22044 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22048 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22050 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
22053 auto it = m_data.
m_value.object->find(std::forward<KeyType>(
key));
22054 if (it == m_data.m_value.object->end())
22056 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
string_t(std::forward<KeyType>(
key)),
"' not found"),
this));
22058 return set_parent(it->second);
22066 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22068 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
22072 if (it == m_data.m_value.object->end())
22074 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
key,
"' not found"),
this));
22081 template<
class KeyType, detail::enable_if_t<
22082 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22086 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22088 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
22091 auto it = m_data.
m_value.object->find(std::forward<KeyType>(
key));
22092 if (it == m_data.m_value.object->end())
22094 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
string_t(std::forward<KeyType>(
key)),
"' not found"),
this));
22106 m_data.m_type = value_t::array;
22107 m_data.m_value.array = create<array_t>();
22108 assert_invariant();
22112 if (JSON_HEDLEY_LIKELY(is_array()))
22115 if (idx >= m_data.m_value.array->size())
22117#if JSON_DIAGNOSTICS
22119 const auto old_size = m_data.m_value.array->size();
22120 const auto old_capacity = m_data.m_value.array->capacity();
22122 m_data.m_value.array->resize(idx + 1);
22124#if JSON_DIAGNOSTICS
22125 if (JSON_HEDLEY_UNLIKELY(m_data.m_value.array->capacity() != old_capacity))
22133 set_parents(begin() +
static_cast<typename iterator::difference_type
>(old_size),
static_cast<typename iterator::difference_type
>(idx + 1 - old_size));
22136 assert_invariant();
22139 return m_data.m_value.array->operator[](idx);
22142 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a numeric argument with ", type_name()),
this));
22150 if (JSON_HEDLEY_LIKELY(is_array()))
22152 return m_data.m_value.array->operator[](idx);
22155 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a numeric argument with ", type_name()),
this));
22165 m_data.m_type = value_t::object;
22166 m_data.m_value.object = create<object_t>();
22167 assert_invariant();
22171 if (JSON_HEDLEY_LIKELY(is_object()))
22173 auto result = m_data.m_value.object->emplace(std::move(
key),
nullptr);
22174 return set_parent(result.first->second);
22177 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
22185 if (JSON_HEDLEY_LIKELY(is_object()))
22187 auto it = m_data.m_value.object->find(
key);
22188 JSON_ASSERT(it != m_data.m_value.object->end());
22192 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
22197 template<
typename T>
22198 reference operator[](T*
key)
22200 return operator[](
typename object_t::key_type(
key));
22203 template<
typename T>
22204 const_reference operator[](T*
key)
const
22206 return operator[](
typename object_t::key_type(
key));
22211 template<
class KeyType, detail::enable_if_t<
22212 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int > = 0 >
22218 m_data.m_type = value_t::object;
22219 m_data.m_value.object = create<object_t>();
22220 assert_invariant();
22224 if (JSON_HEDLEY_LIKELY(is_object()))
22226 auto result = m_data.m_value.object->emplace(std::forward<KeyType>(
key),
nullptr);
22227 return set_parent(result.first->second);
22230 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
22235 template<
class KeyType, detail::enable_if_t<
22236 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int > = 0 >
22240 if (JSON_HEDLEY_LIKELY(is_object()))
22242 auto it = m_data.m_value.object->find(std::forward<KeyType>(
key));
22243 JSON_ASSERT(it != m_data.m_value.object->end());
22247 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
22251 template<
typename KeyType>
22253 object_comparator_t,
const typename object_t::key_type&, KeyType >;
22255 template<
typename ValueType>
22256 using value_return_type = std::conditional <
22258 string_t,
typename std::decay<ValueType>::type >;
22263 template <
class ValueType, detail::enable_if_t <
22266 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22267 ValueType
value(
const typename object_t::key_type&
key,
const ValueType& default_value)
const
22270 if (JSON_HEDLEY_LIKELY(is_object()))
22273 const auto it = find(
key);
22276 return it->template get<ValueType>();
22279 return default_value;
22282 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
22287 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
22288 detail::enable_if_t <
22291 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22292 ReturnType
value(
const typename object_t::key_type&
key, ValueType && default_value)
const
22295 if (JSON_HEDLEY_LIKELY(is_object()))
22298 const auto it = find(
key);
22301 return it->template get<ReturnType>();
22304 return std::forward<ValueType>(default_value);
22307 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
22312 template <
class ValueType,
class KeyType, detail::enable_if_t <
22315 && is_comparable_with_object_key<KeyType>::value
22317 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22318 ValueType
value(KeyType &&
key,
const ValueType& default_value)
const
22321 if (JSON_HEDLEY_LIKELY(is_object()))
22324 const auto it = find(std::forward<KeyType>(
key));
22327 return it->template get<ValueType>();
22330 return default_value;
22333 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
22338 template < class ValueType, class KeyType, class ReturnType = typename value_return_type<ValueType>::type,
22339 detail::enable_if_t <
22342 && is_comparable_with_object_key<KeyType>::value
22344 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22345 ReturnType
value(KeyType &&
key, ValueType && default_value)
const
22348 if (JSON_HEDLEY_LIKELY(is_object()))
22351 const auto it = find(std::forward<KeyType>(
key));
22354 return it->template get<ReturnType>();
22357 return std::forward<ValueType>(default_value);
22360 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
22365 template <
class ValueType, detail::enable_if_t <
22367 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22371 if (JSON_HEDLEY_LIKELY(is_object()))
22376 return ptr.get_checked(
this).template get<ValueType>();
22380 return default_value;
22384 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
22389 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
22390 detail::enable_if_t <
22392 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22396 if (JSON_HEDLEY_LIKELY(is_object()))
22401 return ptr.get_checked(
this).template get<ReturnType>();
22405 return std::forward<ValueType>(default_value);
22409 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
22412 template <
class ValueType,
class BasicJsonType, detail::enable_if_t <
22415 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22417 ValueType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr,
const ValueType& default_value)
const
22419 return value(ptr.convert(), default_value);
22422 template < class ValueType, class BasicJsonType, class ReturnType = typename value_return_type<ValueType>::type,
22423 detail::enable_if_t <
22426 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
22428 ReturnType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, ValueType && default_value)
const
22430 return value(ptr.convert(), std::forward<ValueType>(default_value));
22467 template <
class IteratorType, detail::enable_if_t <
22468 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
22469 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
22473 if (JSON_HEDLEY_UNLIKELY(
this != pos.m_object))
22475 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
22478 IteratorType result = end();
22480 switch (m_data.m_type)
22482 case value_t::boolean:
22483 case value_t::number_float:
22484 case value_t::number_integer:
22485 case value_t::number_unsigned:
22486 case value_t::string:
22487 case value_t::binary:
22489 if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
22491 JSON_THROW(invalid_iterator::create(205,
"iterator out of range",
this));
22496 AllocatorType<string_t> alloc;
22497 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.string);
22498 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.string, 1);
22499 m_data.m_value.string =
nullptr;
22501 else if (is_binary())
22503 AllocatorType<binary_t> alloc;
22504 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.binary);
22505 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.binary, 1);
22506 m_data.m_value.binary =
nullptr;
22509 m_data.m_type = value_t::null;
22510 assert_invariant();
22514 case value_t::object:
22516 result.m_it.object_iterator = m_data.m_value.object->erase(pos.m_it.object_iterator);
22520 case value_t::array:
22522 result.m_it.array_iterator = m_data.m_value.array->erase(pos.m_it.array_iterator);
22526 case value_t::null:
22527 case value_t::discarded:
22529 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
22537 template <
class IteratorType, detail::enable_if_t <
22538 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
22539 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
22540 IteratorType
erase(IteratorType first, IteratorType last)
22543 if (JSON_HEDLEY_UNLIKELY(
this != first.m_object ||
this != last.m_object))
22545 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value",
this));
22548 IteratorType result = end();
22550 switch (m_data.m_type)
22552 case value_t::boolean:
22553 case value_t::number_float:
22554 case value_t::number_integer:
22555 case value_t::number_unsigned:
22556 case value_t::string:
22557 case value_t::binary:
22559 if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
22560 || !last.m_it.primitive_iterator.is_end()))
22562 JSON_THROW(invalid_iterator::create(204,
"iterators out of range",
this));
22567 AllocatorType<string_t> alloc;
22568 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.string);
22569 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.string, 1);
22570 m_data.m_value.string =
nullptr;
22572 else if (is_binary())
22574 AllocatorType<binary_t> alloc;
22575 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.binary);
22576 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.binary, 1);
22577 m_data.m_value.binary =
nullptr;
22580 m_data.m_type = value_t::null;
22581 assert_invariant();
22585 case value_t::object:
22587 result.m_it.object_iterator = m_data.m_value.object->erase(first.m_it.object_iterator,
22588 last.m_it.object_iterator);
22592 case value_t::array:
22594 result.m_it.array_iterator = m_data.m_value.array->erase(first.m_it.array_iterator,
22595 last.m_it.array_iterator);
22599 case value_t::null:
22600 case value_t::discarded:
22602 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
22609 template <
typename KeyType, detail::enable_if_t <
22610 detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int > = 0 >
22611 size_type erase_internal(KeyType &&
key)
22614 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22616 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
22619 return m_data.m_value.object->erase(std::forward<KeyType>(
key));
22622 template <
typename KeyType, detail::enable_if_t <
22623 !detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int > = 0 >
22624 size_type erase_internal(KeyType &&
key)
22627 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22629 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
22632 const auto it = m_data.m_value.object->find(std::forward<KeyType>(
key));
22633 if (it != m_data.m_value.object->end())
22635 m_data.m_value.object->erase(it);
22649 return erase_internal(
key);
22654 template<
class KeyType, detail::enable_if_t<
22655 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22658 return erase_internal(std::forward<KeyType>(
key));
22666 if (JSON_HEDLEY_LIKELY(is_array()))
22668 if (JSON_HEDLEY_UNLIKELY(idx >= size()))
22670 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
22673 m_data.m_value.array->erase(m_data.m_value.array->begin() +
static_cast<difference_type>(idx));
22677 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
22694 auto result = end();
22698 result.m_it.object_iterator = m_data.m_value.object->find(
key);
22708 auto result = cend();
22712 result.m_it.object_iterator = m_data.m_value.object->find(
key);
22720 template<
class KeyType, detail::enable_if_t<
22721 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22724 auto result = end();
22728 result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(
key));
22736 template<
class KeyType, detail::enable_if_t<
22737 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22740 auto result = cend();
22744 result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(
key));
22755 return is_object() ? m_data.m_value.object->count(
key) : 0;
22760 template<
class KeyType, detail::enable_if_t<
22761 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22765 return is_object() ? m_data.m_value.object->count(std::forward<KeyType>(
key)) : 0;
22772 return is_object() && m_data.m_value.object->find(
key) != m_data.m_value.object->end();
22777 template<
class KeyType, detail::enable_if_t<
22778 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22781 return is_object() && m_data.m_value.object->find(std::forward<KeyType>(
key)) != m_data.m_value.object->end();
22788 return ptr.contains(
this);
22791 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
22793 bool contains(
const typename ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
22795 return ptr.contains(
this);
22812 result.set_begin();
22828 result.set_begin();
22905 JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
22908 return ref.items();
22916 JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
22919 return ref.items();
22926 return iteration_proxy<iterator>(*
this);
22931 iteration_proxy<const_iterator>
items() const noexcept
22933 return iteration_proxy<const_iterator>(*
this);
22949 switch (m_data.m_type)
22951 case value_t::null:
22957 case value_t::array:
22960 return m_data.m_value.array->empty();
22963 case value_t::object:
22966 return m_data.m_value.object->empty();
22969 case value_t::string:
22970 case value_t::boolean:
22971 case value_t::number_integer:
22972 case value_t::number_unsigned:
22973 case value_t::number_float:
22974 case value_t::binary:
22975 case value_t::discarded:
22988 switch (m_data.m_type)
22990 case value_t::null:
22996 case value_t::array:
22999 return m_data.m_value.array->size();
23002 case value_t::object:
23005 return m_data.m_value.object->size();
23008 case value_t::string:
23009 case value_t::boolean:
23010 case value_t::number_integer:
23011 case value_t::number_unsigned:
23012 case value_t::number_float:
23013 case value_t::binary:
23014 case value_t::discarded:
23027 switch (m_data.m_type)
23029 case value_t::array:
23032 return m_data.m_value.array->max_size();
23035 case value_t::object:
23038 return m_data.m_value.object->max_size();
23041 case value_t::null:
23042 case value_t::string:
23043 case value_t::boolean:
23044 case value_t::number_integer:
23045 case value_t::number_unsigned:
23046 case value_t::number_float:
23047 case value_t::binary:
23048 case value_t::discarded:
23070 switch (m_data.m_type)
23072 case value_t::number_integer:
23074 m_data.m_value.number_integer = 0;
23078 case value_t::number_unsigned:
23080 m_data.m_value.number_unsigned = 0;
23084 case value_t::number_float:
23086 m_data.m_value.number_float = 0.0;
23090 case value_t::boolean:
23092 m_data.m_value.boolean =
false;
23096 case value_t::string:
23098 m_data.m_value.string->clear();
23102 case value_t::binary:
23104 m_data.m_value.binary->clear();
23108 case value_t::array:
23110 m_data.m_value.array->clear();
23114 case value_t::object:
23116 m_data.m_value.object->clear();
23120 case value_t::null:
23121 case value_t::discarded:
23132 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
23134 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
23140 m_data.m_type = value_t::array;
23141 m_data.m_value = value_t::array;
23142 assert_invariant();
23146 const auto old_capacity = m_data.m_value.array->capacity();
23147 m_data.m_value.array->push_back(std::move(val));
23148 set_parent(m_data.m_value.array->back(), old_capacity);
23156 push_back(std::move(val));
23165 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
23167 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
23173 m_data.m_type = value_t::array;
23174 m_data.m_value = value_t::array;
23175 assert_invariant();
23179 const auto old_capacity = m_data.m_value.array->capacity();
23180 m_data.m_value.array->push_back(val);
23181 set_parent(m_data.m_value.array->back(), old_capacity);
23197 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
23199 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
23205 m_data.m_type = value_t::object;
23206 m_data.m_value = value_t::object;
23207 assert_invariant();
23211 auto res = m_data.m_value.object->insert(val);
23212 set_parent(res.first->second);
23227 if (is_object() && init.size() == 2 && (*init.begin())->is_string())
23230 push_back(
typename object_t::value_type(
23231 std::move(
key.get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
23249 template<
class... Args>
23253 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
23255 JSON_THROW(type_error::create(311, detail::concat(
"cannot use emplace_back() with ", type_name()),
this));
23261 m_data.m_type = value_t::array;
23262 m_data.m_value = value_t::array;
23263 assert_invariant();
23267 const auto old_capacity = m_data.
m_value.array->capacity();
23268 m_data.m_value.array->emplace_back(std::forward<Args>(args)...);
23269 return set_parent(m_data.m_value.array->back(), old_capacity);
23274 template<
class... Args>
23278 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
23280 JSON_THROW(type_error::create(311, detail::concat(
"cannot use emplace() with ", type_name()),
this));
23286 m_data.m_type = value_t::object;
23287 m_data.m_value = value_t::object;
23288 assert_invariant();
23292 auto res = m_data.m_value.object->emplace(std::forward<Args>(args)...);
23293 set_parent(res.first->second);
23297 it.m_it.object_iterator = res.first;
23300 return {it, res.second};
23306 template<
typename... Args>
23310 JSON_ASSERT(m_data.m_value.array !=
nullptr);
23312 auto insert_pos = std::distance(m_data.m_value.array->begin(), pos.m_it.array_iterator);
23313 m_data.m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
23314 result.m_it.array_iterator = m_data.m_value.array->begin() + insert_pos;
23329 if (JSON_HEDLEY_LIKELY(is_array()))
23332 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23334 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
23338 return insert_iterator(pos, val);
23341 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
23348 return insert(pos, val);
23356 if (JSON_HEDLEY_LIKELY(is_array()))
23359 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23361 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
23365 return insert_iterator(pos, cnt, val);
23368 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
23376 if (JSON_HEDLEY_UNLIKELY(!is_array()))
23378 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
23382 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23384 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
23388 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23390 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
23393 if (JSON_HEDLEY_UNLIKELY(first.m_object ==
this))
23395 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container",
this));
23399 return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
23407 if (JSON_HEDLEY_UNLIKELY(!is_array()))
23409 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
23413 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23415 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
23419 return insert_iterator(pos, ilist.begin(), ilist.end());
23427 if (JSON_HEDLEY_UNLIKELY(!is_object()))
23429 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
23433 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23435 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
23439 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
23441 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects",
this));
23444 m_data.m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
23452 update(j.
begin(), j.
end(), merge_objects);
23462 m_data.m_type = value_t::object;
23463 m_data.m_value.object = create<object_t>();
23464 assert_invariant();
23467 if (JSON_HEDLEY_UNLIKELY(!is_object()))
23469 JSON_THROW(type_error::create(312, detail::concat(
"cannot use update() with ", type_name()),
this));
23473 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23475 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
23479 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
23481 JSON_THROW(type_error::create(312, detail::concat(
"cannot use update() with ", first.m_object->type_name()), first.m_object));
23484 for (
auto it = first; it != last; ++it)
23486 if (merge_objects && it.value().is_object())
23488 auto it2 = m_data.m_value.object->find(it.key());
23489 if (it2 != m_data.m_value.object->end())
23491 it2->second.update(it.value(),
true);
23495 m_data.m_value.object->operator[](it.key()) = it.value();
23496#if JSON_DIAGNOSTICS
23497 m_data.m_value.object->operator[](it.key()).m_parent =
this;
23505 std::is_nothrow_move_constructible<value_t>::value&&
23506 std::is_nothrow_move_assignable<value_t>::value&&
23507 std::is_nothrow_move_constructible<json_value>::value&&
23508 std::is_nothrow_move_assignable<json_value>::value
23511 std::swap(m_data.m_type, other.m_data.m_type);
23512 std::swap(m_data.m_value, other.m_data.m_value);
23515 other.set_parents();
23516 assert_invariant();
23522 std::is_nothrow_move_constructible<value_t>::value&&
23523 std::is_nothrow_move_assignable<value_t>::value&&
23524 std::is_nothrow_move_constructible<json_value>::value&&
23525 std::is_nothrow_move_assignable<json_value>::value
23536 if (JSON_HEDLEY_LIKELY(is_array()))
23539 swap(*(m_data.m_value.array), other);
23543 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(array_t&) with ", type_name()),
this));
23552 if (JSON_HEDLEY_LIKELY(is_object()))
23555 swap(*(m_data.m_value.object), other);
23559 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(object_t&) with ", type_name()),
this));
23568 if (JSON_HEDLEY_LIKELY(is_string()))
23571 swap(*(m_data.m_value.string), other);
23575 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(string_t&) with ", type_name()),
this));
23584 if (JSON_HEDLEY_LIKELY(is_binary()))
23587 swap(*(m_data.m_value.binary), other);
23591 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(binary_t&) with ", type_name()),
this));
23597 void swap(
typename binary_t::container_type& other)
23600 if (JSON_HEDLEY_LIKELY(is_binary()))
23603 swap(*(m_data.m_value.binary), other);
23607 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(binary_t::container_type&) with ", type_name()),
this));
23622#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result) \
23623 const auto lhs_type = lhs.type(); \
23624 const auto rhs_type = rhs.type(); \
23626 if (lhs_type == rhs_type) \
23628 switch (lhs_type) \
23630 case value_t::array: \
23631 return (*lhs.m_data.m_value.array) op (*rhs.m_data.m_value.array); \
23633 case value_t::object: \
23634 return (*lhs.m_data.m_value.object) op (*rhs.m_data.m_value.object); \
23636 case value_t::null: \
23637 return (null_result); \
23639 case value_t::string: \
23640 return (*lhs.m_data.m_value.string) op (*rhs.m_data.m_value.string); \
23642 case value_t::boolean: \
23643 return (lhs.m_data.m_value.boolean) op (rhs.m_data.m_value.boolean); \
23645 case value_t::number_integer: \
23646 return (lhs.m_data.m_value.number_integer) op (rhs.m_data.m_value.number_integer); \
23648 case value_t::number_unsigned: \
23649 return (lhs.m_data.m_value.number_unsigned) op (rhs.m_data.m_value.number_unsigned); \
23651 case value_t::number_float: \
23652 return (lhs.m_data.m_value.number_float) op (rhs.m_data.m_value.number_float); \
23654 case value_t::binary: \
23655 return (*lhs.m_data.m_value.binary) op (*rhs.m_data.m_value.binary); \
23657 case value_t::discarded: \
23659 return (unordered_result); \
23662 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) \
23664 return static_cast<number_float_t>(lhs.m_data.m_value.number_integer) op rhs.m_data.m_value.number_float; \
23666 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) \
23668 return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_integer); \
23670 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) \
23672 return static_cast<number_float_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_float; \
23674 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) \
23676 return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_unsigned); \
23678 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) \
23680 return static_cast<number_integer_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_integer; \
23682 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) \
23684 return lhs.m_data.m_value.number_integer op static_cast<number_integer_t>(rhs.m_data.m_value.number_unsigned); \
23686 else if(compares_unordered(lhs, rhs))\
23688 return (unordered_result);\
23691 return (default_result);
23693 JSON_PRIVATE_UNLESS_TESTED:
23699 static bool compares_unordered(const_reference lhs, const_reference rhs,
bool inverse =
false) noexcept
23701 if ((lhs.is_number_float() && std::isnan(lhs.m_data.m_value.number_float) && rhs.is_number())
23702 || (rhs.is_number_float() && std::isnan(rhs.m_data.m_value.number_float) && lhs.is_number()))
23706#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
23707 return (lhs.is_discarded() || rhs.is_discarded()) && !
inverse;
23710 return lhs.is_discarded() || rhs.is_discarded();
23715 bool compares_unordered(const_reference rhs,
bool inverse =
false) const noexcept
23717 return compares_unordered(*
this, rhs, inverse);
23721#if JSON_HAS_THREE_WAY_COMPARISON
23724 bool operator==(const_reference rhs)
const noexcept
23727#pragma GCC diagnostic push
23728#pragma GCC diagnostic ignored "-Wfloat-equal"
23730 const_reference lhs = *
this;
23731 JSON_IMPLEMENT_OPERATOR( ==,
true,
false,
false)
23733#pragma GCC diagnostic pop
23739 template<
typename ScalarType>
23740 requires std::is_scalar_v<ScalarType>
23741 bool operator==(ScalarType rhs)
const noexcept
23748 bool operator!=(const_reference rhs)
const noexcept
23750 if (compares_unordered(rhs,
true))
23754 return !operator==(rhs);
23759 std::partial_ordering operator<=>(const_reference rhs)
const noexcept
23761 const_reference lhs = *
this;
23764 JSON_IMPLEMENT_OPERATOR(<=>,
23765 std::partial_ordering::equivalent,
23766 std::partial_ordering::unordered,
23767 lhs_type <=> rhs_type)
23772 template<
typename ScalarType>
23773 requires std::is_scalar_v<ScalarType>
23774 std::partial_ordering operator<=>(ScalarType rhs)
const noexcept
23779#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
23785 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON)
23786 bool operator<=(const_reference rhs)
const noexcept
23788 if (compares_unordered(rhs,
true))
23792 return !(rhs < *
this);
23797 template<
typename ScalarType>
23798 requires std::is_scalar_v<ScalarType>
23799 bool operator<=(ScalarType rhs)
const noexcept
23806 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON)
23807 bool operator>=(const_reference rhs)
const noexcept
23809 if (compares_unordered(rhs,
true))
23813 return !(*
this < rhs);
23818 template<
typename ScalarType>
23819 requires std::is_scalar_v<ScalarType>
23820 bool operator>=(ScalarType rhs)
const noexcept
23828 friend bool operator==(const_reference lhs, const_reference rhs)
noexcept
23831#pragma GCC diagnostic push
23832#pragma GCC diagnostic ignored "-Wfloat-equal"
23834 JSON_IMPLEMENT_OPERATOR( ==,
true,
false,
false)
23836#pragma GCC diagnostic pop
23842 template<
typename ScalarType,
typename std::enable_if<
23843 std::is_scalar<ScalarType>::value,
int>::type = 0>
23844 friend bool operator==(const_reference lhs, ScalarType rhs)
noexcept
23851 template<
typename ScalarType,
typename std::enable_if<
23852 std::is_scalar<ScalarType>::value,
int>::type = 0>
23853 friend bool operator==(ScalarType lhs, const_reference rhs)
noexcept
23860 friend bool operator!=(const_reference lhs, const_reference rhs)
noexcept
23862 if (compares_unordered(lhs, rhs,
true))
23866 return !(lhs == rhs);
23871 template<
typename ScalarType,
typename std::enable_if<
23872 std::is_scalar<ScalarType>::value,
int>::type = 0>
23873 friend bool operator!=(const_reference lhs, ScalarType rhs)
noexcept
23880 template<
typename ScalarType,
typename std::enable_if<
23881 std::is_scalar<ScalarType>::value,
int>::type = 0>
23882 friend bool operator!=(ScalarType lhs, const_reference rhs)
noexcept
23889 friend bool operator<(const_reference lhs, const_reference rhs)
noexcept
23894 JSON_IMPLEMENT_OPERATOR( <,
false,
false,
operator<(lhs_type, rhs_type))
23899 template<
typename ScalarType,
typename std::enable_if<
23900 std::is_scalar<ScalarType>::value,
int>::type = 0>
23901 friend bool operator<(const_reference lhs, ScalarType rhs)
noexcept
23908 template<
typename ScalarType,
typename std::enable_if<
23909 std::is_scalar<ScalarType>::value,
int>::type = 0>
23910 friend bool operator<(ScalarType lhs, const_reference rhs)
noexcept
23917 friend bool operator<=(const_reference lhs, const_reference rhs)
noexcept
23919 if (compares_unordered(lhs, rhs,
true))
23923 return !(rhs < lhs);
23928 template<
typename ScalarType,
typename std::enable_if<
23929 std::is_scalar<ScalarType>::value,
int>::type = 0>
23930 friend bool operator<=(const_reference lhs, ScalarType rhs)
noexcept
23937 template<
typename ScalarType,
typename std::enable_if<
23938 std::is_scalar<ScalarType>::value,
int>::type = 0>
23939 friend bool operator<=(ScalarType lhs, const_reference rhs)
noexcept
23946 friend bool operator>(const_reference lhs, const_reference rhs)
noexcept
23949 if (compares_unordered(lhs, rhs))
23953 return !(lhs <= rhs);
23958 template<
typename ScalarType,
typename std::enable_if<
23959 std::is_scalar<ScalarType>::value,
int>::type = 0>
23960 friend bool operator>(const_reference lhs, ScalarType rhs)
noexcept
23967 template<
typename ScalarType,
typename std::enable_if<
23968 std::is_scalar<ScalarType>::value,
int>::type = 0>
23969 friend bool operator>(ScalarType lhs, const_reference rhs)
noexcept
23976 friend bool operator>=(const_reference lhs, const_reference rhs)
noexcept
23978 if (compares_unordered(lhs, rhs,
true))
23982 return !(lhs < rhs);
23987 template<
typename ScalarType,
typename std::enable_if<
23988 std::is_scalar<ScalarType>::value,
int>::type = 0>
23989 friend bool operator>=(const_reference lhs, ScalarType rhs)
noexcept
23996 template<
typename ScalarType,
typename std::enable_if<
23997 std::is_scalar<ScalarType>::value,
int>::type = 0>
23998 friend bool operator>=(ScalarType lhs, const_reference rhs)
noexcept
24004#undef JSON_IMPLEMENT_OPERATOR
24017 friend std::ostream& operator<<(std::ostream& o,
const basic_json& j)
24020 const bool pretty_print = o.width() > 0;
24021 const auto indentation = pretty_print ? o.width() : 0;
24028 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
24038 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator<<(std::ostream&,
const basic_json&))
24039 friend std::ostream& operator>>(
const basic_json& j, std::ostream& o)
24055 template<
typename InputType>
24056 JSON_HEDLEY_WARN_UNUSED_RESULT
24058 parser_callback_t cb =
nullptr,
24059 const bool allow_exceptions =
true,
24060 const bool ignore_comments =
false)
24063 parser(detail::input_adapter(std::forward<InputType>(i)), std::move(cb), allow_exceptions, ignore_comments).parse(
true, result);
24069 template<
typename IteratorType>
24070 JSON_HEDLEY_WARN_UNUSED_RESULT
24073 parser_callback_t cb =
nullptr,
24074 const bool allow_exceptions =
true,
24075 const bool ignore_comments =
false)
24078 parser(detail::input_adapter(std::move(first), std::move(last)), std::move(cb), allow_exceptions, ignore_comments).parse(
true, result);
24082 JSON_HEDLEY_WARN_UNUSED_RESULT
24083 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len))
24085 parser_callback_t cb =
nullptr,
24086 const bool allow_exceptions =
true,
24087 const bool ignore_comments =
false)
24090 parser(i.get(), std::move(cb), allow_exceptions, ignore_comments).parse(
true, result);
24096 template<
typename InputType>
24097 static bool accept(InputType&& i,
24098 const bool ignore_comments =
false)
24100 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false, ignore_comments).accept(
true);
24105 template<
typename IteratorType>
24106 static bool accept(IteratorType first, IteratorType last,
24107 const bool ignore_comments =
false)
24109 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false, ignore_comments).accept(
true);
24112 JSON_HEDLEY_WARN_UNUSED_RESULT
24113 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len))
24115 const bool ignore_comments =
false)
24117 return parser(i.get(),
nullptr,
false, ignore_comments).accept(
true);
24122 template <
typename InputType,
typename SAX>
24123 JSON_HEDLEY_NON_NULL(2)
24124 static
bool sax_parse(InputType&& i, SAX* sax,
24125 input_format_t format = input_format_t::json,
24126 const
bool strict = true,
24127 const
bool ignore_comments = false)
24129 auto ia = detail::input_adapter(std::forward<InputType>(i));
24130 return format == input_format_t::json
24131 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
24137 template<
class IteratorType,
class SAX>
24138 JSON_HEDLEY_NON_NULL(3)
24139 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
24141 const
bool strict = true,
24142 const
bool ignore_comments = false)
24144 auto ia = detail::input_adapter(std::move(first), std::move(last));
24145 return format == input_format_t::json
24146 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
24155 template <
typename SAX>
24156 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, sax_parse(ptr, ptr + len, ...))
24157 JSON_HEDLEY_NON_NULL(2)
24158 static
bool sax_parse(
detail::span_input_adapter&& i, SAX* sax,
24160 const
bool strict = true,
24161 const
bool ignore_comments = false)
24164 return format == input_format_t::json
24166 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
24177 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator>>(std::istream&,
basic_json&))
24180 return operator>>(i, j);
24187 parser(detail::input_adapter(i)).parse(
false, j);
24199 JSON_HEDLEY_RETURNS_NON_NULL
24202 switch (m_data.m_type)
24204 case value_t::null:
24206 case value_t::object:
24208 case value_t::array:
24210 case value_t::string:
24212 case value_t::boolean:
24214 case value_t::binary:
24216 case value_t::discarded:
24217 return "discarded";
24218 case value_t::number_integer:
24219 case value_t::number_unsigned:
24220 case value_t::number_float:
24226 JSON_PRIVATE_UNLESS_TESTED:
24234 value_t m_type = value_t::null;
24237 json_value m_value = {};
24239 data(
const value_t v)
24240 : m_type(v), m_value(v)
24247 m_value.array = create<array_t>(cnt, val);
24250 data() noexcept = default;
24251 data(data&&) noexcept = default;
24252 data(const data&) noexcept = delete;
24253 data& operator=(data&&) noexcept = delete;
24254 data& operator=(const data&) noexcept = delete;
24258 m_value.destroy(m_type);
24264#if JSON_DIAGNOSTICS
24269#if JSON_DIAGNOSTIC_POSITIONS
24271 std::size_t start_position = std::string::npos;
24273 std::size_t end_position = std::string::npos;
24275 constexpr std::size_t start_pos() const noexcept
24277 return start_position;
24280 constexpr std::size_t end_pos() const noexcept
24282 return end_position;
24298 std::vector<std::uint8_t> result;
24299 to_cbor(j, result);
24307 binary_writer<std::uint8_t>(o).write_cbor(j);
24314 binary_writer<char>(o).write_cbor(j);
24321 std::vector<std::uint8_t> result;
24322 to_msgpack(j, result);
24330 binary_writer<std::uint8_t>(o).write_msgpack(j);
24337 binary_writer<char>(o).write_msgpack(j);
24343 const bool use_size =
false,
24344 const bool use_type =
false)
24346 std::vector<std::uint8_t> result;
24347 to_ubjson(j, result, use_size, use_type);
24354 const bool use_size =
false,
const bool use_type =
false)
24356 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);
24362 const bool use_size =
false,
const bool use_type =
false)
24364 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
24370 const bool use_size =
false,
24371 const bool use_type =
false,
24374 std::vector<std::uint8_t> result;
24375 to_bjdata(j, result, use_size, use_type, version);
24382 const bool use_size =
false,
const bool use_type =
false,
24385 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type,
true,
true, version);
24391 const bool use_size =
false,
const bool use_type =
false,
24394 binary_writer<char>(o).write_ubjson(j, use_size, use_type,
true,
true, version);
24401 std::vector<std::uint8_t> result;
24402 to_bson(j, result);
24410 binary_writer<std::uint8_t>(o).write_bson(j);
24417 binary_writer<char>(o).write_bson(j);
24422 template<
typename InputType>
24423 JSON_HEDLEY_WARN_UNUSED_RESULT
24425 const bool strict =
true,
24426 const bool allow_exceptions =
true,
24430 auto ia = detail::input_adapter(std::forward<InputType>(i));
24432 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24433 return res ? result :
basic_json(value_t::discarded);
24438 template<
typename IteratorType>
24439 JSON_HEDLEY_WARN_UNUSED_RESULT
24441 const bool strict =
true,
24442 const bool allow_exceptions =
true,
24446 auto ia = detail::input_adapter(std::move(first), std::move(last));
24448 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24449 return res ? result :
basic_json(value_t::discarded);
24452 template<
typename T>
24453 JSON_HEDLEY_WARN_UNUSED_RESULT
24454 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
24455 static basic_json from_cbor(
const T* ptr, std::size_t len,
24456 const bool strict =
true,
24457 const bool allow_exceptions =
true,
24458 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24460 return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
24463 JSON_HEDLEY_WARN_UNUSED_RESULT
24464 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
24466 const bool strict =
true,
24467 const bool allow_exceptions =
true,
24468 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24474 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24475 return res ? result :
basic_json(value_t::discarded);
24480 template<
typename InputType>
24481 JSON_HEDLEY_WARN_UNUSED_RESULT
24483 const bool strict =
true,
24484 const bool allow_exceptions =
true)
24487 auto ia = detail::input_adapter(std::forward<InputType>(i));
24489 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
24490 return res ? result :
basic_json(value_t::discarded);
24495 template<
typename IteratorType>
24496 JSON_HEDLEY_WARN_UNUSED_RESULT
24498 const bool strict =
true,
24499 const bool allow_exceptions =
true)
24502 auto ia = detail::input_adapter(std::move(first), std::move(last));
24504 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
24505 return res ? result :
basic_json(value_t::discarded);
24508 template<
typename T>
24509 JSON_HEDLEY_WARN_UNUSED_RESULT
24510 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
24511 static basic_json from_msgpack(
const T* ptr, std::size_t len,
24512 const bool strict =
true,
24513 const bool allow_exceptions =
true)
24515 return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
24518 JSON_HEDLEY_WARN_UNUSED_RESULT
24519 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
24521 const bool strict =
true,
24522 const bool allow_exceptions =
true)
24528 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
24529 return res ? result :
basic_json(value_t::discarded);
24534 template<
typename InputType>
24535 JSON_HEDLEY_WARN_UNUSED_RESULT
24537 const bool strict =
true,
24538 const bool allow_exceptions =
true)
24541 auto ia = detail::input_adapter(std::forward<InputType>(i));
24543 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
24544 return res ? result :
basic_json(value_t::discarded);
24549 template<
typename IteratorType>
24550 JSON_HEDLEY_WARN_UNUSED_RESULT
24552 const bool strict =
true,
24553 const bool allow_exceptions =
true)
24556 auto ia = detail::input_adapter(std::move(first), std::move(last));
24558 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
24559 return res ? result :
basic_json(value_t::discarded);
24562 template<
typename T>
24563 JSON_HEDLEY_WARN_UNUSED_RESULT
24564 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
24565 static basic_json from_ubjson(
const T* ptr, std::size_t len,
24566 const bool strict =
true,
24567 const bool allow_exceptions =
true)
24569 return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
24572 JSON_HEDLEY_WARN_UNUSED_RESULT
24573 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
24575 const bool strict =
true,
24576 const bool allow_exceptions =
true)
24582 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
24583 return res ? result :
basic_json(value_t::discarded);
24588 template<
typename InputType>
24589 JSON_HEDLEY_WARN_UNUSED_RESULT
24591 const bool strict =
true,
24592 const bool allow_exceptions =
true)
24595 auto ia = detail::input_adapter(std::forward<InputType>(i));
24597 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
24598 return res ? result :
basic_json(value_t::discarded);
24603 template<
typename IteratorType>
24604 JSON_HEDLEY_WARN_UNUSED_RESULT
24606 const bool strict =
true,
24607 const bool allow_exceptions =
true)
24610 auto ia = detail::input_adapter(std::move(first), std::move(last));
24612 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
24613 return res ? result :
basic_json(value_t::discarded);
24618 template<
typename InputType>
24619 JSON_HEDLEY_WARN_UNUSED_RESULT
24621 const bool strict =
true,
24622 const bool allow_exceptions =
true)
24625 auto ia = detail::input_adapter(std::forward<InputType>(i));
24627 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
24628 return res ? result :
basic_json(value_t::discarded);
24633 template<
typename IteratorType>
24634 JSON_HEDLEY_WARN_UNUSED_RESULT
24636 const bool strict =
true,
24637 const bool allow_exceptions =
true)
24640 auto ia = detail::input_adapter(std::move(first), std::move(last));
24642 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
24643 return res ? result :
basic_json(value_t::discarded);
24646 template<
typename T>
24647 JSON_HEDLEY_WARN_UNUSED_RESULT
24648 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
24649 static basic_json from_bson(
const T* ptr, std::size_t len,
24650 const bool strict =
true,
24651 const bool allow_exceptions =
true)
24653 return from_bson(ptr, ptr + len, strict, allow_exceptions);
24656 JSON_HEDLEY_WARN_UNUSED_RESULT
24657 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
24659 const bool strict =
true,
24660 const bool allow_exceptions =
true)
24666 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
24667 return res ? result :
basic_json(value_t::discarded);
24682 return ptr.get_unchecked(
this);
24685 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
24687 reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr)
24689 return ptr.get_unchecked(
this);
24696 return ptr.get_unchecked(
this);
24699 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
24701 const_reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
24703 return ptr.get_unchecked(
this);
24710 return ptr.get_checked(
this);
24713 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
24715 reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr)
24717 return ptr.get_checked(
this);
24724 return ptr.get_checked(
this);
24727 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
24729 const_reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
24731 return ptr.get_checked(
this);
24739 json_pointer::flatten(
"", *
this, result);
24747 return json_pointer::unflatten(*
this);
24765 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
24767 const auto get_op = [](
const string_t& op)
24771 return patch_operations::add;
24773 if (op ==
"remove")
24775 return patch_operations::remove;
24777 if (op ==
"replace")
24779 return patch_operations::replace;
24783 return patch_operations::move;
24787 return patch_operations::copy;
24791 return patch_operations::test;
24794 return patch_operations::invalid;
24809 if (top_pointer != ptr)
24811 result.
at(top_pointer);
24815 const auto last_path = ptr.
back();
24820 switch (parent.m_data.m_type)
24822 case value_t::null:
24823 case value_t::object:
24826 parent[last_path] = val;
24830 case value_t::array:
24832 if (last_path ==
"-")
24839 const auto idx = json_pointer::template array_index<basic_json_t>(last_path);
24840 if (JSON_HEDLEY_UNLIKELY(idx > parent.
size()))
24843 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"), &parent));
24853 case value_t::string:
24854 case value_t::boolean:
24855 case value_t::number_integer:
24856 case value_t::number_unsigned:
24857 case value_t::number_float:
24858 case value_t::binary:
24859 case value_t::discarded:
24861 JSON_ASSERT(
false);
24866 const auto operation_remove = [
this, & result](
json_pointer & ptr)
24869 const auto last_path = ptr.
back();
24877 auto it = parent.
find(last_path);
24878 if (JSON_HEDLEY_LIKELY(it != parent.
end()))
24884 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", last_path,
"' not found"),
this));
24890 parent.
erase(json_pointer::template array_index<basic_json_t>(last_path));
24895 if (JSON_HEDLEY_UNLIKELY(!json_patch.
is_array()))
24897 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", &json_patch));
24901 for (
const auto& val : json_patch)
24904 const auto get_value = [&val](
const string_t& op,
24909 auto it = val.m_data.m_value.object->find(member);
24912 const auto error_msg = (op ==
"op") ?
"operation" : detail::concat(
"operation '", op,
'\'');
24915 if (JSON_HEDLEY_UNLIKELY(it == val.m_data.m_value.object->end()))
24918 JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg,
" must have member '", member,
"'"), &val));
24922 if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
24925 JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg,
" must have string member '", member,
"'"), &val));
24933 if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
24935 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", &val));
24939 const auto op = get_value(
"op",
"op",
true).template get<string_t>();
24940 const auto path = get_value(op,
"path",
true).template get<string_t>();
24943 switch (get_op(op))
24945 case patch_operations::add:
24947 operation_add(ptr, get_value(
"add",
"value",
false));
24951 case patch_operations::remove:
24953 operation_remove(ptr);
24957 case patch_operations::replace:
24960 result.
at(ptr) = get_value(
"replace",
"value",
false);
24964 case patch_operations::move:
24966 const auto from_path = get_value(
"move",
"from",
true).template get<string_t>();
24976 operation_remove(from_ptr);
24977 operation_add(ptr, v);
24981 case patch_operations::copy:
24983 const auto from_path = get_value(
"copy",
"from",
true).template get<string_t>();
24992 operation_add(ptr, v);
24996 case patch_operations::test:
24998 bool success =
false;
25003 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
25011 if (JSON_HEDLEY_UNLIKELY(!success))
25013 JSON_THROW(other_error::create(501, detail::concat(
"unsuccessful: ", val.dump()), &val));
25019 case patch_operations::invalid:
25024 JSON_THROW(parse_error::create(105, 0, detail::concat(
"operation value '", op,
"' is invalid"), &val));
25041 JSON_HEDLEY_WARN_UNUSED_RESULT
25049 if (source == target)
25054 if (source.type() != target.type())
25059 {
"op",
"replace"}, {
"path", path}, {
"value", target}
25064 switch (source.type())
25066 case value_t::array:
25070 while (i < source.size() && i < target.size())
25073 auto temp_diff = diff(source[i], target[i], detail::concat<string_t>(path,
'/', detail::to_string<string_t>(i)));
25074 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
25083 while (i < source.size())
25087 result.
insert(result.
begin() + end_index,
object(
25090 {
"path", detail::concat<string_t>(path,
'/', detail::to_string<string_t>(i))}
25096 while (i < target.size())
25101 {
"path", detail::concat<string_t>(path,
"/-")},
25102 {
"value", target[i]}
25110 case value_t::object:
25113 for (
auto it = source.cbegin(); it != source.cend(); ++it)
25116 const auto path_key = detail::concat<string_t>(path,
'/',
detail::escape(it.key()));
25118 if (target.find(it.key()) != target.end())
25121 auto temp_diff = diff(it.value(), target[it.key()], path_key);
25122 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
25129 {
"op",
"remove"}, {
"path", path_key}
25135 for (
auto it = target.cbegin(); it != target.cend(); ++it)
25137 if (source.find(it.key()) == source.end())
25140 const auto path_key = detail::concat<string_t>(path,
'/',
detail::escape(it.key()));
25143 {
"op",
"add"}, {
"path", path_key},
25144 {
"value", it.value()}
25152 case value_t::null:
25153 case value_t::string:
25154 case value_t::boolean:
25155 case value_t::number_integer:
25156 case value_t::number_unsigned:
25157 case value_t::number_float:
25158 case value_t::binary:
25159 case value_t::discarded:
25165 {
"op",
"replace"}, {
"path", path}, {
"value", target}
25192 for (
auto it = apply_patch.
begin(); it != apply_patch.
end(); ++it)
25194 if (it.value().is_null())
25200 operator[](it.key()).merge_patch(it.value());
25206 *
this = apply_patch;
25215NLOHMANN_BASIC_JSON_TPL_DECLARATION
25216std::string
to_string(
const NLOHMANN_BASIC_JSON_TPL& j)
25221inline namespace literals
25223inline namespace json_literals
25228JSON_HEDLEY_NON_NULL(1)
25229#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
25230 inline nlohmann::json
operator ""_json(
const char* s, std::size_t n)
25232 inline nlohmann::json
operator "" _json(
const char* s, std::size_t n)
25235 return nlohmann::json::parse(s, s + n);
25240JSON_HEDLEY_NON_NULL(1)
25241#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
25242 inline nlohmann::json::json_pointer
operator ""_json_pointer(
const char* s, std::size_t n)
25244 inline nlohmann::json::json_pointer
operator "" _json_pointer(
const char* s, std::size_t n)
25247 return nlohmann::json::json_pointer(std::string(s, n));
25252NLOHMANN_JSON_NAMESPACE_END
25263NLOHMANN_BASIC_JSON_TPL_DECLARATION
25264struct hash<nlohmann::NLOHMANN_BASIC_JSON_TPL>
25266 std::size_t operator()(
const nlohmann::NLOHMANN_BASIC_JSON_TPL& j)
const
25268 return nlohmann::detail::hash(j);
25274struct less< ::nlohmann::detail::value_t>
25281 ::nlohmann::detail::value_t rhs)
const noexcept
25283#if JSON_HAS_THREE_WAY_COMPARISON
25284 return std::is_lt(lhs <=> rhs);
25286 return ::nlohmann::detail::operator<(lhs, rhs);
25292#ifndef JSON_HAS_CPP_20
25296NLOHMANN_BASIC_JSON_TPL_DECLARATION
25297inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC_JSON_TPL& j2)
noexcept(
25298 is_nothrow_move_constructible<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value&&
25299 is_nothrow_move_assignable<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value)
25308#if JSON_USE_GLOBAL_UDLS
25309 #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
25310 using nlohmann::literals::json_literals::operator
""_json;
25311 using nlohmann::literals::json_literals::operator
""_json_pointer;
25313 using nlohmann::literals::json_literals::operator
"" _json;
25314 using nlohmann::literals::json_literals::operator
"" _json_pointer;
25330#if defined(__clang__)
25331 #pragma clang diagnostic pop
25336#undef JSON_INTERNAL_CATCH
25338#undef JSON_PRIVATE_UNLESS_TESTED
25339#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
25340#undef NLOHMANN_BASIC_JSON_TPL
25341#undef JSON_EXPLICIT
25342#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
25343#undef JSON_INLINE_VARIABLE
25344#undef JSON_NO_UNIQUE_ADDRESS
25345#undef JSON_DISABLE_ENUM_SERIALIZATION
25346#undef JSON_USE_GLOBAL_UDLS
25348#ifndef JSON_TEST_KEEP_MACROS
25351 #undef JSON_HAS_CPP_11
25352 #undef JSON_HAS_CPP_14
25353 #undef JSON_HAS_CPP_17
25354 #undef JSON_HAS_CPP_20
25355 #undef JSON_HAS_CPP_23
25356 #undef JSON_HAS_FILESYSTEM
25357 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
25358 #undef JSON_HAS_THREE_WAY_COMPARISON
25359 #undef JSON_HAS_RANGES
25360 #undef JSON_HAS_STATIC_RTTI
25361 #undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
25375#undef JSON_HEDLEY_ALWAYS_INLINE
25376#undef JSON_HEDLEY_ARM_VERSION
25377#undef JSON_HEDLEY_ARM_VERSION_CHECK
25378#undef JSON_HEDLEY_ARRAY_PARAM
25379#undef JSON_HEDLEY_ASSUME
25380#undef JSON_HEDLEY_BEGIN_C_DECLS
25381#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
25382#undef JSON_HEDLEY_CLANG_HAS_BUILTIN
25383#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
25384#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
25385#undef JSON_HEDLEY_CLANG_HAS_EXTENSION
25386#undef JSON_HEDLEY_CLANG_HAS_FEATURE
25387#undef JSON_HEDLEY_CLANG_HAS_WARNING
25388#undef JSON_HEDLEY_COMPCERT_VERSION
25389#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
25390#undef JSON_HEDLEY_CONCAT
25391#undef JSON_HEDLEY_CONCAT3
25392#undef JSON_HEDLEY_CONCAT3_EX
25393#undef JSON_HEDLEY_CONCAT_EX
25394#undef JSON_HEDLEY_CONST
25395#undef JSON_HEDLEY_CONSTEXPR
25396#undef JSON_HEDLEY_CONST_CAST
25397#undef JSON_HEDLEY_CPP_CAST
25398#undef JSON_HEDLEY_CRAY_VERSION
25399#undef JSON_HEDLEY_CRAY_VERSION_CHECK
25400#undef JSON_HEDLEY_C_DECL
25401#undef JSON_HEDLEY_DEPRECATED
25402#undef JSON_HEDLEY_DEPRECATED_FOR
25403#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
25404#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
25405#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
25406#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
25407#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
25408#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
25409#undef JSON_HEDLEY_DIAGNOSTIC_POP
25410#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
25411#undef JSON_HEDLEY_DMC_VERSION
25412#undef JSON_HEDLEY_DMC_VERSION_CHECK
25413#undef JSON_HEDLEY_EMPTY_BASES
25414#undef JSON_HEDLEY_EMSCRIPTEN_VERSION
25415#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
25416#undef JSON_HEDLEY_END_C_DECLS
25417#undef JSON_HEDLEY_FLAGS
25418#undef JSON_HEDLEY_FLAGS_CAST
25419#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
25420#undef JSON_HEDLEY_GCC_HAS_BUILTIN
25421#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
25422#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
25423#undef JSON_HEDLEY_GCC_HAS_EXTENSION
25424#undef JSON_HEDLEY_GCC_HAS_FEATURE
25425#undef JSON_HEDLEY_GCC_HAS_WARNING
25426#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
25427#undef JSON_HEDLEY_GCC_VERSION
25428#undef JSON_HEDLEY_GCC_VERSION_CHECK
25429#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
25430#undef JSON_HEDLEY_GNUC_HAS_BUILTIN
25431#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
25432#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
25433#undef JSON_HEDLEY_GNUC_HAS_EXTENSION
25434#undef JSON_HEDLEY_GNUC_HAS_FEATURE
25435#undef JSON_HEDLEY_GNUC_HAS_WARNING
25436#undef JSON_HEDLEY_GNUC_VERSION
25437#undef JSON_HEDLEY_GNUC_VERSION_CHECK
25438#undef JSON_HEDLEY_HAS_ATTRIBUTE
25439#undef JSON_HEDLEY_HAS_BUILTIN
25440#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
25441#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
25442#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
25443#undef JSON_HEDLEY_HAS_EXTENSION
25444#undef JSON_HEDLEY_HAS_FEATURE
25445#undef JSON_HEDLEY_HAS_WARNING
25446#undef JSON_HEDLEY_IAR_VERSION
25447#undef JSON_HEDLEY_IAR_VERSION_CHECK
25448#undef JSON_HEDLEY_IBM_VERSION
25449#undef JSON_HEDLEY_IBM_VERSION_CHECK
25450#undef JSON_HEDLEY_IMPORT
25451#undef JSON_HEDLEY_INLINE
25452#undef JSON_HEDLEY_INTEL_CL_VERSION
25453#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
25454#undef JSON_HEDLEY_INTEL_VERSION
25455#undef JSON_HEDLEY_INTEL_VERSION_CHECK
25456#undef JSON_HEDLEY_IS_CONSTANT
25457#undef JSON_HEDLEY_IS_CONSTEXPR_
25458#undef JSON_HEDLEY_LIKELY
25459#undef JSON_HEDLEY_MALLOC
25460#undef JSON_HEDLEY_MCST_LCC_VERSION
25461#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
25462#undef JSON_HEDLEY_MESSAGE
25463#undef JSON_HEDLEY_MSVC_VERSION
25464#undef JSON_HEDLEY_MSVC_VERSION_CHECK
25465#undef JSON_HEDLEY_NEVER_INLINE
25466#undef JSON_HEDLEY_NON_NULL
25467#undef JSON_HEDLEY_NO_ESCAPE
25468#undef JSON_HEDLEY_NO_RETURN
25469#undef JSON_HEDLEY_NO_THROW
25470#undef JSON_HEDLEY_NULL
25471#undef JSON_HEDLEY_PELLES_VERSION
25472#undef JSON_HEDLEY_PELLES_VERSION_CHECK
25473#undef JSON_HEDLEY_PGI_VERSION
25474#undef JSON_HEDLEY_PGI_VERSION_CHECK
25475#undef JSON_HEDLEY_PREDICT
25476#undef JSON_HEDLEY_PRINTF_FORMAT
25477#undef JSON_HEDLEY_PRIVATE
25478#undef JSON_HEDLEY_PUBLIC
25479#undef JSON_HEDLEY_PURE
25480#undef JSON_HEDLEY_REINTERPRET_CAST
25481#undef JSON_HEDLEY_REQUIRE
25482#undef JSON_HEDLEY_REQUIRE_CONSTEXPR
25483#undef JSON_HEDLEY_REQUIRE_MSG
25484#undef JSON_HEDLEY_RESTRICT
25485#undef JSON_HEDLEY_RETURNS_NON_NULL
25486#undef JSON_HEDLEY_SENTINEL
25487#undef JSON_HEDLEY_STATIC_ASSERT
25488#undef JSON_HEDLEY_STATIC_CAST
25489#undef JSON_HEDLEY_STRINGIFY
25490#undef JSON_HEDLEY_STRINGIFY_EX
25491#undef JSON_HEDLEY_SUNPRO_VERSION
25492#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
25493#undef JSON_HEDLEY_TINYC_VERSION
25494#undef JSON_HEDLEY_TINYC_VERSION_CHECK
25495#undef JSON_HEDLEY_TI_ARMCL_VERSION
25496#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
25497#undef JSON_HEDLEY_TI_CL2000_VERSION
25498#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
25499#undef JSON_HEDLEY_TI_CL430_VERSION
25500#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
25501#undef JSON_HEDLEY_TI_CL6X_VERSION
25502#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
25503#undef JSON_HEDLEY_TI_CL7X_VERSION
25504#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
25505#undef JSON_HEDLEY_TI_CLPRU_VERSION
25506#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
25507#undef JSON_HEDLEY_TI_VERSION
25508#undef JSON_HEDLEY_TI_VERSION_CHECK
25509#undef JSON_HEDLEY_UNAVAILABLE
25510#undef JSON_HEDLEY_UNLIKELY
25511#undef JSON_HEDLEY_UNPREDICTABLE
25512#undef JSON_HEDLEY_UNREACHABLE
25513#undef JSON_HEDLEY_UNREACHABLE_RETURN
25514#undef JSON_HEDLEY_VERSION
25515#undef JSON_HEDLEY_VERSION_DECODE_MAJOR
25516#undef JSON_HEDLEY_VERSION_DECODE_MINOR
25517#undef JSON_HEDLEY_VERSION_DECODE_REVISION
25518#undef JSON_HEDLEY_VERSION_ENCODE
25519#undef JSON_HEDLEY_WARNING
25520#undef JSON_HEDLEY_WARN_UNUSED_RESULT
25521#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
25522#undef JSON_HEDLEY_FALL_THROUGH
namespace for Niels Lohmann
Definition json.hpp:20114
constexpr bool is_string() const noexcept
return whether value is a string
Definition json.hpp:21412
size_type erase(const typename object_t::key_type &key)
remove element from a JSON object given a key
Definition json.hpp:22645
std::size_t size_type
a type to represent container sizes
Definition json.h:19520
reference operator[](KeyType &&key)
access specified object element
Definition json.hpp:22213
size_type size() const noexcept
returns the number of elements
Definition json.hpp:22986
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:24440
auto get() const noexcept(noexcept(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))) -> decltype(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))
get a (pointer) value (explicit)
Definition json.hpp:21785
const_iterator end() const noexcept
returns an iterator to one past the last element
Definition json.hpp:22843
reference back()
access the last element
Definition json.hpp:22449
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:20852
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
Definition json.hpp:22859
basic_json patch(const basic_json &json_patch) const
applies a JSON patch to a copy of the current object
Definition json.hpp:25032
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string
Definition json.hpp:24200
const_reference front() const
access the first element
Definition json.hpp:22442
constexpr bool is_array() const noexcept
return whether value is an array
Definition json.hpp:21405
void swap(reference other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&//NOLINT(cppcoreguidelines-noexcept-swap, performance-noexcept-swap) std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition json.hpp:23504
ReturnType value(const json_pointer &ptr, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:22393
size_type count(KeyType &&key) const
returns the number of occurrences of a key in a JSON object
Definition json.hpp:22762
constexpr bool is_number_integer() const noexcept
return whether value is an integer number
Definition json.hpp:21377
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:24635
reference operator[](const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.hpp:24680
constexpr bool is_structured() const noexcept
return whether type is structured
Definition json.hpp:21349
const_reference operator[](KeyType &&key) const
access specified object element
Definition json.hpp:22237
void swap(binary_t &other)
exchanges the values
Definition json.hpp:23581
ReferenceType get_ref()
get a reference value (implicit)
Definition json.hpp:21875
size_type max_size() const noexcept
returns the maximum possible number of elements
Definition json.hpp:23025
void update(const_reference j, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
Definition json.hpp:23450
ReferenceType get_ref() const
get a reference value (implicit)
Definition json.hpp:21886
constexpr bool is_discarded() const noexcept
return whether value is discarded
Definition json.hpp:21426
reference operator+=(initializer_list_t init)
add an object to an object
Definition json.hpp:23241
AllocatorType< basic_json > allocator_type
the allocator type
Definition json.h:19523
void push_back(basic_json &&val)
add an object to an array
Definition json.hpp:23129
const_reference operator[](const typename object_t::key_type &key) const
access specified object element
Definition json.hpp:22182
iteration_proxy< const_iterator > items() const noexcept
helper to access iterator member functions in range-based for
Definition json.hpp:22931
const_reference back() const
access the last element
Definition json.hpp:22458
IteratorType erase(IteratorType first, IteratorType last)
remove elements given an iterator range
Definition json.hpp:22540
reference operator+=(const basic_json &val)
add an object to an array
Definition json.hpp:23186
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:23521
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:24536
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:20994
iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
inserts copies of element into array
Definition json.hpp:23353
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:24620
static allocator_type get_allocator()
returns the allocator associated with the container
Definition json.hpp:20257
reference at(KeyType &&key)
access specified object element with bounds checking
Definition json.hpp:22045
iterator end() noexcept
returns an iterator to one past the last element
Definition json.hpp:22834
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
Definition json.hpp:21384
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:23457
static std::vector< std::uint8_t > to_bson(const basic_json &j)
create a BSON serialization of a given JSON value
Definition json.hpp:24399
const_reverse_iterator rbegin() const noexcept
returns an iterator to the reverse-beginning
Definition json.hpp:22866
void push_back(initializer_list_t init)
add an object to an object
Definition json.hpp:23225
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
Definition json.hpp:21035
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:24335
iterator begin() noexcept
returns an iterator to the first element
Definition json.hpp:22809
ReturnType value(const typename object_t::key_type &key, ValueType &&default_value) const
access specified object element with default value
Definition json.hpp:22292
const_iterator cend() const noexcept
returns an iterator to one past the last element
Definition json.hpp:22850
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:24590
const_reference at(const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.hpp:24722
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init)
explicitly create a binary array
Definition json.hpp:21005
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
Definition json.hpp:20840
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:24424
basic_json flatten() const
return flattened JSON value
Definition json.hpp:24736
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:24551
size_type erase(KeyType &&key)
remove element from a JSON object given a key
Definition json.hpp:22656
ArrayType< basic_json, AllocatorType< basic_json > > array_t
a type for an array
Definition json.h:19644
ObjectType< StringType, basic_json, default_object_comparator_t, AllocatorType< std::pair< const StringType, basic_json > > > object_t
a type for an object
Definition json.h:19636
const binary_t & get_binary() const
get a binary value
Definition json.hpp:21957
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
inserts range of elements into array
Definition json.hpp:23373
void patch_inplace(const basic_json &json_patch)
applies a JSON patch in-place without copying the object
Definition json.hpp:24761
ReturnType value(KeyType &&key, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:22345
const_reference operator[](const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.hpp:24694
std::initializer_list< detail::json_ref< basic_json > > initializer_list_t
helper type for initializer lists of basic_json values
Definition json.h:19477
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
a reverse iterator for a basic_json container
Definition json.h:19535
bool contains(KeyType &&key) const
check the existence of an element in a JSON object
Definition json.hpp:22779
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:24305
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:24415
iterator find(const typename object_t::key_type &key)
find an element in a JSON object
Definition json.hpp:22692
::nlohmann::json_pointer< StringType > json_pointer
JSON Pointer, see nlohmann::json_pointer.
Definition json.h:19469
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:20983
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:24369
const_reference at(KeyType &&key) const
access specified object element with bounds checking
Definition json.hpp:22083
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json meta()
returns version information on the library
Definition json.hpp:20265
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
Definition json.hpp:21042
const_iterator find(const typename object_t::key_type &key) const
find an element in a JSON object
Definition json.hpp:22706
static std::vector< std::uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
Definition json.hpp:24296
IteratorType erase(IteratorType pos)
remove element given an iterator
Definition json.hpp:22470
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
the type of an element const pointer
Definition json.h:19528
iterator insert(const_iterator pos, const basic_json &val)
inserts element into array
Definition json.hpp:23326
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition json.hpp:22267
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:21313
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
Definition json.hpp:25184
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:21839
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:24381
reference at(size_type idx)
access specified array element with bounds checking
Definition json.hpp:21979
iterator find(KeyType &&key)
find an element in a JSON object
Definition json.hpp:22722
constexpr bool is_number_float() const noexcept
return whether value is a floating-point number
Definition json.hpp:21391
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
Definition json.hpp:22873
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:24342
reference at(const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.hpp:24708
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:25042
reference operator+=(const typename object_t::value_type &val)
add an object to an object
Definition json.hpp:23217
const_iterator cbegin() const noexcept
returns a const iterator to the first element
Definition json.hpp:22825
reference operator[](typename object_t::key_type key)
access specified object element
Definition json.hpp:22160
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:21597
~basic_json() noexcept
destructor
Definition json.hpp:21295
typename std::allocator_traits< allocator_type >::pointer pointer
the type of an element pointer
Definition json.h:19526
const_reverse_iterator crend() const noexcept
returns a const reverse iterator to one before the first
Definition json.hpp:22894
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:20924
void swap(typename binary_t::container_type &other)
exchanges the values
Definition json.hpp:23597
binary_t & get_binary()
get a binary value
Definition json.hpp:21945
iter_impl< const basic_json > const_iterator
a const iterator for a basic_json container
Definition json.h:19533
const_iterator begin() const noexcept
returns an iterator to the first element
Definition json.hpp:22818
constexpr bool is_number() const noexcept
return whether value is a number
Definition json.hpp:21370
void insert(const_iterator first, const_iterator last)
inserts range of elements into object
Definition json.hpp:23424
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:24482
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
Definition json.hpp:21826
reference operator[](size_type idx)
access specified array element
Definition json.hpp:22101
basic_json & operator=(basic_json other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value &&std::is_nothrow_move_assignable< json_base_class_t >::value)
copy assignment
Definition json.hpp:21266
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:24361
auto get_ptr() noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition json.hpp:21586
const_reference at(const typename object_t::key_type &key) const
access specified object element with bounds checking
Definition json.hpp:22063
constexpr bool is_binary() const noexcept
return whether value is a binary array
Definition json.hpp:21419
void swap(object_t &other)
exchanges the values
Definition json.hpp:23549
nlohmann::byte_container_with_subtype< BinaryType > binary_t
a type for a packed binary type
Definition json.h:19668
basic_json unflatten() const
unflatten a previously flattened JSON value
Definition json.hpp:24745
iterator insert(const_iterator pos, initializer_list_t ilist)
inserts elements from initializer list into array
Definition json.hpp:23404
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
a const reverse iterator for a basic_json container
Definition json.h:19537
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:24390
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:21016
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
Definition json.hpp:22924
bool empty() const noexcept
checks whether the container is empty.
Definition json.hpp:22947
void swap(array_t &other)
exchanges the values
Definition json.hpp:23533
void erase(const size_type idx)
remove element from a JSON array given an index
Definition json.hpp:22663
StringType string_t
a type for a string
Definition json.h:19648
reference operator+=(basic_json &&val)
add an object to an array
Definition json.hpp:23154
bool contains(const json_pointer &ptr) const
check the existence of an element in a JSON object given a JSON pointer
Definition json.hpp:22786
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition json.hpp:21335
reference emplace_back(Args &&... args)
add an object to an array
Definition json.hpp:23250
ValueType value(const json_pointer &ptr, const ValueType &default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:22368
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
Definition json.hpp:21027
void push_back(const basic_json &val)
add an object to an array
Definition json.hpp:23162
ValueType value(KeyType &&key, const ValueType &default_value) const
access specified object element with default value
Definition json.hpp:22318
reference at(const typename object_t::key_type &key)
access specified object element with bounds checking
Definition json.hpp:22025
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:24605
json_value m_value
the value of the current element
Definition json.h:23498
const_reverse_iterator crbegin() const noexcept
returns a const reverse iterator to the last element
Definition json.hpp:22887
constexpr bool is_boolean() const noexcept
return whether value is a boolean
Definition json.hpp:21363
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:22752
iter_impl< basic_json > iterator
an iterator for a basic_json container
Definition json.h:19531
reference front()
access the first element
Definition json.hpp:22435
constexpr bool is_primitive() const noexcept
return whether type is primitive
Definition json.hpp:21342
constexpr bool is_null() const noexcept
return whether value is null
Definition json.hpp:21356
void clear() noexcept
clears the contents
Definition json.hpp:23068
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:24353
basic_json(basic_json &&other) noexcept
move constructor
Definition json.hpp:21240
basic_json(const value_t v)
create an empty value with a given type
Definition json.hpp:20832
const_reference operator[](size_type idx) const
access specified array element
Definition json.hpp:22147
iterator insert(const_iterator pos, basic_json &&val)
inserts element into array
Definition json.hpp:23346
const_reverse_iterator rend() const noexcept
returns an iterator to the reverse-end
Definition json.hpp:22880
friend std::istream & operator>>(std::istream &i, basic_json &j)
deserialize from stream
Definition json.hpp:24185
static std::vector< std::uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
Definition json.hpp:24319
void swap(string_t &other)
exchanges the values
Definition json.hpp:23565
basic_json(const BasicJsonType &val)
create a JSON value from an existing one
Definition json.hpp:20866
const_reference at(size_type idx) const
access specified array element with bounds checking
Definition json.hpp:22002
basic_json(const basic_json &other)
copy constructor
Definition json.hpp:21167
void push_back(const typename object_t::value_type &val)
add an object to an object
Definition json.hpp:23194
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
Definition json.hpp:23275
std::ptrdiff_t difference_type
a type to represent differences between iterators
Definition json.h:19518
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:24312
constexpr bool is_object() const noexcept
return whether value is an object
Definition json.hpp:21398
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:24328
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:24497
iterator insert_iterator(const_iterator pos, Args &&... args)
Definition json.hpp:23307
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
Definition json.hpp:21054
bool contains(const typename object_t::key_type &key) const
check the existence of an element in a JSON object
Definition json.hpp:22770
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:24408
const_iterator find(KeyType &&key) const
find an element in a JSON object
Definition json.hpp:22738
an internal type for a backed binary type
Definition json.h:5892
byte_container_with_subtype() noexcept(noexcept(container_type()))
Definition json.hpp:6200
byte_container_with_subtype(container_type &&b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))
Definition json.hpp:6222
byte_container_with_subtype(container_type &&b) noexcept(noexcept(container_type(std::move(b))))
Definition json.hpp:6210
constexpr subtype_type subtype() const noexcept
return the binary subtype
Definition json.hpp:6249
byte_container_with_subtype(const container_type &b, subtype_type subtype_) noexcept(noexcept(container_type(b)))
Definition json.hpp:6215
constexpr bool has_subtype() const noexcept
return whether the value has a subtype
Definition json.hpp:6256
byte_container_with_subtype(const container_type &b) noexcept(noexcept(container_type(b)))
Definition json.hpp:6205
void set_subtype(subtype_type subtype_) noexcept
sets the binary subtype
Definition json.hpp:6241
void clear_subtype() noexcept
clears the binary subtype
Definition json.hpp:6263
deserialization of CBOR, MessagePack, and UBJSON values
Definition json.hpp:9846
binary_reader(InputAdapterType &&adapter, const input_format_t format=input_format_t::json) noexcept
create a binary reader
Definition json.hpp:9862
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.h:9250
serialization to CBOR and MessagePack values
Definition json.hpp:15787
void write_bson(const BasicJsonType &j)
Definition json.hpp:15807
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:16487
binary_writer(output_adapter_t< CharType > adapter)
create a binary writer
Definition json.hpp:15798
void write_msgpack(const BasicJsonType &j)
Definition json.hpp:16160
void write_cbor(const BasicJsonType &j)
Definition json.hpp:15836
general exception of the basic_json class
Definition json.hpp:4511
const int id
the id of the exception
Definition json.h:4381
const char * what() const noexcept override
returns the explanatory string
Definition json.hpp:4514
exception indicating errors with iterators
Definition json.hpp:4680
a template for a bidirectional iterator for the basic_json class This class implements a both iterato...
Definition json.hpp:13606
iter_impl operator+(difference_type i) const
add to iterator
Definition json.hpp:14189
std::bidirectional_iterator_tag iterator_category
Definition json.h:12942
typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_reference, typename BasicJsonType::reference >::type reference
defines a reference to the type iterated over (value_type)
Definition json.h:12953
iter_impl(pointer object) noexcept
constructor for a given JSON instance
Definition json.hpp:13658
iter_impl & operator=(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting assignment
Definition json.hpp:13743
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
Definition json.hpp:14134
iter_impl(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting constructor
Definition json.hpp:13733
typename BasicJsonType::value_type value_type
the type of the values when the iterator is dereferenced
Definition json.h:12945
bool operator<(const iter_impl &other) const
comparison: smaller
Definition json.hpp:14076
bool operator<=(const iter_impl &other) const
comparison: less than or equal
Definition json.hpp:14116
iter_impl & operator-=(difference_type i)
subtract from iterator
Definition json.hpp:14180
iter_impl & operator--()
pre-decrement (–it)
Definition json.hpp:13986
const object_t::key_type & key() const
return the key of an object iterator
Definition json.hpp:14289
bool operator==(const IterImpl &other) const
comparison: equal
Definition json.hpp:14027
iter_impl operator++(int) &
post-increment (it++)
Definition json.hpp:13924
iter_impl & operator+=(difference_type i)
add to iterator
Definition json.hpp:14143
reference operator[](difference_type n) const
access to successor
Definition json.hpp:14251
pointer operator->() const
dereference the iterator
Definition json.hpp:13882
difference_type operator-(const iter_impl &other) const
return difference
Definition json.hpp:14222
friend iter_impl operator+(difference_type i, const iter_impl &it)
addition of distance and iterator
Definition json.hpp:14200
reference value() const
return the value of an iterator
Definition json.hpp:14305
bool operator>(const iter_impl &other) const
comparison: greater than
Definition json.hpp:14125
iter_impl & operator++()
pre-increment (++it)
Definition json.hpp:13935
reference operator*() const
return a reference to the value pointed to by the iterator
Definition json.hpp:13838
iter_impl operator-(difference_type i) const
subtract from iterator
Definition json.hpp:14211
typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_pointer, typename BasicJsonType::pointer >::type pointer
defines a pointer to the type iterated over (value_type)
Definition json.h:12949
iter_impl & operator=(const iter_impl< const BasicJsonType > &other) noexcept
converting assignment
Definition json.hpp:13718
bool operator!=(const IterImpl &other) const
comparison: not equal
Definition json.hpp:14067
iter_impl operator--(int) &
post-decrement (it–)
Definition json.hpp:13975
typename BasicJsonType::difference_type difference_type
a type to represent differences between iterators
Definition json.h:12947
iter_impl(const iter_impl< const BasicJsonType > &other) noexcept
const copy constructor
Definition json.hpp:13708
void set_end() noexcept
set the iterator past the last value
Definition json.hpp:13799
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition json.h:13616
Definition json.hpp:13586
bool operator==(const iteration_proxy_value &o) const
equality operator (needed for InputIterator)
Definition json.hpp:5527
bool operator!=(const iteration_proxy_value &o) const
inequality operator (needed for range-based for)
Definition json.hpp:5533
iteration_proxy_value & operator++()
increment operator (needed for range-based for)
Definition json.hpp:5510
IteratorType::reference value() const
return value of the iterator
Definition json.hpp:5575
const string_type & key() const
return key of the iterator
Definition json.hpp:5539
proxy class for the items() function
Definition json.hpp:13585
iteration_proxy_value< IteratorType > end() const noexcept
return iterator end (needed for range-based for)
Definition json.hpp:5608
iteration_proxy(typename IteratorType::reference cont) noexcept
construct iteration proxy from a container
Definition json.hpp:5592
Definition json.hpp:15519
a template for a reverse iterator class
Definition json.hpp:14368
json_reverse_iterator operator++(int) &
post-increment (it++)
Definition json.hpp:14384
json_reverse_iterator operator--(int) &
post-decrement (it–)
Definition json.hpp:14396
std::reverse_iterator< Base > base_iterator
shortcut to the reverse iterator adapter
Definition json.h:13674
json_reverse_iterator & operator++()
pre-increment (++it)
Definition json.hpp:14390
json_reverse_iterator & operator+=(difference_type i)
add to iterator
Definition json.hpp:14408
reference operator[](difference_type n) const
access to successor
Definition json.hpp:14432
auto key() const -> decltype(std::declval< Base >().key())
return the key of an object iterator
Definition json.hpp:14438
difference_type operator-(const json_reverse_iterator &other) const
return difference
Definition json.hpp:14426
reference value() const
return the value of an iterator
Definition json.hpp:14445
json_reverse_iterator(const base_iterator &it) noexcept
create reverse iterator from base class
Definition json.hpp:14381
json_reverse_iterator & operator--()
pre-decrement (–it)
Definition json.hpp:14402
json_reverse_iterator operator-(difference_type i) const
subtract from iterator
Definition json.hpp:14420
typename Base::reference reference
the reference type for the pointed-to element
Definition json.h:13676
json_reverse_iterator(const typename base_iterator::iterator_type &it) noexcept
create reverse iterator from iterator
Definition json.hpp:14377
json_reverse_iterator operator+(difference_type i) const
add to iterator
Definition json.hpp:14414
SAX implementation to create a JSON value from SAX events.
Definition json.hpp:8818
json_sax_dom_parser(BasicJsonType &r, const bool allow_exceptions_=true, lexer_t *lexer_=nullptr)
Definition json.hpp:8832
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:7085
token_type
token types for the parser
Definition json.h:7412
@ value_float
an floating point number – use get_number_float() for actual value
@ begin_array
the character for array begin [
@ value_string
a string – use get_string() for actual value
@ end_array
the character for array end ]
@ uninitialized
indicating the scanner is uninitialized
@ parse_error
indicating a parse error
@ value_integer
a signed integer – use get_number_integer() for actual value
@ value_separator
the value separator ,
@ end_object
the character for object end }
@ literal_true
the true literal
@ begin_object
the character for object begin {
@ value_unsigned
an unsigned integer – use get_number_unsigned() for actual value
@ literal_null
the null literal
@ end_of_input
indicating the end of the input buffer
@ name_separator
the name separator :
@ literal_or_value
a literal or the begin of a value (only for diagnostics)
@ literal_false
the false literal
lexical analysis
Definition json.hpp:7135
bool skip_bom()
skip the UTF-8 byte order mark
Definition json.hpp:8517
JSON_HEDLEY_RETURNS_NON_NULL constexpr const char * get_error_message() const noexcept
return syntax error message
Definition json.hpp:8504
std::string get_token_string() const
Definition json.hpp:8479
constexpr number_integer_t get_number_integer() const noexcept
return integer value
Definition json.hpp:8438
constexpr position_t get_position() const noexcept
return position of last read token
Definition json.hpp:8471
constexpr number_unsigned_t get_number_unsigned() const noexcept
return unsigned integer value
Definition json.hpp:8444
string_t & get_string()
return current string value (implicitly resets the token; useful only once)
Definition json.hpp:8456
constexpr number_float_t get_number_float() const noexcept
return floating-point value
Definition json.hpp:8450
exception indicating other library errors
Definition json.hpp:4732
exception indicating access out of the defined range
Definition json.hpp:4715
Definition json.hpp:15738
output adapter for output streams
Definition json.hpp:15690
output adapter for basic_string
Definition json.hpp:15715
output adapter for byte vectors
Definition json.hpp:15665
exception indicating a parse error
Definition json.hpp:4627
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:4639
const std::size_t byte
byte index of the parse error
Definition json.h:4507
syntax analysis
Definition json.hpp:12919
void parse(const bool strict, BasicJsonType &result)
public parser interface
Definition json.hpp:12951
bool accept(const bool strict=true)
public accept interface
Definition json.hpp:13011
parser(InputAdapterType &&adapter, parser_callback_t< BasicJsonType > cb=nullptr, const bool allow_exceptions_=true, const bool skip_comments=false)
a parser reading from an input adapter
Definition json.hpp:12929
Definition json.hpp:13423
constexpr bool is_begin() const noexcept
return whether the iterator can be dereferenced
Definition json.hpp:13452
void set_end() noexcept
set iterator to a defined past the end
Definition json.hpp:13446
constexpr bool is_end() const noexcept
return whether the iterator is at end
Definition json.hpp:13458
void set_begin() noexcept
set iterator to a defined beginning
Definition json.hpp:13440
Definition json.hpp:18773
serializer(output_adapter_t< char > s, const char ichar, error_handler_t error_handler_=error_handler_t::strict)
Definition json.hpp:18788
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:18828
exception indicating executing a member function with a wrong type
Definition json.hpp:4698
JSON Pointer defines a string syntax for identifying a specific value within a JSON document.
Definition json.hpp:14540
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:14635
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:14642
json_pointer(const string_t &s="")
create JSON pointer
Definition json.hpp:14566
bool empty() const noexcept
return whether pointer points to the root document
Definition json.hpp:14701
void pop_back()
remove last reference token
Definition json.h:13965
string_t to_string() const
return a string representation of the JSON pointer
Definition json.hpp:14572
json_pointer & operator/=(std::size_t array_idx)
append an array index at the end of this JSON pointer
Definition json.hpp:14620
void push_back(string_t &&token)
append an unescaped token at the end of the reference pointer
Definition json.hpp:14694
json_pointer & operator/=(const json_pointer &ptr)
append another JSON pointer at the end of this JSON pointer
Definition json.hpp:14602
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:14627
json_pointer parent_pointer() const
returns the parent of this JSON pointer
Definition json.hpp:14649
json_pointer & operator/=(string_t token)
append an unescaped reference token at the end of this JSON pointer
Definition json.hpp:14612
const string_t & back() const
return last reference token
Definition json.hpp:14675
friend std::ostream & operator<<(std::ostream &o, const json_pointer &ptr)
write string representation of the JSON pointer to stream
Definition json.hpp:14593
void push_back(const string_t &token)
append an unescaped token at the end of the reference pointer
Definition json.hpp:14687
GLM_FUNC_QUALIFIER mat< C, R, T, Q > inverse(mat< C, R, T, Q > const &m)
Definition func_matrix.inl:388
GLM_FUNC_DECL GLM_CONSTEXPR genType one()
Definition constants.inl:12
GLM_FUNC_DECL GLM_CONSTEXPR genType e()
Definition constants.inl:102
uint64 uint64_t
Definition fwd.hpp:143
int64 int64_t
Definition fwd.hpp:85
uint32 uint32_t
Definition fwd.hpp:129
uint16 uint16_t
Definition fwd.hpp:115
detail::uint8 byte
Definition raw_data.hpp:34
GLM_FUNC_DECL std::string to_string(genType const &x)
int find_largest_pow10(const std::uint32_t n, std::uint32_t &pow10)
Definition json.h:17400
cached_power get_cached_power_for_binary_exponent(int e)
Definition json.h:17236
boundaries compute_boundaries(FloatType value)
Definition json.h:17097
void grisu2(char *buf, int &len, int &decimal_exponent, diyfp m_minus, diyfp v, diyfp m_plus)
Definition json.h:17736
void grisu2_digit_gen(char *buffer, int &length, int &decimal_exponent, diyfp M_minus, diyfp w, diyfp M_plus)
Definition json.h:17495
JSON_HEDLEY_RETURNS_NON_NULL char * append_exponent(char *buf, int e)
appends a decimal representation of e to buf
Definition json.h:17836
detail namespace with internal helper functions
Definition json.h:249
input_format_t
the supported input formats
Definition json.h:6177
parse_event_t
Definition json.h:12204
@ value
the parser finished reading a JSON value
@ key
the parser read a key of a value in an object
@ array_end
the parser read ] and finished processing a JSON array
@ array_start
the parser read [ and started to process a JSON array
@ object_start
the parser read { and started to process a JSON object
@ object_end
the parser read } and finished processing a JSON object
std::shared_ptr< output_adapter_protocol< CharType > > output_adapter_t
a type to simplify interfaces
Definition json.h:14960
void replace_substring(StringType &s, const StringType &f, const StringType &t)
replace all occurrences of a substring by another string
Definition json.h:2971
cbor_tag_handler_t
how to treat CBOR tags
Definition json.h:9186
@ store
store tags as binary type
@ error
throw a parse_error exception in case of a tag
value_t
the JSON type enumeration
Definition json.h:2873
@ number_integer
number value (signed integer)
@ discarded
discarded by the parser callback function
@ binary
binary array (ordered collection of bytes)
@ object
object (unordered set of name/value pairs)
@ number_float
number value (floating-point)
@ number_unsigned
number value (unsigned integer)
@ array
array (ordered collection of values)
std::size_t hash(const BasicJsonType &j)
hash a JSON value
Definition json.h:6023
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
Definition json.h:2902
error_handler_t
how to treat decoding errors
Definition json.h:18053
@ strict
throw a type_error exception in case of invalid UTF-8
@ replace
replace invalid UTF-8 sequences with U+FFFD
bjdata_version_t
how to encode BJData
Definition json.hpp:15773
StringType escape(StringType s)
string escaping as described in RFC 6901 (Sect. 4)
Definition json.h:2990
namespace for Niels Lohmann
Definition json.hpp:6136
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:6160
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:6150
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:6140
Definition json.hpp:17796
Definition json.hpp:17935
Definition json.hpp:17678
static diyfp mul(const diyfp &x, const diyfp &y) noexcept
returns x * y
Definition json.hpp:17702
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:17784
static diyfp normalize(diyfp x) noexcept
normalize x such that the significand is >= 2^(q-1)
Definition json.hpp:17767
static diyfp sub(const diyfp &x, const diyfp &y) noexcept
returns x - y
Definition json.hpp:17690
an iterator value
Definition json.hpp:13539
Default base class of the basic_json class.
Definition json.hpp:14487
abstract output adapter interface
Definition json.hpp:15646
struct to capture the start position of the current token
Definition json.hpp:3163
std::size_t chars_read_current_line
the number of characters read in the current line
Definition json.h:3040
std::size_t lines_read
the number of lines read
Definition json.h:3042
std::size_t chars_read_total
the total number of characters read
Definition json.h:3038
SAX interface.
Definition json.h:6671
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:19747
bool operator()(::nlohmann::detail::value_t lhs, ::nlohmann::detail::value_t rhs) const noexcept
compare two value_t enum values
Definition json.hpp:25280