32#ifndef INCLUDE_NLOHMANN_JSON_HPP_
33#define INCLUDE_NLOHMANN_JSON_HPP_
38#include <initializer_list>
74#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
75 #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH)
76 #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 3
77 #warning "Already included a different version of the library!"
82#define NLOHMANN_JSON_VERSION_MAJOR 3
83#define NLOHMANN_JSON_VERSION_MINOR 11
84#define NLOHMANN_JSON_VERSION_PATCH 3
86#ifndef JSON_DIAGNOSTICS
87 #define JSON_DIAGNOSTICS 0
90#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
91 #define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0
95 #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag
97 #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS
100#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
101 #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp
103 #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON
106#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION
107 #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0
111#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b
112#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \
113 NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b)
115#define NLOHMANN_JSON_ABI_TAGS \
116 NLOHMANN_JSON_ABI_TAGS_CONCAT( \
117 NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \
118 NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON)
121#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \
122 _v ## major ## _ ## minor ## _ ## patch
123#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \
124 NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch)
126#if NLOHMANN_JSON_NAMESPACE_NO_VERSION
127#define NLOHMANN_JSON_NAMESPACE_VERSION
129#define NLOHMANN_JSON_NAMESPACE_VERSION \
130 NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \
131 NLOHMANN_JSON_VERSION_MINOR, \
132 NLOHMANN_JSON_VERSION_PATCH)
136#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b
137#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \
138 NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b)
140#ifndef NLOHMANN_JSON_NAMESPACE
141#define NLOHMANN_JSON_NAMESPACE \
142 nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \
143 NLOHMANN_JSON_ABI_TAGS, \
144 NLOHMANN_JSON_NAMESPACE_VERSION)
147#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
148#define NLOHMANN_JSON_NAMESPACE_BEGIN \
151 inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \
152 NLOHMANN_JSON_ABI_TAGS, \
153 NLOHMANN_JSON_NAMESPACE_VERSION) \
157#ifndef NLOHMANN_JSON_NAMESPACE_END
158#define NLOHMANN_JSON_NAMESPACE_END \
176#include <forward_list>
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_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_20
2404 #define JSON_HAS_CPP_17
2405 #define JSON_HAS_CPP_14
2406 #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1)
2407 #define JSON_HAS_CPP_17
2408 #define JSON_HAS_CPP_14
2409 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
2410 #define JSON_HAS_CPP_14
2413 #define JSON_HAS_CPP_11
2417 #if __has_include(<version>)
2422#if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM)
2423 #ifdef JSON_HAS_CPP_17
2424 #if defined(__cpp_lib_filesystem)
2425 #define JSON_HAS_FILESYSTEM 1
2426 #elif defined(__cpp_lib_experimental_filesystem)
2427 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2428 #elif !defined(__has_include)
2429 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2430 #elif __has_include(<filesystem>)
2431 #define JSON_HAS_FILESYSTEM 1
2432 #elif __has_include(<experimental/filesystem>)
2433 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2437 #if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8
2438 #undef JSON_HAS_FILESYSTEM
2439 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2443 #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 8
2444 #undef JSON_HAS_FILESYSTEM
2445 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2449 #if defined(__clang_major__) && __clang_major__ < 7
2450 #undef JSON_HAS_FILESYSTEM
2451 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2455 #if defined(_MSC_VER) && _MSC_VER < 1914
2456 #undef JSON_HAS_FILESYSTEM
2457 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2461 #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000
2462 #undef JSON_HAS_FILESYSTEM
2463 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2467 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
2468 #undef JSON_HAS_FILESYSTEM
2469 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2474#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2475 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0
2478#ifndef JSON_HAS_FILESYSTEM
2479 #define JSON_HAS_FILESYSTEM 0
2482#ifndef JSON_HAS_THREE_WAY_COMPARISON
2483 #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L \
2484 && defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L
2485 #define JSON_HAS_THREE_WAY_COMPARISON 1
2487 #define JSON_HAS_THREE_WAY_COMPARISON 0
2491#ifndef JSON_HAS_RANGES
2493 #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427
2494 #define JSON_HAS_RANGES 0
2495 #elif defined(__cpp_lib_ranges)
2496 #define JSON_HAS_RANGES 1
2498 #define JSON_HAS_RANGES 0
2502#ifndef JSON_HAS_STATIC_RTTI
2503 #if !defined(_HAS_STATIC_RTTI) || _HAS_STATIC_RTTI != 0
2504 #define JSON_HAS_STATIC_RTTI 1
2506 #define JSON_HAS_STATIC_RTTI 0
2510#ifdef JSON_HAS_CPP_17
2511 #define JSON_INLINE_VARIABLE inline
2513 #define JSON_INLINE_VARIABLE
2516#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address)
2517 #define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]]
2519 #define JSON_NO_UNIQUE_ADDRESS
2523#if defined(__clang__)
2524 #pragma clang diagnostic push
2525 #pragma clang diagnostic ignored "-Wdocumentation"
2526 #pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
2530#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
2531 #define JSON_THROW(exception) throw exception
2532 #define JSON_TRY try
2533 #define JSON_CATCH(exception) catch(exception)
2534 #define JSON_INTERNAL_CATCH(exception) catch(exception)
2537 #define JSON_THROW(exception) std::abort()
2538 #define JSON_TRY if(true)
2539 #define JSON_CATCH(exception) if(false)
2540 #define JSON_INTERNAL_CATCH(exception) if(false)
2544#if defined(JSON_THROW_USER)
2546 #define JSON_THROW JSON_THROW_USER
2548#if defined(JSON_TRY_USER)
2550 #define JSON_TRY JSON_TRY_USER
2552#if defined(JSON_CATCH_USER)
2554 #define JSON_CATCH JSON_CATCH_USER
2555 #undef JSON_INTERNAL_CATCH
2556 #define JSON_INTERNAL_CATCH JSON_CATCH_USER
2558#if defined(JSON_INTERNAL_CATCH_USER)
2559 #undef JSON_INTERNAL_CATCH
2560 #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2564#if !defined(JSON_ASSERT)
2566 #define JSON_ASSERT(x) assert(x)
2570#if defined(JSON_TESTS_PRIVATE)
2571 #define JSON_PRIVATE_UNLESS_TESTED public
2573 #define JSON_PRIVATE_UNLESS_TESTED private
2581#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2582 template<typename BasicJsonType> \
2583 inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
2585 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2586 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2587 auto it = std::find_if(std::begin(m), std::end(m), \
2588 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2590 return ej_pair.first == e; \
2592 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2594 template<typename BasicJsonType> \
2595 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
2597 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2598 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2599 auto it = std::find_if(std::begin(m), std::end(m), \
2600 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2602 return ej_pair.second == j; \
2604 e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2610#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2611 template<template<typename, typename, typename...> class ObjectType, \
2612 template<typename, typename...> class ArrayType, \
2613 class StringType, class BooleanType, class NumberIntegerType, \
2614 class NumberUnsignedType, class NumberFloatType, \
2615 template<typename> class AllocatorType, \
2616 template<typename, typename = void> class JSONSerializer, \
2618 class CustomBaseClass>
2620#define NLOHMANN_BASIC_JSON_TPL \
2621 basic_json<ObjectType, ArrayType, StringType, BooleanType, \
2622 NumberIntegerType, NumberUnsignedType, NumberFloatType, \
2623 AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>
2627#define NLOHMANN_JSON_EXPAND( x ) x
2628#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
2629#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
2630 NLOHMANN_JSON_PASTE64, \
2631 NLOHMANN_JSON_PASTE63, \
2632 NLOHMANN_JSON_PASTE62, \
2633 NLOHMANN_JSON_PASTE61, \
2634 NLOHMANN_JSON_PASTE60, \
2635 NLOHMANN_JSON_PASTE59, \
2636 NLOHMANN_JSON_PASTE58, \
2637 NLOHMANN_JSON_PASTE57, \
2638 NLOHMANN_JSON_PASTE56, \
2639 NLOHMANN_JSON_PASTE55, \
2640 NLOHMANN_JSON_PASTE54, \
2641 NLOHMANN_JSON_PASTE53, \
2642 NLOHMANN_JSON_PASTE52, \
2643 NLOHMANN_JSON_PASTE51, \
2644 NLOHMANN_JSON_PASTE50, \
2645 NLOHMANN_JSON_PASTE49, \
2646 NLOHMANN_JSON_PASTE48, \
2647 NLOHMANN_JSON_PASTE47, \
2648 NLOHMANN_JSON_PASTE46, \
2649 NLOHMANN_JSON_PASTE45, \
2650 NLOHMANN_JSON_PASTE44, \
2651 NLOHMANN_JSON_PASTE43, \
2652 NLOHMANN_JSON_PASTE42, \
2653 NLOHMANN_JSON_PASTE41, \
2654 NLOHMANN_JSON_PASTE40, \
2655 NLOHMANN_JSON_PASTE39, \
2656 NLOHMANN_JSON_PASTE38, \
2657 NLOHMANN_JSON_PASTE37, \
2658 NLOHMANN_JSON_PASTE36, \
2659 NLOHMANN_JSON_PASTE35, \
2660 NLOHMANN_JSON_PASTE34, \
2661 NLOHMANN_JSON_PASTE33, \
2662 NLOHMANN_JSON_PASTE32, \
2663 NLOHMANN_JSON_PASTE31, \
2664 NLOHMANN_JSON_PASTE30, \
2665 NLOHMANN_JSON_PASTE29, \
2666 NLOHMANN_JSON_PASTE28, \
2667 NLOHMANN_JSON_PASTE27, \
2668 NLOHMANN_JSON_PASTE26, \
2669 NLOHMANN_JSON_PASTE25, \
2670 NLOHMANN_JSON_PASTE24, \
2671 NLOHMANN_JSON_PASTE23, \
2672 NLOHMANN_JSON_PASTE22, \
2673 NLOHMANN_JSON_PASTE21, \
2674 NLOHMANN_JSON_PASTE20, \
2675 NLOHMANN_JSON_PASTE19, \
2676 NLOHMANN_JSON_PASTE18, \
2677 NLOHMANN_JSON_PASTE17, \
2678 NLOHMANN_JSON_PASTE16, \
2679 NLOHMANN_JSON_PASTE15, \
2680 NLOHMANN_JSON_PASTE14, \
2681 NLOHMANN_JSON_PASTE13, \
2682 NLOHMANN_JSON_PASTE12, \
2683 NLOHMANN_JSON_PASTE11, \
2684 NLOHMANN_JSON_PASTE10, \
2685 NLOHMANN_JSON_PASTE9, \
2686 NLOHMANN_JSON_PASTE8, \
2687 NLOHMANN_JSON_PASTE7, \
2688 NLOHMANN_JSON_PASTE6, \
2689 NLOHMANN_JSON_PASTE5, \
2690 NLOHMANN_JSON_PASTE4, \
2691 NLOHMANN_JSON_PASTE3, \
2692 NLOHMANN_JSON_PASTE2, \
2693 NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
2694#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
2695#define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
2696#define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
2697#define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
2698#define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
2699#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)
2700#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)
2701#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)
2702#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)
2703#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)
2704#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)
2705#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)
2706#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)
2707#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)
2708#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)
2709#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)
2710#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)
2711#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)
2712#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)
2713#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)
2714#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)
2715#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)
2716#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)
2717#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)
2718#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)
2719#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)
2720#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)
2721#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)
2722#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)
2723#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)
2724#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)
2725#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)
2726#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)
2727#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)
2728#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)
2729#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)
2730#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)
2731#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)
2732#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)
2733#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)
2734#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)
2735#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)
2736#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)
2737#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)
2738#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)
2739#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)
2740#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)
2741#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)
2742#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)
2743#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)
2744#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)
2745#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)
2746#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)
2747#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)
2748#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)
2749#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)
2750#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)
2751#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)
2752#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)
2753#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)
2754#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)
2755#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)
2756#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)
2758#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2759#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2760#define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) nlohmann_json_t.v1 = nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1);
2767#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
2768 friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2769 friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2771#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \
2772 friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2773 friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
2775#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \
2776 friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) }
2783#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
2784 inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2785 inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2787#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \
2788 inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) }
2790#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \
2791 inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2792 inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
2800#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \
2801 namespace detail { \
2802 using std::std_name; \
2804 template<typename... T> \
2805 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2808 namespace detail2 { \
2809 struct std_name##_tag \
2813 template<typename... T> \
2814 std_name##_tag std_name(T&&...); \
2816 template<typename... T> \
2817 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2819 template<typename... T> \
2820 struct would_call_std_##std_name \
2822 static constexpr auto const value = ::nlohmann::detail:: \
2823 is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \
2827 template<typename... T> \
2828 struct would_call_std_##std_name : detail2::would_call_std_##std_name<T...> \
2832#ifndef JSON_USE_IMPLICIT_CONVERSIONS
2833 #define JSON_USE_IMPLICIT_CONVERSIONS 1
2836#if JSON_USE_IMPLICIT_CONVERSIONS
2837 #define JSON_EXPLICIT
2839 #define JSON_EXPLICIT explicit
2842#ifndef JSON_DISABLE_ENUM_SERIALIZATION
2843 #define JSON_DISABLE_ENUM_SERIALIZATION 0
2846#ifndef JSON_USE_GLOBAL_UDLS
2847 #define JSON_USE_GLOBAL_UDLS 1
2850#if JSON_HAS_THREE_WAY_COMPARISON
2854NLOHMANN_JSON_NAMESPACE_BEGIN
2913#if JSON_HAS_THREE_WAY_COMPARISON
2914 inline std::partial_ordering operator<=>(
const value_t lhs,
const value_t rhs)
noexcept
2919 static constexpr std::array<std::uint8_t, 9> order = {{
2926 const auto l_index =
static_cast<std::size_t
>(lhs);
2927 const auto r_index =
static_cast<std::size_t
>(rhs);
2928#if JSON_HAS_THREE_WAY_COMPARISON
2929 if (l_index < order.size() && r_index < order.size())
2931 return order[l_index] <=> order[r_index];
2933 return std::partial_ordering::unordered;
2935 return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
2943#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__)
2946 return std::is_lt(lhs <=> rhs);
2951NLOHMANN_JSON_NAMESPACE_END
2967NLOHMANN_JSON_NAMESPACE_BEGIN
2984template<
typename StringType>
2986 const StringType& t)
2988 JSON_ASSERT(!f.empty());
2989 for (
auto pos = s.find(f);
2990 pos != StringType::npos;
2991 s.replace(pos, f.size(), t),
2992 pos = s.find(f, pos + t.size()))
3003template<
typename StringType>
3018template<
typename StringType>
3019static void unescape(StringType& s)
3026NLOHMANN_JSON_NAMESPACE_END
3044NLOHMANN_JSON_NAMESPACE_BEGIN
3059 constexpr operator size_t()
const
3066NLOHMANN_JSON_NAMESPACE_END
3084#include <type_traits>
3090NLOHMANN_JSON_NAMESPACE_BEGIN
3095using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
3097#ifdef JSON_HAS_CPP_14
3100using std::enable_if_t;
3101using std::index_sequence;
3102using std::make_index_sequence;
3103using std::index_sequence_for;
3108template<
bool B,
typename T =
void>
3109using enable_if_t =
typename std::enable_if<B, T>::type;
3135template <
typename T, T... Ints>
3138 using value_type = T;
3139 static constexpr std::size_t size()
noexcept
3141 return sizeof...(Ints);
3150template <
size_t... Ints>
3153namespace utility_internal
3156template <
typename Seq,
size_t SeqSize,
size_t Rem>
3160template <
typename T, T... Ints,
size_t SeqSize>
3166template <
typename T, T... Ints,
size_t SeqSize>
3174template <
typename T,
size_t N>
3178 typename Extend <
typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
3181template <
typename T>
3196template <
typename T, T N>
3197using make_integer_sequence =
typename utility_internal::Gen<T, N>::type;
3205using make_index_sequence = make_integer_sequence<size_t, N>;
3212template <
typename... Ts>
3213using index_sequence_for = make_index_sequence<
sizeof...(Ts)>;
3227 static JSON_INLINE_VARIABLE
constexpr T value{};
3230#ifndef JSON_HAS_CPP_17
3231 template<
typename T>
3235template<
typename T,
typename... Args>
3236inline constexpr std::array<T,
sizeof...(Args)> make_array(Args&& ... args)
3238 return std::array<T,
sizeof...(Args)> {{
static_cast<T
>(std::forward<Args>(args))...}};
3242NLOHMANN_JSON_NAMESPACE_END
3256#include <type_traits>
3281NLOHMANN_JSON_NAMESPACE_BEGIN
3285template<
typename It,
typename =
void>
3288template<
typename It>
3291 void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
3292 typename It::reference, typename It::iterator_category >>
3294 using difference_type =
typename It::difference_type;
3295 using value_type =
typename It::value_type;
3296 using pointer =
typename It::pointer;
3297 using reference =
typename It::reference;
3298 using iterator_category =
typename It::iterator_category;
3303template<
typename T,
typename =
void>
3317 using iterator_category = std::random_access_iterator_tag;
3318 using value_type = T;
3319 using difference_type = ptrdiff_t;
3321 using reference = T&;
3325NLOHMANN_JSON_NAMESPACE_END
3343NLOHMANN_JSON_NAMESPACE_BEGIN
3345NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin);
3347NLOHMANN_JSON_NAMESPACE_END
3363NLOHMANN_JSON_NAMESPACE_BEGIN
3365NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end);
3367NLOHMANN_JSON_NAMESPACE_END
3382#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
3383 #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
3399 NLOHMANN_JSON_NAMESPACE_BEGIN
3408 template<
typename T =
void,
typename SFINAE =
void>
3413 template<
template<
typename U,
typename V,
typename... Args>
class ObjectType =
3415 template<
typename U,
typename... Args>
class ArrayType = std::vector,
3416 class StringType = std::string,
class BooleanType = bool,
3417 class NumberIntegerType = std::int64_t,
3418 class NumberUnsignedType = std::uint64_t,
3419 class NumberFloatType = double,
3420 template<
typename U>
class AllocatorType = std::allocator,
3421 template<
typename T,
typename SFINAE =
void>
class JSONSerializer =
3423 class BinaryType = std::vector<std::uint8_t>,
3424 class CustomBaseClass =
void>
3429 template<
typename RefStringType>
3440 template<
class Key,
class T,
class IgnoredLess,
class Allocator>
3447 NLOHMANN_JSON_NAMESPACE_END
3452NLOHMANN_JSON_NAMESPACE_BEGIN
3479NLOHMANN_BASIC_JSON_TPL_DECLARATION
3485template<
typename BasicJsonContext>
3487 std::integral_constant < bool,
3488 is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value
3489 || std::is_same<BasicJsonContext, std::nullptr_t>::value >
3510using mapped_type_t =
typename T::mapped_type;
3513using key_type_t =
typename T::key_type;
3516using value_type_t =
typename T::value_type;
3519using difference_type_t =
typename T::difference_type;
3522using pointer_t =
typename T::pointer;
3525using reference_t =
typename T::reference;
3528using iterator_category_t =
typename T::iterator_category;
3530template<
typename T,
typename... Args>
3531using to_json_function =
decltype(T::to_json(std::declval<Args>()...));
3533template<
typename T,
typename... Args>
3534using from_json_function =
decltype(T::from_json(std::declval<Args>()...));
3536template<
typename T,
typename U>
3537using get_template_function =
decltype(std::declval<T>().template get<U>());
3540template<
typename BasicJsonType,
typename T,
typename =
void>
3547template <
typename BasicJsonType,
typename T>
3550 static constexpr bool value = is_detected<get_template_function, const BasicJsonType&, T>::value;
3553template<
typename BasicJsonType,
typename T>
3556 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3558 static constexpr bool value =
3559 is_detected_exact<void, from_json_function, serializer,
3560 const BasicJsonType&, T&>
::value;
3565template<
typename BasicJsonType,
typename T,
typename =
void>
3568template<
typename BasicJsonType,
typename T>
3571 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3573 static constexpr bool value =
3574 is_detected_exact<T, from_json_function, serializer,
3580template<
typename BasicJsonType,
typename T,
typename =
void>
3583template<
typename BasicJsonType,
typename T>
3586 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3588 static constexpr bool value =
3589 is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
3594using detect_key_compare =
typename T::key_compare;
3597struct has_key_compare : std::integral_constant<bool, is_detected<detect_key_compare, T>::value> {};
3600template<
typename BasicJsonType>
3603 using object_t =
typename BasicJsonType::object_t;
3604 using object_comparator_t =
typename BasicJsonType::default_object_comparator_t;
3605 using type =
typename std::conditional < has_key_compare<object_t>::value,
3606 typename object_t::key_compare, object_comparator_t>::type;
3609template<
typename BasicJsonType>
3610using actual_object_comparator_t =
typename actual_object_comparator<BasicJsonType>::type;
3625 using char_type =
unsigned char;
3626 using int_type = uint64_t;
3629 static int_type to_int_type(char_type c)
noexcept
3631 return static_cast<int_type
>(c);
3634 static char_type to_char_type(int_type i)
noexcept
3636 return static_cast<char_type
>(i);
3639 static constexpr int_type eof()
noexcept
3641 return static_cast<int_type
>(EOF);
3649 using char_type =
signed char;
3650 using int_type = uint64_t;
3653 static int_type to_int_type(char_type c)
noexcept
3655 return static_cast<int_type
>(c);
3658 static char_type to_char_type(int_type i)
noexcept
3660 return static_cast<char_type
>(i);
3663 static constexpr int_type eof()
noexcept
3665 return static_cast<int_type
>(EOF);
3676template<
class B,
class... Bn>
3678: std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {};
3681template<
class B>
struct negation : std::integral_constant < bool, !B::value > { };
3686template <
typename T>
3689template <
typename T1,
typename T2>
3691 :
conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3693template <
typename T1,
typename T2>
3695 :
conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3697template <
typename... Ts>
3699 :
conjunction<is_default_constructible<Ts>...> {};
3701template <
typename... Ts>
3703 :
conjunction<is_default_constructible<Ts>...> {};
3705template <
typename T,
typename... Args>
3708template <
typename T1,
typename T2>
3711template <
typename T1,
typename T2>
3714template <
typename... Ts>
3717template <
typename... Ts>
3720template<
typename T,
typename =
void>
3730 static constexpr auto value =
3731 is_detected<value_type_t, traits>::value &&
3732 is_detected<difference_type_t, traits>::value &&
3733 is_detected<pointer_t, traits>::value &&
3734 is_detected<iterator_category_t, traits>::value &&
3735 is_detected<reference_t, traits>::value;
3742 using t_ref =
typename std::add_lvalue_reference<T>::type;
3744 using iterator = detected_t<result_of_begin, t_ref>;
3745 using sentinel = detected_t<result_of_end, t_ref>;
3750 static constexpr auto is_iterator_begin =
3754 static constexpr bool value = !std::is_same<iterator, nonesuch>::value && !std::is_same<sentinel, nonesuch>::value && is_iterator_begin;
3758using iterator_t = enable_if_t<is_range<R>::value, result_of_begin<decltype(std::declval<R&>())>>;
3761using range_value_t = value_type_t<iterator_traits<iterator_t<T>>>;
3767template<
typename T,
typename =
void>
3773template<
typename BasicJsonType,
typename CompatibleObjectType,
3777template<
typename BasicJsonType,
typename CompatibleObjectType>
3779 BasicJsonType, CompatibleObjectType,
3780 enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::
value&&
3781 is_detected<key_type_t, CompatibleObjectType>
::value >>
3783 using object_t =
typename BasicJsonType::object_t;
3786 static constexpr bool value =
3788 typename CompatibleObjectType::key_type>
::value &&
3790 typename CompatibleObjectType::mapped_type>
::value;
3793template<
typename BasicJsonType,
typename CompatibleObjectType>
3797template<
typename BasicJsonType,
typename ConstructibleObjectType,
3801template<
typename BasicJsonType,
typename ConstructibleObjectType>
3803 BasicJsonType, ConstructibleObjectType,
3804 enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::
value&&
3805 is_detected<key_type_t, ConstructibleObjectType>
::value >>
3807 using object_t =
typename BasicJsonType::object_t;
3809 static constexpr bool value =
3811 (std::is_move_assignable<ConstructibleObjectType>::value ||
3812 std::is_copy_assignable<ConstructibleObjectType>::value) &&
3814 typename object_t::key_type>
::value &&
3816 typename object_t::mapped_type,
3817 typename ConstructibleObjectType::mapped_type >
::value)) ||
3819 typename ConstructibleObjectType::mapped_type>
::value ||
3822 typename ConstructibleObjectType::mapped_type >
::value);
3825template<
typename BasicJsonType,
typename ConstructibleObjectType>
3828 ConstructibleObjectType> {};
3830template<
typename BasicJsonType,
typename CompatibleStringType>
3833 static constexpr auto value =
3837template<
typename BasicJsonType,
typename ConstructibleStringType>
3841#ifdef __INTEL_COMPILER
3842 using laundered_type =
decltype(std::declval<ConstructibleStringType>());
3844 using laundered_type = ConstructibleStringType;
3847 static constexpr auto value =
3850 is_detected_exact<
typename BasicJsonType::string_t::value_type,
3851 value_type_t, laundered_type >>::value;
3854template<
typename BasicJsonType,
typename CompatibleArrayType,
typename =
void>
3857template<
typename BasicJsonType,
typename CompatibleArrayType>
3859 BasicJsonType, CompatibleArrayType,
3861 is_detected<iterator_t, CompatibleArrayType>::
value&&
3865 !std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>
::value >>
3867 static constexpr bool value =
3869 range_value_t<CompatibleArrayType>>
::value;
3872template<
typename BasicJsonType,
typename CompatibleArrayType>
3876template<
typename BasicJsonType,
typename ConstructibleArrayType,
typename =
void>
3879template<
typename BasicJsonType,
typename ConstructibleArrayType>
3881 BasicJsonType, ConstructibleArrayType,
3882 enable_if_t<std::is_same<ConstructibleArrayType,
3883 typename BasicJsonType::value_type>
::value >>
3884 : std::true_type {};
3886template<
typename BasicJsonType,
typename ConstructibleArrayType>
3888 BasicJsonType, ConstructibleArrayType,
3889 enable_if_t < !std::is_same<ConstructibleArrayType,
3890 typename BasicJsonType::value_type>
::value&&
3893(std::is_move_assignable<ConstructibleArrayType>::value ||
3894 std::is_copy_assignable<ConstructibleArrayType>::value)&&
3895is_detected<iterator_t, ConstructibleArrayType>
::value&&
3897is_detected<range_value_t, ConstructibleArrayType>
::value&&
3900!std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>
::value&&
3902 detected_t<range_value_t, ConstructibleArrayType >>
::value >>
3904 using value_type = range_value_t<ConstructibleArrayType>;
3906 static constexpr bool value =
3907 std::is_same<value_type,
3908 typename BasicJsonType::array_t::value_type>
::value ||
3916template<
typename BasicJsonType,
typename ConstructibleArrayType>
3920template<
typename RealIntegerType,
typename CompatibleNumberIntegerType,
3924template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3926 RealIntegerType, CompatibleNumberIntegerType,
3927 enable_if_t < std::is_integral<RealIntegerType>
::value&&
3928 std::is_integral<CompatibleNumberIntegerType>
::value&&
3929 !std::is_same<bool, CompatibleNumberIntegerType>
::value >>
3932 using RealLimits = std::numeric_limits<RealIntegerType>;
3933 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
3935 static constexpr auto value =
3937 CompatibleNumberIntegerType>
::value &&
3938 CompatibleLimits::is_integer &&
3939 RealLimits::is_signed == CompatibleLimits::is_signed;
3942template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3945 CompatibleNumberIntegerType> {};
3947template<
typename BasicJsonType,
typename CompatibleType,
typename =
void>
3950template<
typename BasicJsonType,
typename CompatibleType>
3952 BasicJsonType, CompatibleType,
3955 static constexpr bool value =
3959template<
typename BasicJsonType,
typename CompatibleType>
3963template<
typename T1,
typename T2>
3966template<
typename T1,
typename... Args>
3969template<
typename BasicJsonType,
typename T>
3972template<
typename BasicJsonType>
3975template<
typename BasicJsonType>
3980template<
template <
typename...>
class Primary,
typename T>
3983template<
template <
typename...>
class Primary,
typename... Args>
3990template<
typename Compare,
typename A,
typename B,
typename =
void>
3993template<
typename Compare,
typename A,
typename B>
3995decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())),
3996decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))
3997>> : std::true_type {};
4000using detect_is_transparent =
typename T::is_transparent;
4004template<
typename Comparator,
typename ObjectKeyType,
typename KeyTypeCVRef,
bool RequireTransparentComparator =
true,
4005 bool ExcludeObjectKeyType = RequireTransparentComparator,
typename KeyType = uncvref_t<KeyTypeCVRef>>
4006using is_usable_as_key_type =
typename std::conditional <
4008 && !(ExcludeObjectKeyType && std::is_same<KeyType,
4010 && (!RequireTransparentComparator
4011 || is_detected <detect_is_transparent, Comparator>::value)
4014 std::false_type >::type;
4022template<
typename BasicJsonType,
typename KeyTypeCVRef,
bool RequireTransparentComparator =
true,
4023 bool ExcludeObjectKeyType = RequireTransparentComparator,
typename KeyType = uncvref_t<KeyTypeCVRef>>
4024using is_usable_as_basic_json_key_type =
typename std::conditional <
4025 is_usable_as_key_type<
typename BasicJsonType::object_comparator_t,
4026 typename BasicJsonType::object_t::key_type, KeyTypeCVRef,
4027 RequireTransparentComparator, ExcludeObjectKeyType>
::value
4030 std::false_type >::type;
4032template<
typename ObjectType,
typename KeyType>
4033using detect_erase_with_key_type =
decltype(std::declval<ObjectType&>().erase(std::declval<KeyType>()));
4036template<
typename BasicJsonType,
typename KeyType>
4037using has_erase_with_key_type =
typename std::conditional <
4039 detect_erase_with_key_type,
4040 typename BasicJsonType::object_t, KeyType >
::value,
4042 std::false_type >::type;
4046template <
typename T>
4056 template <
typename C>
static one test(
decltype(&C::capacity) ) ;
4057 template <
typename C>
static two test(...);
4059 enum { value =
sizeof(test<T>(
nullptr)) ==
sizeof(
char) };
4063template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value,
int > = 0 >
4064T conditional_static_cast(U
value)
4066 return static_cast<T
>(
value);
4069template<typename T, typename U, enable_if_t<std::is_same<T, U>::value,
int> = 0>
4070T conditional_static_cast(U
value)
4075template<
typename... Types>
4076using all_integral = conjunction<std::is_integral<Types>...>;
4078template<
typename... Types>
4079using all_signed = conjunction<std::is_signed<Types>...>;
4081template<
typename... Types>
4082using all_unsigned = conjunction<std::is_unsigned<Types>...>;
4085template<
typename... Types>
4086using same_sign = std::integral_constant < bool,
4089template<
typename OfType,
typename T>
4090using never_out_of_range = std::integral_constant < bool,
4091 (std::is_signed<OfType>::value && (
sizeof(T) <
sizeof(OfType)))
4092 || (same_sign<OfType, T>::value &&
sizeof(OfType) ==
sizeof(T)) >;
4094template<
typename OfType,
typename T,
4095 bool OfTypeSigned = std::is_signed<OfType>::value,
4096 bool TSigned = std::is_signed<T>::value>
4099template<
typename OfType,
typename T>
4102 static constexpr bool test(T val)
4104 using CommonType =
typename std::common_type<OfType, T>::type;
4105 return static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4109template<
typename OfType,
typename T>
4112 static constexpr bool test(T val)
4114 using CommonType =
typename std::common_type<OfType, T>::type;
4115 return static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4119template<
typename OfType,
typename T>
4122 static constexpr bool test(T val)
4124 using CommonType =
typename std::common_type<OfType, T>::type;
4125 return val >= 0 &&
static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4129template<
typename OfType,
typename T>
4132 static constexpr bool test(T val)
4134 using CommonType =
typename std::common_type<OfType, T>::type;
4135 return static_cast<CommonType
>(val) >=
static_cast<CommonType
>((std::numeric_limits<OfType>::min)())
4136 &&
static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4140template<
typename OfType,
typename T,
4141 bool NeverOutOfRange = never_out_of_range<OfType, T>::value,
4142 typename = detail::enable_if_t<all_integral<OfType, T>::value>>
4145template<
typename OfType,
typename T>
4148 static constexpr bool test(T val)
4154template<
typename OfType,
typename T>
4157 static constexpr bool test(T )
4163template<
typename OfType,
typename T>
4164inline constexpr bool value_in_range_of(T val)
4170using bool_constant = std::integral_constant<bool, Value>;
4180inline constexpr bool is_c_string()
4182 using TUnExt =
typename std::remove_extent<T>::type;
4183 using TUnCVExt =
typename std::remove_cv<TUnExt>::type;
4184 using TUnPtr =
typename std::remove_pointer<T>::type;
4185 using TUnCVPtr =
typename std::remove_cv<TUnPtr>::type;
4187 (std::is_array<T>::value && std::is_same<TUnCVExt, char>::value)
4188 || (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value);
4210 return is_detected<detect_is_transparent, T>::value;
4222NLOHMANN_JSON_NAMESPACE_END
4244NLOHMANN_JSON_NAMESPACE_BEGIN
4248inline std::size_t concat_length()
4253template<
typename... Args>
4254inline std::size_t concat_length(
const char* cstr,
const Args& ... rest);
4256template<
typename StringType,
typename... Args>
4257inline std::size_t concat_length(
const StringType& str,
const Args& ... rest);
4259template<
typename... Args>
4260inline std::size_t concat_length(
const char ,
const Args& ... rest)
4262 return 1 + concat_length(rest...);
4265template<
typename... Args>
4266inline std::size_t concat_length(
const char* cstr,
const Args& ... rest)
4269 return ::strlen(cstr) + concat_length(rest...);
4272template<
typename StringType,
typename... Args>
4273inline std::size_t concat_length(
const StringType& str,
const Args& ... rest)
4275 return str.size() + concat_length(rest...);
4278template<
typename OutStringType>
4279inline void concat_into(OutStringType& )
4282template<
typename StringType,
typename Arg>
4283using string_can_append =
decltype(std::declval<StringType&>().append(std::declval < Arg && > ()));
4285template<
typename StringType,
typename Arg>
4286using detect_string_can_append = is_detected<string_can_append, StringType, Arg>;
4288template<
typename StringType,
typename Arg>
4289using string_can_append_op =
decltype(std::declval<StringType&>() += std::declval < Arg && > ());
4291template<
typename StringType,
typename Arg>
4292using detect_string_can_append_op = is_detected<string_can_append_op, StringType, Arg>;
4294template<
typename StringType,
typename Arg>
4295using string_can_append_iter =
decltype(std::declval<StringType&>().append(std::declval<const Arg&>().begin(), std::declval<const Arg&>().end()));
4297template<
typename StringType,
typename Arg>
4298using detect_string_can_append_iter = is_detected<string_can_append_iter, StringType, Arg>;
4300template<
typename StringType,
typename Arg>
4301using string_can_append_data =
decltype(std::declval<StringType&>().append(std::declval<const Arg&>().data(), std::declval<const Arg&>().size()));
4303template<
typename StringType,
typename Arg>
4304using detect_string_can_append_data = is_detected<string_can_append_data, StringType, Arg>;
4306template <
typename OutStringType,
typename Arg,
typename... Args,
4307 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4308 && detect_string_can_append_op<OutStringType, Arg>::value,
int > = 0 >
4309inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest);
4311template <
typename OutStringType,
typename Arg,
typename... Args,
4312 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4313 && !detect_string_can_append_op<OutStringType, Arg>::value
4314 && detect_string_can_append_iter<OutStringType, Arg>::value,
int > = 0 >
4315inline void concat_into(OutStringType& out,
const Arg& arg, Args && ... rest);
4317template <
typename OutStringType,
typename Arg,
typename... Args,
4318 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4319 && !detect_string_can_append_op<OutStringType, Arg>::value
4320 && !detect_string_can_append_iter<OutStringType, Arg>::value
4321 && detect_string_can_append_data<OutStringType, Arg>::value,
int > = 0 >
4322inline void concat_into(OutStringType& out,
const Arg& arg, Args && ... rest);
4324template<
typename OutStringType,
typename Arg,
typename... Args,
4325 enable_if_t<detect_string_can_append<OutStringType, Arg>::value,
int> = 0>
4326inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest)
4328 out.append(std::forward<Arg>(arg));
4329 concat_into(out, std::forward<Args>(rest)...);
4332template <
typename OutStringType,
typename Arg,
typename... Args,
4333 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4334 && detect_string_can_append_op<OutStringType, Arg>::value,
int > >
4335inline void concat_into(OutStringType& out, Arg&& arg, Args&& ... rest)
4337 out += std::forward<Arg>(arg);
4338 concat_into(out, std::forward<Args>(rest)...);
4341template <
typename OutStringType,
typename Arg,
typename... Args,
4342 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4343 && !detect_string_can_append_op<OutStringType, Arg>::value
4344 && detect_string_can_append_iter<OutStringType, Arg>::value,
int > >
4345inline void concat_into(OutStringType& out,
const Arg& arg, Args&& ... rest)
4347 out.append(arg.begin(), arg.end());
4348 concat_into(out, std::forward<Args>(rest)...);
4351template <
typename OutStringType,
typename Arg,
typename... Args,
4352 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4353 && !detect_string_can_append_op<OutStringType, Arg>::value
4354 && !detect_string_can_append_iter<OutStringType, Arg>::value
4355 && detect_string_can_append_data<OutStringType, Arg>::value,
int > >
4356inline void concat_into(OutStringType& out,
const Arg& arg, Args&& ... rest)
4358 out.append(arg.data(), arg.size());
4359 concat_into(out, std::forward<Args>(rest)...);
4362template<
typename OutStringType = std::string,
typename... Args>
4363inline OutStringType concat(Args && ... args)
4366 str.reserve(concat_length(args...));
4367 concat_into(str, std::forward<Args>(args)...);
4372NLOHMANN_JSON_NAMESPACE_END
4375NLOHMANN_JSON_NAMESPACE_BEGIN
4389 const char*
what() const noexcept
override
4398 JSON_HEDLEY_NON_NULL(3)
4399 exception(
int id_, const
char* what_arg) :
id(id_), m(what_arg) {}
4401 static std::string name(
const std::string& ename,
int id_)
4403 return concat(
"[json.exception.", ename,
'.', std::to_string(id_),
"] ");
4406 static std::string diagnostics(std::nullptr_t )
4411 template<
typename BasicJsonType>
4412 static std::string diagnostics(
const BasicJsonType* leaf_element)
4415 std::vector<std::string> tokens;
4416 for (
const auto* current = leaf_element; current !=
nullptr && current->m_parent !=
nullptr; current = current->m_parent)
4418 switch (current->m_parent->type())
4422 for (std::size_t i = 0; i < current->m_parent->m_data.m_value.array->size(); ++i)
4424 if (¤t->m_parent->m_data.m_value.array->operator[](i) == current)
4426 tokens.emplace_back(std::to_string(i));
4435 for (
const auto& element : *current->m_parent->m_data.m_value.object)
4437 if (&element.second == current)
4439 tokens.emplace_back(element.first.c_str());
4464 auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
4465 [](
const std::string & a,
const std::string & b)
4467 return concat(a,
'/', detail::escape(b));
4469 return concat(
'(', str,
") ");
4471 static_cast<void>(leaf_element);
4478 std::runtime_error m;
4495 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4498 const std::string w = concat(exception::name(
"parse_error", id_),
"parse error",
4499 position_string(pos),
": ", exception::diagnostics(context), what_arg);
4503 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4504 static parse_error create(
int id_, std::size_t byte_,
const std::string& what_arg, BasicJsonContext context)
4506 const std::string w = concat(exception::name(
"parse_error", id_),
"parse error",
4507 (byte_ != 0 ? (concat(
" at byte ", std::to_string(byte_))) :
""),
4508 ": ", exception::diagnostics(context), what_arg);
4509 return {id_, byte_, w.c_str()};
4524 parse_error(
int id_, std::size_t byte_,
const char* what_arg)
4527 static std::string position_string(
const position_t& pos)
4529 return concat(
" at line ", std::to_string(pos.
lines_read + 1),
4539 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4540 static invalid_iterator create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4542 const std::string w = concat(exception::name(
"invalid_iterator", id_), exception::diagnostics(context), what_arg);
4543 return {id_, w.c_str()};
4547 JSON_HEDLEY_NON_NULL(3)
4557 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4558 static type_error create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4560 const std::string w = concat(exception::name(
"type_error", id_), exception::diagnostics(context), what_arg);
4561 return {id_, w.c_str()};
4565 JSON_HEDLEY_NON_NULL(3)
4574 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4575 static out_of_range create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4577 const std::string w = concat(exception::name(
"out_of_range", id_), exception::diagnostics(context), what_arg);
4578 return {id_, w.c_str()};
4582 JSON_HEDLEY_NON_NULL(3)
4591 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4592 static other_error create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4594 const std::string w = concat(exception::name(
"other_error", id_), exception::diagnostics(context), what_arg);
4595 return {id_, w.c_str()};
4599 JSON_HEDLEY_NON_NULL(3)
4604NLOHMANN_JSON_NAMESPACE_END
4624NLOHMANN_JSON_NAMESPACE_BEGIN
4632NLOHMANN_JSON_NAMESPACE_END
4648#if JSON_HAS_EXPERIMENTAL_FILESYSTEM
4649#include <experimental/filesystem>
4650NLOHMANN_JSON_NAMESPACE_BEGIN
4653namespace std_fs = std::experimental::filesystem;
4655NLOHMANN_JSON_NAMESPACE_END
4656#elif JSON_HAS_FILESYSTEM
4657#include <filesystem>
4658NLOHMANN_JSON_NAMESPACE_BEGIN
4661namespace std_fs = std::filesystem;
4663NLOHMANN_JSON_NAMESPACE_END
4673NLOHMANN_JSON_NAMESPACE_BEGIN
4677template<
typename BasicJsonType>
4678inline void from_json(
const BasicJsonType& j,
typename std::nullptr_t& n)
4680 if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
4682 JSON_THROW(type_error::create(302, concat(
"type must be null, but is ", j.type_name()), &j));
4688template <
typename BasicJsonType,
typename ArithmeticType,
4689 enable_if_t < std::is_arithmetic<ArithmeticType>::value&&
4690 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4692void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val)
4694 switch (
static_cast<value_t>(j))
4698 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4703 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4708 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4720 JSON_THROW(type_error::create(302, concat(
"type must be number, but is ", j.type_name()), &j));
4724template<
typename BasicJsonType>
4725inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::boolean_t& b)
4727 if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
4729 JSON_THROW(type_error::create(302, concat(
"type must be boolean, but is ", j.type_name()), &j));
4731 b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
4734template<
typename BasicJsonType>
4735inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::string_t& s)
4737 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
4739 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
4741 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4745 typename BasicJsonType,
typename StringType,
4747 std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value
4748 && is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value
4749 && !std::is_same<typename BasicJsonType::string_t, StringType>::value
4750 && !is_json_ref<StringType>::value,
int > = 0 >
4751inline void from_json(
const BasicJsonType& j, StringType& s)
4753 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
4755 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
4758 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4761template<
typename BasicJsonType>
4762inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_float_t& val)
4764 get_arithmetic_value(j, val);
4767template<
typename BasicJsonType>
4768inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_unsigned_t& val)
4770 get_arithmetic_value(j, val);
4773template<
typename BasicJsonType>
4774inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_integer_t& val)
4776 get_arithmetic_value(j, val);
4779#if !JSON_DISABLE_ENUM_SERIALIZATION
4780template<
typename BasicJsonType,
typename EnumType,
4781 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
4782inline void from_json(
const BasicJsonType& j, EnumType& e)
4784 typename std::underlying_type<EnumType>::type val;
4785 get_arithmetic_value(j, val);
4786 e =
static_cast<EnumType
>(val);
4791template<
typename BasicJsonType,
typename T,
typename Allocator,
4792 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4793inline void from_json(
const BasicJsonType& j, std::forward_list<T, Allocator>& l)
4795 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4797 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4800 std::transform(j.rbegin(), j.rend(),
4801 std::front_inserter(l), [](
const BasicJsonType & i)
4803 return i.template get<T>();
4808template<
typename BasicJsonType,
typename T,
4809 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4810inline void from_json(
const BasicJsonType& j, std::valarray<T>& l)
4812 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4814 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4817 std::transform(j.begin(), j.end(), std::begin(l),
4818 [](
const BasicJsonType & elem)
4820 return elem.template get<T>();
4824template<
typename BasicJsonType,
typename T, std::
size_t N>
4825auto from_json(
const BasicJsonType& j, T (&arr)[N])
4826->
decltype(j.template get<T>(), void())
4828 for (std::size_t i = 0; i < N; ++i)
4830 arr[i] = j.at(i).template get<T>();
4834template<
typename BasicJsonType>
4835inline void from_json_array_impl(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr, priority_tag<3> )
4837 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
4840template<
typename BasicJsonType,
typename T, std::
size_t N>
4841auto from_json_array_impl(
const BasicJsonType& j, std::array<T, N>& arr,
4843->
decltype(j.template get<T>(), void())
4845 for (std::size_t i = 0; i < N; ++i)
4847 arr[i] = j.at(i).template get<T>();
4851template<
typename BasicJsonType,
typename ConstructibleArrayType,
4853 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4855auto from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> )
4857 arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
4858 j.template get<typename ConstructibleArrayType::value_type>(),
4863 ConstructibleArrayType ret;
4864 ret.reserve(j.size());
4865 std::transform(j.begin(), j.end(),
4866 std::inserter(ret, end(ret)), [](
const BasicJsonType & i)
4870 return i.template get<typename ConstructibleArrayType::value_type>();
4872 arr = std::move(ret);
4875template<
typename BasicJsonType,
typename ConstructibleArrayType,
4877 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4879inline void from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
4884 ConstructibleArrayType ret;
4886 j.begin(), j.end(), std::inserter(ret, end(ret)),
4887 [](
const BasicJsonType & i)
4891 return i.template get<typename ConstructibleArrayType::value_type>();
4893 arr = std::move(ret);
4896template <
typename BasicJsonType,
typename ConstructibleArrayType,
4898 is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&&
4899 !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&&
4900 !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
4901 !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&&
4902 !is_basic_json<ConstructibleArrayType>::value,
4904auto from_json(
const BasicJsonType& j, ConstructibleArrayType& arr)
4905->
decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
4906j.template get<typename ConstructibleArrayType::value_type>(),
4909 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4911 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4914 from_json_array_impl(j, arr, priority_tag<3> {});
4917template <
typename BasicJsonType,
typename T, std::size_t... Idx >
4918std::array<T,
sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j,
4919 identity_tag<std::array<T,
sizeof...(Idx)>> , index_sequence<Idx...> )
4921 return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
4924template <
typename BasicJsonType,
typename T, std::
size_t N >
4925auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag)
4926->
decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}))
4928 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4930 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4933 return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {});
4936template<
typename BasicJsonType>
4937inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::binary_t& bin)
4939 if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
4941 JSON_THROW(type_error::create(302, concat(
"type must be binary, but is ", j.type_name()), &j));
4944 bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
4947template<
typename BasicJsonType,
typename ConstructibleObjectType,
4948 enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value,
int> = 0>
4949inline void from_json(
const BasicJsonType& j, ConstructibleObjectType& obj)
4951 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
4953 JSON_THROW(type_error::create(302, concat(
"type must be object, but is ", j.type_name()), &j));
4956 ConstructibleObjectType ret;
4957 const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
4958 using value_type =
typename ConstructibleObjectType::value_type;
4960 inner_object->begin(), inner_object->end(),
4961 std::inserter(ret, ret.begin()),
4962 [](
typename BasicJsonType::object_t::value_type
const & p)
4964 return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
4966 obj = std::move(ret);
4973template <
typename BasicJsonType,
typename ArithmeticType,
4975 std::is_arithmetic<ArithmeticType>::value&&
4976 !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&&
4977 !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&&
4978 !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&&
4979 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4981inline void from_json(
const BasicJsonType& j, ArithmeticType& val)
4983 switch (
static_cast<value_t>(j))
4987 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4992 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4997 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
5002 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
5013 JSON_THROW(type_error::create(302, concat(
"type must be number, but is ", j.type_name()), &j));
5017template<
typename BasicJsonType,
typename... Args, std::size_t... Idx>
5018std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<Idx...> )
5020 return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).
template get<Args>()...);
5023template <
typename BasicJsonType,
class A1,
class A2 >
5024std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> , priority_tag<0> )
5026 return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
5027 std::forward<BasicJsonType>(j).at(1).template get<A2>()};
5030template<
typename BasicJsonType,
typename A1,
typename A2>
5031inline void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> )
5033 p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {});
5036template<
typename BasicJsonType,
typename... Args>
5037std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> , priority_tag<2> )
5039 return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
5042template<
typename BasicJsonType,
typename... Args>
5043inline void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> )
5045 t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
5048template<
typename BasicJsonType,
typename TupleRelated>
5049auto from_json(BasicJsonType&& j, TupleRelated&& t)
5050->
decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}))
5052 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5054 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5057 return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {});
5060template <
typename BasicJsonType,
typename Key,
typename Value,
typename Compare,
typename Allocator,
5061 typename = enable_if_t < !std::is_constructible <
5062 typename BasicJsonType::string_t, Key >
::value >>
5063inline void from_json(
const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
5065 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5067 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5070 for (
const auto& p : j)
5072 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
5074 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", p.type_name()), &j));
5076 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
5080template <
typename BasicJsonType,
typename Key,
typename Value,
typename Hash,
typename KeyEqual,
typename Allocator,
5081 typename = enable_if_t < !std::is_constructible <
5082 typename BasicJsonType::string_t, Key >
::value >>
5083inline void from_json(
const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
5085 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5087 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5090 for (
const auto& p : j)
5092 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
5094 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", p.type_name()), &j));
5096 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
5100#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
5101template<
typename BasicJsonType>
5102inline void from_json(
const BasicJsonType& j, std_fs::path& p)
5104 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
5106 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
5108 p = *j.template get_ptr<const typename BasicJsonType::string_t*>();
5114 template<
typename BasicJsonType,
typename T>
5115 auto operator()(
const BasicJsonType& j, T&& val)
const
5116 noexcept(
noexcept(from_json(j, std::forward<T>(val))))
5117 ->
decltype(from_json(j, std::forward<T>(val)))
5119 return from_json(j, std::forward<T>(val));
5125#ifndef JSON_HAS_CPP_17
5132JSON_INLINE_VARIABLE
constexpr const auto& from_json =
5134#ifndef JSON_HAS_CPP_17
5138NLOHMANN_JSON_NAMESPACE_END
5155#include <type_traits>
5188NLOHMANN_JSON_NAMESPACE_BEGIN
5192template<
typename string_type>
5193void int_to_string( string_type& target, std::size_t
value )
5196 using std::to_string;
5197 target = to_string(
value);
5199template<
typename IteratorType>
class iteration_proxy_value
5202 using difference_type = std::ptrdiff_t;
5203 using value_type = iteration_proxy_value;
5204 using pointer = value_type *;
5205 using reference = value_type &;
5206 using iterator_category = std::input_iterator_tag;
5207 using string_type =
typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
5211 IteratorType anchor{};
5213 std::size_t array_index = 0;
5215 mutable std::size_t array_index_last = 0;
5217 mutable string_type array_index_str =
"0";
5219 string_type empty_str{};
5222 explicit iteration_proxy_value() =
default;
5223 explicit iteration_proxy_value(IteratorType it, std::size_t array_index_ = 0)
5224 noexcept(std::is_nothrow_move_constructible<IteratorType>::
value
5225 && std::is_nothrow_default_constructible<string_type>::
value)
5226 : anchor(std::move(it))
5227 , array_index(array_index_)
5230 iteration_proxy_value(iteration_proxy_value
const&) =
default;
5231 iteration_proxy_value& operator=(iteration_proxy_value
const&) =
default;
5233 iteration_proxy_value(iteration_proxy_value&&)
5234 noexcept(std::is_nothrow_move_constructible<IteratorType>::
value
5235 && std::is_nothrow_move_constructible<string_type>::
value) = default;
5236 iteration_proxy_value& operator=(iteration_proxy_value&&)
5237 noexcept(std::is_nothrow_move_assignable<IteratorType>::
value
5238 && std::is_nothrow_move_assignable<string_type>::
value) = default;
5239 ~iteration_proxy_value() = default;
5267 return anchor == o.anchor;
5273 return anchor != o.anchor;
5277 const string_type&
key()
const
5279 JSON_ASSERT(anchor.m_object !=
nullptr);
5281 switch (anchor.m_object->type())
5286 if (array_index != array_index_last)
5288 int_to_string( array_index_str, array_index );
5289 array_index_last = array_index;
5291 return array_index_str;
5296 return anchor.key();
5313 typename IteratorType::reference
value()
const
5315 return anchor.value();
5320template<
typename IteratorType>
class iteration_proxy
5324 typename IteratorType::pointer container =
nullptr;
5327 explicit iteration_proxy() =
default;
5331 : container(&cont) {}
5355template<std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
5356auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.key())
5363template<std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
5364auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.value())
5370NLOHMANN_JSON_NAMESPACE_END
5379#if defined(__clang__)
5381 #pragma clang diagnostic push
5382 #pragma clang diagnostic ignored "-Wmismatched-tags"
5384template<
typename IteratorType>
5385class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
5386 :
public std::integral_constant<std::size_t, 2> {};
5388template<std::
size_t N,
typename IteratorType>
5389class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
5392 using type =
decltype(
5393 get<N>(std::declval <
5394 ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));
5396#if defined(__clang__)
5397 #pragma clang diagnostic pop
5403 template <
typename IteratorType>
5404 inline constexpr bool ::std::ranges::enable_borrowed_range<::nlohmann::detail::iteration_proxy<IteratorType>> =
true;
5418NLOHMANN_JSON_NAMESPACE_BEGIN
5438 template<
typename BasicJsonType>
5439 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t b)
noexcept
5441 j.m_data.m_value.destroy(j.m_data.m_type);
5443 j.m_data.m_value = b;
5444 j.assert_invariant();
5451 template<
typename BasicJsonType>
5452 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t& s)
5454 j.m_data.m_value.destroy(j.m_data.m_type);
5456 j.m_data.m_value = s;
5457 j.assert_invariant();
5460 template<
typename BasicJsonType>
5461 static void construct(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
5463 j.m_data.m_value.destroy(j.m_data.m_type);
5465 j.m_data.m_value = std::move(s);
5466 j.assert_invariant();
5469 template <
typename BasicJsonType,
typename CompatibleStringType,
5470 enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
5472 static void construct(BasicJsonType& j,
const CompatibleStringType& str)
5474 j.m_data.m_value.destroy(j.m_data.m_type);
5476 j.m_data.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
5477 j.assert_invariant();
5484 template<
typename BasicJsonType>
5485 static void construct(BasicJsonType& j,
const typename BasicJsonType::binary_t& b)
5487 j.m_data.m_value.destroy(j.m_data.m_type);
5489 j.m_data.m_value =
typename BasicJsonType::binary_t(b);
5490 j.assert_invariant();
5493 template<
typename BasicJsonType>
5494 static void construct(BasicJsonType& j,
typename BasicJsonType::binary_t&& b)
5496 j.m_data.m_value.destroy(j.m_data.m_type);
5498 j.m_data.m_value =
typename BasicJsonType::binary_t(std::move(b));
5499 j.assert_invariant();
5506 template<
typename BasicJsonType>
5507 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val)
noexcept
5509 j.m_data.m_value.destroy(j.m_data.m_type);
5511 j.m_data.m_value = val;
5512 j.assert_invariant();
5519 template<
typename BasicJsonType>
5520 static void construct(BasicJsonType& j,
typename BasicJsonType::number_unsigned_t val)
noexcept
5522 j.m_data.m_value.destroy(j.m_data.m_type);
5524 j.m_data.m_value = val;
5525 j.assert_invariant();
5532 template<
typename BasicJsonType>
5533 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val)
noexcept
5535 j.m_data.m_value.destroy(j.m_data.m_type);
5537 j.m_data.m_value = val;
5538 j.assert_invariant();
5545 template<
typename BasicJsonType>
5546 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
5548 j.m_data.m_value.destroy(j.m_data.m_type);
5550 j.m_data.m_value = arr;
5552 j.assert_invariant();
5555 template<
typename BasicJsonType>
5556 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
5558 j.m_data.m_value.destroy(j.m_data.m_type);
5560 j.m_data.m_value = std::move(arr);
5562 j.assert_invariant();
5565 template <
typename BasicJsonType,
typename CompatibleArrayType,
5566 enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
5568 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
5573 j.m_data.m_value.destroy(j.m_data.m_type);
5575 j.m_data.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
5577 j.assert_invariant();
5580 template<
typename BasicJsonType>
5581 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
5583 j.m_data.m_value.destroy(j.m_data.m_type);
5586 j.m_data.m_value.array->reserve(arr.size());
5587 for (
const bool x : arr)
5589 j.m_data.m_value.array->push_back(x);
5590 j.set_parent(j.m_data.m_value.array->back());
5592 j.assert_invariant();
5595 template<
typename BasicJsonType,
typename T,
5596 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
5597 static void construct(BasicJsonType& j,
const std::valarray<T>& arr)
5599 j.m_data.m_value.destroy(j.m_data.m_type);
5602 j.m_data.m_value.array->resize(arr.size());
5605 std::copy(std::begin(arr), std::end(arr), j.m_data.m_value.array->begin());
5608 j.assert_invariant();
5615 template<
typename BasicJsonType>
5616 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
5618 j.m_data.m_value.destroy(j.m_data.m_type);
5620 j.m_data.m_value = obj;
5622 j.assert_invariant();
5625 template<
typename BasicJsonType>
5626 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
5628 j.m_data.m_value.destroy(j.m_data.m_type);
5630 j.m_data.m_value = std::move(obj);
5632 j.assert_invariant();
5635 template <
typename BasicJsonType,
typename CompatibleObjectType,
5636 enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
int > = 0 >
5637 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
5642 j.m_data.m_value.destroy(j.m_data.m_type);
5644 j.m_data.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
5646 j.assert_invariant();
5654template<
typename BasicJsonType,
typename T,
5655 enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value,
int> = 0>
5656inline void to_json(BasicJsonType& j, T b)
noexcept
5661template <
typename BasicJsonType,
typename BoolRef,
5663 ((std::is_same<std::vector<bool>::reference, BoolRef>
::value
5664 && !std::is_same <std::vector<bool>::reference,
typename BasicJsonType::boolean_t&>
::value)
5665 || (std::is_same<std::vector<bool>::const_reference, BoolRef>
::value
5666 && !std::is_same <detail::uncvref_t<std::vector<bool>::const_reference>,
5667 typename BasicJsonType::boolean_t >
::value))
5668 && std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value,
int > = 0 >
5669inline void to_json(BasicJsonType& j,
const BoolRef& b)
noexcept
5671 external_constructor<value_t::boolean>::construct(j,
static_cast<typename BasicJsonType::boolean_t
>(b));
5674template<
typename BasicJsonType,
typename CompatibleString,
5675 enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value,
int> = 0>
5676inline void to_json(BasicJsonType& j,
const CompatibleString& s)
5678 external_constructor<value_t::string>::construct(j, s);
5681template<
typename BasicJsonType>
5682inline void to_json(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
5684 external_constructor<value_t::string>::construct(j, std::move(s));
5687template<
typename BasicJsonType,
typename FloatType,
5688 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
5689inline void to_json(BasicJsonType& j, FloatType val)
noexcept
5691 external_constructor<value_t::number_float>::construct(j,
static_cast<typename BasicJsonType::number_float_t
>(val));
5694template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
5695 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value,
int> = 0>
5696inline void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val)
noexcept
5698 external_constructor<value_t::number_unsigned>::construct(j,
static_cast<typename BasicJsonType::number_unsigned_t
>(val));
5701template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
5702 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value,
int> = 0>
5703inline void to_json(BasicJsonType& j, CompatibleNumberIntegerType val)
noexcept
5705 external_constructor<value_t::number_integer>::construct(j,
static_cast<typename BasicJsonType::number_integer_t
>(val));
5708#if !JSON_DISABLE_ENUM_SERIALIZATION
5709template<
typename BasicJsonType,
typename EnumType,
5710 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
5711inline void to_json(BasicJsonType& j, EnumType e)
noexcept
5713 using underlying_type =
typename std::underlying_type<EnumType>::type;
5714 external_constructor<value_t::number_integer>::construct(j,
static_cast<underlying_type
>(e));
5718template<
typename BasicJsonType>
5719inline void to_json(BasicJsonType& j,
const std::vector<bool>& e)
5721 external_constructor<value_t::array>::construct(j, e);
5724template <
typename BasicJsonType,
typename CompatibleArrayType,
5725 enable_if_t < is_compatible_array_type<BasicJsonType,
5727 !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&&
5728 !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&&
5729 !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
5730 !is_basic_json<CompatibleArrayType>::value,
5732inline void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
5734 external_constructor<value_t::array>::construct(j, arr);
5737template<
typename BasicJsonType>
5738inline void to_json(BasicJsonType& j,
const typename BasicJsonType::binary_t& bin)
5740 external_constructor<value_t::binary>::construct(j, bin);
5743template<
typename BasicJsonType,
typename T,
5744 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
5745inline void to_json(BasicJsonType& j,
const std::valarray<T>& arr)
5747 external_constructor<value_t::array>::construct(j, std::move(arr));
5750template<
typename BasicJsonType>
5751inline void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
5753 external_constructor<value_t::array>::construct(j, std::move(arr));
5756template <
typename BasicJsonType,
typename CompatibleObjectType,
5757 enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value,
int > = 0 >
5758inline void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
5760 external_constructor<value_t::object>::construct(j, obj);
5763template<
typename BasicJsonType>
5764inline void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
5766 external_constructor<value_t::object>::construct(j, std::move(obj));
5770 typename BasicJsonType,
typename T, std::size_t N,
5771 enable_if_t < !std::is_constructible<
typename BasicJsonType::string_t,
5774inline void to_json(BasicJsonType& j,
const T(&arr)[N])
5776 external_constructor<value_t::array>::construct(j, arr);
5779template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value,
int > = 0 >
5780inline void to_json(BasicJsonType& j,
const std::pair<T1, T2>& p)
5782 j = { p.first, p.second };
5786template<
typename BasicJsonType,
typename T,
5787 enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>
::value,
int> = 0>
5788inline void to_json(BasicJsonType& j,
const T& b)
5790 j = { {b.key(), b.value()} };
5793template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
5794inline void to_json_tuple_impl(BasicJsonType& j,
const Tuple& t, index_sequence<Idx...> )
5796 j = { std::get<Idx>(t)... };
5799template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value,
int > = 0>
5800inline void to_json(BasicJsonType& j,
const T& t)
5802 to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
5805#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
5806template<
typename BasicJsonType>
5807inline void to_json(BasicJsonType& j,
const std_fs::path& p)
5815 template<
typename BasicJsonType,
typename T>
5816 auto operator()(BasicJsonType& j, T&& val)
const noexcept(
noexcept(to_json(j, std::forward<T>(val))))
5817 ->
decltype(to_json(j, std::forward<T>(val)),
void())
5819 return to_json(j, std::forward<T>(val));
5824#ifndef JSON_HAS_CPP_17
5831JSON_INLINE_VARIABLE
constexpr const auto& to_json =
5833#ifndef JSON_HAS_CPP_17
5837NLOHMANN_JSON_NAMESPACE_END
5842NLOHMANN_JSON_NAMESPACE_BEGIN
5845template<
typename ValueType,
typename>
5850 template<
typename BasicJsonType,
typename TargetType = ValueType>
5851 static auto from_json(BasicJsonType && j, TargetType& val)
noexcept(
5852 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
5853 ->
decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val),
void())
5855 ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
5860 template<
typename BasicJsonType,
typename TargetType = ValueType>
5870 template<
typename BasicJsonType,
typename TargetType = ValueType>
5871 static auto to_json(BasicJsonType& j, TargetType && val)
noexcept(
5872 noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
5873 ->
decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)),
void())
5875 ::nlohmann::to_json(j, std::forward<TargetType>(val));
5879NLOHMANN_JSON_NAMESPACE_END
5899NLOHMANN_JSON_NAMESPACE_BEGIN
5903template<
typename BinaryType>
5907 using container_type = BinaryType;
5908 using subtype_type = std::uint64_t;
5922 : container_type(std::move(b))
5928 , m_subtype(subtype_)
5929 , m_has_subtype(true)
5934 : container_type(std::move(b))
5935 , m_subtype(subtype_)
5936 , m_has_subtype(true)
5941 return std::tie(
static_cast<const BinaryType&
>(*
this), m_subtype, m_has_subtype) ==
5942 std::tie(
static_cast<const BinaryType&
>(rhs), rhs.m_subtype, rhs.m_has_subtype);
5947 return !(rhs == *
this);
5954 m_subtype = subtype_;
5955 m_has_subtype =
true;
5962 return m_has_subtype ? m_subtype :
static_cast<subtype_type
>(-1);
5969 return m_has_subtype;
5977 m_has_subtype =
false;
5981 subtype_type m_subtype = 0;
5982 bool m_has_subtype =
false;
5985NLOHMANN_JSON_NAMESPACE_END
6006#include <functional>
6013NLOHMANN_JSON_NAMESPACE_BEGIN
6018inline std::size_t combine(std::size_t seed, std::size_t h)
noexcept
6020 seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
6035template<
typename BasicJsonType>
6036std::size_t
hash(
const BasicJsonType& j)
6038 using string_t =
typename BasicJsonType::string_t;
6039 using number_integer_t =
typename BasicJsonType::number_integer_t;
6040 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6041 using number_float_t =
typename BasicJsonType::number_float_t;
6043 const auto type =
static_cast<std::size_t
>(j.type());
6046 case BasicJsonType::value_t::null:
6047 case BasicJsonType::value_t::discarded:
6049 return combine(type, 0);
6052 case BasicJsonType::value_t::object:
6054 auto seed = combine(type, j.size());
6055 for (
const auto& element : j.items())
6057 const auto h = std::hash<string_t> {}(element.key());
6058 seed = combine(seed, h);
6059 seed = combine(seed,
hash(element.value()));
6064 case BasicJsonType::value_t::array:
6066 auto seed = combine(type, j.size());
6067 for (
const auto& element : j)
6069 seed = combine(seed,
hash(element));
6074 case BasicJsonType::value_t::string:
6076 const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
6077 return combine(type, h);
6080 case BasicJsonType::value_t::boolean:
6082 const auto h = std::hash<bool> {}(j.template get<bool>());
6083 return combine(type, h);
6086 case BasicJsonType::value_t::number_integer:
6088 const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
6089 return combine(type, h);
6092 case BasicJsonType::value_t::number_unsigned:
6094 const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
6095 return combine(type, h);
6098 case BasicJsonType::value_t::number_float:
6100 const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
6101 return combine(type, h);
6104 case BasicJsonType::value_t::binary:
6106 auto seed = combine(type, j.get_binary().size());
6107 const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
6108 seed = combine(seed, h);
6109 seed = combine(seed,
static_cast<std::size_t
>(j.get_binary().subtype()));
6110 for (
const auto byte : j.get_binary())
6112 seed = combine(seed, std::hash<std::uint8_t> {}(byte));
6124NLOHMANN_JSON_NAMESPACE_END
6170#include <type_traits>
6185NLOHMANN_JSON_NAMESPACE_BEGIN
6204 using char_type = char;
6206 JSON_HEDLEY_NON_NULL(2)
6210 JSON_ASSERT(m_file !=
nullptr);
6220 std::char_traits<char>::int_type get_character()
noexcept
6222 return std::fgetc(m_file);
6242 using char_type = char;
6250 is->clear(is->rdstate() & std::ios::eofbit);
6255 : is(&i), sb(i.rdbuf())
6264 : is(rhs.is), sb(rhs.sb)
6273 std::char_traits<char>::int_type get_character()
6275 auto res = sb->sbumpc();
6277 if (JSON_HEDLEY_UNLIKELY(res == std::char_traits<char>::eof()))
6279 is->clear(is->rdstate() | std::ios::eofbit);
6286 std::istream* is =
nullptr;
6287 std::streambuf* sb =
nullptr;
6293template<
typename IteratorType>
6297 using char_type =
typename std::iterator_traits<IteratorType>::value_type;
6300 : current(std::move(first)), end(std::move(last))
6305 if (JSON_HEDLEY_LIKELY(current != end))
6308 std::advance(current, 1);
6316 IteratorType current;
6319 template<
typename BaseInputAdapter,
size_t T>
6324 return current == end;
6328template<
typename BaseInputAdapter,
size_t T>
6331template<
typename BaseInputAdapter>
6335 static void fill_buffer(BaseInputAdapter& input,
6336 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
6337 size_t& utf8_bytes_index,
6338 size_t& utf8_bytes_filled)
6340 utf8_bytes_index = 0;
6342 if (JSON_HEDLEY_UNLIKELY(input.empty()))
6344 utf8_bytes[0] = std::char_traits<char>::eof();
6345 utf8_bytes_filled = 1;
6350 const auto wc = input.get_character();
6355 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6356 utf8_bytes_filled = 1;
6358 else if (wc <= 0x7FF)
6360 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
6361 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6362 utf8_bytes_filled = 2;
6364 else if (wc <= 0xFFFF)
6366 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
6367 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6368 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6369 utf8_bytes_filled = 3;
6371 else if (wc <= 0x10FFFF)
6373 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | ((
static_cast<unsigned int>(wc) >> 18u) & 0x07u));
6374 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
6375 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6376 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6377 utf8_bytes_filled = 4;
6382 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6383 utf8_bytes_filled = 1;
6389template<
typename BaseInputAdapter>
6393 static void fill_buffer(BaseInputAdapter& input,
6394 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
6395 size_t& utf8_bytes_index,
6396 size_t& utf8_bytes_filled)
6398 utf8_bytes_index = 0;
6400 if (JSON_HEDLEY_UNLIKELY(input.empty()))
6402 utf8_bytes[0] = std::char_traits<char>::eof();
6403 utf8_bytes_filled = 1;
6408 const auto wc = input.get_character();
6413 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6414 utf8_bytes_filled = 1;
6416 else if (wc <= 0x7FF)
6418 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u)));
6419 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6420 utf8_bytes_filled = 2;
6422 else if (0xD800 > wc || wc >= 0xE000)
6424 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u)));
6425 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6426 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6427 utf8_bytes_filled = 3;
6431 if (JSON_HEDLEY_UNLIKELY(!input.empty()))
6433 const auto wc2 =
static_cast<unsigned int>(input.get_character());
6434 const auto charcode = 0x10000u + (((
static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
6435 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | (charcode >> 18u));
6436 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 12u) & 0x3Fu));
6437 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 6u) & 0x3Fu));
6438 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (charcode & 0x3Fu));
6439 utf8_bytes_filled = 4;
6443 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6444 utf8_bytes_filled = 1;
6452template<
typename BaseInputAdapter,
typename W
ideCharType>
6456 using char_type = char;
6459 : base_adapter(base) {}
6461 typename std::char_traits<char>::int_type get_character()
noexcept
6464 if (utf8_bytes_index == utf8_bytes_filled)
6466 fill_buffer<sizeof(WideCharType)>();
6468 JSON_ASSERT(utf8_bytes_filled > 0);
6469 JSON_ASSERT(utf8_bytes_index == 0);
6473 JSON_ASSERT(utf8_bytes_filled > 0);
6474 JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);
6475 return utf8_bytes[utf8_bytes_index++];
6479 BaseInputAdapter base_adapter;
6488 std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
6491 std::size_t utf8_bytes_index = 0;
6493 std::size_t utf8_bytes_filled = 0;
6496template<
typename IteratorType,
typename Enable =
void>
6499 using iterator_type = IteratorType;
6500 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
6503 static adapter_type create(IteratorType first, IteratorType last)
6505 return adapter_type(std::move(first), std::move(last));
6512 using value_type =
typename std::iterator_traits<T>::value_type;
6515 value =
sizeof(value_type) > 1
6519template<
typename IteratorType>
6522 using iterator_type = IteratorType;
6523 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
6527 static adapter_type create(IteratorType first, IteratorType last)
6534template<
typename IteratorType>
6538 return factory_type::create(first, last);
6545namespace container_input_adapter_factory_impl
6551template<
typename ContainerType,
typename Enable =
void>
6554template<
typename ContainerType>
6556 void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
6558 using adapter_type =
decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
6560 static adapter_type create(
const ContainerType& container)
6562 return input_adapter(begin(container), end(container));
6568template<
typename ContainerType>
6576inline file_input_adapter input_adapter(std::FILE* file)
6578 return file_input_adapter(file);
6581inline input_stream_adapter input_adapter(std::istream& stream)
6583 return input_stream_adapter(stream);
6586inline input_stream_adapter input_adapter(std::istream&& stream)
6588 return input_stream_adapter(stream);
6592using contiguous_bytes_input_adapter =
decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
6595template <
typename CharT,
6596 typename std::enable_if <
6597 std::is_pointer<CharT>::value&&
6598 !std::is_array<CharT>::value&&
6599 std::is_integral<typename std::remove_pointer<CharT>::type>
::value&&
6600 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
6602contiguous_bytes_input_adapter input_adapter(CharT b)
6604 auto length = std::strlen(
reinterpret_cast<const char*
>(b));
6605 const auto* ptr =
reinterpret_cast<const char*
>(b);
6606 return input_adapter(ptr, ptr + length);
6609template<
typename T, std::
size_t N>
6610auto input_adapter(T (&
array)[N]) ->
decltype(input_adapter(
array,
array + N))
6621 template <
typename CharT,
6622 typename std::enable_if <
6623 std::is_pointer<CharT>::value&&
6624 std::is_integral<typename std::remove_pointer<CharT>::type>
::value&&
6625 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
6628 : ia(
reinterpret_cast<const char*
>(b),
reinterpret_cast<const char*
>(b) + l) {}
6630 template<
class IteratorType,
6631 typename std::enable_if<
6632 std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>
::value,
6635 : ia(input_adapter(first, last)) {}
6637 contiguous_bytes_input_adapter&& get()
6639 return std::move(ia);
6643 contiguous_bytes_input_adapter ia;
6647NLOHMANN_JSON_NAMESPACE_END
6672NLOHMANN_JSON_NAMESPACE_BEGIN
6682template<
typename BasicJsonType>
6685 using number_integer_t =
typename BasicJsonType::number_integer_t;
6686 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6687 using number_float_t =
typename BasicJsonType::number_float_t;
6688 using string_t =
typename BasicJsonType::string_t;
6689 using binary_t =
typename BasicJsonType::binary_t;
6756 virtual bool key(string_t& val) = 0;
6786 const std::string& last_token,
6812template<
typename BasicJsonType>
6816 using number_integer_t =
typename BasicJsonType::number_integer_t;
6817 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6818 using number_float_t =
typename BasicJsonType::number_float_t;
6819 using string_t =
typename BasicJsonType::string_t;
6820 using binary_t =
typename BasicJsonType::binary_t;
6828 : root(r), allow_exceptions(allow_exceptions_)
6840 handle_value(
nullptr);
6844 bool boolean(
bool val)
6862 bool number_float(number_float_t val,
const string_t& )
6868 bool string(string_t& val)
6874 bool binary(binary_t& val)
6876 handle_value(std::move(val));
6880 bool start_object(std::size_t len)
6882 ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
6884 if (JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) && len > ref_stack.back()->max_size()))
6886 JSON_THROW(out_of_range::create(408, concat(
"excessive object size: ", std::to_string(len)), ref_stack.back()));
6892 bool key(string_t& val)
6894 JSON_ASSERT(!ref_stack.empty());
6895 JSON_ASSERT(ref_stack.back()->is_object());
6898 object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val));
6904 JSON_ASSERT(!ref_stack.empty());
6905 JSON_ASSERT(ref_stack.back()->is_object());
6907 ref_stack.back()->set_parents();
6908 ref_stack.pop_back();
6912 bool start_array(std::size_t len)
6914 ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
6916 if (JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) && len > ref_stack.back()->max_size()))
6918 JSON_THROW(out_of_range::create(408, concat(
"excessive array size: ", std::to_string(len)), ref_stack.back()));
6926 JSON_ASSERT(!ref_stack.empty());
6927 JSON_ASSERT(ref_stack.back()->is_array());
6929 ref_stack.back()->set_parents();
6930 ref_stack.pop_back();
6934 template<
class Exception>
6935 bool parse_error(std::size_t ,
const std::string& ,
6936 const Exception& ex)
6939 static_cast<void>(ex);
6940 if (allow_exceptions)
6947 constexpr bool is_errored()
const
6959 template<
typename Value>
6960 JSON_HEDLEY_RETURNS_NON_NULL
6961 BasicJsonType* handle_value(Value&& v)
6963 if (ref_stack.empty())
6965 root = BasicJsonType(std::forward<Value>(v));
6969 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6971 if (ref_stack.back()->is_array())
6973 ref_stack.back()->m_data.m_value.array->emplace_back(std::forward<Value>(v));
6974 return &(ref_stack.back()->m_data.m_value.array->back());
6977 JSON_ASSERT(ref_stack.back()->is_object());
6978 JSON_ASSERT(object_element);
6979 *object_element = BasicJsonType(std::forward<Value>(v));
6980 return object_element;
6984 BasicJsonType& root;
6986 std::vector<BasicJsonType*> ref_stack {};
6988 BasicJsonType* object_element =
nullptr;
6990 bool errored =
false;
6992 const bool allow_exceptions =
true;
6995template<
typename BasicJsonType>
6999 using number_integer_t =
typename BasicJsonType::number_integer_t;
7000 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7001 using number_float_t =
typename BasicJsonType::number_float_t;
7002 using string_t =
typename BasicJsonType::string_t;
7003 using binary_t =
typename BasicJsonType::binary_t;
7004 using parser_callback_t =
typename BasicJsonType::parser_callback_t;
7005 using parse_event_t =
typename BasicJsonType::parse_event_t;
7008 const parser_callback_t cb,
7009 const bool allow_exceptions_ =
true)
7010 : root(r), callback(cb), allow_exceptions(allow_exceptions_)
7012 keep_stack.push_back(
true);
7024 handle_value(
nullptr);
7046 bool number_float(number_float_t val,
const string_t& )
7052 bool string(string_t& val)
7058 bool binary(binary_t& val)
7060 handle_value(std::move(val));
7064 bool start_object(std::size_t len)
7067 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::object_start,
discarded);
7068 keep_stack.push_back(keep);
7070 auto val = handle_value(BasicJsonType::value_t::object,
true);
7071 ref_stack.push_back(val.second);
7074 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) && len > ref_stack.back()->max_size()))
7076 JSON_THROW(out_of_range::create(408, concat(
"excessive object size: ", std::to_string(len)), ref_stack.back()));
7082 bool key(string_t& val)
7084 BasicJsonType k = BasicJsonType(val);
7087 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::key, k);
7088 key_keep_stack.push_back(keep);
7091 if (keep && ref_stack.back())
7093 object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val) =
discarded);
7101 if (ref_stack.back())
7103 if (!callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
7110 ref_stack.back()->set_parents();
7114 JSON_ASSERT(!ref_stack.empty());
7115 JSON_ASSERT(!keep_stack.empty());
7116 ref_stack.pop_back();
7117 keep_stack.pop_back();
7119 if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
7122 for (
auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
7124 if (it->is_discarded())
7126 ref_stack.back()->erase(it);
7135 bool start_array(std::size_t len)
7137 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::array_start,
discarded);
7138 keep_stack.push_back(keep);
7140 auto val = handle_value(BasicJsonType::value_t::array,
true);
7141 ref_stack.push_back(val.second);
7144 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) && len > ref_stack.back()->max_size()))
7146 JSON_THROW(out_of_range::create(408, concat(
"excessive array size: ", std::to_string(len)), ref_stack.back()));
7156 if (ref_stack.back())
7158 keep = callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
7161 ref_stack.back()->set_parents();
7170 JSON_ASSERT(!ref_stack.empty());
7171 JSON_ASSERT(!keep_stack.empty());
7172 ref_stack.pop_back();
7173 keep_stack.pop_back();
7176 if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
7178 ref_stack.back()->m_data.m_value.array->pop_back();
7184 template<
class Exception>
7185 bool parse_error(std::size_t ,
const std::string& ,
7186 const Exception& ex)
7189 static_cast<void>(ex);
7190 if (allow_exceptions)
7197 constexpr bool is_errored()
const
7218 template<
typename Value>
7219 std::pair<bool, BasicJsonType*> handle_value(Value&& v,
const bool skip_callback =
false)
7221 JSON_ASSERT(!keep_stack.empty());
7225 if (!keep_stack.back())
7227 return {
false,
nullptr};
7231 auto value = BasicJsonType(std::forward<Value>(v));
7234 const bool keep = skip_callback || callback(
static_cast<int>(ref_stack.size()), parse_event_t::value,
value);
7239 return {
false,
nullptr};
7242 if (ref_stack.empty())
7244 root = std::move(
value);
7245 return {
true, & root};
7250 if (!ref_stack.back())
7252 return {
false,
nullptr};
7256 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
7259 if (ref_stack.back()->is_array())
7261 ref_stack.back()->m_data.m_value.array->emplace_back(std::move(
value));
7262 return {
true, & (ref_stack.back()->m_data.m_value.array->back())};
7266 JSON_ASSERT(ref_stack.back()->is_object());
7268 JSON_ASSERT(!key_keep_stack.empty());
7269 const bool store_element = key_keep_stack.back();
7270 key_keep_stack.pop_back();
7274 return {
false,
nullptr};
7277 JSON_ASSERT(object_element);
7278 *object_element = std::move(
value);
7279 return {
true, object_element};
7283 BasicJsonType& root;
7285 std::vector<BasicJsonType*> ref_stack {};
7287 std::vector<bool> keep_stack {};
7289 std::vector<bool> key_keep_stack {};
7291 BasicJsonType* object_element =
nullptr;
7293 bool errored =
false;
7295 const parser_callback_t callback =
nullptr;
7297 const bool allow_exceptions =
true;
7299 BasicJsonType
discarded = BasicJsonType::value_t::discarded;
7302template<
typename BasicJsonType>
7306 using number_integer_t =
typename BasicJsonType::number_integer_t;
7307 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7308 using number_float_t =
typename BasicJsonType::number_float_t;
7309 using string_t =
typename BasicJsonType::string_t;
7310 using binary_t =
typename BasicJsonType::binary_t;
7337 bool string(string_t& )
7347 bool start_object(std::size_t =
static_cast<std::size_t
>(-1))
7352 bool key(string_t& )
7362 bool start_array(std::size_t =
static_cast<std::size_t
>(-1))
7379NLOHMANN_JSON_NAMESPACE_END
7397#include <initializer_list>
7411NLOHMANN_JSON_NAMESPACE_BEGIN
7419template<
typename BasicJsonType>
7446 JSON_HEDLEY_RETURNS_NON_NULL
7452 case token_type::uninitialized:
7453 return "<uninitialized>";
7454 case token_type::literal_true:
7455 return "true literal";
7456 case token_type::literal_false:
7457 return "false literal";
7458 case token_type::literal_null:
7459 return "null literal";
7460 case token_type::value_string:
7461 return "string literal";
7462 case token_type::value_unsigned:
7463 case token_type::value_integer:
7464 case token_type::value_float:
7465 return "number literal";
7466 case token_type::begin_array:
7468 case token_type::begin_object:
7470 case token_type::end_array:
7472 case token_type::end_object:
7474 case token_type::name_separator:
7476 case token_type::value_separator:
7478 case token_type::parse_error:
7479 return "<parse error>";
7480 case token_type::end_of_input:
7481 return "end of input";
7482 case token_type::literal_or_value:
7483 return "'[', '{', or a literal";
7486 return "unknown token";
7496template<
typename BasicJsonType,
typename InputAdapterType>
7499 using number_integer_t =
typename BasicJsonType::number_integer_t;
7500 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7501 using number_float_t =
typename BasicJsonType::number_float_t;
7502 using string_t =
typename BasicJsonType::string_t;
7503 using char_type =
typename InputAdapterType::char_type;
7509 explicit lexer(InputAdapterType&& adapter,
bool ignore_comments_ =
false) noexcept
7510 : ia(std::move(adapter))
7511 , ignore_comments(ignore_comments_)
7512 , decimal_point_char(
static_cast<char_int_type
>(get_decimal_point()))
7529 static char get_decimal_point()
noexcept
7531 const auto* loc = localeconv();
7532 JSON_ASSERT(loc !=
nullptr);
7533 return (loc->decimal_point ==
nullptr) ?
'.' : *(loc->decimal_point);
7558 JSON_ASSERT(current ==
'u');
7561 const auto factors = { 12u, 8u, 4u, 0u };
7562 for (
const auto factor : factors)
7566 if (current >=
'0' && current <=
'9')
7568 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x30u) << factor);
7570 else if (current >=
'A' && current <=
'F')
7572 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x37u) << factor);
7574 else if (current >=
'a' && current <=
'f')
7576 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x57u) << factor);
7584 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
7603 bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
7605 JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
7608 for (
auto range = ranges.begin(); range != ranges.end(); ++range)
7611 if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range)))
7617 error_message =
"invalid string: ill-formed UTF-8 byte";
7640 token_type scan_string()
7646 JSON_ASSERT(current ==
'\"');
7656 error_message =
"invalid string: missing closing quote";
7657 return token_type::parse_error;
7663 return token_type::value_string;
7707 const int codepoint1 = get_codepoint();
7708 int codepoint = codepoint1;
7710 if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
7712 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7713 return token_type::parse_error;
7717 if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
7720 if (JSON_HEDLEY_LIKELY(get() ==
'\\' && get() ==
'u'))
7722 const int codepoint2 = get_codepoint();
7724 if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
7726 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7727 return token_type::parse_error;
7731 if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))
7734 codepoint =
static_cast<int>(
7736 (
static_cast<unsigned int>(codepoint1) << 10u)
7738 +
static_cast<unsigned int>(codepoint2)
7746 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
7747 return token_type::parse_error;
7752 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
7753 return token_type::parse_error;
7758 if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))
7760 error_message =
"invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
7761 return token_type::parse_error;
7766 JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
7769 if (codepoint < 0x80)
7772 add(
static_cast<char_int_type
>(codepoint));
7774 else if (codepoint <= 0x7FF)
7777 add(
static_cast<char_int_type
>(0xC0u | (
static_cast<unsigned int>(codepoint) >> 6u)));
7778 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7780 else if (codepoint <= 0xFFFF)
7783 add(
static_cast<char_int_type
>(0xE0u | (
static_cast<unsigned int>(codepoint) >> 12u)));
7784 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7785 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7790 add(
static_cast<char_int_type
>(0xF0u | (
static_cast<unsigned int>(codepoint) >> 18u)));
7791 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
7792 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7793 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7801 error_message =
"invalid string: forbidden character after backslash";
7802 return token_type::parse_error;
7811 error_message =
"invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
7812 return token_type::parse_error;
7817 error_message =
"invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
7818 return token_type::parse_error;
7823 error_message =
"invalid string: control character U+0002 (STX) must be escaped to \\u0002";
7824 return token_type::parse_error;
7829 error_message =
"invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
7830 return token_type::parse_error;
7835 error_message =
"invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
7836 return token_type::parse_error;
7841 error_message =
"invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
7842 return token_type::parse_error;
7847 error_message =
"invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
7848 return token_type::parse_error;
7853 error_message =
"invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
7854 return token_type::parse_error;
7859 error_message =
"invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
7860 return token_type::parse_error;
7865 error_message =
"invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
7866 return token_type::parse_error;
7871 error_message =
"invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
7872 return token_type::parse_error;
7877 error_message =
"invalid string: control character U+000B (VT) must be escaped to \\u000B";
7878 return token_type::parse_error;
7883 error_message =
"invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
7884 return token_type::parse_error;
7889 error_message =
"invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
7890 return token_type::parse_error;
7895 error_message =
"invalid string: control character U+000E (SO) must be escaped to \\u000E";
7896 return token_type::parse_error;
7901 error_message =
"invalid string: control character U+000F (SI) must be escaped to \\u000F";
7902 return token_type::parse_error;
7907 error_message =
"invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
7908 return token_type::parse_error;
7913 error_message =
"invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
7914 return token_type::parse_error;
7919 error_message =
"invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
7920 return token_type::parse_error;
7925 error_message =
"invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
7926 return token_type::parse_error;
7931 error_message =
"invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
7932 return token_type::parse_error;
7937 error_message =
"invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
7938 return token_type::parse_error;
7943 error_message =
"invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
7944 return token_type::parse_error;
7949 error_message =
"invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
7950 return token_type::parse_error;
7955 error_message =
"invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
7956 return token_type::parse_error;
7961 error_message =
"invalid string: control character U+0019 (EM) must be escaped to \\u0019";
7962 return token_type::parse_error;
7967 error_message =
"invalid string: control character U+001A (SUB) must be escaped to \\u001A";
7968 return token_type::parse_error;
7973 error_message =
"invalid string: control character U+001B (ESC) must be escaped to \\u001B";
7974 return token_type::parse_error;
7979 error_message =
"invalid string: control character U+001C (FS) must be escaped to \\u001C";
7980 return token_type::parse_error;
7985 error_message =
"invalid string: control character U+001D (GS) must be escaped to \\u001D";
7986 return token_type::parse_error;
7991 error_message =
"invalid string: control character U+001E (RS) must be escaped to \\u001E";
7992 return token_type::parse_error;
7997 error_message =
"invalid string: control character U+001F (US) must be escaped to \\u001F";
7998 return token_type::parse_error;
8133 if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
8135 return token_type::parse_error;
8143 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
8145 return token_type::parse_error;
8167 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
8169 return token_type::parse_error;
8177 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
8179 return token_type::parse_error;
8187 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
8189 return token_type::parse_error;
8199 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
8201 return token_type::parse_error;
8209 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
8211 return token_type::parse_error;
8219 error_message =
"invalid string: ill-formed UTF-8 byte";
8220 return token_type::parse_error;
8263 error_message =
"invalid comment; missing closing '*/'";
8291 error_message =
"invalid comment; expecting '/' or '*' after '/'";
8297 JSON_HEDLEY_NON_NULL(2)
8298 static void strtof(
float& f,
const char* str,
char** endptr)
noexcept
8300 f = std::strtof(str, endptr);
8303 JSON_HEDLEY_NON_NULL(2)
8304 static void strtof(
double& f,
const char* str,
char** endptr)
noexcept
8306 f = std::strtod(str, endptr);
8309 JSON_HEDLEY_NON_NULL(2)
8310 static void strtof(
long double& f,
const char* str,
char** endptr)
noexcept
8312 f = std::strtold(str, endptr);
8355 token_type scan_number()
8362 token_type number_type = token_type::value_unsigned;
8370 goto scan_number_minus;
8376 goto scan_number_zero;
8390 goto scan_number_any1;
8400 number_type = token_type::value_integer;
8406 goto scan_number_zero;
8420 goto scan_number_any1;
8425 error_message =
"invalid number; expected digit after '-'";
8426 return token_type::parse_error;
8436 add(decimal_point_char);
8437 goto scan_number_decimal1;
8444 goto scan_number_exponent;
8448 goto scan_number_done;
8467 goto scan_number_any1;
8472 add(decimal_point_char);
8473 goto scan_number_decimal1;
8480 goto scan_number_exponent;
8484 goto scan_number_done;
8487scan_number_decimal1:
8489 number_type = token_type::value_float;
8504 goto scan_number_decimal2;
8509 error_message =
"invalid number; expected digit after '.'";
8510 return token_type::parse_error;
8514scan_number_decimal2:
8530 goto scan_number_decimal2;
8537 goto scan_number_exponent;
8541 goto scan_number_done;
8544scan_number_exponent:
8546 number_type = token_type::value_float;
8553 goto scan_number_sign;
8568 goto scan_number_any2;
8574 "invalid number; expected '+', '-', or digit after exponent";
8575 return token_type::parse_error;
8595 goto scan_number_any2;
8600 error_message =
"invalid number; expected digit after exponent sign";
8601 return token_type::parse_error;
8621 goto scan_number_any2;
8625 goto scan_number_done;
8633 char* endptr =
nullptr;
8637 if (number_type == token_type::value_unsigned)
8639 const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
8642 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8646 value_unsigned =
static_cast<number_unsigned_t
>(x);
8647 if (value_unsigned == x)
8649 return token_type::value_unsigned;
8653 else if (number_type == token_type::value_integer)
8655 const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
8658 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8662 value_integer =
static_cast<number_integer_t
>(x);
8663 if (value_integer == x)
8665 return token_type::value_integer;
8672 strtof(value_float, token_buffer.data(), &endptr);
8675 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8677 return token_type::value_float;
8685 JSON_HEDLEY_NON_NULL(2)
8686 token_type scan_literal(
const char_type* literal_text,
const std::size_t length,
8687 token_type return_type)
8690 for (std::size_t i = 1; i < length; ++i)
8694 error_message =
"invalid literal";
8695 return token_type::parse_error;
8706 void reset()
noexcept
8708 token_buffer.clear();
8709 token_string.clear();
8725 ++position.chars_read_total;
8726 ++position.chars_read_current_line;
8735 current = ia.get_character();
8743 if (current ==
'\n')
8745 ++position.lines_read;
8746 position.chars_read_current_line = 0;
8764 --position.chars_read_total;
8767 if (position.chars_read_current_line == 0)
8769 if (position.lines_read > 0)
8771 --position.lines_read;
8776 --position.chars_read_current_line;
8781 JSON_ASSERT(!token_string.empty());
8782 token_string.pop_back();
8787 void add(char_int_type c)
8789 token_buffer.push_back(
static_cast<typename string_t::value_type
>(c));
8800 return value_integer;
8806 return value_unsigned;
8818 return token_buffer;
8838 for (
const auto c : token_string)
8840 if (
static_cast<unsigned char>(c) <=
'\x1F')
8843 std::array<char, 9> cs{{}};
8844 static_cast<void>((std::snprintf)(cs.data(), cs.size(),
"<U+%.4X>",
static_cast<unsigned char>(c)));
8845 result += cs.data();
8850 result.push_back(
static_cast<std::string::value_type
>(c));
8858 JSON_HEDLEY_RETURNS_NON_NULL
8861 return error_message;
8877 return get() == 0xBB && get() == 0xBF;
8886 void skip_whitespace()
8892 while (current ==
' ' || current ==
'\t' || current ==
'\n' || current ==
'\r');
8898 if (position.chars_read_total == 0 && !skip_bom())
8900 error_message =
"invalid BOM; must be 0xEF 0xBB 0xBF if given";
8901 return token_type::parse_error;
8908 while (ignore_comments && current ==
'/')
8910 if (!scan_comment())
8912 return token_type::parse_error;
8923 return token_type::begin_array;
8925 return token_type::end_array;
8927 return token_type::begin_object;
8929 return token_type::end_object;
8931 return token_type::name_separator;
8933 return token_type::value_separator;
8938 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')}};
8939 return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
8943 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')}};
8944 return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
8948 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')}};
8949 return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
8954 return scan_string();
8968 return scan_number();
8973 case char_traits<char_type>::eof():
8974 return token_type::end_of_input;
8978 error_message =
"invalid literal";
8979 return token_type::parse_error;
8985 InputAdapterType ia;
8988 const bool ignore_comments =
false;
8991 char_int_type current = char_traits<char_type>::eof();
8994 bool next_unget =
false;
8997 position_t position {};
9000 std::vector<char_type> token_string {};
9003 string_t token_buffer {};
9006 const char* error_message =
"";
9009 number_integer_t value_integer = 0;
9010 number_unsigned_t value_unsigned = 0;
9011 number_float_t value_float = 0;
9014 const char_int_type decimal_point_char =
'.';
9018NLOHMANN_JSON_NAMESPACE_END
9044NLOHMANN_JSON_NAMESPACE_BEGIN
9049using null_function_t =
decltype(std::declval<T&>().null());
9052using boolean_function_t =
9053 decltype(std::declval<T&>().boolean(std::declval<bool>()));
9055template<
typename T,
typename Integer>
9056using number_integer_function_t =
9057 decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
9059template<
typename T,
typename Un
signed>
9060using number_unsigned_function_t =
9061 decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
9063template<
typename T,
typename Float,
typename String>
9064using number_float_function_t =
decltype(std::declval<T&>().number_float(
9065 std::declval<Float>(), std::declval<const String&>()));
9067template<
typename T,
typename String>
9068using string_function_t =
9069 decltype(std::declval<T&>().string(std::declval<String&>()));
9071template<
typename T,
typename Binary>
9072using binary_function_t =
9073 decltype(std::declval<T&>().binary(std::declval<Binary&>()));
9076using start_object_function_t =
9077 decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
9079template<
typename T,
typename String>
9080using key_function_t =
9081 decltype(std::declval<T&>().key(std::declval<String&>()));
9084using end_object_function_t =
decltype(std::declval<T&>().end_object());
9087using start_array_function_t =
9088 decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
9091using end_array_function_t =
decltype(std::declval<T&>().end_array());
9093template<
typename T,
typename Exception>
9094using parse_error_function_t =
decltype(std::declval<T&>().parse_error(
9095 std::declval<std::size_t>(), std::declval<const std::string&>(),
9096 std::declval<const Exception&>()));
9098template<
typename SAX,
typename BasicJsonType>
9103 "BasicJsonType must be of type basic_json<...>");
9105 using number_integer_t =
typename BasicJsonType::number_integer_t;
9106 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9107 using number_float_t =
typename BasicJsonType::number_float_t;
9108 using string_t =
typename BasicJsonType::string_t;
9109 using binary_t =
typename BasicJsonType::binary_t;
9110 using exception_t =
typename BasicJsonType::exception;
9113 static constexpr bool value =
9114 is_detected_exact<bool, null_function_t, SAX>::value &&
9115 is_detected_exact<bool, boolean_function_t, SAX>::value &&
9116 is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
9117 is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
9118 is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
9119 is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
9120 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
9121 is_detected_exact<bool, start_object_function_t, SAX>::value &&
9122 is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
9123 is_detected_exact<bool, end_object_function_t, SAX>::value &&
9124 is_detected_exact<bool, start_array_function_t, SAX>::value &&
9125 is_detected_exact<bool, end_array_function_t, SAX>::value &&
9126 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
9129template<
typename SAX,
typename BasicJsonType>
9134 "BasicJsonType must be of type basic_json<...>");
9136 using number_integer_t =
typename BasicJsonType::number_integer_t;
9137 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9138 using number_float_t =
typename BasicJsonType::number_float_t;
9139 using string_t =
typename BasicJsonType::string_t;
9140 using binary_t =
typename BasicJsonType::binary_t;
9141 using exception_t =
typename BasicJsonType::exception;
9144 static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
9145 "Missing/invalid function: bool null()");
9146 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
9147 "Missing/invalid function: bool boolean(bool)");
9148 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
9149 "Missing/invalid function: bool boolean(bool)");
9151 is_detected_exact<bool, number_integer_function_t, SAX,
9152 number_integer_t>::value,
9153 "Missing/invalid function: bool number_integer(number_integer_t)");
9155 is_detected_exact<bool, number_unsigned_function_t, SAX,
9156 number_unsigned_t>::value,
9157 "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
9158 static_assert(is_detected_exact<bool, number_float_function_t, SAX,
9159 number_float_t, string_t>::value,
9160 "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
9162 is_detected_exact<bool, string_function_t, SAX, string_t>::value,
9163 "Missing/invalid function: bool string(string_t&)");
9165 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
9166 "Missing/invalid function: bool binary(binary_t&)");
9167 static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
9168 "Missing/invalid function: bool start_object(std::size_t)");
9169 static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
9170 "Missing/invalid function: bool key(string_t&)");
9171 static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
9172 "Missing/invalid function: bool end_object()");
9173 static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
9174 "Missing/invalid function: bool start_array(std::size_t)");
9175 static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
9176 "Missing/invalid function: bool end_array()");
9178 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
9179 "Missing/invalid function: bool parse_error(std::size_t, const "
9180 "std::string&, const exception&)");
9184NLOHMANN_JSON_NAMESPACE_END
9193NLOHMANN_JSON_NAMESPACE_BEGIN
9212static inline bool little_endianness(
int num = 1) noexcept
9214 return *
reinterpret_cast<char*
>(&num) == 1;
9224template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX = json_sax_dom_parser<BasicJsonType>>
9227 using number_integer_t =
typename BasicJsonType::number_integer_t;
9228 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9229 using number_float_t =
typename BasicJsonType::number_float_t;
9230 using string_t =
typename BasicJsonType::string_t;
9231 using binary_t =
typename BasicJsonType::binary_t;
9232 using json_sax_t = SAX;
9233 using char_type =
typename InputAdapterType::char_type;
9242 explicit binary_reader(InputAdapterType&& adapter,
const input_format_t format = input_format_t::json) noexcept : ia(std::move(adapter)), input_format(format)
9262 JSON_HEDLEY_NON_NULL(3)
9265 const
bool strict = true,
9269 bool result =
false;
9273 case input_format_t::bson:
9274 result = parse_bson_internal();
9277 case input_format_t::cbor:
9278 result = parse_cbor_internal(
true, tag_handler);
9281 case input_format_t::msgpack:
9282 result = parse_msgpack_internal();
9285 case input_format_t::ubjson:
9286 case input_format_t::bjdata:
9287 result = parse_ubjson_internal();
9290 case input_format_t::json:
9298 if (input_format == input_format_t::ubjson || input_format == input_format_t::bjdata)
9309 return sax->parse_error(chars_read, get_token_string(), parse_error::create(110, chars_read,
9310 exception_message(input_format, concat(
"expected end of input; last byte: 0x", get_token_string()),
"value"),
nullptr));
9326 bool parse_bson_internal()
9328 std::int32_t document_size{};
9329 get_number<std::int32_t, true>(input_format_t::bson, document_size);
9331 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(
static_cast<std::size_t
>(-1))))
9336 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
false)))
9341 return sax->end_object();
9351 bool get_bson_cstr(string_t& result)
9353 auto out = std::back_inserter(result);
9357 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"cstring")))
9361 if (current == 0x00)
9365 *out++ =
static_cast<typename string_t::value_type
>(current);
9380 template<
typename NumberType>
9381 bool get_bson_string(
const NumberType len, string_t& result)
9383 if (JSON_HEDLEY_UNLIKELY(len < 1))
9385 auto last_token = get_token_string();
9386 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
9387 exception_message(input_format_t::bson, concat(
"string length must be at least 1, is ", std::to_string(len)),
"string"),
nullptr));
9390 return get_string(input_format_t::bson, len -
static_cast<NumberType
>(1), result) && get() != char_traits<char_type>::eof();
9402 template<
typename NumberType>
9403 bool get_bson_binary(
const NumberType len, binary_t& result)
9405 if (JSON_HEDLEY_UNLIKELY(len < 0))
9407 auto last_token = get_token_string();
9408 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
9409 exception_message(input_format_t::bson, concat(
"byte array length cannot be negative, is ", std::to_string(len)),
"binary"),
nullptr));
9413 std::uint8_t subtype{};
9414 get_number<std::uint8_t>(input_format_t::bson, subtype);
9415 result.set_subtype(subtype);
9417 return get_binary(input_format_t::bson, len, result);
9430 bool parse_bson_element_internal(
const char_int_type element_type,
9431 const std::size_t element_type_parse_position)
9433 switch (element_type)
9438 return get_number<double, true>(input_format_t::bson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9445 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
9450 return parse_bson_internal();
9455 return parse_bson_array();
9462 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
9467 return sax->boolean(get() != 0);
9477 std::int32_t
value{};
9478 return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
9483 std::int64_t
value{};
9484 return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
9489 std::array<char, 3> cr{{}};
9490 static_cast<void>((std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(element_type)));
9491 const std::string cr_str{cr.data()};
9492 return sax->parse_error(element_type_parse_position, cr_str,
9493 parse_error::create(114, element_type_parse_position, concat(
"Unsupported BSON record type 0x", cr_str),
nullptr));
9510 bool parse_bson_element_list(
const bool is_array)
9514 while (
auto element_type = get())
9516 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"element list")))
9521 const std::size_t element_type_parse_position = chars_read;
9522 if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key)))
9527 if (!is_array && !sax->key(key))
9532 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
9548 bool parse_bson_array()
9550 std::int32_t document_size{};
9551 get_number<std::int32_t, true>(input_format_t::bson, document_size);
9553 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(
static_cast<std::size_t
>(-1))))
9558 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
true)))
9563 return sax->end_array();
9578 bool parse_cbor_internal(
const bool get_char,
9579 const cbor_tag_handler_t tag_handler)
9581 switch (get_char ? get() : current)
9584 case char_traits<char_type>::eof():
9612 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
9616 std::uint8_t number{};
9617 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9622 std::uint16_t number{};
9623 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9628 std::uint32_t number{};
9629 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9634 std::uint64_t number{};
9635 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9663 return sax->number_integer(
static_cast<std::int8_t
>(0x20 - 1 - current));
9667 std::uint8_t number{};
9668 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
9673 std::uint16_t number{};
9674 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
9679 std::uint32_t number{};
9680 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
9685 std::uint64_t number{};
9686 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1)
9687 -
static_cast<number_integer_t
>(number));
9722 return get_cbor_binary(b) && sax->binary(b);
9757 return get_cbor_string(s) && sax->string(s);
9785 return get_cbor_array(
9786 conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
9791 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
9796 std::uint16_t len{};
9797 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
9802 std::uint32_t len{};
9803 return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
9808 std::uint64_t len{};
9809 return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
9813 return get_cbor_array(
static_cast<std::size_t
>(-1), tag_handler);
9840 return get_cbor_object(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
9845 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
9850 std::uint16_t len{};
9851 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
9856 std::uint32_t len{};
9857 return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
9862 std::uint64_t len{};
9863 return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
9867 return get_cbor_object(
static_cast<std::size_t
>(-1), tag_handler);
9889 switch (tag_handler)
9891 case cbor_tag_handler_t::error:
9893 auto last_token = get_token_string();
9894 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
9895 exception_message(input_format_t::cbor, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
9898 case cbor_tag_handler_t::ignore:
9905 std::uint8_t subtype_to_ignore{};
9906 get_number(input_format_t::cbor, subtype_to_ignore);
9911 std::uint16_t subtype_to_ignore{};
9912 get_number(input_format_t::cbor, subtype_to_ignore);
9917 std::uint32_t subtype_to_ignore{};
9918 get_number(input_format_t::cbor, subtype_to_ignore);
9923 std::uint64_t subtype_to_ignore{};
9924 get_number(input_format_t::cbor, subtype_to_ignore);
9930 return parse_cbor_internal(
true, tag_handler);
9933 case cbor_tag_handler_t::store:
9941 std::uint8_t subtype{};
9942 get_number(input_format_t::cbor, subtype);
9943 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9948 std::uint16_t subtype{};
9949 get_number(input_format_t::cbor, subtype);
9950 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9955 std::uint32_t subtype{};
9956 get_number(input_format_t::cbor, subtype);
9957 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9962 std::uint64_t subtype{};
9963 get_number(input_format_t::cbor, subtype);
9964 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9968 return parse_cbor_internal(
true, tag_handler);
9971 return get_cbor_binary(b) && sax->binary(b);
9981 return sax->boolean(
false);
9984 return sax->boolean(
true);
9991 const auto byte1_raw = get();
9992 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
9996 const auto byte2_raw = get();
9997 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
10002 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
10003 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
10013 const auto half =
static_cast<unsigned int>((byte1 << 8u) + byte2);
10014 const double val = [&half]
10016 const int exp = (half >> 10u) & 0x1Fu;
10017 const unsigned int mant = half & 0x3FFu;
10018 JSON_ASSERT(0 <= exp&& exp <= 32);
10019 JSON_ASSERT(mant <= 1024);
10023 return std::ldexp(mant, -24);
10026 ? std::numeric_limits<double>::infinity()
10027 : std::numeric_limits<double>::quiet_NaN();
10029 return std::ldexp(mant + 1024, exp - 25);
10032 return sax->number_float((half & 0x8000u) != 0
10033 ?
static_cast<number_float_t
>(-val)
10034 :
static_cast<number_float_t
>(val),
"");
10040 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10046 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10051 auto last_token = get_token_string();
10052 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
10053 exception_message(input_format_t::cbor, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
10069 bool get_cbor_string(string_t& result)
10071 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"string")))
10104 return get_string(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
10109 std::uint8_t len{};
10110 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10115 std::uint16_t len{};
10116 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10121 std::uint32_t len{};
10122 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10127 std::uint64_t len{};
10128 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10133 while (get() != 0xFF)
10136 if (!get_cbor_string(chunk))
10140 result.append(chunk);
10147 auto last_token = get_token_string();
10148 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
10149 exception_message(input_format_t::cbor, concat(
"expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token),
"string"),
nullptr));
10165 bool get_cbor_binary(binary_t& result)
10167 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"binary")))
10200 return get_binary(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
10205 std::uint8_t len{};
10206 return get_number(input_format_t::cbor, len) &&
10207 get_binary(input_format_t::cbor, len, result);
10212 std::uint16_t len{};
10213 return get_number(input_format_t::cbor, len) &&
10214 get_binary(input_format_t::cbor, len, result);
10219 std::uint32_t len{};
10220 return get_number(input_format_t::cbor, len) &&
10221 get_binary(input_format_t::cbor, len, result);
10226 std::uint64_t len{};
10227 return get_number(input_format_t::cbor, len) &&
10228 get_binary(input_format_t::cbor, len, result);
10233 while (get() != 0xFF)
10236 if (!get_cbor_binary(chunk))
10240 result.insert(result.end(), chunk.begin(), chunk.end());
10247 auto last_token = get_token_string();
10248 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
10249 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));
10260 bool get_cbor_array(
const std::size_t len,
10261 const cbor_tag_handler_t tag_handler)
10263 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
10268 if (len !=
static_cast<std::size_t
>(-1))
10270 for (std::size_t i = 0; i < len; ++i)
10272 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
10280 while (get() != 0xFF)
10282 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
false, tag_handler)))
10289 return sax->end_array();
10298 bool get_cbor_object(
const std::size_t len,
10299 const cbor_tag_handler_t tag_handler)
10301 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
10309 if (len !=
static_cast<std::size_t
>(-1))
10311 for (std::size_t i = 0; i < len; ++i)
10314 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
10319 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
10328 while (get() != 0xFF)
10330 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
10335 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
10344 return sax->end_object();
10354 bool parse_msgpack_internal()
10359 case char_traits<char_type>::eof():
10491 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
10510 return get_msgpack_object(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x0Fu));
10529 return get_msgpack_array(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x0Fu));
10569 return get_msgpack_string(s) && sax->string(s);
10573 return sax->null();
10576 return sax->boolean(
false);
10579 return sax->boolean(
true);
10594 return get_msgpack_binary(b) && sax->binary(b);
10600 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10606 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10611 std::uint8_t number{};
10612 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10617 std::uint16_t number{};
10618 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10623 std::uint32_t number{};
10624 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10629 std::uint64_t number{};
10630 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10635 std::int8_t number{};
10636 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10641 std::int16_t number{};
10642 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10647 std::int32_t number{};
10648 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10653 std::int64_t number{};
10654 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10659 std::uint16_t len{};
10660 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
10665 std::uint32_t len{};
10666 return get_number(input_format_t::msgpack, len) && get_msgpack_array(conditional_static_cast<std::size_t>(len));
10671 std::uint16_t len{};
10672 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
10677 std::uint32_t len{};
10678 return get_number(input_format_t::msgpack, len) && get_msgpack_object(conditional_static_cast<std::size_t>(len));
10714 return sax->number_integer(
static_cast<std::int8_t
>(current));
10718 auto last_token = get_token_string();
10719 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
10720 exception_message(input_format_t::msgpack, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
10735 bool get_msgpack_string(string_t& result)
10737 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack,
"string")))
10778 return get_string(input_format_t::msgpack,
static_cast<unsigned int>(current) & 0x1Fu, result);
10783 std::uint8_t len{};
10784 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
10789 std::uint16_t len{};
10790 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
10795 std::uint32_t len{};
10796 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
10801 auto last_token = get_token_string();
10802 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
10803 exception_message(input_format_t::msgpack, concat(
"expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token),
"string"),
nullptr));
10818 bool get_msgpack_binary(binary_t& result)
10821 auto assign_and_return_true = [&result](std::int8_t subtype)
10823 result.set_subtype(
static_cast<std::uint8_t
>(subtype));
10831 std::uint8_t len{};
10832 return get_number(input_format_t::msgpack, len) &&
10833 get_binary(input_format_t::msgpack, len, result);
10838 std::uint16_t len{};
10839 return get_number(input_format_t::msgpack, len) &&
10840 get_binary(input_format_t::msgpack, len, result);
10845 std::uint32_t len{};
10846 return get_number(input_format_t::msgpack, len) &&
10847 get_binary(input_format_t::msgpack, len, result);
10852 std::uint8_t len{};
10853 std::int8_t subtype{};
10854 return get_number(input_format_t::msgpack, len) &&
10855 get_number(input_format_t::msgpack, subtype) &&
10856 get_binary(input_format_t::msgpack, len, result) &&
10857 assign_and_return_true(subtype);
10862 std::uint16_t len{};
10863 std::int8_t subtype{};
10864 return get_number(input_format_t::msgpack, len) &&
10865 get_number(input_format_t::msgpack, subtype) &&
10866 get_binary(input_format_t::msgpack, len, result) &&
10867 assign_and_return_true(subtype);
10872 std::uint32_t len{};
10873 std::int8_t subtype{};
10874 return get_number(input_format_t::msgpack, len) &&
10875 get_number(input_format_t::msgpack, subtype) &&
10876 get_binary(input_format_t::msgpack, len, result) &&
10877 assign_and_return_true(subtype);
10882 std::int8_t subtype{};
10883 return get_number(input_format_t::msgpack, subtype) &&
10884 get_binary(input_format_t::msgpack, 1, result) &&
10885 assign_and_return_true(subtype);
10890 std::int8_t subtype{};
10891 return get_number(input_format_t::msgpack, subtype) &&
10892 get_binary(input_format_t::msgpack, 2, result) &&
10893 assign_and_return_true(subtype);
10898 std::int8_t subtype{};
10899 return get_number(input_format_t::msgpack, subtype) &&
10900 get_binary(input_format_t::msgpack, 4, result) &&
10901 assign_and_return_true(subtype);
10906 std::int8_t subtype{};
10907 return get_number(input_format_t::msgpack, subtype) &&
10908 get_binary(input_format_t::msgpack, 8, result) &&
10909 assign_and_return_true(subtype);
10914 std::int8_t subtype{};
10915 return get_number(input_format_t::msgpack, subtype) &&
10916 get_binary(input_format_t::msgpack, 16, result) &&
10917 assign_and_return_true(subtype);
10929 bool get_msgpack_array(
const std::size_t len)
10931 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
10936 for (std::size_t i = 0; i < len; ++i)
10938 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
10944 return sax->end_array();
10951 bool get_msgpack_object(
const std::size_t len)
10953 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
10959 for (std::size_t i = 0; i < len; ++i)
10962 if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key)))
10967 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
10974 return sax->end_object();
10988 bool parse_ubjson_internal(
const bool get_char =
true)
10990 return get_ubjson_value(get_char ? get_ignore_noop() : current);
11007 bool get_ubjson_string(string_t& result,
const bool get_char =
true)
11014 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"value")))
11023 std::uint8_t len{};
11024 return get_number(input_format, len) && get_string(input_format, len, result);
11030 return get_number(input_format, len) && get_string(input_format, len, result);
11035 std::int16_t len{};
11036 return get_number(input_format, len) && get_string(input_format, len, result);
11041 std::int32_t len{};
11042 return get_number(input_format, len) && get_string(input_format, len, result);
11047 std::int64_t len{};
11048 return get_number(input_format, len) && get_string(input_format, len, result);
11053 if (input_format != input_format_t::bjdata)
11057 std::uint16_t len{};
11058 return get_number(input_format, len) && get_string(input_format, len, result);
11063 if (input_format != input_format_t::bjdata)
11067 std::uint32_t len{};
11068 return get_number(input_format, len) && get_string(input_format, len, result);
11073 if (input_format != input_format_t::bjdata)
11077 std::uint64_t len{};
11078 return get_number(input_format, len) && get_string(input_format, len, result);
11084 auto last_token = get_token_string();
11085 std::string message;
11087 if (input_format != input_format_t::bjdata)
11089 message =
"expected length type specification (U, i, I, l, L); last byte: 0x" + last_token;
11093 message =
"expected length type specification (U, i, u, I, m, l, M, L); last byte: 0x" + last_token;
11095 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message,
"string"),
nullptr));
11102 bool get_ubjson_ndarray_size(std::vector<size_t>& dim)
11104 std::pair<std::size_t, char_int_type> size_and_type;
11106 bool no_ndarray =
true;
11108 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type, no_ndarray)))
11113 if (size_and_type.first != npos)
11115 if (size_and_type.second != 0)
11117 if (size_and_type.second !=
'N')
11119 for (std::size_t i = 0; i < size_and_type.first; ++i)
11121 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, size_and_type.second)))
11125 dim.push_back(dimlen);
11131 for (std::size_t i = 0; i < size_and_type.first; ++i)
11133 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray)))
11137 dim.push_back(dimlen);
11143 while (current !=
']')
11145 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, current)))
11149 dim.push_back(dimlen);
11167 bool get_ubjson_size_value(std::size_t& result,
bool& is_ndarray, char_int_type prefix = 0)
11171 prefix = get_ignore_noop();
11178 std::uint8_t number{};
11179 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11183 result =
static_cast<std::size_t
>(number);
11189 std::int8_t number{};
11190 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11196 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11197 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11199 result =
static_cast<std::size_t
>(number);
11205 std::int16_t number{};
11206 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11212 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11213 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11215 result =
static_cast<std::size_t
>(number);
11221 std::int32_t number{};
11222 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11228 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11229 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11231 result =
static_cast<std::size_t
>(number);
11237 std::int64_t number{};
11238 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11244 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11245 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11247 if (!value_in_range_of<std::size_t>(number))
11249 return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,
11250 exception_message(input_format,
"integer value overflow",
"size"),
nullptr));
11252 result =
static_cast<std::size_t
>(number);
11258 if (input_format != input_format_t::bjdata)
11262 std::uint16_t number{};
11263 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11267 result =
static_cast<std::size_t
>(number);
11273 if (input_format != input_format_t::bjdata)
11277 std::uint32_t number{};
11278 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11282 result = conditional_static_cast<std::size_t>(number);
11288 if (input_format != input_format_t::bjdata)
11292 std::uint64_t number{};
11293 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11297 if (!value_in_range_of<std::size_t>(number))
11299 return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,
11300 exception_message(input_format,
"integer value overflow",
"size"),
nullptr));
11302 result = detail::conditional_static_cast<std::size_t>(number);
11308 if (input_format != input_format_t::bjdata)
11314 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));
11316 std::vector<size_t> dim;
11317 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_ndarray_size(dim)))
11321 if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1))
11323 result = dim.at(dim.size() - 1);
11337 string_t
key =
"_ArraySize_";
11338 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(3) || !sax->key(key) || !sax->start_array(dim.size())))
11346 if (result == 0 || result == npos)
11348 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));
11350 if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(
static_cast<number_unsigned_t
>(i))))
11356 return sax->end_array();
11365 auto last_token = get_token_string();
11366 std::string message;
11368 if (input_format != input_format_t::bjdata)
11370 message =
"expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token;
11374 message =
"expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x" + last_token;
11376 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message,
"size"),
nullptr));
11390 bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result,
bool inside_ndarray =
false)
11392 result.first = npos;
11394 bool is_ndarray =
false;
11398 if (current ==
'$')
11400 result.second = get();
11401 if (input_format == input_format_t::bjdata
11402 && JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second)))
11404 auto last_token = get_token_string();
11405 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
11406 exception_message(input_format, concat(
"marker 0x", last_token,
" is not a permitted optimized array type"),
"type"),
nullptr));
11409 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"type")))
11415 if (JSON_HEDLEY_UNLIKELY(current !=
'#'))
11417 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"value")))
11421 auto last_token = get_token_string();
11422 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
11423 exception_message(input_format, concat(
"expected '#' after type information; last byte: 0x", last_token),
"size"),
nullptr));
11426 const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
11427 if (input_format == input_format_t::bjdata && is_ndarray)
11429 if (inside_ndarray)
11431 return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
11432 exception_message(input_format,
"ndarray can not be recursive",
"size"),
nullptr));
11434 result.second |= (1 << 8);
11439 if (current ==
'#')
11441 const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
11442 if (input_format == input_format_t::bjdata && is_ndarray)
11444 return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
11445 exception_message(input_format,
"ndarray requires both type and size",
"size"),
nullptr));
11457 bool get_ubjson_value(
const char_int_type prefix)
11461 case char_traits<char_type>::eof():
11462 return unexpect_eof(input_format,
"value");
11465 return sax->boolean(
true);
11467 return sax->boolean(
false);
11470 return sax->null();
11474 std::uint8_t number{};
11475 return get_number(input_format, number) && sax->number_unsigned(number);
11480 std::int8_t number{};
11481 return get_number(input_format, number) && sax->number_integer(number);
11486 std::int16_t number{};
11487 return get_number(input_format, number) && sax->number_integer(number);
11492 std::int32_t number{};
11493 return get_number(input_format, number) && sax->number_integer(number);
11498 std::int64_t number{};
11499 return get_number(input_format, number) && sax->number_integer(number);
11504 if (input_format != input_format_t::bjdata)
11508 std::uint16_t number{};
11509 return get_number(input_format, number) && sax->number_unsigned(number);
11514 if (input_format != input_format_t::bjdata)
11518 std::uint32_t number{};
11519 return get_number(input_format, number) && sax->number_unsigned(number);
11524 if (input_format != input_format_t::bjdata)
11528 std::uint64_t number{};
11529 return get_number(input_format, number) && sax->number_unsigned(number);
11534 if (input_format != input_format_t::bjdata)
11538 const auto byte1_raw = get();
11539 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
11543 const auto byte2_raw = get();
11544 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
11549 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
11550 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
11560 const auto half =
static_cast<unsigned int>((byte2 << 8u) + byte1);
11561 const double val = [&half]
11563 const int exp = (half >> 10u) & 0x1Fu;
11564 const unsigned int mant = half & 0x3FFu;
11565 JSON_ASSERT(0 <= exp&& exp <= 32);
11566 JSON_ASSERT(mant <= 1024);
11570 return std::ldexp(mant, -24);
11573 ? std::numeric_limits<double>::infinity()
11574 : std::numeric_limits<double>::quiet_NaN();
11576 return std::ldexp(mant + 1024, exp - 25);
11579 return sax->number_float((half & 0x8000u) != 0
11580 ?
static_cast<number_float_t
>(-val)
11581 :
static_cast<number_float_t
>(val),
"");
11587 return get_number(input_format, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
11593 return get_number(input_format, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
11598 return get_ubjson_high_precision_number();
11604 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"char")))
11608 if (JSON_HEDLEY_UNLIKELY(current > 127))
11610 auto last_token = get_token_string();
11611 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
11612 exception_message(input_format, concat(
"byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token),
"char"),
nullptr));
11614 string_t s(1,
static_cast<typename string_t::value_type
>(current));
11615 return sax->string(s);
11621 return get_ubjson_string(s) && sax->string(s);
11625 return get_ubjson_array();
11628 return get_ubjson_object();
11633 auto last_token = get_token_string();
11634 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));
11640 bool get_ubjson_array()
11642 std::pair<std::size_t, char_int_type> size_and_type;
11643 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
11651 if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
11653 size_and_type.second &= ~(
static_cast<char_int_type
>(1) << 8);
11654 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)
11656 return p.first < t;
11658 string_t
key =
"_ArrayType_";
11659 if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second))
11661 auto last_token = get_token_string();
11662 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
11663 exception_message(input_format,
"invalid byte: 0x" + last_token,
"type"),
nullptr));
11666 string_t type = it->second;
11667 if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type)))
11672 if (size_and_type.second ==
'C')
11674 size_and_type.second =
'U';
11677 key =
"_ArrayData_";
11678 if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->start_array(size_and_type.first) ))
11683 for (std::size_t i = 0; i < size_and_type.first; ++i)
11685 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
11691 return (sax->end_array() && sax->end_object());
11694 if (size_and_type.first != npos)
11696 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
11701 if (size_and_type.second != 0)
11703 if (size_and_type.second !=
'N')
11705 for (std::size_t i = 0; i < size_and_type.first; ++i)
11707 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
11716 for (std::size_t i = 0; i < size_and_type.first; ++i)
11718 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
11727 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(
static_cast<std::size_t
>(-1))))
11732 while (current !=
']')
11734 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(
false)))
11742 return sax->end_array();
11748 bool get_ubjson_object()
11750 std::pair<std::size_t, char_int_type> size_and_type;
11751 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
11757 if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
11759 auto last_token = get_token_string();
11760 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
11761 exception_message(input_format,
"BJData object does not support ND-array size in optimized format",
"object"),
nullptr));
11765 if (size_and_type.first != npos)
11767 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))
11772 if (size_and_type.second != 0)
11774 for (std::size_t i = 0; i < size_and_type.first; ++i)
11776 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
11780 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
11789 for (std::size_t i = 0; i < size_and_type.first; ++i)
11791 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
11795 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
11805 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(
static_cast<std::size_t
>(-1))))
11810 while (current !=
'}')
11812 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key,
false) || !sax->key(key)))
11816 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
11825 return sax->end_object();
11831 bool get_ubjson_high_precision_number()
11834 std::size_t size{};
11835 bool no_ndarray =
true;
11836 auto res = get_ubjson_size_value(size, no_ndarray);
11837 if (JSON_HEDLEY_UNLIKELY(!res))
11843 std::vector<char> number_vector;
11844 for (std::size_t i = 0; i < size; ++i)
11847 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
11851 number_vector.push_back(
static_cast<char>(current));
11855 using ia_type =
decltype(detail::input_adapter(number_vector));
11857 const auto result_number = number_lexer.scan();
11858 const auto number_string = number_lexer.get_token_string();
11859 const auto result_remainder = number_lexer.scan();
11863 if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
11865 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
11866 exception_message(input_format, concat(
"invalid number text: ", number_lexer.get_token_string()),
"high-precision number"),
nullptr));
11869 switch (result_number)
11871 case token_type::value_integer:
11872 return sax->number_integer(number_lexer.get_number_integer());
11873 case token_type::value_unsigned:
11874 return sax->number_unsigned(number_lexer.get_number_unsigned());
11875 case token_type::value_float:
11876 return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
11877 case token_type::uninitialized:
11878 case token_type::literal_true:
11879 case token_type::literal_false:
11880 case token_type::literal_null:
11881 case token_type::value_string:
11882 case token_type::begin_array:
11883 case token_type::begin_object:
11884 case token_type::end_array:
11885 case token_type::end_object:
11886 case token_type::name_separator:
11887 case token_type::value_separator:
11888 case token_type::parse_error:
11889 case token_type::end_of_input:
11890 case token_type::literal_or_value:
11892 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
11893 exception_message(input_format, concat(
"invalid number text: ", number_lexer.get_token_string()),
"high-precision number"),
nullptr));
11910 char_int_type get()
11913 return current = ia.get_character();
11919 char_int_type get_ignore_noop()
11925 while (current ==
'N');
11945 template<
typename NumberType,
bool InputIsLittleEndian = false>
11946 bool get_number(
const input_format_t format, NumberType& result)
11949 std::array<std::uint8_t,
sizeof(NumberType)> vec{};
11950 for (std::size_t i = 0; i <
sizeof(NumberType); ++i)
11953 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"number")))
11959 if (is_little_endian != (InputIsLittleEndian || format == input_format_t::bjdata))
11961 vec[
sizeof(NumberType) - i - 1] =
static_cast<std::uint8_t
>(current);
11965 vec[i] =
static_cast<std::uint8_t
>(current);
11970 std::memcpy(&result, vec.data(),
sizeof(NumberType));
11988 template<
typename NumberType>
11989 bool get_string(
const input_format_t format,
11990 const NumberType len,
11993 bool success =
true;
11994 for (NumberType i = 0; i < len; i++)
11997 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"string")))
12002 result.push_back(
static_cast<typename string_t::value_type
>(current));
12021 template<
typename NumberType>
12022 bool get_binary(
const input_format_t format,
12023 const NumberType len,
12026 bool success =
true;
12027 for (NumberType i = 0; i < len; i++)
12030 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"binary")))
12035 result.push_back(
static_cast<std::uint8_t
>(current));
12045 JSON_HEDLEY_NON_NULL(3)
12046 bool unexpect_eof(const input_format_t format, const
char* context)
const
12048 if (JSON_HEDLEY_UNLIKELY(current == char_traits<char_type>::eof()))
12050 return sax->parse_error(chars_read,
"<end of file>",
12051 parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context),
nullptr));
12059 std::string get_token_string()
const
12061 std::array<char, 3> cr{{}};
12062 static_cast<void>((std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(current)));
12063 return std::string{cr.data()};
12072 std::string exception_message(
const input_format_t format,
12073 const std::string&
detail,
12074 const std::string& context)
const
12076 std::string error_msg =
"syntax error while parsing ";
12080 case input_format_t::cbor:
12081 error_msg +=
"CBOR";
12084 case input_format_t::msgpack:
12085 error_msg +=
"MessagePack";
12088 case input_format_t::ubjson:
12089 error_msg +=
"UBJSON";
12092 case input_format_t::bson:
12093 error_msg +=
"BSON";
12096 case input_format_t::bjdata:
12097 error_msg +=
"BJData";
12100 case input_format_t::json:
12102 JSON_ASSERT(
false);
12105 return concat(error_msg,
' ', context,
": ",
detail);
12109 static JSON_INLINE_VARIABLE
constexpr std::size_t npos =
static_cast<std::size_t
>(-1);
12112 InputAdapterType ia;
12115 char_int_type current = char_traits<char_type>::eof();
12118 std::size_t chars_read = 0;
12121 const bool is_little_endian = little_endianness();
12127 json_sax_t* sax =
nullptr;
12130#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ \
12131 make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
12133#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
12134 make_array<bjd_type>( \
12135 bjd_type{'C', "char"}, \
12136 bjd_type{'D', "double"}, \
12137 bjd_type{'I', "int16"}, \
12138 bjd_type{'L', "int64"}, \
12139 bjd_type{'M', "uint64"}, \
12140 bjd_type{'U', "uint8"}, \
12141 bjd_type{'d', "single"}, \
12142 bjd_type{'i', "int8"}, \
12143 bjd_type{'l', "int32"}, \
12144 bjd_type{'m', "uint32"}, \
12145 bjd_type{'u', "uint16"})
12147 JSON_PRIVATE_UNLESS_TESTED:
12150 const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers =
12151 JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_;
12153 using bjd_type = std::pair<char_int_type, string_t>;
12155 const decltype(JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_) bjd_types_map =
12156 JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_;
12158#undef JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_
12159#undef JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_
12162#ifndef JSON_HAS_CPP_17
12163 template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX>
12164 constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos;
12168NLOHMANN_JSON_NAMESPACE_END
12187#include <functional>
12209NLOHMANN_JSON_NAMESPACE_BEGIN
12232template<
typename BasicJsonType>
12233using parser_callback_t =
12234 std::function<bool(
int , parse_event_t , BasicJsonType& )>;
12241template<
typename BasicJsonType,
typename InputAdapterType>
12244 using number_integer_t =
typename BasicJsonType::number_integer_t;
12245 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
12246 using number_float_t =
typename BasicJsonType::number_float_t;
12247 using string_t =
typename BasicJsonType::string_t;
12249 using token_type =
typename lexer_t::token_type;
12254 const parser_callback_t<BasicJsonType> cb =
nullptr,
12255 const bool allow_exceptions_ =
true,
12256 const bool skip_comments =
false)
12258 , m_lexer(std::move(adapter), skip_comments)
12259 , allow_exceptions(allow_exceptions_)
12275 void parse(
const bool strict, BasicJsonType& result)
12280 sax_parse_internal(&sdp);
12283 if (
strict && (get_token() != token_type::end_of_input))
12285 sdp.parse_error(m_lexer.get_position(),
12286 m_lexer.get_token_string(),
12287 parse_error::create(101, m_lexer.get_position(),
12288 exception_message(token_type::end_of_input,
"value"),
nullptr));
12292 if (sdp.is_errored())
12294 result = value_t::discarded;
12300 if (result.is_discarded())
12308 sax_parse_internal(&sdp);
12311 if (
strict && (get_token() != token_type::end_of_input))
12313 sdp.parse_error(m_lexer.get_position(),
12314 m_lexer.get_token_string(),
12315 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"),
nullptr));
12319 if (sdp.is_errored())
12321 result = value_t::discarded;
12326 result.assert_invariant();
12338 return sax_parse(&sax_acceptor,
strict);
12341 template<
typename SAX>
12342 JSON_HEDLEY_NON_NULL(2)
12343 bool sax_parse(SAX* sax, const
bool strict = true)
12346 const bool result = sax_parse_internal(sax);
12349 if (result && strict && (get_token() != token_type::end_of_input))
12351 return sax->parse_error(m_lexer.get_position(),
12352 m_lexer.get_token_string(),
12353 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"),
nullptr));
12360 template<
typename SAX>
12361 JSON_HEDLEY_NON_NULL(2)
12362 bool sax_parse_internal(SAX* sax)
12366 std::vector<bool> states;
12368 bool skip_to_state_evaluation =
false;
12372 if (!skip_to_state_evaluation)
12375 switch (last_token)
12377 case token_type::begin_object:
12379 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(
static_cast<std::size_t
>(-1))))
12385 if (get_token() == token_type::end_object)
12387 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
12395 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
12397 return sax->parse_error(m_lexer.get_position(),
12398 m_lexer.get_token_string(),
12399 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"),
nullptr));
12401 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
12407 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
12409 return sax->parse_error(m_lexer.get_position(),
12410 m_lexer.get_token_string(),
12411 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"),
nullptr));
12415 states.push_back(
false);
12422 case token_type::begin_array:
12424 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(
static_cast<std::size_t
>(-1))))
12430 if (get_token() == token_type::end_array)
12432 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
12440 states.push_back(
true);
12446 case token_type::value_float:
12448 const auto res = m_lexer.get_number_float();
12450 if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))
12452 return sax->parse_error(m_lexer.get_position(),
12453 m_lexer.get_token_string(),
12454 out_of_range::create(406, concat(
"number overflow parsing '", m_lexer.get_token_string(),
'\''),
nullptr));
12457 if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
12465 case token_type::literal_false:
12467 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
false)))
12474 case token_type::literal_null:
12476 if (JSON_HEDLEY_UNLIKELY(!sax->null()))
12483 case token_type::literal_true:
12485 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
true)))
12492 case token_type::value_integer:
12494 if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer())))
12501 case token_type::value_string:
12503 if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))
12510 case token_type::value_unsigned:
12512 if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned())))
12519 case token_type::parse_error:
12522 return sax->parse_error(m_lexer.get_position(),
12523 m_lexer.get_token_string(),
12524 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized,
"value"),
nullptr));
12526 case token_type::end_of_input:
12528 if (JSON_HEDLEY_UNLIKELY(m_lexer.get_position().chars_read_total == 1))
12530 return sax->parse_error(m_lexer.get_position(),
12531 m_lexer.get_token_string(),
12532 parse_error::create(101, m_lexer.get_position(),
12533 "attempting to parse an empty input; check that your input string or stream contains the expected JSON",
nullptr));
12536 return sax->parse_error(m_lexer.get_position(),
12537 m_lexer.get_token_string(),
12538 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value,
"value"),
nullptr));
12540 case token_type::uninitialized:
12541 case token_type::end_array:
12542 case token_type::end_object:
12543 case token_type::name_separator:
12544 case token_type::value_separator:
12545 case token_type::literal_or_value:
12548 return sax->parse_error(m_lexer.get_position(),
12549 m_lexer.get_token_string(),
12550 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value,
"value"),
nullptr));
12556 skip_to_state_evaluation =
false;
12560 if (states.empty())
12569 if (get_token() == token_type::value_separator)
12577 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
12579 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
12588 JSON_ASSERT(!states.empty());
12590 skip_to_state_evaluation =
true;
12594 return sax->parse_error(m_lexer.get_position(),
12595 m_lexer.get_token_string(),
12596 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array,
"array"),
nullptr));
12602 if (get_token() == token_type::value_separator)
12605 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
12607 return sax->parse_error(m_lexer.get_position(),
12608 m_lexer.get_token_string(),
12609 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"),
nullptr));
12612 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
12618 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
12620 return sax->parse_error(m_lexer.get_position(),
12621 m_lexer.get_token_string(),
12622 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"),
nullptr));
12631 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
12633 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
12642 JSON_ASSERT(!states.empty());
12644 skip_to_state_evaluation =
true;
12648 return sax->parse_error(m_lexer.get_position(),
12649 m_lexer.get_token_string(),
12650 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object,
"object"),
nullptr));
12655 token_type get_token()
12657 return last_token = m_lexer.scan();
12660 std::string exception_message(
const token_type expected,
const std::string& context)
12662 std::string error_msg =
"syntax error ";
12664 if (!context.empty())
12666 error_msg += concat(
"while parsing ", context,
' ');
12671 if (last_token == token_type::parse_error)
12673 error_msg += concat(m_lexer.get_error_message(),
"; last read: '",
12674 m_lexer.get_token_string(),
'\'');
12678 error_msg += concat(
"unexpected ", lexer_t::token_type_name(last_token));
12681 if (expected != token_type::uninitialized)
12683 error_msg += concat(
"; expected ", lexer_t::token_type_name(expected));
12691 const parser_callback_t<BasicJsonType> callback =
nullptr;
12693 token_type last_token = token_type::uninitialized;
12697 const bool allow_exceptions =
true;
12701NLOHMANN_JSON_NAMESPACE_END
12733NLOHMANN_JSON_NAMESPACE_BEGIN
12749 using difference_type = std::ptrdiff_t;
12750 static constexpr difference_type begin_value = 0;
12751 static constexpr difference_type end_value = begin_value + 1;
12753 JSON_PRIVATE_UNLESS_TESTED:
12755 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
12758 constexpr difference_type get_value()
const noexcept
12766 m_it = begin_value;
12778 return m_it == begin_value;
12784 return m_it == end_value;
12789 return lhs.m_it == rhs.m_it;
12792 friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
12794 return lhs.m_it < rhs.m_it;
12797 primitive_iterator_t operator+(difference_type n)
noexcept
12799 auto result = *
this;
12804 friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
12806 return lhs.m_it - rhs.m_it;
12809 primitive_iterator_t& operator++() noexcept
12815 primitive_iterator_t operator++(
int)&
noexcept
12817 auto result = *
this;
12822 primitive_iterator_t& operator--() noexcept
12828 primitive_iterator_t operator--(
int)&
noexcept
12830 auto result = *
this;
12835 primitive_iterator_t& operator+=(difference_type n)
noexcept
12841 primitive_iterator_t& operator-=(difference_type n)
noexcept
12849NLOHMANN_JSON_NAMESPACE_END
12852NLOHMANN_JSON_NAMESPACE_BEGIN
12865 typename BasicJsonType::object_t::iterator object_iterator {};
12867 typename BasicJsonType::array_t::iterator array_iterator {};
12873NLOHMANN_JSON_NAMESPACE_END
12887#include <type_traits>
12904NLOHMANN_JSON_NAMESPACE_BEGIN
12928template<
typename BasicJsonType>
12935 friend BasicJsonType;
12939 using object_t =
typename BasicJsonType::object_t;
12940 using array_t =
typename BasicJsonType::array_t;
12943 "iter_impl only accepts (const) basic_json");
12945 static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value
12946 && std::is_base_of<std::bidirectional_iterator_tag, typename std::iterator_traits<typename array_t::iterator>::iterator_category>::value,
12947 "basic_json iterator assumes array and object type iterators satisfy the LegacyBidirectionalIterator named requirement.");
12962 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
12963 typename BasicJsonType::const_pointer,
12964 typename BasicJsonType::pointer>::type;
12967 typename std::conditional<std::is_const<BasicJsonType>::value,
12968 typename BasicJsonType::const_reference,
12969 typename BasicJsonType::reference>::type;
12984 JSON_ASSERT(m_object !=
nullptr);
12986 switch (m_object->m_data.m_type)
12988 case value_t::object:
12990 m_it.object_iterator =
typename object_t::iterator();
12994 case value_t::array:
12996 m_it.array_iterator =
typename array_t::iterator();
13000 case value_t::null:
13001 case value_t::string:
13002 case value_t::boolean:
13003 case value_t::number_integer:
13004 case value_t::number_unsigned:
13005 case value_t::number_float:
13006 case value_t::binary:
13007 case value_t::discarded:
13033 : m_object(other.m_object), m_it(other.m_it)
13044 if (&other !=
this)
13046 m_object = other.m_object;
13058 : m_object(other.m_object), m_it(other.m_it)
13069 m_object = other.m_object;
13074 JSON_PRIVATE_UNLESS_TESTED:
13079 void set_begin() noexcept
13081 JSON_ASSERT(m_object !=
nullptr);
13083 switch (m_object->m_data.m_type)
13085 case value_t::object:
13087 m_it.object_iterator = m_object->m_data.m_value.object->begin();
13091 case value_t::array:
13093 m_it.array_iterator = m_object->m_data.m_value.array->begin();
13097 case value_t::null:
13100 m_it.primitive_iterator.set_end();
13104 case value_t::string:
13105 case value_t::boolean:
13106 case value_t::number_integer:
13107 case value_t::number_unsigned:
13108 case value_t::number_float:
13109 case value_t::binary:
13110 case value_t::discarded:
13113 m_it.primitive_iterator.set_begin();
13125 JSON_ASSERT(m_object !=
nullptr);
13127 switch (m_object->m_data.m_type)
13129 case value_t::object:
13131 m_it.object_iterator = m_object->m_data.m_value.object->end();
13135 case value_t::array:
13137 m_it.array_iterator = m_object->m_data.m_value.array->end();
13141 case value_t::null:
13142 case value_t::string:
13143 case value_t::boolean:
13144 case value_t::number_integer:
13145 case value_t::number_unsigned:
13146 case value_t::number_float:
13147 case value_t::binary:
13148 case value_t::discarded:
13151 m_it.primitive_iterator.set_end();
13164 JSON_ASSERT(m_object !=
nullptr);
13166 switch (m_object->m_data.m_type)
13168 case value_t::object:
13170 JSON_ASSERT(m_it.object_iterator != m_object->m_data.m_value.object->end());
13171 return m_it.object_iterator->second;
13174 case value_t::array:
13176 JSON_ASSERT(m_it.array_iterator != m_object->m_data.m_value.array->end());
13177 return *m_it.array_iterator;
13180 case value_t::null:
13181 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13183 case value_t::string:
13184 case value_t::boolean:
13185 case value_t::number_integer:
13186 case value_t::number_unsigned:
13187 case value_t::number_float:
13188 case value_t::binary:
13189 case value_t::discarded:
13192 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
13197 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13208 JSON_ASSERT(m_object !=
nullptr);
13210 switch (m_object->m_data.m_type)
13212 case value_t::object:
13214 JSON_ASSERT(m_it.object_iterator != m_object->m_data.m_value.object->end());
13215 return &(m_it.object_iterator->second);
13218 case value_t::array:
13220 JSON_ASSERT(m_it.array_iterator != m_object->m_data.m_value.array->end());
13221 return &*m_it.array_iterator;
13224 case value_t::null:
13225 case value_t::string:
13226 case value_t::boolean:
13227 case value_t::number_integer:
13228 case value_t::number_unsigned:
13229 case value_t::number_float:
13230 case value_t::binary:
13231 case value_t::discarded:
13234 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
13239 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13250 auto result = *
this;
13261 JSON_ASSERT(m_object !=
nullptr);
13263 switch (m_object->m_data.m_type)
13265 case value_t::object:
13267 std::advance(m_it.object_iterator, 1);
13271 case value_t::array:
13273 std::advance(m_it.array_iterator, 1);
13277 case value_t::null:
13278 case value_t::string:
13279 case value_t::boolean:
13280 case value_t::number_integer:
13281 case value_t::number_unsigned:
13282 case value_t::number_float:
13283 case value_t::binary:
13284 case value_t::discarded:
13287 ++m_it.primitive_iterator;
13301 auto result = *
this;
13312 JSON_ASSERT(m_object !=
nullptr);
13314 switch (m_object->m_data.m_type)
13316 case value_t::object:
13318 std::advance(m_it.object_iterator, -1);
13322 case value_t::array:
13324 std::advance(m_it.array_iterator, -1);
13328 case value_t::null:
13329 case value_t::string:
13330 case value_t::boolean:
13331 case value_t::number_integer:
13332 case value_t::number_unsigned:
13333 case value_t::number_float:
13334 case value_t::binary:
13335 case value_t::discarded:
13338 --m_it.primitive_iterator;
13350 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 >
13354 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
13356 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", m_object));
13359 JSON_ASSERT(m_object !=
nullptr);
13361 switch (m_object->m_data.m_type)
13363 case value_t::object:
13364 return (m_it.object_iterator == other.m_it.object_iterator);
13366 case value_t::array:
13367 return (m_it.array_iterator == other.m_it.array_iterator);
13369 case value_t::null:
13370 case value_t::string:
13371 case value_t::boolean:
13372 case value_t::number_integer:
13373 case value_t::number_unsigned:
13374 case value_t::number_float:
13375 case value_t::binary:
13376 case value_t::discarded:
13378 return (m_it.primitive_iterator == other.m_it.primitive_iterator);
13386 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 >
13389 return !operator==(other);
13399 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
13401 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", m_object));
13404 JSON_ASSERT(m_object !=
nullptr);
13406 switch (m_object->m_data.m_type)
13408 case value_t::object:
13409 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators", m_object));
13411 case value_t::array:
13412 return (m_it.array_iterator < other.
m_it.array_iterator);
13414 case value_t::null:
13415 case value_t::string:
13416 case value_t::boolean:
13417 case value_t::number_integer:
13418 case value_t::number_unsigned:
13419 case value_t::number_float:
13420 case value_t::binary:
13421 case value_t::discarded:
13423 return (m_it.primitive_iterator < other.
m_it.primitive_iterator);
13433 return !other.operator < (*this);
13442 return !operator<=(other);
13451 return !operator<(other);
13460 JSON_ASSERT(m_object !=
nullptr);
13462 switch (m_object->m_data.m_type)
13464 case value_t::object:
13465 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", m_object));
13467 case value_t::array:
13469 std::advance(m_it.array_iterator, i);
13473 case value_t::null:
13474 case value_t::string:
13475 case value_t::boolean:
13476 case value_t::number_integer:
13477 case value_t::number_unsigned:
13478 case value_t::number_float:
13479 case value_t::binary:
13480 case value_t::discarded:
13483 m_it.primitive_iterator += i;
13497 return operator+=(-i);
13506 auto result = *
this;
13528 auto result = *
this;
13539 JSON_ASSERT(m_object !=
nullptr);
13541 switch (m_object->m_data.m_type)
13543 case value_t::object:
13544 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", m_object));
13546 case value_t::array:
13547 return m_it.array_iterator - other.
m_it.array_iterator;
13549 case value_t::null:
13550 case value_t::string:
13551 case value_t::boolean:
13552 case value_t::number_integer:
13553 case value_t::number_unsigned:
13554 case value_t::number_float:
13555 case value_t::binary:
13556 case value_t::discarded:
13558 return m_it.primitive_iterator - other.
m_it.primitive_iterator;
13568 JSON_ASSERT(m_object !=
nullptr);
13570 switch (m_object->m_data.m_type)
13572 case value_t::object:
13573 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators", m_object));
13575 case value_t::array:
13576 return *std::next(m_it.array_iterator, n);
13578 case value_t::null:
13579 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13581 case value_t::string:
13582 case value_t::boolean:
13583 case value_t::number_integer:
13584 case value_t::number_unsigned:
13585 case value_t::number_float:
13586 case value_t::binary:
13587 case value_t::discarded:
13590 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n))
13595 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13604 const typename object_t::key_type&
key()
const
13606 JSON_ASSERT(m_object !=
nullptr);
13608 if (JSON_HEDLEY_LIKELY(m_object->is_object()))
13610 return m_it.object_iterator->first;
13613 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators", m_object));
13622 return operator*();
13625 JSON_PRIVATE_UNLESS_TESTED:
13627 pointer m_object =
nullptr;
13633NLOHMANN_JSON_NAMESPACE_END
13655NLOHMANN_JSON_NAMESPACE_BEGIN
13681template<
typename Base>
13685 using difference_type = std::ptrdiff_t;
13749 return *(this->operator+(n));
13753 auto key() const -> decltype(std::declval<Base>().key())
13755 auto it = --this->base();
13762 auto it = --this->base();
13763 return it.operator * ();
13768NLOHMANN_JSON_NAMESPACE_END
13783#include <type_traits>
13788NLOHMANN_JSON_NAMESPACE_BEGIN
13805using json_base_class =
typename std::conditional <
13806 std::is_same<T, void>::value,
13812NLOHMANN_JSON_NAMESPACE_END
13825#include <algorithm>
13849NLOHMANN_JSON_NAMESPACE_BEGIN
13853template<
typename RefStringType>
13857 NLOHMANN_BASIC_JSON_TPL_DECLARATION
13863 template<
typename T>
13864 struct string_t_helper
13869 NLOHMANN_BASIC_JSON_TPL_DECLARATION
13870 struct string_t_helper<NLOHMANN_BASIC_JSON_TPL>
13872 using type = StringType;
13877 using string_t =
typename string_t_helper<RefStringType>::type;
13882 : reference_tokens(split(s))
13889 return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
13891 [](
const string_t& a,
const string_t& b)
13893 return detail::concat(a,
'/', detail::escape(b));
13899 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, to_string())
13900 operator string_t()
const
13902 return to_string();
13919 reference_tokens.insert(reference_tokens.end(),
13920 ptr.reference_tokens.begin(),
13921 ptr.reference_tokens.end());
13929 push_back(std::move(token));
13937 return *
this /= std::to_string(array_idx);
13980 if (JSON_HEDLEY_UNLIKELY(empty()))
13982 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
13985 reference_tokens.pop_back();
13992 if (JSON_HEDLEY_UNLIKELY(empty()))
13994 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
13997 return reference_tokens.back();
14004 reference_tokens.push_back(token);
14011 reference_tokens.push_back(std::move(token));
14018 return reference_tokens.empty();
14032 template<
typename BasicJsonType>
14033 static typename BasicJsonType::size_type array_index(
const string_t& s)
14035 using size_type =
typename BasicJsonType::size_type;
14038 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] ==
'0'))
14044 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >=
'1' && s[0] <=
'9')))
14049 const char* p = s.c_str();
14050 char* p_end =
nullptr;
14052 const unsigned long long res = std::strtoull(p, &p_end, 10);
14055 || JSON_HEDLEY_UNLIKELY(
static_cast<std::size_t
>(p_end - p) != s.size()))
14057 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", s,
"'"),
nullptr));
14062 if (res >=
static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))
14064 JSON_THROW(detail::out_of_range::create(410, detail::concat(
"array index ", s,
" exceeds size_type"),
nullptr));
14067 return static_cast<size_type
>(res);
14070 JSON_PRIVATE_UNLESS_TESTED:
14073 if (JSON_HEDLEY_UNLIKELY(empty()))
14075 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
14079 result.reference_tokens = {reference_tokens[0]};
14092 template<
typename BasicJsonType>
14093 BasicJsonType& get_and_create(BasicJsonType& j)
const
14099 for (
const auto& reference_token : reference_tokens)
14101 switch (result->type())
14105 if (reference_token ==
"0")
14108 result = &result->operator[](0);
14113 result = &result->operator[](reference_token);
14121 result = &result->operator[](reference_token);
14128 result = &result->operator[](array_index<BasicJsonType>(reference_token));
14146 JSON_THROW(detail::type_error::create(313,
"invalid value to unflatten", &j));
14172 template<
typename BasicJsonType>
14173 BasicJsonType& get_unchecked(BasicJsonType* ptr)
const
14175 for (
const auto& reference_token : reference_tokens)
14178 if (ptr->is_null())
14182 std::all_of(reference_token.begin(), reference_token.end(),
14183 [](
const unsigned char x)
14185 return std::isdigit(x);
14189 *ptr = (nums || reference_token ==
"-")
14194 switch (ptr->type())
14199 ptr = &ptr->operator[](reference_token);
14205 if (reference_token ==
"-")
14208 ptr = &ptr->operator[](ptr->m_data.m_value.array->size());
14213 ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));
14227 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
14240 template<
typename BasicJsonType>
14241 BasicJsonType& get_checked(BasicJsonType* ptr)
const
14243 for (
const auto& reference_token : reference_tokens)
14245 switch (ptr->type())
14250 ptr = &ptr->at(reference_token);
14256 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
14259 JSON_THROW(detail::out_of_range::create(402, detail::concat(
14260 "array index '-' (", std::to_string(ptr->m_data.m_value.array->size()),
14261 ") is out of range"), ptr));
14265 ptr = &ptr->at(array_index<BasicJsonType>(reference_token));
14278 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
14298 template<
typename BasicJsonType>
14299 const BasicJsonType& get_unchecked(
const BasicJsonType* ptr)
const
14301 for (
const auto& reference_token : reference_tokens)
14303 switch (ptr->type())
14308 ptr = &ptr->operator[](reference_token);
14314 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
14317 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));
14321 ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));
14334 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
14347 template<
typename BasicJsonType>
14348 const BasicJsonType& get_checked(
const BasicJsonType* ptr)
const
14350 for (
const auto& reference_token : reference_tokens)
14352 switch (ptr->type())
14357 ptr = &ptr->at(reference_token);
14363 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
14366 JSON_THROW(detail::out_of_range::create(402, detail::concat(
14367 "array index '-' (", std::to_string(ptr->m_data.m_value.array->size()),
14368 ") is out of range"), ptr));
14372 ptr = &ptr->at(array_index<BasicJsonType>(reference_token));
14385 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
14396 template<
typename BasicJsonType>
14397 bool contains(
const BasicJsonType* ptr)
const
14399 for (
const auto& reference_token : reference_tokens)
14401 switch (ptr->type())
14405 if (!ptr->contains(reference_token))
14411 ptr = &ptr->operator[](reference_token);
14417 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
14422 if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !(
"0" <= reference_token && reference_token <=
"9")))
14427 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
14429 if (JSON_HEDLEY_UNLIKELY(!(
'1' <= reference_token[0] && reference_token[0] <=
'9')))
14434 for (std::size_t i = 1; i < reference_token.size(); i++)
14436 if (JSON_HEDLEY_UNLIKELY(!(
'0' <= reference_token[i] && reference_token[i] <=
'9')))
14444 const auto idx = array_index<BasicJsonType>(reference_token);
14445 if (idx >= ptr->size())
14451 ptr = &ptr->operator[](idx);
14485 static std::vector<string_t> split(
const string_t& reference_string)
14487 std::vector<string_t> result;
14490 if (reference_string.empty())
14496 if (JSON_HEDLEY_UNLIKELY(reference_string[0] !=
'/'))
14498 JSON_THROW(
detail::parse_error::create(107, 1, detail::concat(
"JSON pointer must be empty or begin with '/' - was: '", reference_string,
"'"),
nullptr));
14506 std::size_t slash = reference_string.find_first_of(
'/', 1),
14513 start = (slash == string_t::npos) ? 0 : slash + 1,
14515 slash = reference_string.find_first_of(
'/', start))
14519 auto reference_token = reference_string.substr(start, slash - start);
14522 for (std::size_t pos = reference_token.find_first_of(
'~');
14523 pos != string_t::npos;
14524 pos = reference_token.find_first_of(
'~', pos + 1))
14526 JSON_ASSERT(reference_token[pos] ==
'~');
14529 if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
14530 (reference_token[pos + 1] !=
'0' &&
14531 reference_token[pos + 1] !=
'1')))
14538 detail::unescape(reference_token);
14539 result.push_back(reference_token);
14553 template<
typename BasicJsonType>
14554 static void flatten(
const string_t& reference_string,
14555 const BasicJsonType& value,
14556 BasicJsonType& result)
14558 switch (
value.type())
14562 if (
value.m_data.m_value.array->empty())
14565 result[reference_string] =
nullptr;
14570 for (std::size_t i = 0; i <
value.m_data.m_value.array->size(); ++i)
14572 flatten(detail::concat(reference_string,
'/', std::to_string(i)),
14573 value.m_data.m_value.array->operator[](i), result);
14581 if (
value.m_data.m_value.object->empty())
14584 result[reference_string] =
nullptr;
14589 for (
const auto& element : *
value.m_data.m_value.object)
14591 flatten(detail::concat(reference_string,
'/',
detail::escape(element.first)), element.second, result);
14608 result[reference_string] =
value;
14624 template<
typename BasicJsonType>
14625 static BasicJsonType
14626 unflatten(
const BasicJsonType& value)
14628 if (JSON_HEDLEY_UNLIKELY(!
value.is_object()))
14630 JSON_THROW(detail::type_error::create(314,
"only objects can be unflattened", &value));
14633 BasicJsonType result;
14636 for (
const auto& element : *
value.m_data.m_value.object)
14638 if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
14640 JSON_THROW(detail::type_error::create(315,
"values in object must be primitive", &element.second));
14647 json_pointer(element.first).get_and_create(result) = element.second;
14657 result.reference_tokens = reference_tokens;
14664 result.reference_tokens = std::move(reference_tokens);
14669#if JSON_HAS_THREE_WAY_COMPARISON
14672 template<
typename RefStringTypeRhs>
14675 return reference_tokens == rhs.reference_tokens;
14680 JSON_HEDLEY_DEPRECATED_FOR(3.11.2,
operator==(
json_pointer))
14681 bool operator==(
const string_t& rhs)
const
14687 template<
typename RefStringTypeRhs>
14690 return reference_tokens <=> rhs.reference_tokens;
14695 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14702 template<
typename RefStringTypeLhs,
typename StringType>
14705 const StringType& rhs);
14709 template<
typename RefStringTypeRhs,
typename StringType>
14711 friend bool operator==(
const StringType& lhs,
14716 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14723 template<
typename RefStringTypeLhs,
typename StringType>
14726 const StringType& rhs);
14730 template<
typename RefStringTypeRhs,
typename StringType>
14732 friend bool operator!=(
const StringType& lhs,
14736 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14744 std::vector<string_t> reference_tokens;
14747#if !JSON_HAS_THREE_WAY_COMPARISON
14749template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14753 return lhs.reference_tokens == rhs.reference_tokens;
14756template<
typename RefStringTypeLhs,
14757 typename StringType =
typename json_pointer<RefStringTypeLhs>::string_t>
14760 const StringType& rhs)
14765template<
typename RefStringTypeRhs,
14766 typename StringType =
typename json_pointer<RefStringTypeRhs>::string_t>
14768inline
bool operator==(const StringType& lhs,
14774template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14778 return !(lhs == rhs);
14781template<
typename RefStringTypeLhs,
14782 typename StringType =
typename json_pointer<RefStringTypeLhs>::string_t>
14785 const StringType& rhs)
14787 return !(lhs == rhs);
14790template<
typename RefStringTypeRhs,
14791 typename StringType =
typename json_pointer<RefStringTypeRhs>::string_t>
14793inline
bool operator!=(const StringType& lhs,
14796 return !(lhs == rhs);
14799template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14803 return lhs.reference_tokens < rhs.reference_tokens;
14807NLOHMANN_JSON_NAMESPACE_END
14820#include <initializer_list>
14828NLOHMANN_JSON_NAMESPACE_BEGIN
14832template<
typename BasicJsonType>
14836 using value_type = BasicJsonType;
14839 : owned_value(std::move(
value))
14843 : value_ref(&
value)
14846 json_ref(std::initializer_list<json_ref> init)
14847 : owned_value(init)
14852 enable_if_t<std::is_constructible<value_type, Args...>::value,
int> = 0 >
14854 : owned_value(std::forward<Args>(args)...)
14864 value_type moved_or_copied()
const
14866 if (value_ref ==
nullptr)
14868 return std::move(owned_value);
14873 value_type
const& operator*()
const
14875 return value_ref ? *value_ref : owned_value;
14878 value_type
const* operator->()
const
14884 mutable value_type owned_value =
nullptr;
14885 value_type
const* value_ref =
nullptr;
14889NLOHMANN_JSON_NAMESPACE_END
14912#include <algorithm>
14938#include <algorithm>
14953NLOHMANN_JSON_NAMESPACE_BEGIN
14960 virtual void write_character(CharType c) = 0;
14961 virtual void write_characters(
const CharType* s, std::size_t length) = 0;
14972template<
typename CharType>
14976template<
typename CharType,
typename AllocatorType = std::allocator<CharType>>
14984 void write_character(CharType c)
override
14989 JSON_HEDLEY_NON_NULL(2)
14990 void write_characters(
const CharType* s, std::size_t length)
override
14992 v.insert(v.end(), s, s + length);
14996 std::vector<CharType, AllocatorType>& v;
15001template<
typename CharType>
15009 void write_character(CharType c)
override
15014 JSON_HEDLEY_NON_NULL(2)
15015 void write_characters(
const CharType* s, std::size_t length)
override
15017 stream.write(s,
static_cast<std::streamsize
>(length));
15021 std::basic_ostream<CharType>& stream;
15026template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
15034 void write_character(CharType c)
override
15039 JSON_HEDLEY_NON_NULL(2)
15040 void write_characters(
const CharType* s, std::size_t length)
override
15042 str.append(s, length);
15049template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
15053 template<
typename AllocatorType = std::allocator<CharType>>
15075NLOHMANN_JSON_NAMESPACE_END
15080NLOHMANN_JSON_NAMESPACE_BEGIN
15091template<
typename BasicJsonType,
typename CharType>
15094 using string_t =
typename BasicJsonType::string_t;
15095 using binary_t =
typename BasicJsonType::binary_t;
15096 using number_float_t =
typename BasicJsonType::number_float_t;
15117 case value_t::object:
15119 write_bson_object(*j.m_data.m_value.object);
15123 case value_t::null:
15124 case value_t::array:
15125 case value_t::string:
15126 case value_t::boolean:
15127 case value_t::number_integer:
15128 case value_t::number_unsigned:
15129 case value_t::number_float:
15130 case value_t::binary:
15131 case value_t::discarded:
15134 JSON_THROW(type_error::create(317, concat(
"to serialize to BSON, top-level type must be object, but is ", j.type_name()), &j));
15146 case value_t::null:
15148 oa->write_character(to_char_type(0xF6));
15152 case value_t::boolean:
15154 oa->write_character(j.m_data.m_value.boolean
15155 ? to_char_type(0xF5)
15156 : to_char_type(0xF4));
15160 case value_t::number_integer:
15162 if (j.m_data.m_value.number_integer >= 0)
15167 if (j.m_data.m_value.number_integer <= 0x17)
15169 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15171 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
15173 oa->write_character(to_char_type(0x18));
15174 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15176 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
15178 oa->write_character(to_char_type(0x19));
15179 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
15181 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
15183 oa->write_character(to_char_type(0x1A));
15184 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
15188 oa->write_character(to_char_type(0x1B));
15189 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
15196 const auto positive_number = -1 - j.m_data.m_value.number_integer;
15197 if (j.m_data.m_value.number_integer >= -24)
15199 write_number(
static_cast<std::uint8_t
>(0x20 + positive_number));
15201 else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
15203 oa->write_character(to_char_type(0x38));
15204 write_number(
static_cast<std::uint8_t
>(positive_number));
15206 else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
15208 oa->write_character(to_char_type(0x39));
15209 write_number(
static_cast<std::uint16_t
>(positive_number));
15211 else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
15213 oa->write_character(to_char_type(0x3A));
15214 write_number(
static_cast<std::uint32_t
>(positive_number));
15218 oa->write_character(to_char_type(0x3B));
15219 write_number(
static_cast<std::uint64_t
>(positive_number));
15225 case value_t::number_unsigned:
15227 if (j.m_data.m_value.number_unsigned <= 0x17)
15229 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_unsigned));
15231 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
15233 oa->write_character(to_char_type(0x18));
15234 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_unsigned));
15236 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
15238 oa->write_character(to_char_type(0x19));
15239 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_unsigned));
15241 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
15243 oa->write_character(to_char_type(0x1A));
15244 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_unsigned));
15248 oa->write_character(to_char_type(0x1B));
15249 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_unsigned));
15254 case value_t::number_float:
15256 if (std::isnan(j.m_data.m_value.number_float))
15259 oa->write_character(to_char_type(0xF9));
15260 oa->write_character(to_char_type(0x7E));
15261 oa->write_character(to_char_type(0x00));
15263 else if (std::isinf(j.m_data.m_value.number_float))
15266 oa->write_character(to_char_type(0xf9));
15267 oa->write_character(j.m_data.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
15268 oa->write_character(to_char_type(0x00));
15272 write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::cbor);
15277 case value_t::string:
15280 const auto N = j.m_data.m_value.string->size();
15283 write_number(
static_cast<std::uint8_t
>(0x60 + N));
15285 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15287 oa->write_character(to_char_type(0x78));
15288 write_number(
static_cast<std::uint8_t
>(N));
15290 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15292 oa->write_character(to_char_type(0x79));
15293 write_number(
static_cast<std::uint16_t
>(N));
15295 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15297 oa->write_character(to_char_type(0x7A));
15298 write_number(
static_cast<std::uint32_t
>(N));
15301 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15303 oa->write_character(to_char_type(0x7B));
15304 write_number(
static_cast<std::uint64_t
>(N));
15309 oa->write_characters(
15310 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
15311 j.m_data.m_value.string->size());
15315 case value_t::array:
15318 const auto N = j.m_data.m_value.array->size();
15321 write_number(
static_cast<std::uint8_t
>(0x80 + N));
15323 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15325 oa->write_character(to_char_type(0x98));
15326 write_number(
static_cast<std::uint8_t
>(N));
15328 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15330 oa->write_character(to_char_type(0x99));
15331 write_number(
static_cast<std::uint16_t
>(N));
15333 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15335 oa->write_character(to_char_type(0x9A));
15336 write_number(
static_cast<std::uint32_t
>(N));
15339 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15341 oa->write_character(to_char_type(0x9B));
15342 write_number(
static_cast<std::uint64_t
>(N));
15347 for (
const auto& el : *j.m_data.m_value.array)
15354 case value_t::binary:
15356 if (j.m_data.m_value.binary->has_subtype())
15358 if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)())
15360 write_number(
static_cast<std::uint8_t
>(0xd8));
15361 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.binary->subtype()));
15363 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint16_t>::max)())
15365 write_number(
static_cast<std::uint8_t
>(0xd9));
15366 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.binary->subtype()));
15368 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint32_t>::max)())
15370 write_number(
static_cast<std::uint8_t
>(0xda));
15371 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.binary->subtype()));
15373 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint64_t>::max)())
15375 write_number(
static_cast<std::uint8_t
>(0xdb));
15376 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.binary->subtype()));
15381 const auto N = j.m_data.m_value.binary->size();
15384 write_number(
static_cast<std::uint8_t
>(0x40 + N));
15386 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15388 oa->write_character(to_char_type(0x58));
15389 write_number(
static_cast<std::uint8_t
>(N));
15391 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15393 oa->write_character(to_char_type(0x59));
15394 write_number(
static_cast<std::uint16_t
>(N));
15396 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15398 oa->write_character(to_char_type(0x5A));
15399 write_number(
static_cast<std::uint32_t
>(N));
15402 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15404 oa->write_character(to_char_type(0x5B));
15405 write_number(
static_cast<std::uint64_t
>(N));
15410 oa->write_characters(
15411 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
15417 case value_t::object:
15420 const auto N = j.m_data.m_value.object->size();
15423 write_number(
static_cast<std::uint8_t
>(0xA0 + N));
15425 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15427 oa->write_character(to_char_type(0xB8));
15428 write_number(
static_cast<std::uint8_t
>(N));
15430 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15432 oa->write_character(to_char_type(0xB9));
15433 write_number(
static_cast<std::uint16_t
>(N));
15435 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15437 oa->write_character(to_char_type(0xBA));
15438 write_number(
static_cast<std::uint32_t
>(N));
15441 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15443 oa->write_character(to_char_type(0xBB));
15444 write_number(
static_cast<std::uint64_t
>(N));
15449 for (
const auto& el : *j.m_data.m_value.object)
15451 write_cbor(el.first);
15452 write_cbor(el.second);
15457 case value_t::discarded:
15470 case value_t::null:
15472 oa->write_character(to_char_type(0xC0));
15476 case value_t::boolean:
15478 oa->write_character(j.m_data.m_value.boolean
15479 ? to_char_type(0xC3)
15480 : to_char_type(0xC2));
15484 case value_t::number_integer:
15486 if (j.m_data.m_value.number_integer >= 0)
15491 if (j.m_data.m_value.number_unsigned < 128)
15494 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15496 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
15499 oa->write_character(to_char_type(0xCC));
15500 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15502 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
15505 oa->write_character(to_char_type(0xCD));
15506 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
15508 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
15511 oa->write_character(to_char_type(0xCE));
15512 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
15514 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
15517 oa->write_character(to_char_type(0xCF));
15518 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
15523 if (j.m_data.m_value.number_integer >= -32)
15526 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.number_integer));
15528 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&
15529 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
15532 oa->write_character(to_char_type(0xD0));
15533 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.number_integer));
15535 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&
15536 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
15539 oa->write_character(to_char_type(0xD1));
15540 write_number(
static_cast<std::int16_t
>(j.m_data.m_value.number_integer));
15542 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&
15543 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
15546 oa->write_character(to_char_type(0xD2));
15547 write_number(
static_cast<std::int32_t
>(j.m_data.m_value.number_integer));
15549 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&
15550 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
15553 oa->write_character(to_char_type(0xD3));
15554 write_number(
static_cast<std::int64_t
>(j.m_data.m_value.number_integer));
15560 case value_t::number_unsigned:
15562 if (j.m_data.m_value.number_unsigned < 128)
15565 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15567 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
15570 oa->write_character(to_char_type(0xCC));
15571 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15573 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
15576 oa->write_character(to_char_type(0xCD));
15577 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
15579 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
15582 oa->write_character(to_char_type(0xCE));
15583 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
15585 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
15588 oa->write_character(to_char_type(0xCF));
15589 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
15594 case value_t::number_float:
15596 write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::msgpack);
15600 case value_t::string:
15603 const auto N = j.m_data.m_value.string->size();
15607 write_number(
static_cast<std::uint8_t
>(0xA0 | N));
15609 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15612 oa->write_character(to_char_type(0xD9));
15613 write_number(
static_cast<std::uint8_t
>(N));
15615 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15618 oa->write_character(to_char_type(0xDA));
15619 write_number(
static_cast<std::uint16_t
>(N));
15621 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15624 oa->write_character(to_char_type(0xDB));
15625 write_number(
static_cast<std::uint32_t
>(N));
15629 oa->write_characters(
15630 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
15631 j.m_data.m_value.string->size());
15635 case value_t::array:
15638 const auto N = j.m_data.m_value.array->size();
15642 write_number(
static_cast<std::uint8_t
>(0x90 | N));
15644 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15647 oa->write_character(to_char_type(0xDC));
15648 write_number(
static_cast<std::uint16_t
>(N));
15650 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15653 oa->write_character(to_char_type(0xDD));
15654 write_number(
static_cast<std::uint32_t
>(N));
15658 for (
const auto& el : *j.m_data.m_value.array)
15665 case value_t::binary:
15669 const bool use_ext = j.m_data.m_value.binary->has_subtype();
15672 const auto N = j.m_data.m_value.binary->size();
15673 if (N <= (std::numeric_limits<std::uint8_t>::max)())
15675 std::uint8_t output_type{};
15682 output_type = 0xD4;
15685 output_type = 0xD5;
15688 output_type = 0xD6;
15691 output_type = 0xD7;
15694 output_type = 0xD8;
15697 output_type = 0xC7;
15705 output_type = 0xC4;
15709 oa->write_character(to_char_type(output_type));
15712 write_number(
static_cast<std::uint8_t
>(N));
15715 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15717 const std::uint8_t output_type = use_ext
15721 oa->write_character(to_char_type(output_type));
15722 write_number(
static_cast<std::uint16_t
>(N));
15724 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15726 const std::uint8_t output_type = use_ext
15730 oa->write_character(to_char_type(output_type));
15731 write_number(
static_cast<std::uint32_t
>(N));
15737 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.binary->subtype()));
15741 oa->write_characters(
15742 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
15748 case value_t::object:
15751 const auto N = j.m_data.m_value.object->size();
15755 write_number(
static_cast<std::uint8_t
>(0x80 | (N & 0xF)));
15757 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15760 oa->write_character(to_char_type(0xDE));
15761 write_number(
static_cast<std::uint16_t
>(N));
15763 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15766 oa->write_character(to_char_type(0xDF));
15767 write_number(
static_cast<std::uint32_t
>(N));
15771 for (
const auto& el : *j.m_data.m_value.object)
15773 write_msgpack(el.first);
15774 write_msgpack(el.second);
15779 case value_t::discarded:
15793 const bool use_type,
const bool add_prefix =
true,
15794 const bool use_bjdata =
false)
15798 case value_t::null:
15802 oa->write_character(to_char_type(
'Z'));
15807 case value_t::boolean:
15811 oa->write_character(j.m_data.m_value.boolean
15812 ? to_char_type(
'T')
15813 : to_char_type(
'F'));
15818 case value_t::number_integer:
15820 write_number_with_ubjson_prefix(j.m_data.m_value.number_integer, add_prefix, use_bjdata);
15824 case value_t::number_unsigned:
15826 write_number_with_ubjson_prefix(j.m_data.m_value.number_unsigned, add_prefix, use_bjdata);
15830 case value_t::number_float:
15832 write_number_with_ubjson_prefix(j.m_data.m_value.number_float, add_prefix, use_bjdata);
15836 case value_t::string:
15840 oa->write_character(to_char_type(
'S'));
15842 write_number_with_ubjson_prefix(j.m_data.m_value.string->size(),
true, use_bjdata);
15843 oa->write_characters(
15844 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
15845 j.m_data.m_value.string->size());
15849 case value_t::array:
15853 oa->write_character(to_char_type(
'['));
15856 bool prefix_required =
true;
15857 if (use_type && !j.m_data.m_value.array->empty())
15859 JSON_ASSERT(use_count);
15860 const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
15861 const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
15862 [
this, first_prefix, use_bjdata](
const BasicJsonType & v)
15864 return ubjson_prefix(v, use_bjdata) == first_prefix;
15867 std::vector<CharType> bjdx = {
'[',
'{',
'S',
'H',
'T',
'F',
'N',
'Z'};
15869 if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
15871 prefix_required =
false;
15872 oa->write_character(to_char_type(
'$'));
15873 oa->write_character(first_prefix);
15879 oa->write_character(to_char_type(
'#'));
15880 write_number_with_ubjson_prefix(j.m_data.m_value.array->size(),
true, use_bjdata);
15883 for (
const auto& el : *j.m_data.m_value.array)
15885 write_ubjson(el, use_count, use_type, prefix_required, use_bjdata);
15890 oa->write_character(to_char_type(
']'));
15896 case value_t::binary:
15900 oa->write_character(to_char_type(
'['));
15903 if (use_type && !j.m_data.m_value.binary->empty())
15905 JSON_ASSERT(use_count);
15906 oa->write_character(to_char_type(
'$'));
15907 oa->write_character(
'U');
15912 oa->write_character(to_char_type(
'#'));
15913 write_number_with_ubjson_prefix(j.m_data.m_value.binary->size(),
true, use_bjdata);
15918 oa->write_characters(
15919 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
15920 j.m_data.m_value.binary->size());
15924 for (
size_t i = 0; i < j.m_data.m_value.binary->size(); ++i)
15926 oa->write_character(to_char_type(
'U'));
15927 oa->write_character(j.m_data.m_value.binary->data()[i]);
15933 oa->write_character(to_char_type(
']'));
15939 case value_t::object:
15941 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())
15943 if (!write_bjdata_ndarray(*j.m_data.m_value.object, use_count, use_type))
15951 oa->write_character(to_char_type(
'{'));
15954 bool prefix_required =
true;
15955 if (use_type && !j.m_data.m_value.object->empty())
15957 JSON_ASSERT(use_count);
15958 const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
15959 const bool same_prefix = std::all_of(j.begin(), j.end(),
15960 [
this, first_prefix, use_bjdata](
const BasicJsonType & v)
15962 return ubjson_prefix(v, use_bjdata) == first_prefix;
15965 std::vector<CharType> bjdx = {
'[',
'{',
'S',
'H',
'T',
'F',
'N',
'Z'};
15967 if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
15969 prefix_required =
false;
15970 oa->write_character(to_char_type(
'$'));
15971 oa->write_character(first_prefix);
15977 oa->write_character(to_char_type(
'#'));
15978 write_number_with_ubjson_prefix(j.m_data.m_value.object->size(),
true, use_bjdata);
15981 for (
const auto& el : *j.m_data.m_value.object)
15983 write_number_with_ubjson_prefix(el.first.size(),
true, use_bjdata);
15984 oa->write_characters(
15985 reinterpret_cast<const CharType*
>(el.first.c_str()),
15987 write_ubjson(el.second, use_count, use_type, prefix_required, use_bjdata);
15992 oa->write_character(to_char_type(
'}'));
15998 case value_t::discarded:
16013 static std::size_t calc_bson_entry_header_size(
const string_t& name,
const BasicJsonType& j)
16015 const auto it = name.find(
static_cast<typename string_t::value_type
>(0));
16016 if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
16018 JSON_THROW(out_of_range::create(409, concat(
"BSON key cannot contain code point U+0000 (at byte ", std::to_string(it),
")"), &j));
16019 static_cast<void>(j);
16022 return 1ul + name.size() + 1u;
16028 void write_bson_entry_header(
const string_t& name,
16029 const std::uint8_t element_type)
16031 oa->write_character(to_char_type(element_type));
16032 oa->write_characters(
16033 reinterpret_cast<const CharType*
>(name.c_str()),
16040 void write_bson_boolean(
const string_t& name,
16043 write_bson_entry_header(name, 0x08);
16044 oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
16050 void write_bson_double(
const string_t& name,
16051 const double value)
16053 write_bson_entry_header(name, 0x01);
16054 write_number<double>(value,
true);
16060 static std::size_t calc_bson_string_size(
const string_t& value)
16062 return sizeof(std::int32_t) +
value.size() + 1ul;
16068 void write_bson_string(
const string_t& name,
16069 const string_t& value)
16071 write_bson_entry_header(name, 0x02);
16073 write_number<std::int32_t>(
static_cast<std::int32_t
>(
value.size() + 1ul),
true);
16074 oa->write_characters(
16075 reinterpret_cast<const CharType*
>(
value.c_str()),
16082 void write_bson_null(
const string_t& name)
16084 write_bson_entry_header(name, 0x0A);
16090 static std::size_t calc_bson_integer_size(
const std::int64_t value)
16092 return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()
16093 ?
sizeof(std::int32_t)
16094 :
sizeof(std::int64_t);
16100 void write_bson_integer(
const string_t& name,
16101 const std::int64_t value)
16103 if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
16105 write_bson_entry_header(name, 0x10);
16106 write_number<std::int32_t>(
static_cast<std::int32_t
>(value),
true);
16110 write_bson_entry_header(name, 0x12);
16111 write_number<std::int64_t>(
static_cast<std::int64_t
>(value),
true);
16118 static constexpr std::size_t calc_bson_unsigned_size(
const std::uint64_t value)
noexcept
16120 return (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16121 ?
sizeof(std::int32_t)
16122 : sizeof(std::int64_t);
16128 void write_bson_unsigned(
const string_t& name,
16129 const BasicJsonType& j)
16131 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16133 write_bson_entry_header(name, 0x10 );
16134 write_number<std::int32_t>(
static_cast<std::int32_t
>(j.m_data.m_value.number_unsigned),
true);
16136 else if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
16138 write_bson_entry_header(name, 0x12 );
16139 write_number<std::int64_t>(
static_cast<std::int64_t
>(j.m_data.m_value.number_unsigned),
true);
16143 JSON_THROW(out_of_range::create(407, concat(
"integer number ", std::to_string(j.m_data.m_value.number_unsigned),
" cannot be represented by BSON as it does not fit int64"), &j));
16150 void write_bson_object_entry(
const string_t& name,
16151 const typename BasicJsonType::object_t& value)
16153 write_bson_entry_header(name, 0x03);
16154 write_bson_object(value);
16160 static std::size_t calc_bson_array_size(
const typename BasicJsonType::array_t& value)
16162 std::size_t array_index = 0ul;
16164 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)
16166 return result + calc_bson_element_size(std::to_string(array_index++), el);
16169 return sizeof(std::int32_t) + embedded_document_size + 1ul;
16175 static std::size_t calc_bson_binary_size(
const typename BasicJsonType::binary_t& value)
16177 return sizeof(std::int32_t) +
value.size() + 1ul;
16183 void write_bson_array(
const string_t& name,
16184 const typename BasicJsonType::array_t& value)
16186 write_bson_entry_header(name, 0x04);
16187 write_number<std::int32_t>(
static_cast<std::int32_t
>(calc_bson_array_size(value)),
true);
16189 std::size_t array_index = 0ul;
16191 for (
const auto& el : value)
16193 write_bson_element(std::to_string(array_index++), el);
16196 oa->write_character(to_char_type(0x00));
16202 void write_bson_binary(
const string_t& name,
16203 const binary_t& value)
16205 write_bson_entry_header(name, 0x05);
16207 write_number<std::int32_t>(
static_cast<std::int32_t
>(
value.size()),
true);
16208 write_number(
value.has_subtype() ?
static_cast<std::uint8_t
>(
value.subtype()) :
static_cast<std::uint8_t
>(0x00));
16210 oa->write_characters(
reinterpret_cast<const CharType*
>(
value.data()),
value.size());
16217 static std::size_t calc_bson_element_size(
const string_t& name,
16218 const BasicJsonType& j)
16220 const auto header_size = calc_bson_entry_header_size(name, j);
16223 case value_t::object:
16224 return header_size + calc_bson_object_size(*j.m_data.m_value.object);
16226 case value_t::array:
16227 return header_size + calc_bson_array_size(*j.m_data.m_value.array);
16229 case value_t::binary:
16230 return header_size + calc_bson_binary_size(*j.m_data.m_value.binary);
16232 case value_t::boolean:
16233 return header_size + 1ul;
16235 case value_t::number_float:
16236 return header_size + 8ul;
16238 case value_t::number_integer:
16239 return header_size + calc_bson_integer_size(j.m_data.m_value.number_integer);
16241 case value_t::number_unsigned:
16242 return header_size + calc_bson_unsigned_size(j.m_data.m_value.number_unsigned);
16244 case value_t::string:
16245 return header_size + calc_bson_string_size(*j.m_data.m_value.string);
16247 case value_t::null:
16248 return header_size + 0ul;
16251 case value_t::discarded:
16253 JSON_ASSERT(
false);
16265 void write_bson_element(
const string_t& name,
16266 const BasicJsonType& j)
16270 case value_t::object:
16271 return write_bson_object_entry(name, *j.m_data.m_value.object);
16273 case value_t::array:
16274 return write_bson_array(name, *j.m_data.m_value.array);
16276 case value_t::binary:
16277 return write_bson_binary(name, *j.m_data.m_value.binary);
16279 case value_t::boolean:
16280 return write_bson_boolean(name, j.m_data.m_value.boolean);
16282 case value_t::number_float:
16283 return write_bson_double(name, j.m_data.m_value.number_float);
16285 case value_t::number_integer:
16286 return write_bson_integer(name, j.m_data.m_value.number_integer);
16288 case value_t::number_unsigned:
16289 return write_bson_unsigned(name, j);
16291 case value_t::string:
16292 return write_bson_string(name, *j.m_data.m_value.string);
16294 case value_t::null:
16295 return write_bson_null(name);
16298 case value_t::discarded:
16300 JSON_ASSERT(
false);
16312 static std::size_t calc_bson_object_size(
const typename BasicJsonType::object_t& value)
16314 const std::size_t document_size = std::accumulate(
value.begin(),
value.end(),
static_cast<std::size_t
>(0),
16315 [](
size_t result,
const typename BasicJsonType::object_t::value_type & el)
16317 return result += calc_bson_element_size(el.first, el.second);
16320 return sizeof(std::int32_t) + document_size + 1ul;
16327 void write_bson_object(
const typename BasicJsonType::object_t& value)
16329 write_number<std::int32_t>(
static_cast<std::int32_t
>(calc_bson_object_size(value)),
true);
16331 for (
const auto& el : value)
16333 write_bson_element(el.first, el.second);
16336 oa->write_character(to_char_type(0x00));
16343 static constexpr CharType get_cbor_float_prefix(
float )
16345 return to_char_type(0xFA);
16348 static constexpr CharType get_cbor_float_prefix(
double )
16350 return to_char_type(0xFB);
16357 static constexpr CharType get_msgpack_float_prefix(
float )
16359 return to_char_type(0xCA);
16362 static constexpr CharType get_msgpack_float_prefix(
double )
16364 return to_char_type(0xCB);
16372 template<
typename NumberType,
typename std::enable_if<
16373 std::is_floating_point<NumberType>::value,
int>::type = 0>
16374 void write_number_with_ubjson_prefix(
const NumberType n,
16375 const bool add_prefix,
16376 const bool use_bjdata)
16380 oa->write_character(get_ubjson_float_prefix(n));
16382 write_number(n, use_bjdata);
16386 template<
typename NumberType,
typename std::enable_if<
16387 std::is_unsigned<NumberType>::value,
int>::type = 0>
16388 void write_number_with_ubjson_prefix(
const NumberType n,
16389 const bool add_prefix,
16390 const bool use_bjdata)
16392 if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
16396 oa->write_character(to_char_type(
'i'));
16398 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
16400 else if (n <= (std::numeric_limits<std::uint8_t>::max)())
16404 oa->write_character(to_char_type(
'U'));
16406 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
16408 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
16412 oa->write_character(to_char_type(
'I'));
16414 write_number(
static_cast<std::int16_t
>(n), use_bjdata);
16416 else if (use_bjdata && n <=
static_cast<uint64_t
>((std::numeric_limits<uint16_t>::max)()))
16420 oa->write_character(to_char_type(
'u'));
16422 write_number(
static_cast<std::uint16_t
>(n), use_bjdata);
16424 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16428 oa->write_character(to_char_type(
'l'));
16430 write_number(
static_cast<std::int32_t
>(n), use_bjdata);
16432 else if (use_bjdata && n <=
static_cast<uint64_t
>((std::numeric_limits<uint32_t>::max)()))
16436 oa->write_character(to_char_type(
'm'));
16438 write_number(
static_cast<std::uint32_t
>(n), use_bjdata);
16440 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
16444 oa->write_character(to_char_type(
'L'));
16446 write_number(
static_cast<std::int64_t
>(n), use_bjdata);
16448 else if (use_bjdata && n <= (std::numeric_limits<uint64_t>::max)())
16452 oa->write_character(to_char_type(
'M'));
16454 write_number(
static_cast<std::uint64_t
>(n), use_bjdata);
16460 oa->write_character(to_char_type(
'H'));
16463 const auto number = BasicJsonType(n).dump();
16464 write_number_with_ubjson_prefix(number.size(),
true, use_bjdata);
16465 for (std::size_t i = 0; i < number.size(); ++i)
16467 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
16473 template <
typename NumberType,
typename std::enable_if <
16474 std::is_signed<NumberType>::value&&
16475 !std::is_floating_point<NumberType>::value,
int >::type = 0 >
16476 void write_number_with_ubjson_prefix(
const NumberType n,
16477 const bool add_prefix,
16478 const bool use_bjdata)
16480 if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
16484 oa->write_character(to_char_type(
'i'));
16486 write_number(
static_cast<std::int8_t
>(n), use_bjdata);
16488 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)()))
16492 oa->write_character(to_char_type(
'U'));
16494 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
16496 else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
16500 oa->write_character(to_char_type(
'I'));
16502 write_number(
static_cast<std::int16_t
>(n), use_bjdata);
16504 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)())))
16508 oa->write_character(to_char_type(
'u'));
16510 write_number(
static_cast<uint16_t
>(n), use_bjdata);
16512 else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
16516 oa->write_character(to_char_type(
'l'));
16518 write_number(
static_cast<std::int32_t
>(n), use_bjdata);
16520 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)())))
16524 oa->write_character(to_char_type(
'm'));
16526 write_number(
static_cast<uint32_t
>(n), use_bjdata);
16528 else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
16532 oa->write_character(to_char_type(
'L'));
16534 write_number(
static_cast<std::int64_t
>(n), use_bjdata);
16541 oa->write_character(to_char_type(
'H'));
16544 const auto number = BasicJsonType(n).dump();
16545 write_number_with_ubjson_prefix(number.size(),
true, use_bjdata);
16546 for (std::size_t i = 0; i < number.size(); ++i)
16548 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
16557 CharType ubjson_prefix(
const BasicJsonType& j,
const bool use_bjdata)
const noexcept
16561 case value_t::null:
16564 case value_t::boolean:
16565 return j.m_data.m_value.boolean ?
'T' :
'F';
16567 case value_t::number_integer:
16569 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)())
16573 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)())
16577 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)())
16581 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)()))
16585 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)())
16589 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)()))
16593 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)())
16601 case value_t::number_unsigned:
16603 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
16607 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint8_t>::max)()))
16611 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
16615 if (use_bjdata && j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint16_t>::max)()))
16619 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16623 if (use_bjdata && j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint32_t>::max)()))
16627 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
16631 if (use_bjdata && j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
16639 case value_t::number_float:
16640 return get_ubjson_float_prefix(j.m_data.m_value.number_float);
16642 case value_t::string:
16645 case value_t::array:
16646 case value_t::binary:
16649 case value_t::object:
16652 case value_t::discarded:
16658 static constexpr CharType get_ubjson_float_prefix(
float )
16663 static constexpr CharType get_ubjson_float_prefix(
double )
16671 bool write_bjdata_ndarray(
const typename BasicJsonType::object_t& value,
const bool use_count,
const bool use_type)
16673 std::map<string_t, CharType> bjdtype = {{
"uint8",
'U'}, {
"int8",
'i'}, {
"uint16",
'u'}, {
"int16",
'I'},
16674 {
"uint32",
'm'}, {
"int32",
'l'}, {
"uint64",
'M'}, {
"int64",
'L'}, {
"single",
'd'}, {
"double",
'D'}, {
"char",
'C'}
16677 string_t
key =
"_ArrayType_";
16678 auto it = bjdtype.find(
static_cast<string_t
>(
value.at(key)));
16679 if (it == bjdtype.end())
16683 CharType dtype = it->second;
16685 key =
"_ArraySize_";
16686 std::size_t len = (
value.at(key).empty() ? 0 : 1);
16687 for (
const auto& el :
value.at(key))
16689 len *=
static_cast<std::size_t
>(el.m_data.m_value.number_unsigned);
16692 key =
"_ArrayData_";
16693 if (
value.at(key).size() != len)
16698 oa->write_character(
'[');
16699 oa->write_character(
'$');
16700 oa->write_character(dtype);
16701 oa->write_character(
'#');
16703 key =
"_ArraySize_";
16704 write_ubjson(
value.at(key), use_count, use_type,
true,
true);
16706 key =
"_ArrayData_";
16707 if (dtype ==
'U' || dtype ==
'C')
16709 for (
const auto& el :
value.at(key))
16711 write_number(
static_cast<std::uint8_t
>(el.m_data.m_value.number_unsigned),
true);
16714 else if (dtype ==
'i')
16716 for (
const auto& el :
value.at(key))
16718 write_number(
static_cast<std::int8_t
>(el.m_data.m_value.number_integer),
true);
16721 else if (dtype ==
'u')
16723 for (
const auto& el :
value.at(key))
16725 write_number(
static_cast<std::uint16_t
>(el.m_data.m_value.number_unsigned),
true);
16728 else if (dtype ==
'I')
16730 for (
const auto& el :
value.at(key))
16732 write_number(
static_cast<std::int16_t
>(el.m_data.m_value.number_integer),
true);
16735 else if (dtype ==
'm')
16737 for (
const auto& el :
value.at(key))
16739 write_number(
static_cast<std::uint32_t
>(el.m_data.m_value.number_unsigned),
true);
16742 else if (dtype ==
'l')
16744 for (
const auto& el :
value.at(key))
16746 write_number(
static_cast<std::int32_t
>(el.m_data.m_value.number_integer),
true);
16749 else if (dtype ==
'M')
16751 for (
const auto& el :
value.at(key))
16753 write_number(
static_cast<std::uint64_t
>(el.m_data.m_value.number_unsigned),
true);
16756 else if (dtype ==
'L')
16758 for (
const auto& el :
value.at(key))
16760 write_number(
static_cast<std::int64_t
>(el.m_data.m_value.number_integer),
true);
16763 else if (dtype ==
'd')
16765 for (
const auto& el :
value.at(key))
16767 write_number(
static_cast<float>(el.m_data.m_value.number_float),
true);
16770 else if (dtype ==
'D')
16772 for (
const auto& el :
value.at(key))
16774 write_number(
static_cast<double>(el.m_data.m_value.number_float),
true);
16797 template<
typename NumberType>
16798 void write_number(
const NumberType n,
const bool OutputIsLittleEndian =
false)
16801 std::array<CharType,
sizeof(NumberType)> vec{};
16802 std::memcpy(vec.data(), &n,
sizeof(NumberType));
16805 if (is_little_endian != OutputIsLittleEndian)
16808 std::reverse(vec.begin(), vec.end());
16811 oa->write_characters(vec.data(),
sizeof(NumberType));
16817#pragma GCC diagnostic push
16818#pragma GCC diagnostic ignored "-Wfloat-equal"
16820 if (
static_cast<double>(n) >=
static_cast<double>(std::numeric_limits<float>::lowest()) &&
16821 static_cast<double>(n) <=
static_cast<double>((std::numeric_limits<float>::max)()) &&
16822 static_cast<double>(
static_cast<float>(n)) ==
static_cast<double>(n))
16824 oa->write_character(format == detail::input_format_t::cbor
16825 ? get_cbor_float_prefix(
static_cast<float>(n))
16826 : get_msgpack_float_prefix(
static_cast<float>(n)));
16827 write_number(
static_cast<float>(n));
16831 oa->write_character(format == detail::input_format_t::cbor
16832 ? get_cbor_float_prefix(n)
16833 : get_msgpack_float_prefix(n));
16837#pragma GCC diagnostic pop
16846 template <
typename C = CharType,
16847 enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * =
nullptr >
16848 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
16850 return *
reinterpret_cast<char*
>(&x);
16853 template <
typename C = CharType,
16854 enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * =
nullptr >
16855 static CharType to_char_type(std::uint8_t x)
noexcept
16857 static_assert(
sizeof(std::uint8_t) ==
sizeof(CharType),
"size of CharType must be equal to std::uint8_t");
16858 static_assert(std::is_trivial<CharType>::value,
"CharType must be trivial");
16860 std::memcpy(&result, &x,
sizeof(x));
16864 template<
typename C = CharType,
16865 enable_if_t<std::is_unsigned<C>::value>* =
nullptr>
16866 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
16871 template <
typename InputCharType,
typename C = CharType,
16873 std::is_signed<C>::value &&
16874 std::is_signed<char>::value &&
16875 std::is_same<char, typename std::remove_cv<InputCharType>::type>::value
16877 static constexpr CharType to_char_type(InputCharType x)
noexcept
16884 const bool is_little_endian = little_endianness();
16887 output_adapter_t<CharType> oa =
nullptr;
16891NLOHMANN_JSON_NAMESPACE_END
16907#include <algorithm>
16917#include <type_traits>
16937#include <type_traits>
16942NLOHMANN_JSON_NAMESPACE_BEGIN
16968template<
typename Target,
typename Source>
16969Target reinterpret_bits(
const Source source)
16971 static_assert(
sizeof(Target) ==
sizeof(Source),
"size mismatch");
16974 std::memcpy(&target, &source,
sizeof(Source));
16980 static constexpr int kPrecision = 64;
16982 std::uint64_t f = 0;
16985 constexpr diyfp(std::uint64_t f_,
int e_) noexcept : f(f_), e(e_) {}
16993 JSON_ASSERT(x.e == y.e);
16994 JSON_ASSERT(x.f >= y.f);
16996 return {x.f - y.f, x.e};
17005 static_assert(kPrecision == 64,
"internal error");
17030 const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
17031 const std::uint64_t u_hi = x.f >> 32u;
17032 const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
17033 const std::uint64_t v_hi = y.f >> 32u;
17035 const std::uint64_t p0 = u_lo * v_lo;
17036 const std::uint64_t p1 = u_lo * v_hi;
17037 const std::uint64_t p2 = u_hi * v_lo;
17038 const std::uint64_t p3 = u_hi * v_hi;
17040 const std::uint64_t p0_hi = p0 >> 32u;
17041 const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
17042 const std::uint64_t p1_hi = p1 >> 32u;
17043 const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
17044 const std::uint64_t p2_hi = p2 >> 32u;
17046 std::uint64_t Q = p0_hi + p1_lo + p2_lo;
17057 Q += std::uint64_t{1} << (64u - 32u - 1u);
17059 const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
17061 return {h, x.e + y.e + 64};
17070 JSON_ASSERT(x.f != 0);
17072 while ((x.f >> 63u) == 0)
17087 const int delta = x.e - target_exponent;
17089 JSON_ASSERT(delta >= 0);
17090 JSON_ASSERT(((x.f << delta) >> delta) == x.f);
17092 return {x.f << delta, target_exponent};
17109template<
typename FloatType>
17112 JSON_ASSERT(std::isfinite(
value));
17113 JSON_ASSERT(
value > 0);
17122 static_assert(std::numeric_limits<FloatType>::is_iec559,
17123 "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
17125 constexpr int kPrecision = std::numeric_limits<FloatType>::digits;
17126 constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
17127 constexpr int kMinExp = 1 - kBias;
17128 constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
17130 using bits_type =
typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
17132 const auto bits =
static_cast<std::uint64_t
>(reinterpret_bits<bits_type>(
value));
17133 const std::uint64_t E = bits >> (kPrecision - 1);
17134 const std::uint64_t F = bits & (kHiddenBit - 1);
17136 const bool is_denormal = E == 0;
17137 const diyfp v = is_denormal
17138 ?
diyfp(F, kMinExp)
17139 :
diyfp(F + kHiddenBit,
static_cast<int>(E) - kBias);
17162 const bool lower_boundary_is_closer = F == 0 && E > 1;
17163 const diyfp m_plus =
diyfp(2 * v.f + 1, v.e - 1);
17164 const diyfp m_minus = lower_boundary_is_closer
17165 ?
diyfp(4 * v.f - 1, v.e - 2)
17166 :
diyfp(2 * v.f - 1, v.e - 1);
17169 const diyfp w_plus = diyfp::normalize(m_plus);
17172 const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
17174 return {diyfp::normalize(v), w_minus, w_plus};
17232constexpr int kAlpha = -60;
17233constexpr int kGamma = -32;
17301 constexpr int kCachedPowersMinDecExp = -300;
17302 constexpr int kCachedPowersDecStep = 8;
17304 static constexpr std::array<cached_power, 79> kCachedPowers =
17307 { 0xAB70FE17C79AC6CA, -1060, -300 },
17308 { 0xFF77B1FCBEBCDC4F, -1034, -292 },
17309 { 0xBE5691EF416BD60C, -1007, -284 },
17310 { 0x8DD01FAD907FFC3C, -980, -276 },
17311 { 0xD3515C2831559A83, -954, -268 },
17312 { 0x9D71AC8FADA6C9B5, -927, -260 },
17313 { 0xEA9C227723EE8BCB, -901, -252 },
17314 { 0xAECC49914078536D, -874, -244 },
17315 { 0x823C12795DB6CE57, -847, -236 },
17316 { 0xC21094364DFB5637, -821, -228 },
17317 { 0x9096EA6F3848984F, -794, -220 },
17318 { 0xD77485CB25823AC7, -768, -212 },
17319 { 0xA086CFCD97BF97F4, -741, -204 },
17320 { 0xEF340A98172AACE5, -715, -196 },
17321 { 0xB23867FB2A35B28E, -688, -188 },
17322 { 0x84C8D4DFD2C63F3B, -661, -180 },
17323 { 0xC5DD44271AD3CDBA, -635, -172 },
17324 { 0x936B9FCEBB25C996, -608, -164 },
17325 { 0xDBAC6C247D62A584, -582, -156 },
17326 { 0xA3AB66580D5FDAF6, -555, -148 },
17327 { 0xF3E2F893DEC3F126, -529, -140 },
17328 { 0xB5B5ADA8AAFF80B8, -502, -132 },
17329 { 0x87625F056C7C4A8B, -475, -124 },
17330 { 0xC9BCFF6034C13053, -449, -116 },
17331 { 0x964E858C91BA2655, -422, -108 },
17332 { 0xDFF9772470297EBD, -396, -100 },
17333 { 0xA6DFBD9FB8E5B88F, -369, -92 },
17334 { 0xF8A95FCF88747D94, -343, -84 },
17335 { 0xB94470938FA89BCF, -316, -76 },
17336 { 0x8A08F0F8BF0F156B, -289, -68 },
17337 { 0xCDB02555653131B6, -263, -60 },
17338 { 0x993FE2C6D07B7FAC, -236, -52 },
17339 { 0xE45C10C42A2B3B06, -210, -44 },
17340 { 0xAA242499697392D3, -183, -36 },
17341 { 0xFD87B5F28300CA0E, -157, -28 },
17342 { 0xBCE5086492111AEB, -130, -20 },
17343 { 0x8CBCCC096F5088CC, -103, -12 },
17344 { 0xD1B71758E219652C, -77, -4 },
17345 { 0x9C40000000000000, -50, 4 },
17346 { 0xE8D4A51000000000, -24, 12 },
17347 { 0xAD78EBC5AC620000, 3, 20 },
17348 { 0x813F3978F8940984, 30, 28 },
17349 { 0xC097CE7BC90715B3, 56, 36 },
17350 { 0x8F7E32CE7BEA5C70, 83, 44 },
17351 { 0xD5D238A4ABE98068, 109, 52 },
17352 { 0x9F4F2726179A2245, 136, 60 },
17353 { 0xED63A231D4C4FB27, 162, 68 },
17354 { 0xB0DE65388CC8ADA8, 189, 76 },
17355 { 0x83C7088E1AAB65DB, 216, 84 },
17356 { 0xC45D1DF942711D9A, 242, 92 },
17357 { 0x924D692CA61BE758, 269, 100 },
17358 { 0xDA01EE641A708DEA, 295, 108 },
17359 { 0xA26DA3999AEF774A, 322, 116 },
17360 { 0xF209787BB47D6B85, 348, 124 },
17361 { 0xB454E4A179DD1877, 375, 132 },
17362 { 0x865B86925B9BC5C2, 402, 140 },
17363 { 0xC83553C5C8965D3D, 428, 148 },
17364 { 0x952AB45CFA97A0B3, 455, 156 },
17365 { 0xDE469FBD99A05FE3, 481, 164 },
17366 { 0xA59BC234DB398C25, 508, 172 },
17367 { 0xF6C69A72A3989F5C, 534, 180 },
17368 { 0xB7DCBF5354E9BECE, 561, 188 },
17369 { 0x88FCF317F22241E2, 588, 196 },
17370 { 0xCC20CE9BD35C78A5, 614, 204 },
17371 { 0x98165AF37B2153DF, 641, 212 },
17372 { 0xE2A0B5DC971F303A, 667, 220 },
17373 { 0xA8D9D1535CE3B396, 694, 228 },
17374 { 0xFB9B7CD9A4A7443C, 720, 236 },
17375 { 0xBB764C4CA7A44410, 747, 244 },
17376 { 0x8BAB8EEFB6409C1A, 774, 252 },
17377 { 0xD01FEF10A657842C, 800, 260 },
17378 { 0x9B10A4E5E9913129, 827, 268 },
17379 { 0xE7109BFBA19C0C9D, 853, 276 },
17380 { 0xAC2820D9623BF429, 880, 284 },
17381 { 0x80444B5E7AA7CF85, 907, 292 },
17382 { 0xBF21E44003ACDD2D, 933, 300 },
17383 { 0x8E679C2F5E44FF8F, 960, 308 },
17384 { 0xD433179D9C8CB841, 986, 316 },
17385 { 0x9E19DB92B4E31BA9, 1013, 324 },
17393 JSON_ASSERT(e >= -1500);
17394 JSON_ASSERT(e <= 1500);
17395 const int f = kAlpha - e - 1;
17396 const int k = (f * 78913) / (1 << 18) +
static_cast<int>(f > 0);
17398 const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
17399 JSON_ASSERT(index >= 0);
17400 JSON_ASSERT(
static_cast<std::size_t
>(index) < kCachedPowers.size());
17402 const cached_power cached = kCachedPowers[
static_cast<std::size_t
>(index)];
17403 JSON_ASSERT(kAlpha <= cached.e + e + 64);
17404 JSON_ASSERT(kGamma >= cached.e + e + 64);
17416 if (n >= 1000000000)
17418 pow10 = 1000000000;
17422 if (n >= 100000000)
17467inline void grisu2_round(
char* buf,
int len, std::uint64_t dist, std::uint64_t delta,
17468 std::uint64_t rest, std::uint64_t ten_k)
17470 JSON_ASSERT(len >= 1);
17471 JSON_ASSERT(dist <= delta);
17472 JSON_ASSERT(rest <= delta);
17473 JSON_ASSERT(ten_k > 0);
17495 && delta - rest >= ten_k
17496 && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
17498 JSON_ASSERT(buf[len - 1] !=
'0');
17511 static_assert(kAlpha >= -60,
"internal error");
17512 static_assert(kGamma <= -32,
"internal error");
17526 JSON_ASSERT(M_plus.e >= kAlpha);
17527 JSON_ASSERT(M_plus.e <= kGamma);
17529 std::uint64_t delta = diyfp::sub(M_plus, M_minus).f;
17530 std::uint64_t dist = diyfp::sub(M_plus, w ).f;
17539 const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
17541 auto p1 =
static_cast<std::uint32_t
>(M_plus.f >> -one.e);
17542 std::uint64_t p2 = M_plus.f & (one.f - 1);
17548 JSON_ASSERT(p1 > 0);
17550 std::uint32_t pow10{};
17578 const std::uint32_t d = p1 / pow10;
17579 const std::uint32_t r = p1 % pow10;
17584 JSON_ASSERT(d <= 9);
17585 buffer[length++] =
static_cast<char>(
'0' + d);
17604 const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
17609 decimal_exponent += n;
17620 const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
17621 grisu2_round(buffer, length, dist, delta, rest, ten_n);
17671 JSON_ASSERT(p2 > delta);
17682 JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
17684 const std::uint64_t d = p2 >> -one.e;
17685 const std::uint64_t r = p2 & (one.f - 1);
17691 JSON_ASSERT(d <= 9);
17692 buffer[length++] =
static_cast<char>(
'0' + d);
17717 decimal_exponent -= m;
17725 const std::uint64_t ten_m = one.f;
17726 grisu2_round(buffer, length, dist, delta, p2, ten_m);
17748JSON_HEDLEY_NON_NULL(1)
17749inline
void grisu2(
char* buf,
int& len,
int& decimal_exponent,
17752 JSON_ASSERT(m_plus.e == m_minus.e);
17753 JSON_ASSERT(m_plus.e == v.e);
17766 const diyfp c_minus_k(cached.f, cached.e);
17769 const diyfp w = diyfp::mul(v, c_minus_k);
17770 const diyfp w_minus = diyfp::mul(m_minus, c_minus_k);
17771 const diyfp w_plus = diyfp::mul(m_plus, c_minus_k);
17794 const diyfp M_minus(w_minus.f + 1, w_minus.e);
17795 const diyfp M_plus (w_plus.f - 1, w_plus.e );
17797 decimal_exponent = -cached.k;
17807template<
typename FloatType>
17808JSON_HEDLEY_NON_NULL(1)
17809void grisu2(
char* buf,
int& len,
int& decimal_exponent, FloatType value)
17811 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
17812 "internal error: not enough precision");
17814 JSON_ASSERT(std::isfinite(
value));
17815 JSON_ASSERT(
value > 0);
17839 grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
17847JSON_HEDLEY_NON_NULL(1)
17848JSON_HEDLEY_RETURNS_NON_NULL
17849inline
char* append_exponent(
char* buf,
int e)
17851 JSON_ASSERT(e > -1000);
17852 JSON_ASSERT(e < 1000);
17864 auto k =
static_cast<std::uint32_t
>(e);
17870 *buf++ =
static_cast<char>(
'0' + k);
17874 *buf++ =
static_cast<char>(
'0' + k / 10);
17876 *buf++ =
static_cast<char>(
'0' + k);
17880 *buf++ =
static_cast<char>(
'0' + k / 100);
17882 *buf++ =
static_cast<char>(
'0' + k / 10);
17884 *buf++ =
static_cast<char>(
'0' + k);
17899JSON_HEDLEY_NON_NULL(1)
17900JSON_HEDLEY_RETURNS_NON_NULL
17901inline
char* format_buffer(
char* buf,
int len,
int decimal_exponent,
17902 int min_exp,
int max_exp)
17904 JSON_ASSERT(min_exp < 0);
17905 JSON_ASSERT(max_exp > 0);
17908 const int n = len + decimal_exponent;
17914 if (k <= n && n <= max_exp)
17919 std::memset(buf + k,
'0',
static_cast<size_t>(n) -
static_cast<size_t>(k));
17923 return buf + (
static_cast<size_t>(n) + 2);
17926 if (0 < n && n <= max_exp)
17931 JSON_ASSERT(k > n);
17933 std::memmove(buf + (
static_cast<size_t>(n) + 1), buf + n,
static_cast<size_t>(k) -
static_cast<size_t>(n));
17935 return buf + (
static_cast<size_t>(k) + 1U);
17938 if (min_exp < n && n <= 0)
17943 std::memmove(buf + (2 +
static_cast<size_t>(-n)), buf,
static_cast<size_t>(k));
17946 std::memset(buf + 2,
'0',
static_cast<size_t>(-n));
17947 return buf + (2U +
static_cast<size_t>(-n) +
static_cast<size_t>(k));
17962 std::memmove(buf + 2, buf + 1,
static_cast<size_t>(k) - 1);
17964 buf += 1 +
static_cast<size_t>(k);
17983template<
typename FloatType>
17984JSON_HEDLEY_NON_NULL(1, 2)
17985JSON_HEDLEY_RETURNS_NON_NULL
17986char* to_chars(
char* first, const
char* last, FloatType value)
17988 static_cast<void>(last);
17989 JSON_ASSERT(std::isfinite(
value));
17992 if (std::signbit(
value))
17999#pragma GCC diagnostic push
18000#pragma GCC diagnostic ignored "-Wfloat-equal"
18011#pragma GCC diagnostic pop
18014 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
18021 int decimal_exponent = 0;
18022 dtoa_impl::grisu2(first, len, decimal_exponent,
value);
18024 JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
18027 constexpr int kMinExp = -4;
18029 constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10;
18031 JSON_ASSERT(last - first >= kMaxExp + 2);
18032 JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
18033 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
18035 return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);
18039NLOHMANN_JSON_NAMESPACE_END
18056NLOHMANN_JSON_NAMESPACE_BEGIN
18072template<
typename BasicJsonType>
18075 using string_t =
typename BasicJsonType::string_t;
18076 using number_float_t =
typename BasicJsonType::number_float_t;
18077 using number_integer_t =
typename BasicJsonType::number_integer_t;
18078 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
18079 using binary_char_t =
typename BasicJsonType::binary_t::value_type;
18080 static constexpr std::uint8_t UTF8_ACCEPT = 0;
18081 static constexpr std::uint8_t UTF8_REJECT = 1;
18092 , loc(std::localeconv())
18093 , thousands_sep(loc->thousands_sep == nullptr ?
'\0' : std::
char_traits<char>::to_char_type(* (loc->thousands_sep)))
18094 , decimal_point(loc->decimal_point == nullptr ?
'\0' : std::
char_traits<char>::to_char_type(* (loc->decimal_point)))
18095 , indent_char(ichar)
18096 , indent_string(512, indent_char)
18097 , error_handler(error_handler_)
18130 const bool pretty_print,
18131 const bool ensure_ascii,
18132 const unsigned int indent_step,
18133 const unsigned int current_indent = 0)
18135 switch (val.m_data.m_type)
18137 case value_t::object:
18139 if (val.m_data.m_value.object->empty())
18141 o->write_characters(
"{}", 2);
18147 o->write_characters(
"{\n", 2);
18150 const auto new_indent = current_indent + indent_step;
18151 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
18153 indent_string.resize(indent_string.size() * 2,
' ');
18157 auto i = val.m_data.m_value.object->cbegin();
18158 for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)
18160 o->write_characters(indent_string.c_str(), new_indent);
18161 o->write_character(
'\"');
18162 dump_escaped(i->first, ensure_ascii);
18163 o->write_characters(
"\": ", 3);
18164 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
18165 o->write_characters(
",\n", 2);
18169 JSON_ASSERT(i != val.m_data.m_value.object->cend());
18170 JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
18171 o->write_characters(indent_string.c_str(), new_indent);
18172 o->write_character(
'\"');
18173 dump_escaped(i->first, ensure_ascii);
18174 o->write_characters(
"\": ", 3);
18175 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
18177 o->write_character(
'\n');
18178 o->write_characters(indent_string.c_str(), current_indent);
18179 o->write_character(
'}');
18183 o->write_character(
'{');
18186 auto i = val.m_data.m_value.object->cbegin();
18187 for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)
18189 o->write_character(
'\"');
18190 dump_escaped(i->first, ensure_ascii);
18191 o->write_characters(
"\":", 2);
18192 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
18193 o->write_character(
',');
18197 JSON_ASSERT(i != val.m_data.m_value.object->cend());
18198 JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
18199 o->write_character(
'\"');
18200 dump_escaped(i->first, ensure_ascii);
18201 o->write_characters(
"\":", 2);
18202 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
18204 o->write_character(
'}');
18210 case value_t::array:
18212 if (val.m_data.m_value.array->empty())
18214 o->write_characters(
"[]", 2);
18220 o->write_characters(
"[\n", 2);
18223 const auto new_indent = current_indent + indent_step;
18224 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
18226 indent_string.resize(indent_string.size() * 2,
' ');
18230 for (
auto i = val.m_data.m_value.array->cbegin();
18231 i != val.m_data.m_value.array->cend() - 1; ++i)
18233 o->write_characters(indent_string.c_str(), new_indent);
18234 dump(*i,
true, ensure_ascii, indent_step, new_indent);
18235 o->write_characters(
",\n", 2);
18239 JSON_ASSERT(!val.m_data.m_value.array->empty());
18240 o->write_characters(indent_string.c_str(), new_indent);
18241 dump(val.m_data.m_value.array->back(),
true, ensure_ascii, indent_step, new_indent);
18243 o->write_character(
'\n');
18244 o->write_characters(indent_string.c_str(), current_indent);
18245 o->write_character(
']');
18249 o->write_character(
'[');
18252 for (
auto i = val.m_data.m_value.array->cbegin();
18253 i != val.m_data.m_value.array->cend() - 1; ++i)
18255 dump(*i,
false, ensure_ascii, indent_step, current_indent);
18256 o->write_character(
',');
18260 JSON_ASSERT(!val.m_data.m_value.array->empty());
18261 dump(val.m_data.m_value.array->back(),
false, ensure_ascii, indent_step, current_indent);
18263 o->write_character(
']');
18269 case value_t::string:
18271 o->write_character(
'\"');
18272 dump_escaped(*val.m_data.m_value.string, ensure_ascii);
18273 o->write_character(
'\"');
18277 case value_t::binary:
18281 o->write_characters(
"{\n", 2);
18284 const auto new_indent = current_indent + indent_step;
18285 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
18287 indent_string.resize(indent_string.size() * 2,
' ');
18290 o->write_characters(indent_string.c_str(), new_indent);
18292 o->write_characters(
"\"bytes\": [", 10);
18294 if (!val.m_data.m_value.binary->empty())
18296 for (
auto i = val.m_data.m_value.binary->cbegin();
18297 i != val.m_data.m_value.binary->cend() - 1; ++i)
18300 o->write_characters(
", ", 2);
18302 dump_integer(val.m_data.m_value.binary->back());
18305 o->write_characters(
"],\n", 3);
18306 o->write_characters(indent_string.c_str(), new_indent);
18308 o->write_characters(
"\"subtype\": ", 11);
18309 if (val.m_data.m_value.binary->has_subtype())
18311 dump_integer(val.m_data.m_value.binary->subtype());
18315 o->write_characters(
"null", 4);
18317 o->write_character(
'\n');
18318 o->write_characters(indent_string.c_str(), current_indent);
18319 o->write_character(
'}');
18323 o->write_characters(
"{\"bytes\":[", 10);
18325 if (!val.m_data.m_value.binary->empty())
18327 for (
auto i = val.m_data.m_value.binary->cbegin();
18328 i != val.m_data.m_value.binary->cend() - 1; ++i)
18331 o->write_character(
',');
18333 dump_integer(val.m_data.m_value.binary->back());
18336 o->write_characters(
"],\"subtype\":", 12);
18337 if (val.m_data.m_value.binary->has_subtype())
18339 dump_integer(val.m_data.m_value.binary->subtype());
18340 o->write_character(
'}');
18344 o->write_characters(
"null}", 5);
18350 case value_t::boolean:
18352 if (val.m_data.m_value.boolean)
18354 o->write_characters(
"true", 4);
18358 o->write_characters(
"false", 5);
18363 case value_t::number_integer:
18365 dump_integer(val.m_data.m_value.number_integer);
18369 case value_t::number_unsigned:
18371 dump_integer(val.m_data.m_value.number_unsigned);
18375 case value_t::number_float:
18377 dump_float(val.m_data.m_value.number_float);
18381 case value_t::discarded:
18383 o->write_characters(
"<discarded>", 11);
18387 case value_t::null:
18389 o->write_characters(
"null", 4);
18394 JSON_ASSERT(
false);
18398 JSON_PRIVATE_UNLESS_TESTED:
18413 void dump_escaped(
const string_t& s,
const bool ensure_ascii)
18415 std::uint32_t codepoint{};
18416 std::uint8_t state = UTF8_ACCEPT;
18417 std::size_t bytes = 0;
18420 std::size_t bytes_after_last_accept = 0;
18421 std::size_t undumped_chars = 0;
18423 for (std::size_t i = 0; i < s.size(); ++i)
18425 const auto byte =
static_cast<std::uint8_t
>(s[i]);
18427 switch (decode(state, codepoint,
byte))
18435 string_buffer[bytes++] =
'\\';
18436 string_buffer[bytes++] =
'b';
18442 string_buffer[bytes++] =
'\\';
18443 string_buffer[bytes++] =
't';
18449 string_buffer[bytes++] =
'\\';
18450 string_buffer[bytes++] =
'n';
18456 string_buffer[bytes++] =
'\\';
18457 string_buffer[bytes++] =
'f';
18463 string_buffer[bytes++] =
'\\';
18464 string_buffer[bytes++] =
'r';
18470 string_buffer[bytes++] =
'\\';
18471 string_buffer[bytes++] =
'\"';
18477 string_buffer[bytes++] =
'\\';
18478 string_buffer[bytes++] =
'\\';
18486 if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
18488 if (codepoint <= 0xFFFF)
18491 static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 7,
"\\u%04x",
18492 static_cast<std::uint16_t
>(codepoint)));
18498 static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 13,
"\\u%04x\\u%04x",
18499 static_cast<std::uint16_t
>(0xD7C0u + (codepoint >> 10u)),
18500 static_cast<std::uint16_t
>(0xDC00u + (codepoint & 0x3FFu))));
18508 string_buffer[bytes++] = s[i];
18517 if (string_buffer.size() - bytes < 13)
18519 o->write_characters(string_buffer.data(), bytes);
18524 bytes_after_last_accept = bytes;
18525 undumped_chars = 0;
18531 switch (error_handler)
18533 case error_handler_t::strict:
18535 JSON_THROW(type_error::create(316, concat(
"invalid UTF-8 byte at index ", std::to_string(i),
": 0x", hex_bytes(
byte | 0)),
nullptr));
18538 case error_handler_t::ignore:
18539 case error_handler_t::replace:
18545 if (undumped_chars > 0)
18552 bytes = bytes_after_last_accept;
18554 if (error_handler == error_handler_t::replace)
18559 string_buffer[bytes++] =
'\\';
18560 string_buffer[bytes++] =
'u';
18561 string_buffer[bytes++] =
'f';
18562 string_buffer[bytes++] =
'f';
18563 string_buffer[bytes++] =
'f';
18564 string_buffer[bytes++] =
'd';
18576 if (string_buffer.size() - bytes < 13)
18578 o->write_characters(string_buffer.data(), bytes);
18582 bytes_after_last_accept = bytes;
18585 undumped_chars = 0;
18588 state = UTF8_ACCEPT;
18593 JSON_ASSERT(
false);
18603 string_buffer[bytes++] = s[i];
18612 if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
18617 o->write_characters(string_buffer.data(), bytes);
18623 switch (error_handler)
18625 case error_handler_t::strict:
18627 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));
18630 case error_handler_t::ignore:
18633 o->write_characters(string_buffer.data(), bytes_after_last_accept);
18637 case error_handler_t::replace:
18640 o->write_characters(string_buffer.data(), bytes_after_last_accept);
18644 o->write_characters(
"\\ufffd", 6);
18648 o->write_characters(
"\xEF\xBF\xBD", 3);
18654 JSON_ASSERT(
false);
18668 inline unsigned int count_digits(number_unsigned_t x)
noexcept
18670 unsigned int n_digits = 1;
18679 return n_digits + 1;
18683 return n_digits + 2;
18687 return n_digits + 3;
18699 static std::string hex_bytes(std::uint8_t
byte)
18701 std::string result =
"FF";
18702 constexpr const char* nibble_to_hex =
"0123456789ABCDEF";
18703 result[0] = nibble_to_hex[
byte / 16];
18704 result[1] = nibble_to_hex[
byte % 16];
18709 template <typename NumberType, enable_if_t<std::is_signed<NumberType>::value,
int> = 0>
18710 bool is_negative_number(NumberType x)
18715 template < typename NumberType, enable_if_t <std::is_unsigned<NumberType>::value,
int > = 0 >
18716 bool is_negative_number(NumberType )
18730 template <
typename NumberType, detail::enable_if_t <
18731 std::is_integral<NumberType>::value ||
18732 std::is_same<NumberType, number_unsigned_t>::value ||
18733 std::is_same<NumberType, number_integer_t>::value ||
18734 std::is_same<NumberType, binary_char_t>::value,
18736 void dump_integer(NumberType x)
18738 static constexpr std::array<std::array<char, 2>, 100> digits_to_99
18741 {{
'0',
'0'}}, {{
'0',
'1'}}, {{
'0',
'2'}}, {{
'0',
'3'}}, {{
'0',
'4'}}, {{
'0',
'5'}}, {{
'0',
'6'}}, {{
'0',
'7'}}, {{
'0',
'8'}}, {{
'0',
'9'}},
18742 {{
'1',
'0'}}, {{
'1',
'1'}}, {{
'1',
'2'}}, {{
'1',
'3'}}, {{
'1',
'4'}}, {{
'1',
'5'}}, {{
'1',
'6'}}, {{
'1',
'7'}}, {{
'1',
'8'}}, {{
'1',
'9'}},
18743 {{
'2',
'0'}}, {{
'2',
'1'}}, {{
'2',
'2'}}, {{
'2',
'3'}}, {{
'2',
'4'}}, {{
'2',
'5'}}, {{
'2',
'6'}}, {{
'2',
'7'}}, {{
'2',
'8'}}, {{
'2',
'9'}},
18744 {{
'3',
'0'}}, {{
'3',
'1'}}, {{
'3',
'2'}}, {{
'3',
'3'}}, {{
'3',
'4'}}, {{
'3',
'5'}}, {{
'3',
'6'}}, {{
'3',
'7'}}, {{
'3',
'8'}}, {{
'3',
'9'}},
18745 {{
'4',
'0'}}, {{
'4',
'1'}}, {{
'4',
'2'}}, {{
'4',
'3'}}, {{
'4',
'4'}}, {{
'4',
'5'}}, {{
'4',
'6'}}, {{
'4',
'7'}}, {{
'4',
'8'}}, {{
'4',
'9'}},
18746 {{
'5',
'0'}}, {{
'5',
'1'}}, {{
'5',
'2'}}, {{
'5',
'3'}}, {{
'5',
'4'}}, {{
'5',
'5'}}, {{
'5',
'6'}}, {{
'5',
'7'}}, {{
'5',
'8'}}, {{
'5',
'9'}},
18747 {{
'6',
'0'}}, {{
'6',
'1'}}, {{
'6',
'2'}}, {{
'6',
'3'}}, {{
'6',
'4'}}, {{
'6',
'5'}}, {{
'6',
'6'}}, {{
'6',
'7'}}, {{
'6',
'8'}}, {{
'6',
'9'}},
18748 {{
'7',
'0'}}, {{
'7',
'1'}}, {{
'7',
'2'}}, {{
'7',
'3'}}, {{
'7',
'4'}}, {{
'7',
'5'}}, {{
'7',
'6'}}, {{
'7',
'7'}}, {{
'7',
'8'}}, {{
'7',
'9'}},
18749 {{
'8',
'0'}}, {{
'8',
'1'}}, {{
'8',
'2'}}, {{
'8',
'3'}}, {{
'8',
'4'}}, {{
'8',
'5'}}, {{
'8',
'6'}}, {{
'8',
'7'}}, {{
'8',
'8'}}, {{
'8',
'9'}},
18750 {{
'9',
'0'}}, {{
'9',
'1'}}, {{
'9',
'2'}}, {{
'9',
'3'}}, {{
'9',
'4'}}, {{
'9',
'5'}}, {{
'9',
'6'}}, {{
'9',
'7'}}, {{
'9',
'8'}}, {{
'9',
'9'}},
18757 o->write_character(
'0');
18762 auto buffer_ptr = number_buffer.begin();
18764 number_unsigned_t abs_value;
18766 unsigned int n_chars{};
18768 if (is_negative_number(x))
18771 abs_value = remove_sign(
static_cast<number_integer_t
>(x));
18774 n_chars = 1 + count_digits(abs_value);
18778 abs_value =
static_cast<number_unsigned_t
>(x);
18779 n_chars = count_digits(abs_value);
18783 JSON_ASSERT(n_chars < number_buffer.size() - 1);
18787 buffer_ptr += n_chars;
18791 while (abs_value >= 100)
18793 const auto digits_index =
static_cast<unsigned>((abs_value % 100));
18795 *(--buffer_ptr) = digits_to_99[digits_index][1];
18796 *(--buffer_ptr) = digits_to_99[digits_index][0];
18799 if (abs_value >= 10)
18801 const auto digits_index =
static_cast<unsigned>(abs_value);
18802 *(--buffer_ptr) = digits_to_99[digits_index][1];
18803 *(--buffer_ptr) = digits_to_99[digits_index][0];
18807 *(--buffer_ptr) =
static_cast<char>(
'0' + abs_value);
18810 o->write_characters(number_buffer.data(), n_chars);
18821 void dump_float(number_float_t x)
18824 if (!std::isfinite(x))
18826 o->write_characters(
"null", 4);
18835 static constexpr bool is_ieee_single_or_double
18836 = (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) ||
18837 (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);
18839 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
18842 void dump_float(number_float_t x, std::true_type )
18844 auto* begin = number_buffer.data();
18845 auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
18847 o->write_characters(begin,
static_cast<size_t>(end - begin));
18850 void dump_float(number_float_t x, std::false_type )
18853 static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
18857 std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(),
"%.*g", d, x);
18860 JSON_ASSERT(len > 0);
18862 JSON_ASSERT(
static_cast<std::size_t
>(len) < number_buffer.size());
18865 if (thousands_sep !=
'\0')
18868 const auto end = std::remove(number_buffer.begin(), number_buffer.begin() + len, thousands_sep);
18869 std::fill(end, number_buffer.end(),
'\0');
18870 JSON_ASSERT((end - number_buffer.begin()) <= len);
18871 len = (end - number_buffer.begin());
18875 if (decimal_point !=
'\0' && decimal_point !=
'.')
18878 const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
18879 if (dec_pos != number_buffer.end())
18885 o->write_characters(number_buffer.data(),
static_cast<std::size_t
>(len));
18888 const bool value_is_int_like =
18889 std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
18892 return c ==
'.' || c ==
'e';
18895 if (value_is_int_like)
18897 o->write_characters(
".0", 2);
18922 static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep,
const std::uint8_t
byte)
noexcept
18924 static const std::array<std::uint8_t, 400> utf8d =
18927 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,
18928 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,
18929 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,
18930 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,
18931 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,
18932 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,
18933 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,
18934 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3,
18935 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
18936 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1,
18937 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,
18938 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,
18939 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,
18940 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
18944 JSON_ASSERT(
byte < utf8d.size());
18945 const std::uint8_t type = utf8d[byte];
18947 codep = (state != UTF8_ACCEPT)
18948 ? (
byte & 0x3fu) | (codep << 6u)
18949 : (0xFFu >> type) & (byte);
18951 const std::size_t index = 256u +
static_cast<size_t>(state) * 16u +
static_cast<size_t>(type);
18952 JSON_ASSERT(index < utf8d.size());
18953 state = utf8d[index];
18962 number_unsigned_t remove_sign(number_unsigned_t x)
18964 JSON_ASSERT(
false);
18977 inline number_unsigned_t remove_sign(number_integer_t x)
noexcept
18979 JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)());
18980 return static_cast<number_unsigned_t
>(-(x + 1)) + 1;
18985 output_adapter_t<char> o =
nullptr;
18988 std::array<char, 64> number_buffer{{}};
18991 const std::lconv* loc =
nullptr;
18993 const char thousands_sep =
'\0';
18995 const char decimal_point =
'\0';
18998 std::array<char, 512> string_buffer{{}};
19010NLOHMANN_JSON_NAMESPACE_END
19027#include <functional>
19028#include <initializer_list>
19031#include <stdexcept>
19032#include <type_traits>
19041NLOHMANN_JSON_NAMESPACE_BEGIN
19045template <
class Key,
class T,
class IgnoredLess = std::less<Key>,
19046 class Allocator = std::allocator<std::pair<const Key, T>>>
19049 using key_type = Key;
19050 using mapped_type = T;
19051 using Container = std::vector<std::pair<const Key, T>, Allocator>;
19052 using iterator =
typename Container::iterator;
19053 using const_iterator =
typename Container::const_iterator;
19054 using size_type =
typename Container::size_type;
19055 using value_type =
typename Container::value_type;
19056#ifdef JSON_HAS_CPP_14
19057 using key_compare = std::equal_to<>;
19059 using key_compare = std::equal_to<Key>;
19064 ordered_map()
noexcept(
noexcept(Container())) : Container{} {}
19065 explicit ordered_map(
const Allocator& alloc)
noexcept(
noexcept(Container(alloc))) : Container{alloc} {}
19066 template <
class It>
19067 ordered_map(It first, It last,
const Allocator& alloc = Allocator())
19068 : Container{first, last, alloc} {}
19069 ordered_map(std::initializer_list<value_type> init,
const Allocator& alloc = Allocator() )
19070 : Container{init, alloc} {}
19072 std::pair<iterator, bool> emplace(
const key_type& key, T&& t)
19074 for (
auto it = this->begin(); it != this->end(); ++it)
19076 if (m_compare(it->first, key))
19078 return {it,
false};
19081 Container::emplace_back(key, std::forward<T>(t));
19082 return {std::prev(this->end()),
true};
19085 template<
class KeyType, detail::enable_if_t<
19086 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19087 std::pair<iterator, bool> emplace(KeyType && key, T && t)
19089 for (
auto it = this->begin(); it != this->end(); ++it)
19091 if (m_compare(it->first, key))
19093 return {it,
false};
19096 Container::emplace_back(std::forward<KeyType>(key), std::forward<T>(t));
19097 return {std::prev(this->end()),
true};
19100 T& operator[](
const key_type& key)
19102 return emplace(key, T{}).first->second;
19105 template<
class KeyType, detail::enable_if_t<
19106 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19107 T & operator[](KeyType && key)
19109 return emplace(std::forward<KeyType>(key), T{}).first->second;
19112 const T& operator[](
const key_type& key)
const
19117 template<
class KeyType, detail::enable_if_t<
19118 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19119 const T & operator[](KeyType && key)
const
19121 return at(std::forward<KeyType>(key));
19124 T& at(
const key_type& key)
19126 for (
auto it = this->begin(); it != this->end(); ++it)
19128 if (m_compare(it->first, key))
19134 JSON_THROW(std::out_of_range(
"key not found"));
19137 template<
class KeyType, detail::enable_if_t<
19138 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19139 T & at(KeyType && key)
19141 for (
auto it = this->begin(); it != this->end(); ++it)
19143 if (m_compare(it->first, key))
19149 JSON_THROW(std::out_of_range(
"key not found"));
19152 const T& at(
const key_type& key)
const
19154 for (
auto it = this->begin(); it != this->end(); ++it)
19156 if (m_compare(it->first, key))
19162 JSON_THROW(std::out_of_range(
"key not found"));
19165 template<
class KeyType, detail::enable_if_t<
19166 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19167 const T & at(KeyType && key)
const
19169 for (
auto it = this->begin(); it != this->end(); ++it)
19171 if (m_compare(it->first, key))
19177 JSON_THROW(std::out_of_range(
"key not found"));
19180 size_type erase(
const key_type& key)
19182 for (
auto it = this->begin(); it != this->end(); ++it)
19184 if (m_compare(it->first, key))
19187 for (
auto next = it; ++next != this->end(); ++it)
19190 new (&*it) value_type{std::move(*next)};
19192 Container::pop_back();
19199 template<
class KeyType, detail::enable_if_t<
19200 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19201 size_type erase(KeyType && key)
19203 for (
auto it = this->begin(); it != this->end(); ++it)
19205 if (m_compare(it->first, key))
19208 for (
auto next = it; ++next != this->end(); ++it)
19211 new (&*it) value_type{std::move(*next)};
19213 Container::pop_back();
19220 iterator erase(iterator pos)
19222 return erase(pos, std::next(pos));
19225 iterator erase(iterator first, iterator last)
19232 const auto elements_affected = std::distance(first, last);
19233 const auto offset = std::distance(Container::begin(), first);
19255 for (
auto it = first; std::next(it, elements_affected) != Container::end(); ++it)
19258 new (&*it) value_type{std::move(*std::next(it, elements_affected))};
19266 Container::resize(this->size() -
static_cast<size_type
>(elements_affected));
19275 return Container::begin() + offset;
19278 size_type count(
const key_type& key)
const
19280 for (
auto it = this->begin(); it != this->end(); ++it)
19282 if (m_compare(it->first, key))
19290 template<
class KeyType, detail::enable_if_t<
19291 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19292 size_type count(KeyType && key)
const
19294 for (
auto it = this->begin(); it != this->end(); ++it)
19296 if (m_compare(it->first, key))
19304 iterator find(
const key_type& key)
19306 for (
auto it = this->begin(); it != this->end(); ++it)
19308 if (m_compare(it->first, key))
19313 return Container::end();
19316 template<
class KeyType, detail::enable_if_t<
19317 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19318 iterator find(KeyType && key)
19320 for (
auto it = this->begin(); it != this->end(); ++it)
19322 if (m_compare(it->first, key))
19327 return Container::end();
19330 const_iterator find(
const key_type& key)
const
19332 for (
auto it = this->begin(); it != this->end(); ++it)
19334 if (m_compare(it->first, key))
19339 return Container::end();
19342 std::pair<iterator, bool> insert( value_type&& value )
19344 return emplace(value.first, std::move(value.second));
19347 std::pair<iterator, bool> insert(
const value_type& value )
19349 for (
auto it = this->begin(); it != this->end(); ++it)
19351 if (m_compare(it->first, value.first))
19353 return {it,
false};
19356 Container::push_back(value);
19357 return {--this->end(),
true};
19360 template<
typename InputIt>
19361 using require_input_iter =
typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
19362 std::input_iterator_tag>::value>::type;
19364 template<
typename InputIt,
typename = require_input_iter<InputIt>>
19365 void insert(InputIt first, InputIt last)
19367 for (
auto it = first; it != last; ++it)
19374 JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare();
19377NLOHMANN_JSON_NAMESPACE_END
19380#if defined(JSON_HAS_CPP_17)
19381 #if JSON_HAS_STATIC_RTTI
19384 #include <string_view>
19392NLOHMANN_JSON_NAMESPACE_BEGIN
19412NLOHMANN_BASIC_JSON_TPL_DECLARATION
19414 :
public ::nlohmann::detail::json_base_class<CustomBaseClass>
19420 friend class ::nlohmann::json_pointer;
19424 template<
typename BasicJsonType,
typename InputType>
19425 friend class ::nlohmann::detail::parser;
19426 friend ::nlohmann::detail::serializer<basic_json>;
19427 template<
typename BasicJsonType>
19428 friend class ::nlohmann::detail::iter_impl;
19429 template<
typename BasicJsonType,
typename CharType>
19430 friend class ::nlohmann::detail::binary_writer;
19431 template<
typename BasicJsonType,
typename InputType,
typename SAX>
19432 friend class ::nlohmann::detail::binary_reader;
19433 template<
typename BasicJsonType>
19434 friend class ::nlohmann::detail::json_sax_dom_parser;
19435 template<
typename BasicJsonType>
19436 friend class ::nlohmann::detail::json_sax_dom_callback_parser;
19437 friend class ::nlohmann::detail::exception;
19440 using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
19441 using json_base_class_t = ::nlohmann::detail::json_base_class<CustomBaseClass>;
19443 JSON_PRIVATE_UNLESS_TESTED:
19445 using lexer = ::nlohmann::detail::lexer_base<basic_json>;
19447 template<
typename InputAdapterType>
19448 static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
19449 InputAdapterType adapter,
19450 detail::parser_callback_t<basic_json>cb =
nullptr,
19451 const bool allow_exceptions =
true,
19452 const bool ignore_comments =
false
19455 return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
19456 std::move(cb), allow_exceptions, ignore_comments);
19460 using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
19461 template<
typename BasicJsonType>
19462 using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
19463 template<
typename BasicJsonType>
19464 using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>;
19465 template<
typename Iterator>
19466 using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>;
19467 template<
typename Base>
using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>;
19469 template<
typename CharType>
19470 using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>;
19472 template<
typename InputType>
19473 using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
19474 template<
typename CharType>
using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
19476 JSON_PRIVATE_UNLESS_TESTED:
19477 using serializer = ::nlohmann::detail::serializer<basic_json>;
19483 template<
typename T,
typename SFINAE>
19484 using json_serializer = JSONSerializer<T, SFINAE>;
19539 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
19541 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
19563 JSON_HEDLEY_WARN_UNUSED_RESULT
19568 result[
"copyright"] =
"(C) 2013-2023 Niels Lohmann";
19569 result[
"name"] =
"JSON for Modern C++";
19570 result[
"url"] =
"https://github.com/nlohmann/json";
19571 result[
"version"][
"string"] =
19572 detail::concat(std::to_string(NLOHMANN_JSON_VERSION_MAJOR),
'.',
19573 std::to_string(NLOHMANN_JSON_VERSION_MINOR),
'.',
19574 std::to_string(NLOHMANN_JSON_VERSION_PATCH));
19575 result[
"version"][
"major"] = NLOHMANN_JSON_VERSION_MAJOR;
19576 result[
"version"][
"minor"] = NLOHMANN_JSON_VERSION_MINOR;
19577 result[
"version"][
"patch"] = NLOHMANN_JSON_VERSION_PATCH;
19580 result[
"platform"] =
"win32";
19581#elif defined __linux__
19582 result[
"platform"] =
"linux";
19583#elif defined __APPLE__
19584 result[
"platform"] =
"apple";
19585#elif defined __unix__
19586 result[
"platform"] =
"unix";
19588 result[
"platform"] =
"unknown";
19591#if defined(__ICC) || defined(__INTEL_COMPILER)
19592 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
19593#elif defined(__clang__)
19594 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
19595#elif defined(__GNUC__) || defined(__GNUG__)
19596 result[
"compiler"] = {{
"family",
"gcc"}, {
"version", detail::concat(
19597 std::to_string(__GNUC__),
'.',
19598 std::to_string(__GNUC_MINOR__),
'.',
19599 std::to_string(__GNUC_PATCHLEVEL__))
19602#elif defined(__HP_cc) || defined(__HP_aCC)
19603 result[
"compiler"] =
"hp"
19604#elif defined(__IBMCPP__)
19605 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
19606#elif defined(_MSC_VER)
19607 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
19608#elif defined(__PGI)
19609 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
19610#elif defined(__SUNPRO_CC)
19611 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
19613 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
19616#if defined(_MSVC_LANG)
19617 result[
"compiler"][
"c++"] = std::to_string(_MSVC_LANG);
19618#elif defined(__cplusplus)
19619 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
19621 result[
"compiler"][
"c++"] =
"unknown";
19639#if defined(JSON_HAS_CPP_14)
19642 using default_object_comparator_t = std::less<>;
19652 AllocatorType<std::pair<
const StringType,
19657 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
19681 using binary_t = nlohmann::byte_container_with_subtype<BinaryType>;
19692 template<
typename T,
typename... Args>
19693 JSON_HEDLEY_RETURNS_NON_NULL
19694 static T* create(Args&& ... args)
19696 AllocatorType<T> alloc;
19697 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
19699 auto deleter = [&](T * obj)
19701 AllocatorTraits::deallocate(alloc, obj, 1);
19703 std::unique_ptr<T,
decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
19704 AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
19705 JSON_ASSERT(obj !=
nullptr);
19706 return obj.release();
19713 JSON_PRIVATE_UNLESS_TESTED:
19752 number_integer_t number_integer;
19754 number_unsigned_t number_unsigned;
19756 number_float_t number_float;
19759 json_value() =
default;
19761 json_value(boolean_t v) noexcept : boolean(v) {}
19767 json_value(number_float_t v) noexcept :
number_float(v) {}
19769 json_value(value_t t)
19773 case value_t::object:
19775 object = create<object_t>();
19779 case value_t::array:
19781 array = create<array_t>();
19785 case value_t::string:
19787 string = create<string_t>(
"");
19791 case value_t::binary:
19793 binary = create<binary_t>();
19797 case value_t::boolean:
19799 boolean =
static_cast<boolean_t
>(
false);
19803 case value_t::number_integer:
19809 case value_t::number_unsigned:
19815 case value_t::number_float:
19821 case value_t::null:
19827 case value_t::discarded:
19831 if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
19833 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.11.3",
nullptr));
19841 json_value(
const string_t& value) : string(create<string_t>(
value)) {}
19844 json_value(string_t&& value) : string(create<string_t>(std::move(
value))) {}
19847 json_value(
const object_t& value) :
object(create<object_t>(
value)) {}
19850 json_value(object_t&& value) :
object(create<object_t>(std::move(
value))) {}
19853 json_value(
const array_t& value) :
array(create<array_t>(
value)) {}
19856 json_value(array_t&& value) :
array(create<array_t>(std::move(
value))) {}
19859 json_value(
const typename binary_t::container_type& value) :
binary(create<binary_t>(
value)) {}
19862 json_value(
typename binary_t::container_type&& value) :
binary(create<binary_t>(std::move(
value))) {}
19865 json_value(
const binary_t& value) :
binary(create<binary_t>(
value)) {}
19868 json_value(binary_t&& value) :
binary(create<binary_t>(std::move(
value))) {}
19870 void destroy(value_t t)
19873 (t == value_t::object &&
object ==
nullptr) ||
19874 (t == value_t::array && array ==
nullptr) ||
19875 (t == value_t::string &&
string ==
nullptr) ||
19876 (t == value_t::binary && binary ==
nullptr)
19882 if (t == value_t::array || t == value_t::object)
19885 std::vector<basic_json> stack;
19888 if (t == value_t::array)
19890 stack.reserve(
array->size());
19891 std::move(
array->begin(),
array->end(), std::back_inserter(stack));
19895 stack.reserve(
object->size());
19896 for (
auto&& it : *
object)
19898 stack.push_back(std::move(it.second));
19902 while (!stack.empty())
19905 basic_json current_item(std::move(stack.back()));
19910 if (current_item.is_array())
19912 std::move(current_item.m_data.m_value.array->begin(), current_item.m_data.m_value.array->end(), std::back_inserter(stack));
19914 current_item.m_data.m_value.array->clear();
19916 else if (current_item.is_object())
19918 for (
auto&& it : *current_item.m_data.m_value.object)
19920 stack.push_back(std::move(it.second));
19923 current_item.m_data.m_value.object->clear();
19933 case value_t::object:
19935 AllocatorType<object_t> alloc;
19936 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
object);
19937 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
object, 1);
19941 case value_t::array:
19943 AllocatorType<array_t> alloc;
19944 std::allocator_traits<
decltype(alloc)>::destroy(alloc, array);
19945 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, array, 1);
19949 case value_t::string:
19951 AllocatorType<string_t> alloc;
19952 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
string);
19953 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
string, 1);
19957 case value_t::binary:
19959 AllocatorType<binary_t> alloc;
19960 std::allocator_traits<
decltype(alloc)>::destroy(alloc, binary);
19961 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, binary, 1);
19965 case value_t::null:
19966 case value_t::boolean:
19967 case value_t::number_integer:
19968 case value_t::number_unsigned:
19969 case value_t::number_float:
19970 case value_t::discarded:
19998 void assert_invariant(
bool check_parents =
true) const noexcept
20000 JSON_ASSERT(m_data.m_type != value_t::object || m_data.m_value.object !=
nullptr);
20001 JSON_ASSERT(m_data.m_type != value_t::array || m_data.m_value.array !=
nullptr);
20002 JSON_ASSERT(m_data.m_type != value_t::string || m_data.m_value.string !=
nullptr);
20003 JSON_ASSERT(m_data.m_type != value_t::binary || m_data.m_value.binary !=
nullptr);
20005#if JSON_DIAGNOSTICS
20009 JSON_ASSERT(!check_parents || !is_structured() || std::all_of(begin(), end(), [
this](
const basic_json & j)
20011 return j.m_parent ==
this;
20016 static_cast<void>(check_parents);
20021#if JSON_DIAGNOSTICS
20022 switch (m_data.m_type)
20024 case value_t::array:
20026 for (
auto& element : *m_data.m_value.array)
20028 element.m_parent =
this;
20033 case value_t::object:
20035 for (
auto& element : *m_data.m_value.object)
20037 element.second.m_parent =
this;
20042 case value_t::null:
20043 case value_t::string:
20044 case value_t::boolean:
20045 case value_t::number_integer:
20046 case value_t::number_unsigned:
20047 case value_t::number_float:
20048 case value_t::binary:
20049 case value_t::discarded:
20056 iterator set_parents(iterator it,
typename iterator::difference_type count_set_parents)
20058#if JSON_DIAGNOSTICS
20059 for (
typename iterator::difference_type i = 0; i < count_set_parents; ++i)
20061 (it + i)->m_parent =
this;
20064 static_cast<void>(count_set_parents);
20069 reference set_parent(reference j, std::size_t old_capacity =
static_cast<std::size_t
>(-1))
20071#if JSON_DIAGNOSTICS
20072 if (old_capacity !=
static_cast<std::size_t
>(-1))
20075 JSON_ASSERT(type() == value_t::array);
20076 if (JSON_HEDLEY_UNLIKELY(m_data.m_value.array->capacity() != old_capacity))
20086#ifdef JSON_HEDLEY_MSVC_VERSION
20087#pragma warning(push )
20088#pragma warning(disable : 4127)
20095#ifdef JSON_HEDLEY_MSVC_VERSION
20096#pragma warning( pop )
20101 static_cast<void>(j);
20102 static_cast<void>(old_capacity);
20134 assert_invariant();
20142 assert_invariant();
20147 template <
typename CompatibleType,
20148 typename U = detail::uncvref_t<CompatibleType>,
20149 detail::enable_if_t <
20152 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
20153 std::forward<CompatibleType>(val))))
20155 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
20157 assert_invariant();
20162 template <
typename BasicJsonType,
20163 detail::enable_if_t <
20167 using other_boolean_t =
typename BasicJsonType::boolean_t;
20168 using other_number_float_t =
typename BasicJsonType::number_float_t;
20169 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
20170 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
20171 using other_string_t =
typename BasicJsonType::string_t;
20172 using other_object_t =
typename BasicJsonType::object_t;
20173 using other_array_t =
typename BasicJsonType::array_t;
20174 using other_binary_t =
typename BasicJsonType::binary_t;
20176 switch (val.type())
20178 case value_t::boolean:
20179 JSONSerializer<other_boolean_t>::to_json(*
this, val.template get<other_boolean_t>());
20181 case value_t::number_float:
20182 JSONSerializer<other_number_float_t>::to_json(*
this, val.template get<other_number_float_t>());
20184 case value_t::number_integer:
20185 JSONSerializer<other_number_integer_t>::to_json(*
this, val.template get<other_number_integer_t>());
20187 case value_t::number_unsigned:
20188 JSONSerializer<other_number_unsigned_t>::to_json(*
this, val.template get<other_number_unsigned_t>());
20190 case value_t::string:
20191 JSONSerializer<other_string_t>::to_json(*
this, val.template get_ref<const other_string_t&>());
20193 case value_t::object:
20194 JSONSerializer<other_object_t>::to_json(*
this, val.template get_ref<const other_object_t&>());
20196 case value_t::array:
20197 JSONSerializer<other_array_t>::to_json(*
this, val.template get_ref<const other_array_t&>());
20199 case value_t::binary:
20200 JSONSerializer<other_binary_t>::to_json(*
this, val.template get_ref<const other_binary_t&>());
20202 case value_t::null:
20205 case value_t::discarded:
20206 m_data.m_type = value_t::discarded;
20209 JSON_ASSERT(
false);
20211 JSON_ASSERT(m_data.m_type == val.type());
20213 assert_invariant();
20219 bool type_deduction =
true,
20220 value_t manual_type = value_t::array)
20224 bool is_an_object = std::all_of(init.begin(), init.end(),
20230 return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[static_cast<size_type>(0)].is_string();
20234 if (!type_deduction)
20237 if (manual_type == value_t::array)
20239 is_an_object =
false;
20243 if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))
20245 JSON_THROW(type_error::create(301,
"cannot create object from initializer list",
nullptr));
20252 m_data.m_type = value_t::object;
20253 m_data.m_value = value_t::object;
20255 for (
auto& element_ref : init)
20257 auto element = element_ref.moved_or_copied();
20258 m_data.m_value.object->emplace(
20259 std::move(*((*element.m_data.m_value.array)[0].m_data.m_value.string)),
20260 std::move((*element.m_data.m_value.array)[1]));
20266 m_data.m_type = value_t::array;
20267 m_data.m_value.array = create<array_t>(init.begin(), init.end());
20271 assert_invariant();
20276 JSON_HEDLEY_WARN_UNUSED_RESULT
20280 res.m_data.m_type = value_t::binary;
20281 res.m_data.m_value = init;
20287 JSON_HEDLEY_WARN_UNUSED_RESULT
20288 static basic_json binary(
const typename binary_t::container_type& init,
typename binary_t::subtype_type subtype)
20291 res.m_data.m_type = value_t::binary;
20292 res.m_data.m_value =
binary_t(init, subtype);
20298 JSON_HEDLEY_WARN_UNUSED_RESULT
20302 res.m_data.m_type = value_t::binary;
20303 res.m_data.m_value = std::move(init);
20309 JSON_HEDLEY_WARN_UNUSED_RESULT
20310 static basic_json binary(
typename binary_t::container_type&& init,
typename binary_t::subtype_type subtype)
20313 res.m_data.m_type = value_t::binary;
20314 res.m_data.m_value =
binary_t(std::move(init), subtype);
20320 JSON_HEDLEY_WARN_UNUSED_RESULT
20323 return basic_json(init,
false, value_t::array);
20328 JSON_HEDLEY_WARN_UNUSED_RESULT
20331 return basic_json(init,
false, value_t::object);
20340 assert_invariant();
20345 template <
class InputIT,
typename std::enable_if <
20346 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
20347 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int >::type = 0 >
20350 JSON_ASSERT(first.m_object !=
nullptr);
20351 JSON_ASSERT(last.m_object !=
nullptr);
20354 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
20356 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible",
nullptr));
20360 m_data.m_type = first.m_object->m_data.m_type;
20363 switch (m_data.m_type)
20365 case value_t::boolean:
20366 case value_t::number_float:
20367 case value_t::number_integer:
20368 case value_t::number_unsigned:
20369 case value_t::string:
20371 if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
20372 || !last.m_it.primitive_iterator.is_end()))
20374 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", first.m_object));
20379 case value_t::null:
20380 case value_t::object:
20381 case value_t::array:
20382 case value_t::binary:
20383 case value_t::discarded:
20388 switch (m_data.m_type)
20390 case value_t::number_integer:
20392 m_data.m_value.number_integer = first.m_object->m_data.m_value.number_integer;
20396 case value_t::number_unsigned:
20398 m_data.m_value.number_unsigned = first.m_object->m_data.m_value.number_unsigned;
20402 case value_t::number_float:
20404 m_data.m_value.number_float = first.m_object->m_data.m_value.number_float;
20408 case value_t::boolean:
20410 m_data.m_value.boolean = first.m_object->m_data.m_value.boolean;
20414 case value_t::string:
20416 m_data.m_value = *first.m_object->m_data.m_value.string;
20420 case value_t::object:
20422 m_data.m_value.object = create<object_t>(first.m_it.object_iterator,
20423 last.m_it.object_iterator);
20427 case value_t::array:
20429 m_data.m_value.array = create<array_t>(first.m_it.array_iterator,
20430 last.m_it.array_iterator);
20434 case value_t::binary:
20436 m_data.m_value = *first.m_object->m_data.m_value.binary;
20440 case value_t::null:
20441 case value_t::discarded:
20443 JSON_THROW(invalid_iterator::create(206, detail::concat(
"cannot construct with iterators from ", first.m_object->type_name()), first.m_object));
20447 assert_invariant();
20454 template<
typename JsonRef,
20455 detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
20456 std::is_same<typename JsonRef::value_type, basic_json>>::value,
int> = 0 >
20462 : json_base_class_t(other)
20464 m_data.m_type = other.m_data.m_type;
20466 other.assert_invariant();
20468 switch (m_data.m_type)
20470 case value_t::object:
20472 m_data.m_value = *other.m_data.m_value.object;
20476 case value_t::array:
20478 m_data.m_value = *other.m_data.m_value.array;
20482 case value_t::string:
20484 m_data.m_value = *other.m_data.m_value.string;
20488 case value_t::boolean:
20490 m_data.m_value = other.m_data.m_value.boolean;
20494 case value_t::number_integer:
20496 m_data.m_value = other.m_data.m_value.number_integer;
20500 case value_t::number_unsigned:
20502 m_data.m_value = other.m_data.m_value.number_unsigned;
20506 case value_t::number_float:
20508 m_data.m_value = other.m_data.m_value.number_float;
20512 case value_t::binary:
20514 m_data.m_value = *other.m_data.m_value.binary;
20518 case value_t::null:
20519 case value_t::discarded:
20525 assert_invariant();
20531 : json_base_class_t(std::forward<json_base_class_t>(other)),
20532 m_data(std::move(other.m_data))
20535 other.assert_invariant(
false);
20538 other.m_data.m_type = value_t::null;
20539 other.m_data.m_value = {};
20542 assert_invariant();
20548 std::is_nothrow_move_constructible<value_t>::value&&
20549 std::is_nothrow_move_assignable<value_t>::value&&
20550 std::is_nothrow_move_constructible<json_value>::value&&
20551 std::is_nothrow_move_assignable<json_value>::value&&
20552 std::is_nothrow_move_assignable<json_base_class_t>::value
20556 other.assert_invariant();
20559 swap(m_data.m_type, other.m_data.m_type);
20560 swap(m_data.m_value, other.m_data.m_value);
20561 json_base_class_t::operator=(std::move(other));
20564 assert_invariant();
20572 assert_invariant(
false);
20589 const char indent_char =
' ',
20590 const bool ensure_ascii =
false,
20598 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
20602 s.dump(*
this,
false, ensure_ascii, 0);
20612 return m_data.m_type;
20619 return is_null() || is_string() || is_boolean() || is_number() || is_binary();
20626 return is_array() || is_object();
20633 return m_data.m_type == value_t::null;
20640 return m_data.m_type == value_t::boolean;
20647 return is_number_integer() || is_number_float();
20654 return m_data.m_type == value_t::number_integer || m_data.m_type == value_t::number_unsigned;
20661 return m_data.m_type == value_t::number_unsigned;
20668 return m_data.m_type == value_t::number_float;
20675 return m_data.m_type == value_t::object;
20682 return m_data.m_type == value_t::array;
20689 return m_data.m_type == value_t::string;
20696 return m_data.m_type == value_t::binary;
20703 return m_data.m_type == value_t::discarded;
20710 return m_data.m_type;
20721 boolean_t get_impl(boolean_t* )
const
20723 if (JSON_HEDLEY_LIKELY(is_boolean()))
20725 return m_data.m_value.boolean;
20728 JSON_THROW(type_error::create(302, detail::concat(
"type must be boolean, but is ", type_name()),
this));
20732 object_t* get_impl_ptr(object_t* )
noexcept
20734 return is_object() ? m_data.m_value.object :
nullptr;
20738 constexpr const object_t* get_impl_ptr(
const object_t* )
const noexcept
20740 return is_object() ? m_data.m_value.object :
nullptr;
20744 array_t* get_impl_ptr(array_t* )
noexcept
20746 return is_array() ? m_data.m_value.array :
nullptr;
20750 constexpr const array_t* get_impl_ptr(
const array_t* )
const noexcept
20752 return is_array() ? m_data.m_value.array :
nullptr;
20756 string_t* get_impl_ptr(string_t* )
noexcept
20758 return is_string() ? m_data.m_value.string :
nullptr;
20762 constexpr const string_t* get_impl_ptr(
const string_t* )
const noexcept
20764 return is_string() ? m_data.m_value.string :
nullptr;
20768 boolean_t* get_impl_ptr(boolean_t* )
noexcept
20770 return is_boolean() ? &m_data.m_value.boolean :
nullptr;
20774 constexpr const boolean_t* get_impl_ptr(
const boolean_t* )
const noexcept
20776 return is_boolean() ? &m_data.m_value.boolean :
nullptr;
20780 number_integer_t* get_impl_ptr(number_integer_t* )
noexcept
20782 return is_number_integer() ? &m_data.m_value.number_integer :
nullptr;
20786 constexpr const number_integer_t* get_impl_ptr(
const number_integer_t* )
const noexcept
20788 return is_number_integer() ? &m_data.m_value.number_integer :
nullptr;
20792 number_unsigned_t* get_impl_ptr(number_unsigned_t* )
noexcept
20794 return is_number_unsigned() ? &m_data.m_value.number_unsigned :
nullptr;
20798 constexpr const number_unsigned_t* get_impl_ptr(
const number_unsigned_t* )
const noexcept
20800 return is_number_unsigned() ? &m_data.m_value.number_unsigned :
nullptr;
20804 number_float_t* get_impl_ptr(number_float_t* )
noexcept
20806 return is_number_float() ? &m_data.m_value.number_float :
nullptr;
20810 constexpr const number_float_t* get_impl_ptr(
const number_float_t* )
const noexcept
20812 return is_number_float() ? &m_data.m_value.number_float :
nullptr;
20816 binary_t* get_impl_ptr(binary_t* )
noexcept
20818 return is_binary() ? m_data.m_value.binary :
nullptr;
20822 constexpr const binary_t* get_impl_ptr(
const binary_t* )
const noexcept
20824 return is_binary() ? m_data.m_value.binary :
nullptr;
20838 template<
typename ReferenceType,
typename ThisType>
20839 static ReferenceType get_ref_impl(ThisType& obj)
20842 auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
20844 if (JSON_HEDLEY_LIKELY(ptr !=
nullptr))
20849 JSON_THROW(type_error::create(303, detail::concat(
"incompatible ReferenceType for get_ref, actual type is ", obj.type_name()), &obj));
20859 template<
typename PointerType,
typename std::enable_if<
20860 std::is_pointer<PointerType>::value,
int>::type = 0>
20861 auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
20864 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
20869 template <
typename PointerType,
typename std::enable_if <
20870 std::is_pointer<PointerType>::value&&
20871 std::is_const<typename std::remove_pointer<PointerType>::type>::value,
int >::type = 0 >
20872 constexpr auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
20875 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
20917 template <
typename ValueType,
20918 detail::enable_if_t <
20923 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
20925 auto ret = ValueType();
20926 JSONSerializer<ValueType>::from_json(*
this, ret);
20960 template <
typename ValueType,
20961 detail::enable_if_t <
20965 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
20967 return JSONSerializer<ValueType>::from_json(*
this);
20985 template <
typename BasicJsonType,
20986 detail::enable_if_t <
21008 template<
typename BasicJsonType,
21009 detail::enable_if_t<
21010 std::is_same<BasicJsonType, basic_json_t>::value,
21021 template<
typename PointerType,
21022 detail::enable_if_t<
21023 std::is_pointer<PointerType>::value,
21026 ->
decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>())
21029 return get_ptr<PointerType>();
21056 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>>
21057#if defined(JSON_HAS_CPP_14)
21061 noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(
detail::priority_tag<4> {})))
21067 static_assert(!std::is_reference<ValueTypeCV>::value,
21068 "get() cannot be used with reference types, you might want to use get_ref()");
21099 template<
typename PointerType,
typename std::enable_if<
21100 std::is_pointer<PointerType>::value,
int>::type = 0>
21101 auto get() noexcept -> decltype(std::declval<basic_json_t&>().template get_ptr<PointerType>())
21104 return get_ptr<PointerType>();
21109 template <
typename ValueType,
21110 detail::enable_if_t <
21114 ValueType &
get_to(ValueType& v)
const noexcept(
noexcept(
21115 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
21117 JSONSerializer<ValueType>::from_json(*
this, v);
21123 template<
typename ValueType,
21124 detail::enable_if_t <
21127 ValueType & get_to(ValueType& v)
const
21134 typename T, std::size_t N,
21135 typename Array = T (&)[N],
21136 detail::enable_if_t <
21138 Array get_to(T (&v)[N])
const
21139 noexcept(
noexcept(JSONSerializer<Array>::from_json(
21140 std::declval<const basic_json_t&>(), v)))
21142 JSONSerializer<Array>::from_json(*
this, v);
21148 template<
typename ReferenceType,
typename std::enable_if<
21149 std::is_reference<ReferenceType>::value,
int>::type = 0>
21153 return get_ref_impl<ReferenceType>(*
this);
21158 template <
typename ReferenceType,
typename std::enable_if <
21159 std::is_reference<ReferenceType>::value&&
21160 std::is_const<typename std::remove_reference<ReferenceType>::type>::value,
int >::type = 0 >
21164 return get_ref_impl<ReferenceType>(*
this);
21196 template <
typename ValueType,
typename std::enable_if <
21204#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
21207#if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI
21211 >::value,
int >::type = 0 >
21212 JSON_EXPLICIT
operator ValueType()
const
21215 return get<ValueType>();
21224 JSON_THROW(type_error::create(302, detail::concat(
"type must be binary, but is ", type_name()),
this));
21227 return *get_ptr<binary_t*>();
21236 JSON_THROW(type_error::create(302, detail::concat(
"type must be binary, but is ", type_name()),
this));
21239 return *get_ptr<const binary_t*>();
21257 if (JSON_HEDLEY_LIKELY(is_array()))
21261 return set_parent(m_data.m_value.array->at(idx));
21263 JSON_CATCH (std::out_of_range&)
21266 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
21271 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21280 if (JSON_HEDLEY_LIKELY(is_array()))
21284 return m_data.m_value.array->at(idx);
21286 JSON_CATCH (std::out_of_range&)
21289 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
21294 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21303 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21305 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21309 if (it == m_data.m_value.object->end())
21311 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
key,
"' not found"),
this));
21313 return set_parent(it->second);
21318 template<
class KeyType, detail::enable_if_t<
21319 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
21323 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21325 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21328 auto it = m_data.
m_value.object->find(std::forward<KeyType>(
key));
21329 if (it == m_data.m_value.object->end())
21331 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
string_t(std::forward<KeyType>(
key)),
"' not found"),
this));
21333 return set_parent(it->second);
21341 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21343 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21347 if (it == m_data.m_value.object->end())
21349 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
key,
"' not found"),
this));
21356 template<
class KeyType, detail::enable_if_t<
21357 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
21361 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21363 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21366 auto it = m_data.
m_value.object->find(std::forward<KeyType>(
key));
21367 if (it == m_data.m_value.object->end())
21369 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
string_t(std::forward<KeyType>(
key)),
"' not found"),
this));
21381 m_data.m_type = value_t::array;
21382 m_data.m_value.array = create<array_t>();
21383 assert_invariant();
21387 if (JSON_HEDLEY_LIKELY(is_array()))
21390 if (idx >= m_data.m_value.array->size())
21392#if JSON_DIAGNOSTICS
21394 const auto old_size = m_data.m_value.array->size();
21395 const auto old_capacity = m_data.m_value.array->capacity();
21397 m_data.m_value.array->resize(idx + 1);
21399#if JSON_DIAGNOSTICS
21400 if (JSON_HEDLEY_UNLIKELY(m_data.m_value.array->capacity() != old_capacity))
21408 set_parents(begin() +
static_cast<typename iterator::difference_type
>(old_size),
static_cast<typename iterator::difference_type
>(idx + 1 - old_size));
21411 assert_invariant();
21414 return m_data.m_value.array->operator[](idx);
21417 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a numeric argument with ", type_name()),
this));
21425 if (JSON_HEDLEY_LIKELY(is_array()))
21427 return m_data.m_value.array->operator[](idx);
21430 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a numeric argument with ", type_name()),
this));
21440 m_data.m_type = value_t::object;
21441 m_data.m_value.object = create<object_t>();
21442 assert_invariant();
21446 if (JSON_HEDLEY_LIKELY(is_object()))
21448 auto result = m_data.m_value.object->emplace(std::move(
key),
nullptr);
21449 return set_parent(result.first->second);
21452 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
21460 if (JSON_HEDLEY_LIKELY(is_object()))
21462 auto it = m_data.m_value.object->find(
key);
21463 JSON_ASSERT(it != m_data.m_value.object->end());
21467 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
21472 template<
typename T>
21473 reference operator[](T*
key)
21475 return operator[](
typename object_t::key_type(
key));
21478 template<
typename T>
21479 const_reference operator[](T*
key)
const
21481 return operator[](
typename object_t::key_type(
key));
21486 template<
class KeyType, detail::enable_if_t<
21487 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int > = 0 >
21493 m_data.m_type = value_t::object;
21494 m_data.m_value.object = create<object_t>();
21495 assert_invariant();
21499 if (JSON_HEDLEY_LIKELY(is_object()))
21501 auto result = m_data.m_value.object->emplace(std::forward<KeyType>(
key),
nullptr);
21502 return set_parent(result.first->second);
21505 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
21510 template<
class KeyType, detail::enable_if_t<
21511 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int > = 0 >
21515 if (JSON_HEDLEY_LIKELY(is_object()))
21517 auto it = m_data.m_value.object->find(std::forward<KeyType>(
key));
21518 JSON_ASSERT(it != m_data.m_value.object->end());
21522 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
21526 template<
typename KeyType>
21528 object_comparator_t,
const typename object_t::key_type&, KeyType >;
21530 template<
typename ValueType>
21531 using value_return_type = std::conditional <
21533 string_t,
typename std::decay<ValueType>::type >;
21538 template <
class ValueType, detail::enable_if_t <
21541 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21542 ValueType
value(
const typename object_t::key_type&
key,
const ValueType& default_value)
const
21545 if (JSON_HEDLEY_LIKELY(is_object()))
21548 const auto it = find(
key);
21551 return it->template get<ValueType>();
21554 return default_value;
21557 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21562 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
21563 detail::enable_if_t <
21566 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21567 ReturnType
value(
const typename object_t::key_type&
key, ValueType && default_value)
const
21570 if (JSON_HEDLEY_LIKELY(is_object()))
21573 const auto it = find(
key);
21576 return it->template get<ReturnType>();
21579 return std::forward<ValueType>(default_value);
21582 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21587 template <
class ValueType,
class KeyType, detail::enable_if_t <
21590 && is_comparable_with_object_key<KeyType>::value
21592 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21593 ValueType
value(KeyType &&
key,
const ValueType& default_value)
const
21596 if (JSON_HEDLEY_LIKELY(is_object()))
21599 const auto it = find(std::forward<KeyType>(
key));
21602 return it->template get<ValueType>();
21605 return default_value;
21608 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21613 template < class ValueType, class KeyType, class ReturnType = typename value_return_type<ValueType>::type,
21614 detail::enable_if_t <
21617 && is_comparable_with_object_key<KeyType>::value
21619 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21620 ReturnType
value(KeyType &&
key, ValueType && default_value)
const
21623 if (JSON_HEDLEY_LIKELY(is_object()))
21626 const auto it = find(std::forward<KeyType>(
key));
21629 return it->template get<ReturnType>();
21632 return std::forward<ValueType>(default_value);
21635 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21640 template <
class ValueType, detail::enable_if_t <
21642 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21646 if (JSON_HEDLEY_LIKELY(is_object()))
21651 return ptr.get_checked(
this).template get<ValueType>();
21655 return default_value;
21659 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21664 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
21665 detail::enable_if_t <
21667 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21671 if (JSON_HEDLEY_LIKELY(is_object()))
21676 return ptr.get_checked(
this).template get<ReturnType>();
21680 return std::forward<ValueType>(default_value);
21684 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21687 template <
class ValueType,
class BasicJsonType, detail::enable_if_t <
21690 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21692 ValueType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr,
const ValueType& default_value)
const
21694 return value(ptr.convert(), default_value);
21697 template < class ValueType, class BasicJsonType, class ReturnType = typename value_return_type<ValueType>::type,
21698 detail::enable_if_t <
21701 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21703 ReturnType
value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, ValueType && default_value)
const
21705 return value(ptr.convert(), std::forward<ValueType>(default_value));
21742 template <
class IteratorType, detail::enable_if_t <
21743 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21744 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
21748 if (JSON_HEDLEY_UNLIKELY(
this != pos.m_object))
21750 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
21753 IteratorType result = end();
21755 switch (m_data.m_type)
21757 case value_t::boolean:
21758 case value_t::number_float:
21759 case value_t::number_integer:
21760 case value_t::number_unsigned:
21761 case value_t::string:
21762 case value_t::binary:
21764 if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
21766 JSON_THROW(invalid_iterator::create(205,
"iterator out of range",
this));
21771 AllocatorType<string_t> alloc;
21772 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.string);
21773 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.string, 1);
21774 m_data.m_value.string =
nullptr;
21776 else if (is_binary())
21778 AllocatorType<binary_t> alloc;
21779 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.binary);
21780 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.binary, 1);
21781 m_data.m_value.binary =
nullptr;
21784 m_data.m_type = value_t::null;
21785 assert_invariant();
21789 case value_t::object:
21791 result.m_it.object_iterator = m_data.m_value.object->erase(pos.m_it.object_iterator);
21795 case value_t::array:
21797 result.m_it.array_iterator = m_data.m_value.array->erase(pos.m_it.array_iterator);
21801 case value_t::null:
21802 case value_t::discarded:
21804 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
21812 template <
class IteratorType, detail::enable_if_t <
21813 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21814 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
21815 IteratorType
erase(IteratorType first, IteratorType last)
21818 if (JSON_HEDLEY_UNLIKELY(
this != first.m_object ||
this != last.m_object))
21820 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value",
this));
21823 IteratorType result = end();
21825 switch (m_data.m_type)
21827 case value_t::boolean:
21828 case value_t::number_float:
21829 case value_t::number_integer:
21830 case value_t::number_unsigned:
21831 case value_t::string:
21832 case value_t::binary:
21834 if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
21835 || !last.m_it.primitive_iterator.is_end()))
21837 JSON_THROW(invalid_iterator::create(204,
"iterators out of range",
this));
21842 AllocatorType<string_t> alloc;
21843 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.string);
21844 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.string, 1);
21845 m_data.m_value.string =
nullptr;
21847 else if (is_binary())
21849 AllocatorType<binary_t> alloc;
21850 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.binary);
21851 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.binary, 1);
21852 m_data.m_value.binary =
nullptr;
21855 m_data.m_type = value_t::null;
21856 assert_invariant();
21860 case value_t::object:
21862 result.m_it.object_iterator = m_data.m_value.object->erase(first.m_it.object_iterator,
21863 last.m_it.object_iterator);
21867 case value_t::array:
21869 result.m_it.array_iterator = m_data.m_value.array->erase(first.m_it.array_iterator,
21870 last.m_it.array_iterator);
21874 case value_t::null:
21875 case value_t::discarded:
21877 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
21884 template <
typename KeyType, detail::enable_if_t <
21885 detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int > = 0 >
21886 size_type erase_internal(KeyType &&
key)
21889 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21891 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
21894 return m_data.m_value.object->erase(std::forward<KeyType>(
key));
21897 template <
typename KeyType, detail::enable_if_t <
21898 !detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int > = 0 >
21899 size_type erase_internal(KeyType &&
key)
21902 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21904 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
21907 const auto it = m_data.m_value.object->find(std::forward<KeyType>(
key));
21908 if (it != m_data.m_value.object->end())
21910 m_data.m_value.object->erase(it);
21924 return erase_internal(
key);
21929 template<
class KeyType, detail::enable_if_t<
21930 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
21933 return erase_internal(std::forward<KeyType>(
key));
21941 if (JSON_HEDLEY_LIKELY(is_array()))
21943 if (JSON_HEDLEY_UNLIKELY(idx >= size()))
21945 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
21948 m_data.m_value.array->erase(m_data.m_value.array->begin() +
static_cast<difference_type>(idx));
21952 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
21969 auto result = end();
21973 result.m_it.object_iterator = m_data.m_value.object->find(
key);
21983 auto result = cend();
21987 result.m_it.object_iterator = m_data.m_value.object->find(
key);
21995 template<
class KeyType, detail::enable_if_t<
21996 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
21999 auto result = end();
22003 result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(
key));
22011 template<
class KeyType, detail::enable_if_t<
22012 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22015 auto result = cend();
22019 result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(
key));
22030 return is_object() ? m_data.m_value.object->count(
key) : 0;
22035 template<
class KeyType, detail::enable_if_t<
22036 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22040 return is_object() ? m_data.m_value.object->count(std::forward<KeyType>(
key)) : 0;
22047 return is_object() && m_data.m_value.object->find(
key) != m_data.m_value.object->end();
22052 template<
class KeyType, detail::enable_if_t<
22053 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22056 return is_object() && m_data.m_value.object->find(std::forward<KeyType>(
key)) != m_data.m_value.object->end();
22063 return ptr.contains(
this);
22066 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
22068 bool contains(
const typename ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
22070 return ptr.contains(
this);
22087 result.set_begin();
22103 result.set_begin();
22180 JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
22183 return ref.items();
22191 JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
22194 return ref.items();
22201 return iteration_proxy<iterator>(*
this);
22206 iteration_proxy<const_iterator>
items() const noexcept
22208 return iteration_proxy<const_iterator>(*
this);
22224 switch (m_data.m_type)
22226 case value_t::null:
22232 case value_t::array:
22235 return m_data.m_value.array->empty();
22238 case value_t::object:
22241 return m_data.m_value.object->empty();
22244 case value_t::string:
22245 case value_t::boolean:
22246 case value_t::number_integer:
22247 case value_t::number_unsigned:
22248 case value_t::number_float:
22249 case value_t::binary:
22250 case value_t::discarded:
22263 switch (m_data.m_type)
22265 case value_t::null:
22271 case value_t::array:
22274 return m_data.m_value.array->size();
22277 case value_t::object:
22280 return m_data.m_value.object->size();
22283 case value_t::string:
22284 case value_t::boolean:
22285 case value_t::number_integer:
22286 case value_t::number_unsigned:
22287 case value_t::number_float:
22288 case value_t::binary:
22289 case value_t::discarded:
22302 switch (m_data.m_type)
22304 case value_t::array:
22307 return m_data.m_value.array->max_size();
22310 case value_t::object:
22313 return m_data.m_value.object->max_size();
22316 case value_t::null:
22317 case value_t::string:
22318 case value_t::boolean:
22319 case value_t::number_integer:
22320 case value_t::number_unsigned:
22321 case value_t::number_float:
22322 case value_t::binary:
22323 case value_t::discarded:
22345 switch (m_data.m_type)
22347 case value_t::number_integer:
22349 m_data.m_value.number_integer = 0;
22353 case value_t::number_unsigned:
22355 m_data.m_value.number_unsigned = 0;
22359 case value_t::number_float:
22361 m_data.m_value.number_float = 0.0;
22365 case value_t::boolean:
22367 m_data.m_value.boolean =
false;
22371 case value_t::string:
22373 m_data.m_value.string->clear();
22377 case value_t::binary:
22379 m_data.m_value.binary->clear();
22383 case value_t::array:
22385 m_data.m_value.array->clear();
22389 case value_t::object:
22391 m_data.m_value.object->clear();
22395 case value_t::null:
22396 case value_t::discarded:
22407 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
22409 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
22415 m_data.m_type = value_t::array;
22416 m_data.m_value = value_t::array;
22417 assert_invariant();
22421 const auto old_capacity = m_data.m_value.array->capacity();
22422 m_data.m_value.array->push_back(std::move(val));
22423 set_parent(m_data.m_value.array->back(), old_capacity);
22431 push_back(std::move(val));
22440 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
22442 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
22448 m_data.m_type = value_t::array;
22449 m_data.m_value = value_t::array;
22450 assert_invariant();
22454 const auto old_capacity = m_data.m_value.array->capacity();
22455 m_data.m_value.array->push_back(val);
22456 set_parent(m_data.m_value.array->back(), old_capacity);
22472 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
22474 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
22480 m_data.m_type = value_t::object;
22481 m_data.m_value = value_t::object;
22482 assert_invariant();
22486 auto res = m_data.m_value.object->insert(val);
22487 set_parent(res.first->second);
22502 if (is_object() && init.size() == 2 && (*init.begin())->is_string())
22505 push_back(
typename object_t::value_type(
22506 std::move(
key.get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
22524 template<
class... Args>
22528 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
22530 JSON_THROW(type_error::create(311, detail::concat(
"cannot use emplace_back() with ", type_name()),
this));
22536 m_data.m_type = value_t::array;
22537 m_data.m_value = value_t::array;
22538 assert_invariant();
22542 const auto old_capacity = m_data.
m_value.array->capacity();
22543 m_data.m_value.array->emplace_back(std::forward<Args>(args)...);
22544 return set_parent(m_data.m_value.array->back(), old_capacity);
22549 template<
class... Args>
22553 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
22555 JSON_THROW(type_error::create(311, detail::concat(
"cannot use emplace() with ", type_name()),
this));
22561 m_data.m_type = value_t::object;
22562 m_data.m_value = value_t::object;
22563 assert_invariant();
22567 auto res = m_data.m_value.object->emplace(std::forward<Args>(args)...);
22568 set_parent(res.first->second);
22572 it.m_it.object_iterator = res.first;
22575 return {it, res.second};
22581 template<
typename... Args>
22585 JSON_ASSERT(m_data.m_value.array !=
nullptr);
22587 auto insert_pos = std::distance(m_data.m_value.array->begin(), pos.m_it.array_iterator);
22588 m_data.m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
22589 result.m_it.array_iterator = m_data.m_value.array->begin() + insert_pos;
22604 if (JSON_HEDLEY_LIKELY(is_array()))
22607 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22609 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
22613 return insert_iterator(pos, val);
22616 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
22623 return insert(pos, val);
22631 if (JSON_HEDLEY_LIKELY(is_array()))
22634 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22636 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
22640 return insert_iterator(pos, cnt, val);
22643 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
22651 if (JSON_HEDLEY_UNLIKELY(!is_array()))
22653 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
22657 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22659 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
22663 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22665 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
22668 if (JSON_HEDLEY_UNLIKELY(first.m_object ==
this))
22670 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container",
this));
22674 return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
22682 if (JSON_HEDLEY_UNLIKELY(!is_array()))
22684 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
22688 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22690 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
22694 return insert_iterator(pos, ilist.begin(), ilist.end());
22702 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22704 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
22708 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22710 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
22714 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
22716 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects",
this));
22719 m_data.m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
22726 update(j.
begin(), j.
end(), merge_objects);
22736 m_data.m_type = value_t::object;
22737 m_data.m_value.object = create<object_t>();
22738 assert_invariant();
22741 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22743 JSON_THROW(type_error::create(312, detail::concat(
"cannot use update() with ", type_name()),
this));
22747 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22749 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
22753 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
22755 JSON_THROW(type_error::create(312, detail::concat(
"cannot use update() with ", first.m_object->type_name()), first.m_object));
22758 for (
auto it = first; it != last; ++it)
22760 if (merge_objects && it.value().is_object())
22762 auto it2 = m_data.m_value.object->find(it.key());
22763 if (it2 != m_data.m_value.object->end())
22765 it2->second.update(it.value(),
true);
22769 m_data.m_value.object->operator[](it.key()) = it.value();
22770#if JSON_DIAGNOSTICS
22771 m_data.m_value.object->operator[](it.key()).m_parent =
this;
22779 std::is_nothrow_move_constructible<value_t>::value&&
22780 std::is_nothrow_move_assignable<value_t>::value&&
22781 std::is_nothrow_move_constructible<json_value>::value&&
22782 std::is_nothrow_move_assignable<json_value>::value
22785 std::swap(m_data.m_type, other.m_data.m_type);
22786 std::swap(m_data.m_value, other.m_data.m_value);
22789 other.set_parents();
22790 assert_invariant();
22796 std::is_nothrow_move_constructible<value_t>::value&&
22797 std::is_nothrow_move_assignable<value_t>::value&&
22798 std::is_nothrow_move_constructible<json_value>::value&&
22799 std::is_nothrow_move_assignable<json_value>::value
22810 if (JSON_HEDLEY_LIKELY(is_array()))
22813 swap(*(m_data.m_value.array), other);
22817 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(array_t&) with ", type_name()),
this));
22826 if (JSON_HEDLEY_LIKELY(is_object()))
22829 swap(*(m_data.m_value.object), other);
22833 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(object_t&) with ", type_name()),
this));
22842 if (JSON_HEDLEY_LIKELY(is_string()))
22845 swap(*(m_data.m_value.string), other);
22849 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(string_t&) with ", type_name()),
this));
22858 if (JSON_HEDLEY_LIKELY(is_binary()))
22861 swap(*(m_data.m_value.binary), other);
22865 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(binary_t&) with ", type_name()),
this));
22871 void swap(
typename binary_t::container_type& other)
22874 if (JSON_HEDLEY_LIKELY(is_binary()))
22877 swap(*(m_data.m_value.binary), other);
22881 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(binary_t::container_type&) with ", type_name()),
this));
22896#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result) \
22897 const auto lhs_type = lhs.type(); \
22898 const auto rhs_type = rhs.type(); \
22900 if (lhs_type == rhs_type) \
22902 switch (lhs_type) \
22904 case value_t::array: \
22905 return (*lhs.m_data.m_value.array) op (*rhs.m_data.m_value.array); \
22907 case value_t::object: \
22908 return (*lhs.m_data.m_value.object) op (*rhs.m_data.m_value.object); \
22910 case value_t::null: \
22911 return (null_result); \
22913 case value_t::string: \
22914 return (*lhs.m_data.m_value.string) op (*rhs.m_data.m_value.string); \
22916 case value_t::boolean: \
22917 return (lhs.m_data.m_value.boolean) op (rhs.m_data.m_value.boolean); \
22919 case value_t::number_integer: \
22920 return (lhs.m_data.m_value.number_integer) op (rhs.m_data.m_value.number_integer); \
22922 case value_t::number_unsigned: \
22923 return (lhs.m_data.m_value.number_unsigned) op (rhs.m_data.m_value.number_unsigned); \
22925 case value_t::number_float: \
22926 return (lhs.m_data.m_value.number_float) op (rhs.m_data.m_value.number_float); \
22928 case value_t::binary: \
22929 return (*lhs.m_data.m_value.binary) op (*rhs.m_data.m_value.binary); \
22931 case value_t::discarded: \
22933 return (unordered_result); \
22936 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) \
22938 return static_cast<number_float_t>(lhs.m_data.m_value.number_integer) op rhs.m_data.m_value.number_float; \
22940 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) \
22942 return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_integer); \
22944 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) \
22946 return static_cast<number_float_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_float; \
22948 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) \
22950 return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_unsigned); \
22952 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) \
22954 return static_cast<number_integer_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_integer; \
22956 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) \
22958 return lhs.m_data.m_value.number_integer op static_cast<number_integer_t>(rhs.m_data.m_value.number_unsigned); \
22960 else if(compares_unordered(lhs, rhs))\
22962 return (unordered_result);\
22965 return (default_result);
22967 JSON_PRIVATE_UNLESS_TESTED:
22973 static bool compares_unordered(const_reference lhs, const_reference rhs,
bool inverse =
false) noexcept
22975 if ((lhs.is_number_float() && std::isnan(lhs.m_data.m_value.number_float) && rhs.is_number())
22976 || (rhs.is_number_float() && std::isnan(rhs.m_data.m_value.number_float) && lhs.is_number()))
22980#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
22981 return (lhs.is_discarded() || rhs.is_discarded()) && !inverse;
22983 static_cast<void>(inverse);
22984 return lhs.is_discarded() || rhs.is_discarded();
22989 bool compares_unordered(const_reference rhs,
bool inverse =
false) const noexcept
22991 return compares_unordered(*
this, rhs, inverse);
22995#if JSON_HAS_THREE_WAY_COMPARISON
22998 bool operator==(const_reference rhs)
const noexcept
23001#pragma GCC diagnostic push
23002#pragma GCC diagnostic ignored "-Wfloat-equal"
23004 const_reference lhs = *
this;
23005 JSON_IMPLEMENT_OPERATOR( ==,
true,
false,
false)
23007#pragma GCC diagnostic pop
23013 template<
typename ScalarType>
23014 requires std::is_scalar_v<ScalarType>
23015 bool operator==(ScalarType rhs)
const noexcept
23022 bool operator!=(const_reference rhs)
const noexcept
23024 if (compares_unordered(rhs,
true))
23028 return !operator==(rhs);
23033 std::partial_ordering operator<=>(const_reference rhs)
const noexcept
23035 const_reference lhs = *
this;
23038 JSON_IMPLEMENT_OPERATOR(<=>,
23039 std::partial_ordering::equivalent,
23040 std::partial_ordering::unordered,
23041 lhs_type <=> rhs_type)
23046 template<
typename ScalarType>
23047 requires std::is_scalar_v<ScalarType>
23048 std::partial_ordering operator<=>(ScalarType rhs)
const noexcept
23053#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
23059 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON)
23060 bool operator<=(const_reference rhs)
const noexcept
23062 if (compares_unordered(rhs,
true))
23066 return !(rhs < *
this);
23071 template<
typename ScalarType>
23072 requires std::is_scalar_v<ScalarType>
23073 bool operator<=(ScalarType rhs)
const noexcept
23080 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON)
23081 bool operator>=(const_reference rhs)
const noexcept
23083 if (compares_unordered(rhs,
true))
23087 return !(*
this < rhs);
23092 template<
typename ScalarType>
23093 requires std::is_scalar_v<ScalarType>
23094 bool operator>=(ScalarType rhs)
const noexcept
23102 friend bool operator==(const_reference lhs, const_reference rhs)
noexcept
23105#pragma GCC diagnostic push
23106#pragma GCC diagnostic ignored "-Wfloat-equal"
23108 JSON_IMPLEMENT_OPERATOR( ==,
true,
false,
false)
23110#pragma GCC diagnostic pop
23116 template<
typename ScalarType,
typename std::enable_if<
23117 std::is_scalar<ScalarType>::value,
int>::type = 0>
23118 friend bool operator==(const_reference lhs, ScalarType rhs)
noexcept
23125 template<
typename ScalarType,
typename std::enable_if<
23126 std::is_scalar<ScalarType>::value,
int>::type = 0>
23127 friend bool operator==(ScalarType lhs, const_reference rhs)
noexcept
23134 friend bool operator!=(const_reference lhs, const_reference rhs)
noexcept
23136 if (compares_unordered(lhs, rhs,
true))
23140 return !(lhs == rhs);
23145 template<
typename ScalarType,
typename std::enable_if<
23146 std::is_scalar<ScalarType>::value,
int>::type = 0>
23147 friend bool operator!=(const_reference lhs, ScalarType rhs)
noexcept
23154 template<
typename ScalarType,
typename std::enable_if<
23155 std::is_scalar<ScalarType>::value,
int>::type = 0>
23156 friend bool operator!=(ScalarType lhs, const_reference rhs)
noexcept
23163 friend bool operator<(const_reference lhs, const_reference rhs)
noexcept
23168 JSON_IMPLEMENT_OPERATOR( <,
false,
false,
operator<(lhs_type, rhs_type))
23173 template<
typename ScalarType,
typename std::enable_if<
23174 std::is_scalar<ScalarType>::value,
int>::type = 0>
23175 friend bool operator<(const_reference lhs, ScalarType rhs)
noexcept
23182 template<
typename ScalarType,
typename std::enable_if<
23183 std::is_scalar<ScalarType>::value,
int>::type = 0>
23184 friend bool operator<(ScalarType lhs, const_reference rhs)
noexcept
23191 friend bool operator<=(const_reference lhs, const_reference rhs)
noexcept
23193 if (compares_unordered(lhs, rhs,
true))
23197 return !(rhs < lhs);
23202 template<
typename ScalarType,
typename std::enable_if<
23203 std::is_scalar<ScalarType>::value,
int>::type = 0>
23204 friend bool operator<=(const_reference lhs, ScalarType rhs)
noexcept
23211 template<
typename ScalarType,
typename std::enable_if<
23212 std::is_scalar<ScalarType>::value,
int>::type = 0>
23213 friend bool operator<=(ScalarType lhs, const_reference rhs)
noexcept
23220 friend bool operator>(const_reference lhs, const_reference rhs)
noexcept
23223 if (compares_unordered(lhs, rhs))
23227 return !(lhs <= rhs);
23232 template<
typename ScalarType,
typename std::enable_if<
23233 std::is_scalar<ScalarType>::value,
int>::type = 0>
23234 friend bool operator>(const_reference lhs, ScalarType rhs)
noexcept
23241 template<
typename ScalarType,
typename std::enable_if<
23242 std::is_scalar<ScalarType>::value,
int>::type = 0>
23243 friend bool operator>(ScalarType lhs, const_reference rhs)
noexcept
23250 friend bool operator>=(const_reference lhs, const_reference rhs)
noexcept
23252 if (compares_unordered(lhs, rhs,
true))
23256 return !(lhs < rhs);
23261 template<
typename ScalarType,
typename std::enable_if<
23262 std::is_scalar<ScalarType>::value,
int>::type = 0>
23263 friend bool operator>=(const_reference lhs, ScalarType rhs)
noexcept
23270 template<
typename ScalarType,
typename std::enable_if<
23271 std::is_scalar<ScalarType>::value,
int>::type = 0>
23272 friend bool operator>=(ScalarType lhs, const_reference rhs)
noexcept
23278#undef JSON_IMPLEMENT_OPERATOR
23291 friend std::ostream& operator<<(std::ostream& o,
const basic_json& j)
23294 const bool pretty_print = o.width() > 0;
23295 const auto indentation = pretty_print ? o.width() : 0;
23302 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
23312 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator<<(std::ostream&,
const basic_json&))
23313 friend std::ostream& operator>>(
const basic_json& j, std::ostream& o)
23329 template<
typename InputType>
23330 JSON_HEDLEY_WARN_UNUSED_RESULT
23332 const parser_callback_t cb =
nullptr,
23333 const bool allow_exceptions =
true,
23334 const bool ignore_comments =
false)
23337 parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(
true, result);
23343 template<
typename IteratorType>
23344 JSON_HEDLEY_WARN_UNUSED_RESULT
23347 const parser_callback_t cb =
nullptr,
23348 const bool allow_exceptions =
true,
23349 const bool ignore_comments =
false)
23352 parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(
true, result);
23356 JSON_HEDLEY_WARN_UNUSED_RESULT
23357 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len))
23359 const parser_callback_t cb =
nullptr,
23360 const bool allow_exceptions =
true,
23361 const bool ignore_comments =
false)
23364 parser(i.get(), cb, allow_exceptions, ignore_comments).parse(
true, result);
23370 template<
typename InputType>
23371 static bool accept(InputType&& i,
23372 const bool ignore_comments =
false)
23374 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false, ignore_comments).accept(
true);
23379 template<
typename IteratorType>
23380 static bool accept(IteratorType first, IteratorType last,
23381 const bool ignore_comments =
false)
23383 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false, ignore_comments).accept(
true);
23386 JSON_HEDLEY_WARN_UNUSED_RESULT
23387 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len))
23389 const bool ignore_comments =
false)
23391 return parser(i.get(),
nullptr,
false, ignore_comments).accept(
true);
23396 template <
typename InputType,
typename SAX>
23397 JSON_HEDLEY_NON_NULL(2)
23398 static
bool sax_parse(InputType&& i, SAX* sax,
23399 input_format_t format = input_format_t::
json,
23400 const
bool strict = true,
23401 const
bool ignore_comments = false)
23403 auto ia = detail::input_adapter(std::forward<InputType>(i));
23404 return format == input_format_t::json
23405 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23411 template<
class IteratorType,
class SAX>
23412 JSON_HEDLEY_NON_NULL(3)
23413 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
23415 const
bool strict = true,
23416 const
bool ignore_comments = false)
23418 auto ia = detail::input_adapter(std::move(first), std::move(last));
23419 return format == input_format_t::json
23420 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23429 template <
typename SAX>
23430 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, sax_parse(ptr, ptr + len, ...))
23431 JSON_HEDLEY_NON_NULL(2)
23432 static
bool sax_parse(
detail::span_input_adapter&& i, SAX* sax,
23434 const
bool strict = true,
23435 const
bool ignore_comments = false)
23438 return format == input_format_t::json
23440 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23451 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator>>(std::istream&,
basic_json&))
23454 return operator>>(i, j);
23461 parser(detail::input_adapter(i)).parse(
false, j);
23473 JSON_HEDLEY_RETURNS_NON_NULL
23476 switch (m_data.m_type)
23478 case value_t::null:
23480 case value_t::object:
23482 case value_t::array:
23484 case value_t::string:
23486 case value_t::boolean:
23488 case value_t::binary:
23490 case value_t::discarded:
23491 return "discarded";
23492 case value_t::number_integer:
23493 case value_t::number_unsigned:
23494 case value_t::number_float:
23500 JSON_PRIVATE_UNLESS_TESTED:
23508 value_t m_type = value_t::null;
23511 json_value m_value = {};
23513 data(
const value_t v)
23514 : m_type(v), m_value(v)
23521 m_value.array = create<array_t>(cnt, val);
23524 data() noexcept = default;
23525 data(data&&) noexcept = default;
23526 data(const data&) noexcept = delete;
23527 data& operator=(data&&) noexcept = delete;
23528 data& operator=(const data&) noexcept = delete;
23532 m_value.destroy(m_type);
23538#if JSON_DIAGNOSTICS
23555 std::vector<std::uint8_t> result;
23556 to_cbor(j, result);
23564 binary_writer<std::uint8_t>(o).write_cbor(j);
23571 binary_writer<char>(o).write_cbor(j);
23578 std::vector<std::uint8_t> result;
23579 to_msgpack(j, result);
23587 binary_writer<std::uint8_t>(o).write_msgpack(j);
23594 binary_writer<char>(o).write_msgpack(j);
23600 const bool use_size =
false,
23601 const bool use_type =
false)
23603 std::vector<std::uint8_t> result;
23604 to_ubjson(j, result, use_size, use_type);
23611 const bool use_size =
false,
const bool use_type =
false)
23613 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);
23619 const bool use_size =
false,
const bool use_type =
false)
23621 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
23627 const bool use_size =
false,
23628 const bool use_type =
false)
23630 std::vector<std::uint8_t> result;
23631 to_bjdata(j, result, use_size, use_type);
23638 const bool use_size =
false,
const bool use_type =
false)
23640 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type,
true,
true);
23646 const bool use_size =
false,
const bool use_type =
false)
23648 binary_writer<char>(o).write_ubjson(j, use_size, use_type,
true,
true);
23655 std::vector<std::uint8_t> result;
23656 to_bson(j, result);
23664 binary_writer<std::uint8_t>(o).write_bson(j);
23671 binary_writer<char>(o).write_bson(j);
23676 template<
typename InputType>
23677 JSON_HEDLEY_WARN_UNUSED_RESULT
23679 const bool strict =
true,
23680 const bool allow_exceptions =
true,
23685 auto ia = detail::input_adapter(std::forward<InputType>(i));
23686 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
23687 return res ? result :
basic_json(value_t::discarded);
23692 template<
typename IteratorType>
23693 JSON_HEDLEY_WARN_UNUSED_RESULT
23695 const bool strict =
true,
23696 const bool allow_exceptions =
true,
23701 auto ia = detail::input_adapter(std::move(first), std::move(last));
23702 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
23703 return res ? result :
basic_json(value_t::discarded);
23706 template<
typename T>
23707 JSON_HEDLEY_WARN_UNUSED_RESULT
23708 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
23709 static basic_json from_cbor(
const T* ptr, std::size_t len,
23710 const bool strict =
true,
23711 const bool allow_exceptions =
true,
23712 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
23714 return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
23717 JSON_HEDLEY_WARN_UNUSED_RESULT
23718 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
23720 const bool strict =
true,
23721 const bool allow_exceptions =
true,
23722 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
23728 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
23729 return res ? result :
basic_json(value_t::discarded);
23734 template<
typename InputType>
23735 JSON_HEDLEY_WARN_UNUSED_RESULT
23737 const bool strict =
true,
23738 const bool allow_exceptions =
true)
23742 auto ia = detail::input_adapter(std::forward<InputType>(i));
23743 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
23744 return res ? result :
basic_json(value_t::discarded);
23749 template<
typename IteratorType>
23750 JSON_HEDLEY_WARN_UNUSED_RESULT
23752 const bool strict =
true,
23753 const bool allow_exceptions =
true)
23757 auto ia = detail::input_adapter(std::move(first), std::move(last));
23758 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
23759 return res ? result :
basic_json(value_t::discarded);
23762 template<
typename T>
23763 JSON_HEDLEY_WARN_UNUSED_RESULT
23764 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
23765 static basic_json from_msgpack(
const T* ptr, std::size_t len,
23766 const bool strict =
true,
23767 const bool allow_exceptions =
true)
23769 return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
23772 JSON_HEDLEY_WARN_UNUSED_RESULT
23773 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
23775 const bool strict =
true,
23776 const bool allow_exceptions =
true)
23782 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
23783 return res ? result :
basic_json(value_t::discarded);
23788 template<
typename InputType>
23789 JSON_HEDLEY_WARN_UNUSED_RESULT
23791 const bool strict =
true,
23792 const bool allow_exceptions =
true)
23796 auto ia = detail::input_adapter(std::forward<InputType>(i));
23797 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
23798 return res ? result :
basic_json(value_t::discarded);
23803 template<
typename IteratorType>
23804 JSON_HEDLEY_WARN_UNUSED_RESULT
23806 const bool strict =
true,
23807 const bool allow_exceptions =
true)
23811 auto ia = detail::input_adapter(std::move(first), std::move(last));
23812 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
23813 return res ? result :
basic_json(value_t::discarded);
23816 template<
typename T>
23817 JSON_HEDLEY_WARN_UNUSED_RESULT
23818 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
23819 static basic_json from_ubjson(
const T* ptr, std::size_t len,
23820 const bool strict =
true,
23821 const bool allow_exceptions =
true)
23823 return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
23826 JSON_HEDLEY_WARN_UNUSED_RESULT
23827 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
23829 const bool strict =
true,
23830 const bool allow_exceptions =
true)
23836 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
23837 return res ? result :
basic_json(value_t::discarded);
23842 template<
typename InputType>
23843 JSON_HEDLEY_WARN_UNUSED_RESULT
23845 const bool strict =
true,
23846 const bool allow_exceptions =
true)
23850 auto ia = detail::input_adapter(std::forward<InputType>(i));
23851 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
23852 return res ? result :
basic_json(value_t::discarded);
23857 template<
typename IteratorType>
23858 JSON_HEDLEY_WARN_UNUSED_RESULT
23860 const bool strict =
true,
23861 const bool allow_exceptions =
true)
23865 auto ia = detail::input_adapter(std::move(first), std::move(last));
23866 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
23867 return res ? result :
basic_json(value_t::discarded);
23872 template<
typename InputType>
23873 JSON_HEDLEY_WARN_UNUSED_RESULT
23875 const bool strict =
true,
23876 const bool allow_exceptions =
true)
23880 auto ia = detail::input_adapter(std::forward<InputType>(i));
23881 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
23882 return res ? result :
basic_json(value_t::discarded);
23887 template<
typename IteratorType>
23888 JSON_HEDLEY_WARN_UNUSED_RESULT
23890 const bool strict =
true,
23891 const bool allow_exceptions =
true)
23895 auto ia = detail::input_adapter(std::move(first), std::move(last));
23896 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
23897 return res ? result :
basic_json(value_t::discarded);
23900 template<
typename T>
23901 JSON_HEDLEY_WARN_UNUSED_RESULT
23902 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
23903 static basic_json from_bson(
const T* ptr, std::size_t len,
23904 const bool strict =
true,
23905 const bool allow_exceptions =
true)
23907 return from_bson(ptr, ptr + len, strict, allow_exceptions);
23910 JSON_HEDLEY_WARN_UNUSED_RESULT
23911 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
23913 const bool strict =
true,
23914 const bool allow_exceptions =
true)
23920 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
23921 return res ? result :
basic_json(value_t::discarded);
23936 return ptr.get_unchecked(
this);
23939 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
23941 reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr)
23943 return ptr.get_unchecked(
this);
23950 return ptr.get_unchecked(
this);
23953 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
23955 const_reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
23957 return ptr.get_unchecked(
this);
23964 return ptr.get_checked(
this);
23967 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
23969 reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr)
23971 return ptr.get_checked(
this);
23978 return ptr.get_checked(
this);
23981 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
23983 const_reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
23985 return ptr.get_checked(
this);
23993 json_pointer::flatten(
"", *
this, result);
24001 return json_pointer::unflatten(*
this);
24019 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
24021 const auto get_op = [](
const std::string & op)
24025 return patch_operations::add;
24027 if (op ==
"remove")
24029 return patch_operations::remove;
24031 if (op ==
"replace")
24033 return patch_operations::replace;
24037 return patch_operations::move;
24041 return patch_operations::copy;
24045 return patch_operations::test;
24048 return patch_operations::invalid;
24063 if (top_pointer != ptr)
24065 result.
at(top_pointer);
24069 const auto last_path = ptr.
back();
24074 switch (parent.m_data.m_type)
24076 case value_t::null:
24077 case value_t::object:
24080 parent[last_path] = val;
24084 case value_t::array:
24086 if (last_path ==
"-")
24093 const auto idx = json_pointer::template array_index<basic_json_t>(last_path);
24094 if (JSON_HEDLEY_UNLIKELY(idx > parent.
size()))
24097 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"), &parent));
24107 case value_t::string:
24108 case value_t::boolean:
24109 case value_t::number_integer:
24110 case value_t::number_unsigned:
24111 case value_t::number_float:
24112 case value_t::binary:
24113 case value_t::discarded:
24115 JSON_ASSERT(
false);
24120 const auto operation_remove = [
this, & result](
json_pointer & ptr)
24123 const auto last_path = ptr.
back();
24131 auto it = parent.
find(last_path);
24132 if (JSON_HEDLEY_LIKELY(it != parent.
end()))
24138 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", last_path,
"' not found"),
this));
24144 parent.
erase(json_pointer::template array_index<basic_json_t>(last_path));
24149 if (JSON_HEDLEY_UNLIKELY(!json_patch.
is_array()))
24151 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", &json_patch));
24155 for (
const auto& val : json_patch)
24158 const auto get_value = [&val](
const std::string & op,
24159 const std::string & member,
24163 auto it = val.m_data.m_value.object->find(member);
24166 const auto error_msg = (op ==
"op") ?
"operation" : detail::concat(
"operation '", op,
'\'');
24169 if (JSON_HEDLEY_UNLIKELY(it == val.m_data.m_value.object->end()))
24172 JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg,
" must have member '", member,
"'"), &val));
24176 if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
24179 JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg,
" must have string member '", member,
"'"), &val));
24187 if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
24189 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", &val));
24193 const auto op = get_value(
"op",
"op",
true).template get<std::string>();
24194 const auto path = get_value(op,
"path",
true).template get<std::string>();
24197 switch (get_op(op))
24199 case patch_operations::add:
24201 operation_add(ptr, get_value(
"add",
"value",
false));
24205 case patch_operations::remove:
24207 operation_remove(ptr);
24211 case patch_operations::replace:
24214 result.
at(ptr) = get_value(
"replace",
"value",
false);
24218 case patch_operations::move:
24220 const auto from_path = get_value(
"move",
"from",
true).template get<std::string>();
24230 operation_remove(from_ptr);
24231 operation_add(ptr, v);
24235 case patch_operations::copy:
24237 const auto from_path = get_value(
"copy",
"from",
true).template get<std::string>();
24246 operation_add(ptr, v);
24250 case patch_operations::test:
24252 bool success =
false;
24257 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
24265 if (JSON_HEDLEY_UNLIKELY(!success))
24267 JSON_THROW(other_error::create(501, detail::concat(
"unsuccessful: ", val.dump()), &val));
24273 case patch_operations::invalid:
24278 JSON_THROW(parse_error::create(105, 0, detail::concat(
"operation value '", op,
"' is invalid"), &val));
24295 JSON_HEDLEY_WARN_UNUSED_RESULT
24297 const std::string& path =
"")
24303 if (source == target)
24308 if (source.
type() != target.
type())
24313 {
"op",
"replace"}, {
"path", path}, {
"value", target}
24318 switch (source.
type())
24320 case value_t::array:
24324 while (i < source.
size() && i < target.
size())
24327 auto temp_diff = diff(source[i], target[i], detail::concat(path,
'/', std::to_string(i)));
24328 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
24337 while (i < source.
size())
24341 result.
insert(result.
begin() + end_index,
object(
24344 {
"path", detail::concat(path,
'/', std::to_string(i))}
24350 while (i < target.
size())
24355 {
"path", detail::concat(path,
"/-")},
24356 {
"value", target[i]}
24364 case value_t::object:
24367 for (
auto it = source.
cbegin(); it != source.
cend(); ++it)
24370 const auto path_key = detail::concat(path,
'/',
detail::escape(it.key()));
24372 if (target.
find(it.key()) != target.
end())
24375 auto temp_diff = diff(it.value(), target[it.key()], path_key);
24376 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
24383 {
"op",
"remove"}, {
"path", path_key}
24389 for (
auto it = target.
cbegin(); it != target.
cend(); ++it)
24391 if (source.
find(it.key()) == source.
end())
24394 const auto path_key = detail::concat(path,
'/',
detail::escape(it.key()));
24397 {
"op",
"add"}, {
"path", path_key},
24398 {
"value", it.value()}
24406 case value_t::null:
24407 case value_t::string:
24408 case value_t::boolean:
24409 case value_t::number_integer:
24410 case value_t::number_unsigned:
24411 case value_t::number_float:
24412 case value_t::binary:
24413 case value_t::discarded:
24419 {
"op",
"replace"}, {
"path", path}, {
"value", target}
24446 for (
auto it = apply_patch.
begin(); it != apply_patch.
end(); ++it)
24448 if (it.value().is_null())
24454 operator[](it.key()).merge_patch(it.value());
24460 *
this = apply_patch;
24469NLOHMANN_BASIC_JSON_TPL_DECLARATION
24470std::string to_string(
const NLOHMANN_BASIC_JSON_TPL& j)
24475inline namespace literals
24477inline namespace json_literals
24482JSON_HEDLEY_NON_NULL(1)
24483#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
24484 inline nlohmann::json
operator ""_json(
const char* s, std::size_t n)
24486 inline nlohmann::json
operator "" _json(
const char* s, std::size_t n)
24489 return nlohmann::json::parse(s, s + n);
24494JSON_HEDLEY_NON_NULL(1)
24495#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
24506NLOHMANN_JSON_NAMESPACE_END
24517NLOHMANN_BASIC_JSON_TPL_DECLARATION
24518struct hash<nlohmann::NLOHMANN_BASIC_JSON_TPL>
24520 std::size_t operator()(
const nlohmann::NLOHMANN_BASIC_JSON_TPL& j)
const
24522 return nlohmann::detail::hash(j);
24528struct less< ::nlohmann::detail::value_t>
24535 ::nlohmann::detail::value_t rhs)
const noexcept
24537#if JSON_HAS_THREE_WAY_COMPARISON
24538 return std::is_lt(lhs <=> rhs);
24540 return ::nlohmann::detail::operator<(lhs, rhs);
24546#ifndef JSON_HAS_CPP_20
24550NLOHMANN_BASIC_JSON_TPL_DECLARATION
24551inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC_JSON_TPL& j2)
noexcept(
24552 is_nothrow_move_constructible<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value&&
24553 is_nothrow_move_assignable<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value)
24562#if JSON_USE_GLOBAL_UDLS
24563 #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
24564 using nlohmann::literals::json_literals::operator
""_json;
24565 using nlohmann::literals::json_literals::operator
""_json_pointer;
24567 using nlohmann::literals::json_literals::operator
"" _json;
24568 using nlohmann::literals::json_literals::operator
"" _json_pointer;
24584#if defined(__clang__)
24585 #pragma clang diagnostic pop
24590#undef JSON_INTERNAL_CATCH
24592#undef JSON_PRIVATE_UNLESS_TESTED
24593#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
24594#undef NLOHMANN_BASIC_JSON_TPL
24595#undef JSON_EXPLICIT
24596#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
24597#undef JSON_INLINE_VARIABLE
24598#undef JSON_NO_UNIQUE_ADDRESS
24599#undef JSON_DISABLE_ENUM_SERIALIZATION
24600#undef JSON_USE_GLOBAL_UDLS
24602#ifndef JSON_TEST_KEEP_MACROS
24605 #undef JSON_HAS_CPP_11
24606 #undef JSON_HAS_CPP_14
24607 #undef JSON_HAS_CPP_17
24608 #undef JSON_HAS_CPP_20
24609 #undef JSON_HAS_FILESYSTEM
24610 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
24611 #undef JSON_HAS_THREE_WAY_COMPARISON
24612 #undef JSON_HAS_RANGES
24613 #undef JSON_HAS_STATIC_RTTI
24614 #undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
24628#undef JSON_HEDLEY_ALWAYS_INLINE
24629#undef JSON_HEDLEY_ARM_VERSION
24630#undef JSON_HEDLEY_ARM_VERSION_CHECK
24631#undef JSON_HEDLEY_ARRAY_PARAM
24632#undef JSON_HEDLEY_ASSUME
24633#undef JSON_HEDLEY_BEGIN_C_DECLS
24634#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
24635#undef JSON_HEDLEY_CLANG_HAS_BUILTIN
24636#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
24637#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
24638#undef JSON_HEDLEY_CLANG_HAS_EXTENSION
24639#undef JSON_HEDLEY_CLANG_HAS_FEATURE
24640#undef JSON_HEDLEY_CLANG_HAS_WARNING
24641#undef JSON_HEDLEY_COMPCERT_VERSION
24642#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
24643#undef JSON_HEDLEY_CONCAT
24644#undef JSON_HEDLEY_CONCAT3
24645#undef JSON_HEDLEY_CONCAT3_EX
24646#undef JSON_HEDLEY_CONCAT_EX
24647#undef JSON_HEDLEY_CONST
24648#undef JSON_HEDLEY_CONSTEXPR
24649#undef JSON_HEDLEY_CONST_CAST
24650#undef JSON_HEDLEY_CPP_CAST
24651#undef JSON_HEDLEY_CRAY_VERSION
24652#undef JSON_HEDLEY_CRAY_VERSION_CHECK
24653#undef JSON_HEDLEY_C_DECL
24654#undef JSON_HEDLEY_DEPRECATED
24655#undef JSON_HEDLEY_DEPRECATED_FOR
24656#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
24657#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
24658#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
24659#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
24660#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
24661#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
24662#undef JSON_HEDLEY_DIAGNOSTIC_POP
24663#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
24664#undef JSON_HEDLEY_DMC_VERSION
24665#undef JSON_HEDLEY_DMC_VERSION_CHECK
24666#undef JSON_HEDLEY_EMPTY_BASES
24667#undef JSON_HEDLEY_EMSCRIPTEN_VERSION
24668#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
24669#undef JSON_HEDLEY_END_C_DECLS
24670#undef JSON_HEDLEY_FLAGS
24671#undef JSON_HEDLEY_FLAGS_CAST
24672#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
24673#undef JSON_HEDLEY_GCC_HAS_BUILTIN
24674#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
24675#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
24676#undef JSON_HEDLEY_GCC_HAS_EXTENSION
24677#undef JSON_HEDLEY_GCC_HAS_FEATURE
24678#undef JSON_HEDLEY_GCC_HAS_WARNING
24679#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
24680#undef JSON_HEDLEY_GCC_VERSION
24681#undef JSON_HEDLEY_GCC_VERSION_CHECK
24682#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
24683#undef JSON_HEDLEY_GNUC_HAS_BUILTIN
24684#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
24685#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
24686#undef JSON_HEDLEY_GNUC_HAS_EXTENSION
24687#undef JSON_HEDLEY_GNUC_HAS_FEATURE
24688#undef JSON_HEDLEY_GNUC_HAS_WARNING
24689#undef JSON_HEDLEY_GNUC_VERSION
24690#undef JSON_HEDLEY_GNUC_VERSION_CHECK
24691#undef JSON_HEDLEY_HAS_ATTRIBUTE
24692#undef JSON_HEDLEY_HAS_BUILTIN
24693#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
24694#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
24695#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
24696#undef JSON_HEDLEY_HAS_EXTENSION
24697#undef JSON_HEDLEY_HAS_FEATURE
24698#undef JSON_HEDLEY_HAS_WARNING
24699#undef JSON_HEDLEY_IAR_VERSION
24700#undef JSON_HEDLEY_IAR_VERSION_CHECK
24701#undef JSON_HEDLEY_IBM_VERSION
24702#undef JSON_HEDLEY_IBM_VERSION_CHECK
24703#undef JSON_HEDLEY_IMPORT
24704#undef JSON_HEDLEY_INLINE
24705#undef JSON_HEDLEY_INTEL_CL_VERSION
24706#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
24707#undef JSON_HEDLEY_INTEL_VERSION
24708#undef JSON_HEDLEY_INTEL_VERSION_CHECK
24709#undef JSON_HEDLEY_IS_CONSTANT
24710#undef JSON_HEDLEY_IS_CONSTEXPR_
24711#undef JSON_HEDLEY_LIKELY
24712#undef JSON_HEDLEY_MALLOC
24713#undef JSON_HEDLEY_MCST_LCC_VERSION
24714#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
24715#undef JSON_HEDLEY_MESSAGE
24716#undef JSON_HEDLEY_MSVC_VERSION
24717#undef JSON_HEDLEY_MSVC_VERSION_CHECK
24718#undef JSON_HEDLEY_NEVER_INLINE
24719#undef JSON_HEDLEY_NON_NULL
24720#undef JSON_HEDLEY_NO_ESCAPE
24721#undef JSON_HEDLEY_NO_RETURN
24722#undef JSON_HEDLEY_NO_THROW
24723#undef JSON_HEDLEY_NULL
24724#undef JSON_HEDLEY_PELLES_VERSION
24725#undef JSON_HEDLEY_PELLES_VERSION_CHECK
24726#undef JSON_HEDLEY_PGI_VERSION
24727#undef JSON_HEDLEY_PGI_VERSION_CHECK
24728#undef JSON_HEDLEY_PREDICT
24729#undef JSON_HEDLEY_PRINTF_FORMAT
24730#undef JSON_HEDLEY_PRIVATE
24731#undef JSON_HEDLEY_PUBLIC
24732#undef JSON_HEDLEY_PURE
24733#undef JSON_HEDLEY_REINTERPRET_CAST
24734#undef JSON_HEDLEY_REQUIRE
24735#undef JSON_HEDLEY_REQUIRE_CONSTEXPR
24736#undef JSON_HEDLEY_REQUIRE_MSG
24737#undef JSON_HEDLEY_RESTRICT
24738#undef JSON_HEDLEY_RETURNS_NON_NULL
24739#undef JSON_HEDLEY_SENTINEL
24740#undef JSON_HEDLEY_STATIC_ASSERT
24741#undef JSON_HEDLEY_STATIC_CAST
24742#undef JSON_HEDLEY_STRINGIFY
24743#undef JSON_HEDLEY_STRINGIFY_EX
24744#undef JSON_HEDLEY_SUNPRO_VERSION
24745#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
24746#undef JSON_HEDLEY_TINYC_VERSION
24747#undef JSON_HEDLEY_TINYC_VERSION_CHECK
24748#undef JSON_HEDLEY_TI_ARMCL_VERSION
24749#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
24750#undef JSON_HEDLEY_TI_CL2000_VERSION
24751#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
24752#undef JSON_HEDLEY_TI_CL430_VERSION
24753#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
24754#undef JSON_HEDLEY_TI_CL6X_VERSION
24755#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
24756#undef JSON_HEDLEY_TI_CL7X_VERSION
24757#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
24758#undef JSON_HEDLEY_TI_CLPRU_VERSION
24759#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
24760#undef JSON_HEDLEY_TI_VERSION
24761#undef JSON_HEDLEY_TI_VERSION_CHECK
24762#undef JSON_HEDLEY_UNAVAILABLE
24763#undef JSON_HEDLEY_UNLIKELY
24764#undef JSON_HEDLEY_UNPREDICTABLE
24765#undef JSON_HEDLEY_UNREACHABLE
24766#undef JSON_HEDLEY_UNREACHABLE_RETURN
24767#undef JSON_HEDLEY_VERSION
24768#undef JSON_HEDLEY_VERSION_DECODE_MAJOR
24769#undef JSON_HEDLEY_VERSION_DECODE_MINOR
24770#undef JSON_HEDLEY_VERSION_DECODE_REVISION
24771#undef JSON_HEDLEY_VERSION_ENCODE
24772#undef JSON_HEDLEY_WARNING
24773#undef JSON_HEDLEY_WARN_UNUSED_RESULT
24774#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
24775#undef JSON_HEDLEY_FALL_THROUGH
namespace for Niels Lohmann
Definition json.hpp:19415
constexpr bool is_string() const noexcept
return whether value is a string
Definition json.hpp:20687
size_type erase(const typename object_t::key_type &key)
remove element from a JSON object given a key
Definition json.hpp:21920
reference operator[](KeyType &&key)
access specified object element
Definition json.hpp:21488
size_type size() const noexcept
returns the number of elements
Definition json.hpp:22261
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:23694
static std::vector< std::uint8_t > to_bjdata(const basic_json &j, const bool use_size=false, const bool use_type=false)
create a BJData serialization of a given JSON value
Definition json.hpp:23626
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:21060
const_iterator end() const noexcept
returns an iterator to one past the last element
Definition json.hpp:22118
reference back()
access the last element
Definition json.hpp:21724
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:20151
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
Definition json.hpp:22134
basic_json patch(const basic_json &json_patch) const
applies a JSON patch to a copy of the current object
Definition json.hpp:24286
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string
Definition json.hpp:23474
const_reference front() const
access the first element
Definition json.hpp:21717
constexpr bool is_array() const noexcept
return whether value is an array
Definition json.hpp:20680
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:22778
ReturnType value(const json_pointer &ptr, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:21668
size_type count(KeyType &&key) const
returns the number of occurrences of a key in a JSON object
Definition json.hpp:22037
iter_impl< const basic_json > const_iterator
a const iterator for a basic_json container
Definition json.hpp:19546
static void to_bjdata(const basic_json &j, detail::output_adapter< char > o, const bool use_size=false, const bool use_type=false)
create a BJData serialization of a given JSON value
Definition json.hpp:23645
constexpr bool is_number_integer() const noexcept
return whether value is an integer number
Definition json.hpp:20652
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
a const reverse iterator for a basic_json container
Definition json.hpp:19550
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:23889
static void to_bjdata(const basic_json &j, detail::output_adapter< std::uint8_t > o, const bool use_size=false, const bool use_type=false)
create a BJData serialization of a given JSON value
Definition json.hpp:23637
reference operator[](const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.hpp:23934
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
the type of an element const pointer
Definition json.hpp:19541
std::size_t size_type
a type to represent container sizes
Definition json.hpp:19533
constexpr bool is_structured() const noexcept
return whether type is structured
Definition json.hpp:20624
const_reference operator[](KeyType &&key) const
access specified object element
Definition json.hpp:21512
void swap(binary_t &other)
exchanges the values
Definition json.hpp:22855
ReferenceType get_ref()
get a reference value (implicit)
Definition json.hpp:21150
size_type max_size() const noexcept
returns the maximum possible number of elements
Definition json.hpp:22300
void update(const_reference j, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
Definition json.hpp:22724
ReferenceType get_ref() const
get a reference value (implicit)
Definition json.hpp:21161
constexpr bool is_discarded() const noexcept
return whether value is discarded
Definition json.hpp:20701
reference operator+=(initializer_list_t init)
add an object to an object
Definition json.hpp:22516
void push_back(basic_json &&val)
add an object to an array
Definition json.hpp:22404
const_reference operator[](const typename object_t::key_type &key) const
access specified object element
Definition json.hpp:21457
iteration_proxy< const_iterator > items() const noexcept
helper to access iterator member functions in range-based for
Definition json.hpp:22206
const_reference back() const
access the last element
Definition json.hpp:21733
IteratorType erase(IteratorType first, IteratorType last)
remove elements given an iterator range
Definition json.hpp:21815
reference operator+=(const basic_json &val)
add an object to an array
Definition json.hpp:22461
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:22795
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:23790
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:20288
iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
inserts copies of element into array
Definition json.hpp:22628
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:23874
static allocator_type get_allocator()
returns the allocator associated with the container
Definition json.hpp:19556
nlohmann::byte_container_with_subtype< BinaryType > binary_t
a type for a packed binary type
Definition json.hpp:19681
reference at(KeyType &&key)
access specified object element with bounds checking
Definition json.hpp:21320
iterator end() noexcept
returns an iterator to one past the last element
Definition json.hpp:22109
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
Definition json.hpp:20659
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:22731
static std::vector< std::uint8_t > to_bson(const basic_json &j)
create a BSON serialization of a given JSON value
Definition json.hpp:23653
const_reverse_iterator rbegin() const noexcept
returns an iterator to the reverse-beginning
Definition json.hpp:22141
void push_back(initializer_list_t init)
add an object to an object
Definition json.hpp:22500
detail::parser_callback_t< basic_json > parser_callback_t
per-element parser callback type
Definition json.hpp:20118
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
Definition json.hpp:20329
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:23592
iterator begin() noexcept
returns an iterator to the first element
Definition json.hpp:22084
ReturnType value(const typename object_t::key_type &key, ValueType &&default_value) const
access specified object element with default value
Definition json.hpp:21567
const_iterator cend() const noexcept
returns an iterator to one past the last element
Definition json.hpp:22125
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:23844
const_reference at(const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.hpp:23976
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init)
explicitly create a binary array
Definition json.hpp:20299
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
Definition json.hpp:20139
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:23678
basic_json flatten() const
return flattened JSON value
Definition json.hpp:23990
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:23805
size_type erase(KeyType &&key)
remove element from a JSON object given a key
Definition json.hpp:21931
ArrayType< basic_json, AllocatorType< basic_json > > array_t
a type for an array
Definition json.hpp:19657
ObjectType< StringType, basic_json, default_object_comparator_t, AllocatorType< std::pair< const StringType, basic_json > > > object_t
a type for an object
Definition json.hpp:19649
const binary_t & get_binary() const
get a binary value
Definition json.hpp:21232
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
inserts range of elements into array
Definition json.hpp:22648
void patch_inplace(const basic_json &json_patch)
applies a JSON patch in-place without copying the object
Definition json.hpp:24015
ReturnType value(KeyType &&key, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:21620
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json diff(const basic_json &source, const basic_json &target, const std::string &path="")
creates a diff as a JSON patch
Definition json.hpp:24296
const_reference operator[](const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.hpp:23948
std::initializer_list< detail::json_ref< basic_json > > initializer_list_t
helper type for initializer lists of basic_json values
Definition json.hpp:19490
bool contains(KeyType &&key) const
check the existence of an element in a JSON object
Definition json.hpp:22054
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:23562
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:23669
iterator find(const typename object_t::key_type &key)
find an element in a JSON object
Definition json.hpp:21967
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:20277
const_reference at(KeyType &&key) const
access specified object element with bounds checking
Definition json.hpp:21358
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json meta()
returns version information on the library
Definition json.hpp:19564
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
Definition json.hpp:20336
const_iterator find(const typename object_t::key_type &key) const
find an element in a JSON object
Definition json.hpp:21981
static std::vector< std::uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
Definition json.hpp:23553
IteratorType erase(IteratorType pos)
remove element given an iterator
Definition json.hpp:21745
iterator insert(const_iterator pos, const basic_json &val)
inserts element into array
Definition json.hpp:22601
NumberFloatType number_float_t
a type for a number (floating-point)
Definition json.hpp:19677
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition json.hpp:21542
AllocatorType< basic_json > allocator_type
the allocator type
Definition json.hpp:19536
typename std::allocator_traits< allocator_type >::pointer pointer
the type of an element pointer
Definition json.hpp:19539
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:20588
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
Definition json.hpp:24438
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:21114
reference at(size_type idx)
access specified array element with bounds checking
Definition json.hpp:21254
iterator find(KeyType &&key)
find an element in a JSON object
Definition json.hpp:21997
constexpr bool is_number_float() const noexcept
return whether value is a floating-point number
Definition json.hpp:20666
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
Definition json.hpp:22148
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:23599
reference at(const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.hpp:23962
BooleanType boolean_t
a type for a boolean
Definition json.hpp:19665
std::less< StringType > default_object_comparator_t
default object key comparator type The actual object key comparator type (object_comparator_t) may be...
Definition json.hpp:19644
reference operator+=(const typename object_t::value_type &val)
add an object to an object
Definition json.hpp:22492
const_iterator cbegin() const noexcept
returns a const iterator to the first element
Definition json.hpp:22100
reference operator[](typename object_t::key_type key)
access specified object element
Definition json.hpp:21435
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:20872
~basic_json() noexcept
destructor
Definition json.hpp:20570
const_reverse_iterator crend() const noexcept
returns a const reverse iterator to one before the first
Definition json.hpp:22169
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:20218
void swap(typename binary_t::container_type &other)
exchanges the values
Definition json.hpp:22871
binary_t & get_binary()
get a binary value
Definition json.hpp:21220
const_iterator begin() const noexcept
returns an iterator to the first element
Definition json.hpp:22093
constexpr bool is_number() const noexcept
return whether value is a number
Definition json.hpp:20645
void insert(const_iterator first, const_iterator last)
inserts range of elements into object
Definition json.hpp:22699
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:23736
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
Definition json.hpp:21101
reference operator[](size_type idx)
access specified array element
Definition json.hpp:21376
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:20547
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:23618
NumberIntegerType number_integer_t
a type for a number (integer)
Definition json.hpp:19669
auto get_ptr() noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition json.hpp:20861
const_reference at(const typename object_t::key_type &key) const
access specified object element with bounds checking
Definition json.hpp:21338
constexpr bool is_binary() const noexcept
return whether value is a binary array
Definition json.hpp:20694
void swap(object_t &other)
exchanges the values
Definition json.hpp:22823
basic_json unflatten() const
unflatten a previously flattened JSON value
Definition json.hpp:23999
iterator insert(const_iterator pos, initializer_list_t ilist)
inserts elements from initializer list into array
Definition json.hpp:22679
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:20310
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
Definition json.hpp:22199
bool empty() const noexcept
checks whether the container is empty.
Definition json.hpp:22222
void swap(array_t &other)
exchanges the values
Definition json.hpp:22807
void erase(const size_type idx)
remove element from a JSON array given an index
Definition json.hpp:21938
reference operator+=(basic_json &&val)
add an object to an array
Definition json.hpp:22429
bool contains(const json_pointer &ptr) const
check the existence of an element in a JSON object given a JSON pointer
Definition json.hpp:22061
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition json.hpp:20610
reference emplace_back(Args &&... args)
add an object to an array
Definition json.hpp:22525
ValueType value(const json_pointer &ptr, const ValueType &default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:21643
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
Definition json.hpp:20321
StringType string_t
a type for a string
Definition json.hpp:19661
void push_back(const basic_json &val)
add an object to an array
Definition json.hpp:22437
ValueType value(KeyType &&key, const ValueType &default_value) const
access specified object element with default value
Definition json.hpp:21593
reference at(const typename object_t::key_type &key)
access specified object element with bounds checking
Definition json.hpp:21300
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:23859
json_value m_value
the value of the current element
Definition json.hpp:23511
const_reverse_iterator crbegin() const noexcept
returns a const reverse iterator to the last element
Definition json.hpp:22162
constexpr bool is_boolean() const noexcept
return whether value is a boolean
Definition json.hpp:20638
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:22027
reference front()
access the first element
Definition json.hpp:21710
constexpr bool is_primitive() const noexcept
return whether type is primitive
Definition json.hpp:20617
constexpr bool is_null() const noexcept
return whether value is null
Definition json.hpp:20631
void clear() noexcept
clears the contents
Definition json.hpp:22343
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:23610
basic_json(basic_json &&other) noexcept
move constructor
Definition json.hpp:20530
iter_impl< basic_json > iterator
an iterator for a basic_json container
Definition json.hpp:19544
basic_json(const value_t v)
create an empty value with a given type
Definition json.hpp:20131
const_reference operator[](size_type idx) const
access specified array element
Definition json.hpp:21422
std::ptrdiff_t difference_type
a type to represent differences between iterators
Definition json.hpp:19531
iterator insert(const_iterator pos, basic_json &&val)
inserts element into array
Definition json.hpp:22621
const_reverse_iterator rend() const noexcept
returns an iterator to the reverse-end
Definition json.hpp:22155
NumberUnsignedType number_unsigned_t
a type for a number (unsigned)
Definition json.hpp:19673
friend std::istream & operator>>(std::istream &i, basic_json &j)
deserialize from stream
Definition json.hpp:23459
static std::vector< std::uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
Definition json.hpp:23576
void swap(string_t &other)
exchanges the values
Definition json.hpp:22839
basic_json(const BasicJsonType &val)
create a JSON value from an existing one
Definition json.hpp:20165
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
a reverse iterator for a basic_json container
Definition json.hpp:19548
const_reference at(size_type idx) const
access specified array element with bounds checking
Definition json.hpp:21277
detail::actual_object_comparator_t< basic_json > object_comparator_t
object key comparator type
Definition json.hpp:19685
basic_json(const basic_json &other)
copy constructor
Definition json.hpp:20461
void push_back(const typename object_t::value_type &val)
add an object to an object
Definition json.hpp:22469
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
Definition json.hpp:22550
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:23569
constexpr bool is_object() const noexcept
return whether value is an object
Definition json.hpp:20673
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:23585
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:23751
iterator insert_iterator(const_iterator pos, Args &&... args)
Definition json.hpp:22582
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
Definition json.hpp:20348
bool contains(const typename object_t::key_type &key) const
check the existence of an element in a JSON object
Definition json.hpp:22045
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:23662
const_iterator find(KeyType &&key) const
find an element in a JSON object
Definition json.hpp:22013
::nlohmann::json_pointer< StringType > json_pointer
JSON Pointer, see nlohmann::json_pointer.
Definition json.hpp:19482
an internal type for a backed binary type
Definition json.hpp:5905
byte_container_with_subtype() noexcept(noexcept(container_type()))
Definition json.hpp:5911
byte_container_with_subtype(container_type &&b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))
Definition json.hpp:5933
byte_container_with_subtype(container_type &&b) noexcept(noexcept(container_type(std::move(b))))
Definition json.hpp:5921
constexpr subtype_type subtype() const noexcept
return the binary subtype
Definition json.hpp:5960
byte_container_with_subtype(const container_type &b, subtype_type subtype_) noexcept(noexcept(container_type(b)))
Definition json.hpp:5926
constexpr bool has_subtype() const noexcept
return whether the value has a subtype
Definition json.hpp:5967
byte_container_with_subtype(const container_type &b) noexcept(noexcept(container_type(b)))
Definition json.hpp:5916
void set_subtype(subtype_type subtype_) noexcept
sets the binary subtype
Definition json.hpp:5952
void clear_subtype() noexcept
clears the binary subtype
Definition json.hpp:5974
deserialization of CBOR, MessagePack, and UBJSON values
Definition json.hpp:9226
binary_reader(InputAdapterType &&adapter, const input_format_t format=input_format_t::json) noexcept
create a binary reader
Definition json.hpp:9242
bool sax_parse(const input_format_t format, json_sax_t *sax_, const bool strict=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
Definition json.hpp:9263
serialization to CBOR and MessagePack values
Definition json.hpp:15093
void write_bson(const BasicJsonType &j)
Definition json.hpp:15113
binary_writer(output_adapter_t< CharType > adapter)
create a binary writer
Definition json.hpp:15104
void write_ubjson(const BasicJsonType &j, const bool use_count, const bool use_type, const bool add_prefix=true, const bool use_bjdata=false)
Definition json.hpp:15792
void write_msgpack(const BasicJsonType &j)
Definition json.hpp:15466
void write_cbor(const BasicJsonType &j)
Definition json.hpp:15142
general exception of the basic_json class
Definition json.hpp:4386
const int id
the id of the exception
Definition json.hpp:4395
const char * what() const noexcept override
returns the explanatory string
Definition json.hpp:4389
exception indicating errors with iterators
Definition json.hpp:4537
a template for a bidirectional iterator for the basic_json class This class implements a both iterato...
Definition json.hpp:12930
iter_impl operator+(difference_type i) const
add to iterator
Definition json.hpp:13504
iter_impl & operator=(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting assignment
Definition json.hpp:13067
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
Definition json.hpp:13449
iter_impl(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting constructor
Definition json.hpp:13057
bool operator<(const iter_impl &other) const
comparison: smaller
Definition json.hpp:13396
bool operator<=(const iter_impl &other) const
comparison: less than or equal
Definition json.hpp:13431
iter_impl & operator-=(difference_type i)
subtract from iterator
Definition json.hpp:13495
iter_impl & operator--()
pre-decrement (–it)
Definition json.hpp:13310
const object_t::key_type & key() const
return the key of an object iterator
Definition json.hpp:13604
bool operator==(const IterImpl &other) const
comparison: equal
Definition json.hpp:13351
iter_impl operator++(int) &
post-increment (it++)
Definition json.hpp:13248
iter_impl & operator+=(difference_type i)
add to iterator
Definition json.hpp:13458
reference operator[](difference_type n) const
access to successor
Definition json.hpp:13566
typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_pointer, typename BasicJsonType::pointer >::type pointer
defines a pointer to the type iterated over (value_type)
Definition json.hpp:12962
typename BasicJsonType::difference_type difference_type
a type to represent differences between iterators
Definition json.hpp:12960
pointer operator->() const
dereference the iterator
Definition json.hpp:13206
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition json.hpp:13629
difference_type operator-(const iter_impl &other) const
return difference
Definition json.hpp:13537
std::bidirectional_iterator_tag iterator_category
Definition json.hpp:12955
friend iter_impl operator+(difference_type i, const iter_impl &it)
addition of distance and iterator
Definition json.hpp:13515
reference value() const
return the value of an iterator
Definition json.hpp:13620
bool operator>(const iter_impl &other) const
comparison: greater than
Definition json.hpp:13440
iter_impl & operator++()
pre-increment (++it)
Definition json.hpp:13259
typename BasicJsonType::value_type value_type
the type of the values when the iterator is dereferenced
Definition json.hpp:12958
reference operator*() const
return a reference to the value pointed to by the iterator
Definition json.hpp:13162
iter_impl operator-(difference_type i) const
subtract from iterator
Definition json.hpp:13526
typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_reference, typename BasicJsonType::reference >::type reference
defines a reference to the type iterated over (value_type)
Definition json.hpp:12966
iter_impl & operator=(const iter_impl< const BasicJsonType > &other) noexcept
converting assignment
Definition json.hpp:13042
bool operator!=(const IterImpl &other) const
comparison: not equal
Definition json.hpp:13387
iter_impl operator--(int) &
post-decrement (it–)
Definition json.hpp:13299
iter_impl(const iter_impl< const BasicJsonType > &other) noexcept
const copy constructor
Definition json.hpp:13032
void set_end() noexcept
set the iterator past the last value
Definition json.hpp:13123
Definition json.hpp:12910
bool operator==(const iteration_proxy_value &o) const
equality operator (needed for InputIterator)
Definition json.hpp:5265
bool operator!=(const iteration_proxy_value &o) const
inequality operator (needed for range-based for)
Definition json.hpp:5271
iteration_proxy_value & operator++()
increment operator (needed for range-based for)
Definition json.hpp:5248
IteratorType::reference value() const
return value of the iterator
Definition json.hpp:5313
const string_type & key() const
return key of the iterator
Definition json.hpp:5277
proxy class for the items() function
Definition json.hpp:12909
iteration_proxy_value< IteratorType > end() const noexcept
return iterator end (needed for range-based for)
Definition json.hpp:5346
iteration_proxy(typename IteratorType::reference cont) noexcept
construct iteration proxy from a container
Definition json.hpp:5330
Definition json.hpp:14834
a template for a reverse iterator class
Definition json.hpp:13683
json_reverse_iterator operator++(int) &
post-increment (it++)
Definition json.hpp:13699
json_reverse_iterator operator--(int) &
post-decrement (it–)
Definition json.hpp:13711
json_reverse_iterator & operator++()
pre-increment (++it)
Definition json.hpp:13705
json_reverse_iterator & operator+=(difference_type i)
add to iterator
Definition json.hpp:13723
reference operator[](difference_type n) const
access to successor
Definition json.hpp:13747
auto key() const -> decltype(std::declval< Base >().key())
return the key of an object iterator
Definition json.hpp:13753
difference_type operator-(const json_reverse_iterator &other) const
return difference
Definition json.hpp:13741
typename Base::reference reference
the reference type for the pointed-to element
Definition json.hpp:13689
reference value() const
return the value of an iterator
Definition json.hpp:13760
json_reverse_iterator(const base_iterator &it) noexcept
create reverse iterator from base class
Definition json.hpp:13696
json_reverse_iterator & operator--()
pre-decrement (–it)
Definition json.hpp:13717
std::reverse_iterator< Base > base_iterator
shortcut to the reverse iterator adapter
Definition json.hpp:13687
json_reverse_iterator operator-(difference_type i) const
subtract from iterator
Definition json.hpp:13735
json_reverse_iterator(const typename base_iterator::iterator_type &it) noexcept
create reverse iterator from iterator
Definition json.hpp:13692
json_reverse_iterator operator+(difference_type i) const
add to iterator
Definition json.hpp:13729
SAX implementation to create a JSON value from SAX events.
Definition json.hpp:6814
json_sax_dom_parser(BasicJsonType &r, const bool allow_exceptions_=true)
Definition json.hpp:6827
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:7448
token_type
token types for the parser
Definition json.hpp:7425
lexical analysis
Definition json.hpp:7498
bool skip_bom()
skip the UTF-8 byte order mark
Definition json.hpp:8872
JSON_HEDLEY_RETURNS_NON_NULL constexpr const char * get_error_message() const noexcept
return syntax error message
Definition json.hpp:8859
std::string get_token_string() const
Definition json.hpp:8834
constexpr number_integer_t get_number_integer() const noexcept
return integer value
Definition json.hpp:8798
constexpr position_t get_position() const noexcept
return position of last read token
Definition json.hpp:8826
constexpr number_unsigned_t get_number_unsigned() const noexcept
return unsigned integer value
Definition json.hpp:8804
string_t & get_string()
return current string value (implicitly resets the token; useful only once)
Definition json.hpp:8816
constexpr number_float_t get_number_float() const noexcept
return floating-point value
Definition json.hpp:8810
exception indicating other library errors
Definition json.hpp:4589
exception indicating access out of the defined range
Definition json.hpp:4572
Definition json.hpp:15051
output adapter for output streams
Definition json.hpp:15003
output adapter for basic_string
Definition json.hpp:15028
output adapter for byte vectors
Definition json.hpp:14978
exception indicating a parse error
Definition json.hpp:4484
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:4496
const std::size_t byte
byte index of the parse error
Definition json.hpp:4521
syntax analysis
Definition json.hpp:12243
parser(InputAdapterType &&adapter, const parser_callback_t< BasicJsonType > cb=nullptr, const bool allow_exceptions_=true, const bool skip_comments=false)
a parser reading from an input adapter
Definition json.hpp:12253
void parse(const bool strict, BasicJsonType &result)
public parser interface
Definition json.hpp:12275
bool accept(const bool strict=true)
public accept interface
Definition json.hpp:12335
Definition json.hpp:12747
constexpr bool is_begin() const noexcept
return whether the iterator can be dereferenced
Definition json.hpp:12776
void set_end() noexcept
set iterator to a defined past the end
Definition json.hpp:12770
constexpr bool is_end() const noexcept
return whether the iterator is at end
Definition json.hpp:12782
void set_begin() noexcept
set iterator to a defined beginning
Definition json.hpp:12764
Definition json.hpp:18074
serializer(output_adapter_t< char > s, const char ichar, error_handler_t error_handler_=error_handler_t::strict)
Definition json.hpp:18089
const error_handler_t error_handler
error_handler how to react on decoding errors
Definition json.hpp:19006
string_t indent_string
the indentation string
Definition json.hpp:19003
const char indent_char
the indentation character
Definition json.hpp:19001
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:18129
exception indicating executing a member function with a wrong type
Definition json.hpp:4555
JSON Pointer defines a string syntax for identifying a specific value within a JSON document.
Definition json.hpp:13855
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:13950
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:13957
json_pointer(const string_t &s="")
create JSON pointer
Definition json.hpp:13881
bool empty() const noexcept
return whether pointer points to the root document
Definition json.hpp:14016
void pop_back()
remove last reference token
Definition json.hpp:13978
string_t to_string() const
return a string representation of the JSON pointer
Definition json.hpp:13887
json_pointer & operator/=(std::size_t array_idx)
append an array index at the end of this JSON pointer
Definition json.hpp:13935
void push_back(string_t &&token)
append an unescaped token at the end of the reference pointer
Definition json.hpp:14009
json_pointer & operator/=(const json_pointer &ptr)
append another JSON pointer at the end of this JSON pointer
Definition json.hpp:13917
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:13942
json_pointer parent_pointer() const
returns the parent of this JSON pointer
Definition json.hpp:13964
json_pointer & operator/=(string_t token)
append an unescaped reference token at the end of this JSON pointer
Definition json.hpp:13927
const string_t & back() const
return last reference token
Definition json.hpp:13990
friend std::ostream & operator<<(std::ostream &o, const json_pointer &ptr)
write string representation of the JSON pointer to stream
Definition json.hpp:13908
void push_back(const string_t &token)
append an unescaped token at the end of the reference pointer
Definition json.hpp:14002
int find_largest_pow10(const std::uint32_t n, std::uint32_t &pow10)
Definition json.hpp:17413
cached_power get_cached_power_for_binary_exponent(int e)
Definition json.hpp:17249
boundaries compute_boundaries(FloatType value)
Definition json.hpp:17110
void grisu2(char *buf, int &len, int &decimal_exponent, diyfp m_minus, diyfp v, diyfp m_plus)
Definition json.hpp:17749
void grisu2_digit_gen(char *buffer, int &length, int &decimal_exponent, diyfp M_minus, diyfp w, diyfp M_plus)
Definition json.hpp:17508
JSON_HEDLEY_RETURNS_NON_NULL char * append_exponent(char *buf, int e)
appends a decimal representation of e to buf
Definition json.hpp:17849
detail namespace with internal helper functions
Definition json.hpp:263
input_format_t
the supported input formats
Definition json.hpp:6190
parse_event_t
Definition json.hpp:12217
@ 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.hpp:14973
void replace_substring(StringType &s, const StringType &f, const StringType &t)
replace all occurrences of a substring by another string
Definition json.hpp:2985
cbor_tag_handler_t
how to treat CBOR tags
Definition json.hpp:9199
@ store
store tags as binary type
@ error
throw a parse_error exception in case of a tag
value_t
the JSON type enumeration
Definition json.hpp:2887
@ 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.hpp:6036
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
Definition json.hpp:2916
error_handler_t
how to treat decoding errors
Definition json.hpp:18066
@ strict
throw a type_error exception in case of invalid UTF-8
@ replace
replace invalid UTF-8 sequences with U+FFFD
StringType escape(StringType s)
string escaping as described in RFC 6901 (Sect. 4)
Definition json.hpp:3004
namespace for Niels Lohmann
Definition json.hpp:5847
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:5871
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:5861
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:5851
Definition json.hpp:17097
Definition json.hpp:17236
Definition json.hpp:16979
static diyfp mul(const diyfp &x, const diyfp &y) noexcept
returns x * y
Definition json.hpp:17003
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:17085
static diyfp normalize(diyfp x) noexcept
normalize x such that the significand is >= 2^(q-1)
Definition json.hpp:17068
static diyfp sub(const diyfp &x, const diyfp &y) noexcept
returns x - y
Definition json.hpp:16991
an iterator value
Definition json.hpp:12863
Default base class of the basic_json class.
Definition json.hpp:13802
abstract output adapter interface
Definition json.hpp:14959
struct to capture the start position of the current token
Definition json.hpp:3050
std::size_t chars_read_current_line
the number of characters read in the current line
Definition json.hpp:3054
std::size_t lines_read
the number of lines read
Definition json.hpp:3056
std::size_t chars_read_total
the total number of characters read
Definition json.hpp:3052
SAX interface.
Definition json.hpp:6684
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:19048
bool operator()(::nlohmann::detail::value_t lhs, ::nlohmann::detail::value_t rhs) const noexcept
compare two value_t enum values
Definition json.hpp:24534